detailAlert_frm.html 17.3 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="../../css/style.css"/>

      <style>
          html,
          body{
            background: rgba(0, 0, 0, 0);
          }
      </style>
  </head>
  <body>
    <div id="app" >
        <div class="device-detail-white-area">
          <el-row class="device-alert-title">
            <el-col :span=20>
              <span class="store-name" >设备编号:{{ pageInfos.imei }}</span>
            </el-col>
            <el-col :span=4>
              <div class="device-status-online" v-if="pageInfos.status === true || pageInfos.status === '1'">
                <span>在线</span>
              </div>
              <div class="device-status-offline" v-else>
                <span>离线</span>
              </div>
            </el-col>
          </el-row>

          <div style="background:rgba(247,249,252,1);">
            <el-row class="device-alert-params-area">
              <div v-if="bind_list_data_params.length > 0" class="device-alert-params-inside-area" v-for="(list_d, list_i) in bind_list_data_params">
                <el-col v-if="list_d.name.length <= 5"  :span=10 class="device-alert-params-details">
                  {{ list_d.name }} <span style="color:rgba(51,51,51,1);">{{ list_d.value }}</span>
                </el-col>
                <el-col v-else  :span=22 class="device-alert-params-details">
                  {{ list_d.name }} <span style="color:rgba(51,51,51,1);">{{ list_d.value }}</span>
                </el-col>
                <el-col :span=2>
                  <div v-show="editVisable">
                    <!-- fix bug -->
                    <img :id= "'selectPic_'+list_i" :src="list_d.showPicUrl" class="devie-alert-detail-img" @click="handleIndexParams(list_d.type, list_d.id, list_d.showing, list_i)"/>
                  </div>
                  <!-- <div v-if="!editVisable">&nbsp;</div> -->
                </el-col>
                <!-- <el-col :span=10 class="device-alert-params-details">
                  电流  <span style="color:rgba(51,51,51,1);">12.8A</span>
                </el-col>
                <el-col :span=2>
                  <img src="../../image/icon_unselected_sm.png" class="devie-alert-detail-img" />
                </el-col> -->
              </div>
            </el-row>
            <div class="device-alert-params-line"></div>
            <el-row style="padding-bottom: 10.5px;">
              <el-col :span=18 :offset=2><span v-if="editVisable" tapmode class="device-alert-params-submit-info">勾选需要在首页展示的信息</span>&nbsp;</el-col>
              <el-col :span=4>
                <span v-if="editVisable" class="device-alert-params-submit-text" tapmode @click="editParams(false)">确定</span>
                <span v-else class="device-alert-params-submit-text" tapmode @click="editParams(true)">编辑</span>
              </el-col>
            </el-row>
          </div>
          <div id="device_other_area"></div>
          <div class="login-out-btn detail-alert-botton-text" tapmode @click="showProductPage">查看更多信息</div>
          <!-- <div id="bottom_text" class="detail-alert-botton-text" tapmode @click="showProductPage">查看更多信息→</div> -->
      </div>
    </div>
    <!-- <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/common.js"></script>
    <script type="text/javascript" src="../../script/element.js"></script>
    <script type="text/javascript" src="../../script/ctrl.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js "></script> -->
    <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="../../script/ctrl.js"></script>
    <script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/fastclick.js "></script>
  </body>
  <script type="text/javascript">
      var vm;
      apiready = function(){
        $(function() {
          FastClick.attach(document.body);
        });
        $api.css($api.byId('app'), 'height:'+api.frameHeight+'px;')

        api.parseTapmode();
        //---------初始化vue
        vm = new Vue({
          el: '#app',
          data: {
            pageInfos: {},
            userId: api.getPrefs({sync: true,key: 'userID'}),
            token: api.getPrefs({sync: true,key: 'userToken'}),
            userPreferenceList: [],
            bind_list: {
              user_id: "",
              params: {},
              type: "",
              imei: "",
              limit: 1,
              page: 1,
              dtu_imei: "",
              group_id: "",
            },
            bind_list_data: [],
            bind_list_data_params: [],
            editVisable: false,
            selectedPic: "http://iot.uccc.cc:9090/product/01001/icon_selected_sm.png",
            unselectPic: "http://iot.uccc.cc:9090/product/01001/icon_unselected_sm.png",
            indexParamsTemp: {},
            product_id: "",
            userType: Number(api.getPrefs({sync: true,key: 'userType'})),
          },
          mounted() {
            //window.chooseProduct = this.chooseProduct;
          },
          created() {
            this.pageInfos = api.pageParam.value
            this.initPages()  //一定在initDetailParams执行完毕后执行openOperaterAndAlarm
          },
          methods: {
            initPages() {
              this.initDetailParams().then(val => {
                this.openOperaterAndAlarm()
              })
              //调试
              // setTimeout(() => {
              //   this.showProductPage()
              // }, 2000);
              //-----
            },
            async initDetailParams() {
              var user_perference = await get_product_perference(this.userId)
              // console.log(JSON.stringify(user_perference));
              this.userPreferenceList = user_perference.data
              this.bind_list_data = []

              for (let i = 0; i < this.userPreferenceList.length; i++) {
                const productPref = JSON.parse(this.userPreferenceList[i]);
                const prefList = []
                productPref.data_detail.forEach(d => {
                  prefList.push('"'+d+'"')
                });
                eval('this.bind_list.params["' + productPref.name +'"]=[' + prefList + ']')
              }
              this.bind_list.user_id = this.userId
              this.bind_list.imei = this.pageInfos.imei
              if (this.pageInfos.imei.indexOf("_") != -1) {
                this.bind_list.dtu_imei = this.bind_list.imei.split('_')[0]
              }
              this.bind_list.token = this.token
              let bind_list_data_ = null
              if (this.userType === 1) {
                bind_list_data_ = await get_bind_list_data(this.bind_list)
              }else if(this.userType === 2){
                bind_list_data_ = await get_enterprise_group_store(this.bind_list)
              }
              let props_ = api.getPrefs({sync: true,key: 'props'})
              let props =  eval('(' + props_ + ')');
              list_rows = bind_list_data_.data.list.rows
              // console.log(JSON.stringify(this.bind_list));
              this.product_id = list_rows[0].store.storeType.id

              list_rows.forEach(d => {
                if (d.store.storeType.id === '01001') {

                  let deviceInfos = {
                    pic_url: d.store.storeType.pic_url,
                    imei: d.imei,
                    name: d.store.storeType.name,
                    storename: d.storename,
                    detailParams: [{name: "电流", type: "etc_current", value: d.store.etc_current+"A"},
                                  {name: "剩余电流", type: "etc_rest_current", value: d.store.etc_rest_current+"mA"},
                                  {name: "电压", type: "etc_voltage", value: d.store.etc_voltage+"V"},
                                  {name: "频率", type:"etc_rate", value: d.store.etc_rate+"Hz"},
                                  {name: "线缆温度", type:"etc_line_temp", value: d.store.etc_line_temp+"℃"},
                                  {name: "内部温度", type:"etc_temp1", value: d.store.etc_temp1+"℃"}],
                    status: d.online,
                  }
                  if (d.store.gate_status === "1") {
                    deviceInfos.gate_status = true
                  }else if (d.store.gate_status === "0") {
                    deviceInfos.gate_status = false
                  }else{
                    deviceInfos.gate_status = null
                  }
                  this.bind_list_data.push(deviceInfos)
                }else {
                  const detailParams_ = []
                  let json_ = eval('d.store.store' + d.store.storeType.id )

                  // for (let i = 0; i < json_.length; i++) {
                  for(var key in json_){
                    props.forEach(p => {
                      if (d.store.storeType.id === p.type_id && key === p.col_name) {
                        let v_ = eval('d.store.store' + d.store.storeType.id + '.' + key)
                        detailParams_.push({name: p.title, type: key, value: v_ + p.unit, id: p.id})
                      }
                    });
                  }

                  const gate_status = eval('d.store.store' + d.store.storeType.table + '.switch')
                  let normalInfos = {
                    pic_url: d.store.storeType.pic_url,
                    imei: d.imei,
                    name: d.store.storeType.name,
                    storename: d.storename,
                    detailParams: detailParams_,
                    status: d.online,
                    gate_status: gate_status,
                  }

                  this.bind_list_data.push(normalInfos)
                }
              })
              this.bind_list_data_params = jsonSort(this.bind_list_data[0].detailParams)
              indexParams_ = this.pageInfos.indexParams

              this.bind_list_data_params.forEach(d => {
                d.showing = false
                d.showPicUrl = this.unselectPic
                indexParams_.forEach(e => {
                  if (d.type === e.type) {
                    d.showing = true
                    d.showPicUrl = this.selectedPic
                    eval('this.indexParamsTemp["' + d.id + '"] = "' + d.type + '"')
                  }
                })
              })
            },
            async editParams(bool) {
              if (!bool) { //保存首页偏好
                if (this.product_id != '01001') {
                  const params = {
                    user_id: this.userId,
                    product_id: this.product_id,
                    show_counts: Object.keys(this.indexParamsTemp).length,
                    params: this.indexParamsTemp,
                    detail_show_counts: -1,
                    detail_params: {}
                  }
                  if (params.show_counts <= 0) {
                    api.toast({msg: '请至少选择一种参数展示!',duration: 2000,location: 'bottom'});
                    return;
                  }
                  // console.log(JSON.stringify(params));
                  var result = await post_create_update_user_perference(params)

                  api.toast({msg: '修改成功!',duration: 2000,location: 'bottom'});
                  api.sendEvent({
                    name: 'change_device',
                  });
                }else {
                  api.toast({msg: '无效操作,当前产品不支持修改!',duration: 2000,location: 'bottom'});
                }
              }else {
                this.initDetailParams()
              }
              this.editVisable = bool
            },
            handleIndexParams(type, id, showing, index) {
              if (!showing) { //点击未选择的图片,即为 选择
                this.bind_list_data_params[index].showing = true
                this.bind_list_data_params[index].showPicUrl = this.selectedPic
                $api.byId('selectPic_' + index).src = this.selectedPic
                eval('this.indexParamsTemp["' + id + '"] = "' + type + '"')

                const param = {
                  name: this.bind_list_data_params[index].name,
                  type: type,
                  value: this.bind_list_data_params[index].value
                }
                this.pageInfos.indexParams.push(param)
              }else {
                this.bind_list_data_params[index].showing = false
                this.bind_list_data_params[index].showPicUrl = this.unselectPic
                $api.byId('selectPic_' + index).src = this.unselectPic;
                delete this.indexParamsTemp[id];
                for (let i = 0; i < this.pageInfos.indexParams.length; i++) {
                  const element = this.pageInfos.indexParams[i];
                  if (element.type === type) {
                    this.pageInfos.indexParams.splice(i, 1);
                  }
                }
              }
            },
            openOperaterAndAlarm() {
              setTimeout(() => {
                let offset = $api.offset($api.byId('device_other_area'));
                let top = offset.t;
                let left = offset.l;
                let width = offset.w;
                let height = offset.h;
                api.sendEvent({
                  name: 'operate_and_alert_page',
                  extra: {url: 'store_'+this.product_id+'operateHtml'}
                });
                //这里以后全部是配置对应的http地址...
                let url_ = ''
                if (this.product_id === '01001') { //|| this.product_id === '02000' || this.product_id === '02001'  || this.product_id === '03001'  || this.product_id === '03002' || this.product_id === '03003'  || this.product_id === '03004'
                  url_ = 'http://iot.uccc.cc:9090/app_html/store'+this.product_id+'/operateFun.html'
                }else {
                  url_ = '../projects/store_' + this.product_id + '/' + 'operateFun.html'
                }
                api.openFrame({
                  name: 'store_'+this.product_id+'operateHtml',
                  url: url_,
                  bounces: false,
                  rect: {
                    x: api.winWidth/11,
                    y: api.winHeight/8 + top ,
                    w: api.winWidth- (api.winWidth/11) *2,
                    h: api.frameHeight- top - 40,
                  },
                  pageParam: {
                    imei: this.pageInfos.imei,
                    userId: this.userId,
                    token: this.token,
                    status: this.pageInfos.status,
                    deviceType: this.pageInfos.name,
                  },
                  vScrollBarEnabled: true,
                  animation: {
                    type:"push",
                    subType:"from_right",
                    duration:300
                  }
                });
              }, 300);
            },
            showProductPage() {
              // let res = await get_alert_html_str(api.pageParam.value.storeType)
              //这里以后全部是配置对应的http地址...
              //测试写法--start
              // console.log(this.product_id);
              let url_ = ''
              if (this.product_id === '01001') { //|| this.product_id === '02000'   || this.product_id === '02001'  || this.product_id === '03001' || this.product_id === '03002' || this.product_id === '03003'  || this.product_id === '03004' 
                url_ = 'http://iot.uccc.cc:9090/app_html/store'+this.product_id+'/index_win.html'
              }else {
                url_ = '../projects/store_' + this.product_id + '/' + 'index_win.html'
              }
              //测试写法--end
              //正式写法--start
                // url_ = 'http://iot.uccc.cc:9090/app_html/store'+this.product_id+'/index_win.html'
              //正式写法--end
              console.log(url_);
              api.openWin({
                name: 'store_' + this.product_id + '_indexWin',
                url: url_,
                // url:  'http://iot.uccc.cc:9090/app_html/store01001/index_win.html',
                bounces: false,
                pageParam: {imei : this.pageInfos.imei,
                            productId: this.product_id}
              });
            }
          }
        })
      };
  </script>
</html>