perfectInfo_frm.html 13.9 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>设备列表窗口</title>
    <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/api.css"/>
    <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/home.css"/>
    <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/element.css"/>
    <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/style.css"/>
    <style>
        html,
        body{
          background-color: #F4F6F9;
        }
    </style>
</head>
<body>
  <div id="app">
    <template>
    <div class="perfect-header-area">
      <div class="perfect-header-area-inside">
        <el-row>
          <el-col :span=5>
            <div style="border:1px solid rgba(174,184,206,1);">
              <img :src="productInfos.pic_url" />
            </div>
          </el-col>
          <el-col :span=18 :offset="1">
            <div class="perfect-header-title">
              <p class="hidden-font-one-line">设备类型: <span style="font-weight: bold;">{{ productInfos.name }} {{ productInfos.remark }}</span></p>
              <p class="hidden-font-one-line">设备编号: <span style="font-weight: bold;">{{ imei }}</span></p>
            </div>
          </el-col>          
        </el-row>  
      </div>
    </div>
    <div class="info-panel">
      <div class="info-inside-panel">
        <div class="aui-row aui-row-flex padding-top-21">
          <div class="aui-col aui-col-span-9 aui-row-flex-start">
            <span class="measure-obj">设备名称</span>
          </div>
          <div class="aui-col aui-col-span-15 aui-row-flex-end">
            <input v-model="formData.storeName" id="device_name" class="aui-input" placeholder="设备名不可超过12个字符" type="text" maxlength="12" style="height:1.26rem;text-align:right;font-weight:500;color:rgba(174,184,206,1);font-size:14px;" >
          </div>
        </div>
        <div class="panel-line margin-top-21"></div>
        <div v-if="!formData.firstAdd">
          <div class="aui-row aui-row-flex padding-top-21">
            <div class="aui-col aui-col-span-9 aui-row-flex-start">
              <span class="measure-obj">输入设备密码</span>
            </div>
            <div class="aui-col aui-col-span-15 aui-row-flex-end">
              <input id="normal_pwd" class="aui-input" placeholder="请输入6位数字设备密码" type="tel" style="-webkit-text-security:disc;height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
            </div>
          </div>
          <div class="panel-line margin-top-21"></div>
        </div>
        <div v-if="formData.firstAdd">
          <div class="aui-row aui-row-flex padding-top-21">
            <div class="aui-col aui-col-span-9 aui-row-flex-start">
              <span class="measure-obj">设置设备密码</span>
            </div>
            <div class="aui-col aui-col-span-15 aui-row-flex-end">
              <input id="device_pwd" class="aui-input" placeholder="请设置6位数字设备密码" type="tel" maxlength="6"  style="-webkit-text-security:disc;height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
            </div>
          </div>
          <div class="panel-line margin-top-21"></div>
        </div>
        <div v-if="formData.firstAdd">
          <div class="aui-row aui-row-flex padding-top-21">
            <div class="aui-col aui-col-span-9 aui-row-flex-start">
              <span class="measure-obj">确认设备密码</span>
            </div>
            <div class="aui-col aui-col-span-15 aui-row-flex-end">
              <input id="pwd_check" class="aui-input" placeholder="请再次确认设备密码" type="tel" maxlength="6" style="-webkit-text-security:disc;height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
            </div>
          </div>
          <div class="panel-line margin-top-21"></div>
        </div>
        <div class="aui-row aui-row-flex">
          <div class="aui-col aui-col-span-8 aui-row-flex-start  padding-top-21">
            <span class="measure-obj">设备所在地址</span>
          </div>
          <div class="aui-col aui-col-span-14 aui-row-flex-end padding-top-21" style="height:auto;vertical-align:middle;" tapmode @click="chooseLocationType">
            <span class="num-value" id="device_position">请添加设备所在位置</span>
          </div>
          <div class="aui-col aui-col-span-2 aui-row-flex-end  padding-top-21" tapmode @click="chooseLocationType">
            <i class="aui-iconfont aui-icon-right" style="color:#5B7FF8;font-size:16px;margin-top:-0.1rem;"></i>
          </div>
        </div>
        <div class="panel-line margin-top-21"></div>
        <div class="aui-row aui-row-flex padding-top-21">
          <div class="aui-col aui-col-span-7 aui-row-flex-start">
            <span class="measure-obj">完善详细地址</span>
          </div>
          <div class="aui-col aui-col-span-17 aui-row-flex-end">
            <input v-model="formData.address" id="detail_address" class="aui-input" placeholder="请输入详细地址" type="text" maxlength="15" style="height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
          </div>
        </div>
        <div class="panel-line margin-top-21"></div>
      </div>
    </div>
    <div class="confirm-btn" tapmode @click="handleAddDevice">确认</div>
  </template> 
  </div>
