operateFun.html 11.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">
      <meta name="referrer" content="no-referrer">
      <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: #FFFFFF;
        }
      </style>
  </head>
  <body>
    <div id="app">
      <template>
        <div class="operate-and-alert-area-inside">
          <span class="operate-and-alert-title">{{ operateTitle }}</span>
          <div class="normal-line-s"></div>
        </div>
        <div class="operation-menu-list" >
          <el-row>
            <div v-for="(list_d, list_i) in operateList1">
              <el-col :span=12 style="margin-top: 10px;">
                <div class="operation-panel" style="margin-right:5px;height: 110px;">
                  <div style="margin-left:15px;margin-right:15px;margin-bottom:10px;">
                    <div class="aui-row aui-row-flex">
                      <div class="aui-col aui-col-span-24 aui-row-flex-start" style="margin-top:12.5px;margin-bottom:10px;">
                        <img :src="list_d.url" style="height:44px;width:44px;margin: 0 auto;">
                      </div>
                      <div class="aui-col aui-col-span-24">
                        <div class="operation-btn" style="width: 3.5rem;margin: 0 auto;" :id="'btn_'+ (list_i+1)" tapmode @click="deviceOperation(list_i+1, list_d.name ,'ctr', list_d.command);"><span :id="'loading'+ (list_i+1)" style="text-align: center;"> {{ list_d.name }}</span></div>
                      </div>
                    </div>
                  </div>
                </div>
              </el-col>  
            </div>
          </el-row>
        </div>
        <div class="operate-and-alert-area-inside">
          <span class="operate-and-alert-title">{{ alertStatus }}</span>
          <div class="normal-line-s"></div>
          <div v-if="alertList.length > 0" class="operate-and-alert-alert-lists" v-for="(list_d, list_i) in alertList">
            <p class="operate-and-alert-alert-list">
              <el-row>
                <el-col :span=8 class="operate-and-alert-alert-list-title">
                  {{ list_d.type }}
                </el-col>
                <el-col :span=16 class="operate-and-alert-alert-list-time">
                  {{ list_d.time }}
                </el-col>
              </el-row>
            </p>
          </div>
          <div v-if="alertList.length === 0" class="operate-and-alert-alert-lists" >
            <p style="text-align: center;">暂无报警信息</p>
          </div>
        </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="http://iot.uccc.cc:9090/app/js/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/ctrl.js"></script> -->
  <script type="text/javascript" src="../../../script/common.js"></script>
  <script type="text/javascript" src="../../../script/ctrl.js"></script>

  <script type="text/javascript">
      var vm,
          inputDialogJSON,
          that;
      apiready = function(){
        api.parseTapmode();
        inputDialogJSON = returnInputDialogJSON()
        //---------初始化vue
        vm = new Vue({
          el: '#app',
          data: {
            operateTitle: '远程操作',
            alertStatus: '报警状态',
            operateList1: [
            {
                name: "分闸",
                url: "http://iot.uccc.cc:9090/product/01001/lazha.png",
                command: "OPEN_GATE"
              },
              {
                name: "合闸",
                url: "http://iot.uccc.cc:9090/product/03001/icon_remoteOperation_hz.png",
                command: "CLOSE_GATE"
              },
            ],
            alertList: [],
            userType: Number(api.getPrefs({sync: true,key: 'userType'})),
          },
          mounted() {
            // window.returnInputDialogJSON = this.chooseProduct;
          },
          created() {
            that = this
            this.initAlarm()
          },
          methods: {
            async deviceOperation(index,name,cmd,val) {
              const params = {
                imei: api.pageParam.imei,
                userId: api.pageParam.userId,
                token: api.pageParam.token,
              }
              let infos = await get_device_infos_by_imei(params)
              console.log(JSON.stringify(infos));
              let currentStatus = infos.data.device.store03003.r_switch_status
              if (currentStatus.substring(15,16) == '0' && currentStatus.substring(4,8) == '0000') {
                api.toast({msg: '当前设备为手动分闸!需先手动合闸后再操作!',duration: 2000,location: 'bottom'});
                return;
              }

              let dialogBox = api.require('dialogBox')
              let dom = $api.byId('btn_'+index);
              dialogBox.input(inputDialogJSON, async function(ret) {
                  if (ret.eventType == 'left') {
                      var dialogBox = api.require('dialogBox');
                      dialogBox.close({
                          dialogName: 'input'
                      });
                  }else if (ret.eventType == "right") {
                    if (!api.pageParam.status) {
                      api.toast({msg: '该设备不在线无法操作!',duration: 2000,location: 'bottom'});
                      return;
                    }
                    let deviceInfos = await get_device_infos_by_imei(params)
                    let pass = false
                    if (that.userType === 1) {
                      deviceInfos.data.device.password === ret.text ? pass = true : pass = false
                    }else if (that.userType === 2) {
                      deviceInfos.data.device.password === md5(ret.text) ? pass = true : pass = false
                    }
                    if (pass) {
                      //handle operate...
                      var dialogBox = api.require('dialogBox');
                      dialogBox.close({
                          dialogName: 'input'
                      });
                      var spanDom = $api.byId('loading'+index);
                      $api.html(spanDom, '');
                      $api.addCls(dom, 'store01001-operate-operation-doing');    //缩放效果,改变宽度
                      $api.addCls(dom, 'store01001-operate-not-click');    //不可点击
                      $api.addCls(spanDom, 'aui-loading');  //加gif
                      console.log(JSON.stringify({
                            user_id: api.pageParam.userId,
                            imei: api.pageParam.imei,
                            type: deviceInfos.data.device.storeType.table,
                            command: cmd,
                            control_name: val,
                            
                          }));
                      $.ajax({
                          url: HOST + '/iot_api/v2/app/tyControl',
                          type: 'POST',
                          dataType: 'json',
                          headers:{
                              'Content-Type':'application/json;charset=utf-8',
                              'token': api.pageParam.token
                          },
                          data: JSON.stringify({
                            user_id: api.pageParam.userId,
                            imei: api.pageParam.imei,
                            type: deviceInfos.data.device.storeType.table,
                            command: cmd,
                            control_name: val,
                            
                          }),
                          complete: function() {
                              api.hideProgress();
                          },
                          success: function(ret) {
                            console.log(JSON.stringify(ret));
                            setTimeout(function(){
                              $api.html(spanDom, name);
                              $api.removeCls(dom, 'store01001-operate-operation-doing');
                              $api.removeCls(dom, 'store01001-operate-not-click');
                              $api.removeCls(spanDom, 'aui-loading');
                              if (ret.data.upRet) {
                                let upRet = JSON.parse(ret.data.upRet)
                                if (ret.code == 0 && ret.msg == '操作成功' && upRet.rescode == 200) {
                                api.toast({
                                    msg: '操作' + name + '成功',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                              }else {
                                api.toast({
                                    msg: '操作' + name + '失败',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                              }
                              that.initAlarm()
                              }
                            }, 1000);
                          },
                          error: function() {
                            api.toast({
                                msg: '操作' + name + '失败',
                                duration: 2000,
                                location: 'bottom'
                            });
                          }
                      });
                    }else {
                      api.toast({msg: '设备密码错误!',duration: 2000,location: 'bottom'});
                    }
                  }
              });
              
            },
            async initAlarm() {
              let params = {
                page: 1,
                limit: 20,
                type: 'app',
                status: '未解决',
                keyword: api.pageParam.imei,
                userId: api.getPrefs({sync: true,key: 'userID'}),
              }
              
              let res = await get_warning_list_by_user_id(params, api.pageParam.token)
              let resList = res.data.rows
              
              if (api.pageParam.deviceType === 'TY-610-2P') {
                resList.forEach(d => {
                  let date2 = new Date(d.createdAt);
                  this.alertList.push({
                    type: d.warning[0],
                    time: date2.toLocaleString()
                  })
                });
              }
            }
          }
        })
      };
  </script>
</html>