detailAlert_frm.html 15 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: 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">
                <span>在线</span>
              </div>
              <div class="device-status-offline" v-if="!pageInfos.status">
                <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 <= 6"  :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 id="bottom_text" class="detail-alert-botton-text" tapmode @click="showProductPage">查看更多信息→</div>          
      </div>
    </div>
    <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="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.getStorage('userID'),
            token: $api.getStorage('userToken'),
            userPreferenceList: [],
            bind_list: {
              user_id: "",
              params: {},
              type: "",
              imei: "",
              limit: 1,
              page: 1
            },
            bind_list_data: [],
            bind_list_data_params: [],
            editVisable: false,
            selectedPic: "../../image/icon_selected_sm.png",
            unselectPic: "../../image/icon_unselected_sm.png",
            indexParamsTemp: {},
            product_id: "",
          },
          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() 
              // }, 1000);
              //-----
            },
            async initDetailParams() {
              api.showProgress({
                  style: 'default',
                  animationType: 'fade',
                  title: '加载中...',
                  text: '',
                  modal: false
              });
              var user_perference = await get_product_perference(this.userId)
              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
              console.log(JSON.stringify(this.bind_list));
              let bind_list_data_ = await get_bind_list_data(this.bind_list)
              
              
              let props = $api.getStorage('props')
              list_rows = bind_list_data_.data.list.rows
              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_ = []
                    for (let i = 0; i < props.length; i++) {
                      
                      const prop = props[i];
                      
                      let json_ = eval('d.store.store' + d.store.storeType.id )
                      for(var key in json_){
                        if (d.store.storeType.id === prop.type_id && key === prop.col_name) {
                          let v_ = eval('d.store.store' + d.store.storeType.id + '.' + key)
                          detailParams_.push({name: prop.title, type: key, value: v_ + prop.unit, id: prop.id})
                        }
                      }
                    }
                    
                    const gate_status = eval('d.store.store' + d.store.storeType.id + '.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)   
                  }             
              })
              api.hideProgress();
              this.bind_list_data_params = 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) {
              this.editVisable = 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: {}
                  }
                  // console.log(JSON.stringify(params));
                  var result = await post_create_update_user_perference(params)
                  
                  api.toast({msg: '修改成功!',duration: 2000,location: 'bottom'});
                }else {
                  api.toast({msg: '无效操作,当前产品不支持修改!',duration: 2000,location: 'bottom'});
                }
              }else {
                this.initDetailParams()
              }
            },
            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地址...
                
                api.openFrame({
                  name: 'store_'+this.product_id+'operateHtml',
                  url: '../projects/store_' + this.product_id + '/' + 'operateFun.html',
                  bounces: false,
                  rect: {
                    x: api.winWidth/11,
                    y: api.winHeight/8 + top ,
                    w: api.winWidth- (api.winWidth/11) *2,
                    h: api.frameHeight- top - 30,
                  },
                  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地址...
              api.openWin({
                name: 'store_' + this.product_id + '_indexWin',
                url: '../projects/store_' + this.product_id + '/' + 'index_win.html',
                bounces: false,
                pageParam: {imei : this.pageInfos.imei,
                            productId: this.product_id}
              });
            }
          }
        })
      };
  </script>
</html>