</body>
<script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/api.js"></script>
<script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/vue.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/element.js"></script>
<script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/addr.js"></script>
<script type="text/javascript" src="../../script/ctrl.js"></script>
<script type="text/javascript">
    var vm;
        // selectedAddress
    var locationInfos = {
      province: "",
      city: "",
      address: "",
    }
    apiready = function(){
      api.parseTapmode();
      var UIActionSelector = api.require('UIActionSelector');
      // var bmap = api.require('bMap');

      // api.addEventListener({
      //     name: 'changeDeviceLocation'
      // }, function(ret, err){
      //     if( ret ){
      //       if (ret.value.info) {
      //         $api.html($api.byId('device_position'), ret.value.info.address);
      //         selectedAddress = ret.value.info
      //         bindDeviceInfo();
      //       }
      //     }
      // });

      //---------初始化vue
      vm = new Vue({
        el: '#app',
        data: {
          imei: api.pageParam.imei,
          productInfos: api.pageParam.productInfos,
          userId: api.getPrefs({sync: true,key: 'userID'}),
          token: api.getPrefs({sync: true,key: 'userToken'}),
          userName: api.getPrefs({sync: true,key: 'userName'}),
          formData: {
            password: "",
            firstAdd: false,
            storeName: "",
            address: "", //详细地址
          }
        },
        created() {
          this.checkIsFirstAdd();
        },
        mounted() {
          // window.bindDeviceInfo = this.bindDeviceInfo;
        },  
        methods: {
          async checkIsFirstAdd() {
            let res_ = await get_check_is_first_add(this.imei, this.token)
            if (res_ && res_.data > 0) {
              this.formData.firstAdd = false
            }else {
              this.formData.firstAdd = true
            }
          },
          chooseLocationType() {
            // api.showProgress({
            //     style: 'default',
            //     animationType: 'fade',
            //     title: '加载中...',
            //     text: '',
            //     modal: false
            // });
            // api.getLocation(function(ret, err) {
            //   api.hideProgress();
            //   if (ret && ret.status) {
            //     console.log('1111');
            //     api.openWin({
            //       name: 'map_win',
            //       url: './map_win.html',
            //       slidBackEnabled: false,
            //     });
            //   } else {
            //     console.log('2222');
            //     reqPermission('location')
            //   }
				    // });
            UIActionSelector.open({
                datas: subjson,
                layout: {
                    row: 5,
                    col: 2,
                    height: 30,
                    size: 12,
                    sizeActive: 14,
                    rowSpacing: 5,
                    colSpacing: 10,
                    maskBg: 'rgba(0,0,0,0.2)',
                    bg: '#fff',
                    color: '#888',
                    colorActive: '#f00',
                    colorSelected: '#f00'
                },
                animation: true,
                cancel: {
                    text: '取消',
                    size: 12,
                    w: 90,
                    h: 35,
                    bg: '#fff',
                    bgActive: '#ccc',
                    color: '#888',
                    colorActive: '#fff'
                },
                ok: {
                    text: '确定',
                    size: 12,
                    w: 90,
                    h: 35,
                    bg: '#fff',
                    bgActive: '#ccc',
                    color: '#888',
                    colorActive: '#fff'
                },
                title: {
                    text: '选择所属城市',
                    size: 12,
                    h: 44,
                    bg: '#eee',
                    color: '#888'
                },
                // fixedOn: api.frameName
            }, function(ret, err) {
                if (ret && ret['eventType'] == "ok") {
                  locationInfos.province = ret['level1'];
                  locationInfos.city = ret['level2'];
                  $api.html($api.byId('device_position'), ret['level1'] + " " + ret['level2']);
                }
            });
          },
          async handleAddDevice() { 
            if (locationInfos.city != "") {
              this.formData.province = locationInfos.province
              this.formData.city = locationInfos.city
            }else {
              api.alert({
                title: '提示', 
                msg: '请定位设备当前位置!'
              });
              return;
            }
            if (this.formData.storeName == "") {
              api.toast({ msg: "设备名称不可为空"});
              return;
            }
            if (this.formData.province == "") {
              api.toast({ msg: "设备所在省份不可为空"});
              return;
            }
            if (this.formData.city == "") {
              api.toast({ msg: "设备所在城市不可为空"});
              return;
            }
            if (this.formData.address == "") {
              api.toast({ msg: "详细地址不可为空"});
              return;
            }
            if (this.formData.firstAdd) {
              var setInput = $api.val($api.byId('device_pwd'));
              var checkInput = $api.val($api.byId('pwd_check'));
              if (setInput == '') {
                api.toast({ msg: "设置密码不可为空"});
                return;
              }
              if (checkInput == '' || setInput != checkInput) {
                api.toast({ msg: "两次密码不一致"});
                return;
              }
              this.formData.password = setInput
            }else {
              var normalInput = $api.val($api.byId('normal_pwd'));
              if (normalInput == '') {
                api.toast({ msg: "密码不可为空"});
                return;
              }
              this.formData.password = normalInput
            }
            var params = {
              qrstr: this.imei,
              user_id: this.userId,
              username: this.userName,
              province: this.formData.province,
              city: this.formData.city,
              address: this.formData.address,
              password: this.formData.password,
              first_add: this.formData.firstAdd,
              store_name: this.formData.storeName
            }
            let bind_result = await post_user_bind_device(params, this.token)
            if (bind_result.code === 0) {
              //添加新设备同步推送
              var ajpush = api.require('ajpush');
              initAndListenPush(ajpush, false);
              api.sendEvent({
                  name: 'change_device'
              });//更新报警数量标记
              alert("绑定成功!");   
              api.sendEvent({
                  name: 'closeAddDevicePage',
              });                         
            }else {
              api.toast({
                msg: "绑定失败," + ajaxCodeCheck(bind_result.code, bind_result.msg, '请重试!')
              });
            }
            //接口!!
          }
        }
      })

      // function bindDeviceInfo() {
      //   bmap.getNameFromCoords({
      //       lon: selectedAddress.extra_lon,
      //       lat: selectedAddress.extra_lat
      //   }, function(rett, err) {
      //       if (rett.status) {
      //         let info_ = {
      //           "province": rett.province,
      //           "city": rett.city,
      //           "address": rett.address
      //         }
      //         locationInfos = info_
      //         console.log(JSON.stringify(locationInfos));
              
      //       }
      //   });
        
      // }
    };
</script>
</html>