safeUser.html 4 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="save-user-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="closeWin()">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title">安全联系人</div>
        </header>
        <ul>
            <li>
                <label>安全联系人</label>
                <span class="aui-pull-right" style="margin-right:0;" id="contact"></span>
            </li>
            <li>
                <label>联系电话</label>
                <span class="aui-pull-right tytx-color-b" style="margin-right:0;" tapmode onclick="openCall();" id="contactNum"></span>
            </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/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    var header = $api.byId('header');
    var contact = '';
    var phone = '';
    var imei = '';
    fixStatusBar_API(header);
    apiready = function() {
        api.setStatusBarStyle({
            style: 'dark',
            color: 'rgba(0,0,0,0)'
        });
        api.parseTapmode();
        imei = $api.getStorage('defaultDevice');
        if(!imei || imei == ''){
          api.toast({
              msg: '设备信息不存在',
              duration: 3000,
              location: 'bottom'
          });
          setTimeout(function(){
            api.closeWin();
          }, 2000)
        }

        var token = $api.getStorage('userToken');

        if(token && token != ''){
          $.ajax({
            url: HOST + '/iot_api/v1/app/get_contact?imei='+imei,
            type: 'GET',
            dataType: 'json',
            headers: {
                'Content-Type': 'application/json;charset=utf-8',
                'token': token
            },
            success: function(ret) {
                if (ret) {
                    if (ret.code == 0) {
                        $api.html($api.byId("contact"), ret.data.name);
                        $api.html($api.byId("contactNum"), ret.data.phone);
                        phone = ret.data.phone;
                    }else{
                      api.toast({
                          msg: '紧急联系人信息获取失败!',
                          duration: 2000,
                          location: 'bottom'
                      });
                      setTimeout(function(){
                        api.closeWin();
                      }, 2000)
                    }
                }else{
                  api.toast({
                      msg: '紧急联系人信息获取失败!',
                      duration: 2000,
                      location: 'bottom'
                  });
                  setTimeout(function(){
                    api.closeWin();
                  }, 2000)
                }
            },
            error: function() {
              api.toast({
                  msg: '紧急联系人信息获取失败!',
                  duration: 2000,
                  location: 'bottom'
              });
              setTimeout(function(){
                api.closeWin();
              }, 2000)
            }
        });
        }
    }
    function openCall(){
      if(phone != ''){
        api.call({
          type: 'tel_prompt',
          number: phone
        })
      }

    }
</script>