perfectInfo.html 9.55 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="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>

<body class="perfect-info-view repair-view">
    <div class="aui-content aui-margin-b-15">
        <header class="aui-bar aui-bar-nav" id="header">
            <a class="aui-btn aui-pull-left" tapmode onclick="cancelConfirm();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title">完善设备信息</div>
            <a class="aui-btn aui-pull-right" tapmode onclick="confirmEqu();">添加</a>
        </header>
        <p class="thing-small-title aui-margin-b-10" id="eqNum"><s></s>设备编号:</p>
        <ul>
            <li class="phone-input">
                <label>姓名</label>
                <input id="username" class="aui-pull-right" value="" type="text" />
            </li>
            <li tapmode onclick="choseCity()">
                <label>设备所在地址</label>
                <span class="aui-pull-right" id="addr">所属城市</span>
                <i></i>
            </li>
            <li>
                <label>完善详细地址</label>
                <input id="detail" type="text" placeholder="请填写详细地址" />
            </li>
        </ul>
    </div>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/addr.js"></script>
<script type="text/javascript" src="../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    var header = $api.byId('header');
    var code = "";
    var qtstr = "";
    var chose_pro = "";
    var chose_city = "";
    fixStatusBar_API(header);
    apiready = function() {
        api.setStatusBarStyle({
            style: 'dark',
            color: 'rgba(0,0,0,0)'
        });
        api.parseTapmode();
        var params = api.pageParam;
        code = params.code;
        qtstr = code;
        var token = $api.getStorage('userToken');
        $.ajax({
          url: HOST + '/iot_api/v1/app/get_imei_by_qr?qrstr='+code,
          type: 'GET',
          dataType: 'json',
          headers: {
              'Content-Type': 'application/json;charset=utf-8',
              'token': token
          },
          success: function(ret) {
              if (ret) {
                  if (ret.code == 0) {
                      code = ret.data;
                      $api.html($api.byId("eqNum"), "<s></s>设备编号:"+ code)
                  }else{
                    api.toast({
                        msg: '设备编号不存在,请确认',
                        duration: 2000,
                        location: 'bottom'
                    });
                    setTimeout(function(){
                      api.closeWin();
                      openCanner(api.pageParam.isEmpty);
                    }, 2000);
                  }
              }
          },
          error: function() {
            api.toast({
                msg: '获取设备编号失败,请重试',
                duration: 2000,
                location: 'bottom'
            });
            setTimeout(function(){
              openCanner(api.pageParam.isEmpty);
              api.closeWin();

            },2000);
          }
      });

        var username = $api.getStorage('userName');
        $api.val($api.byId("username"), username);
        // api.openWin({ slidBackEnabled:false,
        //     name: 'index',
        //     url: './html/index.html',
        //     pageParam: {}
        // });
    }

    function choseCity() {
        var UIActionSelector = api.require('UIActionSelector');
        UIActionSelector.open({
            datas: subjson,
            layout: {
                row: 5,
                col: 3,
                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") {
                chose_pro = ret['level1'];
                chose_city = ret['level2'];
                $api.html($api.byId("addr"), ret['level1'] + " " + ret['level2']);
            }
        });

    }
    function cancelConfirm(){
      if(api.pageParam.isEmpty){
        openCanner(api.pageParam.isEmpty);
      }else{
        api.closeWin();

      }
    }

    function login() {
        api.openWin({ slidBackEnabled:false,
            name: 'index',
            url: 'index.html',
            pageParam: {}
        });
    }

    function confirmEqu(){
      if(code==""){
        api.toast({
            msg: '添加设备失败,设备编号不存在',
            duration: 3000,
            location: 'bottom'
        });
        return false;

      }
      if(chose_pro=="" || chose_city==""){
        api.toast({
            msg: '添加设备失败,请选择设备地址',
            duration: 3000,
            location: 'bottom'
        });
        return false;
      }
      var detailAddr = $api.val($api.byId("detail"));
      if(detailAddr==""){
        api.toast({
            msg: '添加设备失败,请填写详细地址',
            duration: 3000,
            location: 'bottom'
        });
        return false;

      }

      api.showProgress({
          style: 'default',
          animationType: 'fade',
          title: '正在绑定中...',
          text: '',
          modal: true
      });
      var token = $api.getStorage('userToken');
      $.ajax({
          url: HOST + '/iot_api/v1/app/bind_device',
          type: 'POST',
          dataType: 'json',
          headers: {
              'Content-Type': 'application/json;charset=utf-8',
              'token': token
          },
          data: JSON.stringify({
              qrstr: qtstr,
              user_id: $api.getStorage('userID'),
              username: $api.getStorage('userName'),
              province: chose_pro,
              city: chose_city,
              address:detailAddr
          }),
          complete: function() {
              api.hideProgress();
          },
          success: function(ret) {
              if (ret) {
                  if (ret.code == 0) {
                      api.toast({
                          msg: '绑定成功!',
                          duration: 4000,
                          location: 'bottom'
                      });

                      //添加新设备同步推送
                      var ajpush = api.require('ajpush');
                      initAndListenPush(ajpush, false);
                      setTimeout(function() {
                        api.openFrame({historyGestureEnabled :false,
                            reload: true,
                            name: 'root',
                            url: 'widget://html/index.html',
                            rect: {
                                x: 0,
                                y: 0,
                                w: 'auto',
                                h: 'auto'
                            }
                        });
                        api.sendEvent({
                            name: 'change_first'
                        });
                        api.sendEvent({
                            name: 'add_device'
                        });
                        var dest = $api.getStorage('defaultDevice');

                        api.sendEvent({
                            name: 'change_device',
                            extra: {
                                imei: dest?dest:code
                            }
                        });

                        api.closeWin({
                            name: 'equipmentList'
                        });
                        api.closeWin({
                            name: 'equipment'
                        });

                        api.closeWin();
                      }, 3000);
                  } else {
                      api.toast({
                          msg: "绑定失败," + ajaxCodeCheck(ret.code, ret.msg, '请重试!')
                      });
                  }
              }
          },
          error: function() {
              api.toast({
                  msg: "绑定失败,请稍候再试"
              });
          }
      });

    }
</script>