home.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">
      <title>home</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/home.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/element.css"/>
      <style>
        html,
        body{
          background: rgba(255,255,255,0);
          height: 100%;
          width: 100%;
        }
      </style>
  </head>
  <body>
    <div id="app">
      <div id="status"></div>
      <header class="aui-header-bar  title-home" style="width:'auto';height:44px;">
        <div class="aui-header-left">
          <span class="header-title" style="margin-left:15px;">智慧用电</span>
        </div>
        <div v-if="userType === 1" class="aui-header-right" tapmode onclick="openCanner(false);">
          <img src="../../image/open-scanner.png" style="width:24px;height:24px;margin-top:0.35rem;"/>
        </div>
      </header>
      <div class="bg-color">
        <template>
          <el-row class="device-counts">
            <el-col :span=8>
              {{ count.allCount }}
            </el-col>
            <el-col :span=8>
              {{ count.onlineCount }}
            </el-col>
            <el-col :span=8>
              {{ count.allCount-count.onlineCount }}
            </el-col>
          </el-row>
        </template>
        <el-row class="device-counts-name">
          <el-col :span=8>设备总数</el-col>
          <el-col :span=8>在线设备</el-col>
          <el-col :span=8>离线设备</el-col>
        </el-row>
        <div class="split-line"></div>
        <el-tabs class="tab-style">
          <!-- <el-tab-pane label="我的设备" name="my-device">我的设备</el-tab-pane>
          <el-tab-pane label="我的分组" name="my-group">我的分组</el-tab-pane> -->
          <el-row>
            <el-col :span=11>
              <span class="my-tab tab-selected" style="float:right;" id="my_device" @click="chooseTab('my_device','my_group')">我的设备</span>
            </el-col>
            <el-col :span=2>
              &nbsp;
            </el-col>
            <el-col v-if="userType === 1" :span=11>
              <span class="my-tab" style="float:left;" id="my_group" @click="chooseTab('my_group','my_device')">我的分组</span>
            </el-col>
            <el-col v-if="userType === 2" :span=11>
              <span class="my-tab" style="float:left;" id="my_group" @click="chooseTab('my_group','my_device')">我的单位</span>
            </el-col>
          </el-row>
        </el-tabs>
      </div>
    </div>
    <footer></footer>
  </body>
  <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">
      var vm,
          clickRow,
          htmlStrTemp,
          that;
      apiready = function(){
        var footer = $api.dom('footer'); // 获取 footer 标签元素
        var footerH = $api.fixTabBar(footer);
        api.parseTapmode();
        //------设置状态栏
        var statusH = api.getPrefs({sync: true,key: 'SAFEAREATOP'});
        document.getElementById("status").style.cssText = "height:"+ statusH +"px;width:'auto';background:linear-gradient(90deg,rgba(91,127,248,1) 0%,rgba(75,175,239,1) 100%);"
        setStatusBg('light');

        api.addEventListener({
          name: 'change_device'
        }, function(ret, err){
          getCounts()
        });

        api.addEventListener({
          name: 'open_device_alert'
        }, function(ret, err){
          //  if (that.userType === 1) {
            clickRow = ret.value.clickRow
            openDeviceDetailAlert();
          //  }
        });

        api.addEventListener({
          name: 'operate_and_alert_page'
        }, function(ret, err){
          if (that.userType === 1) {
            htmlStrTemp = ret.value.url
          }
        });

        api.addEventListener({
          name: 'close_cover_page'
        }, function(ret, err){
            setTimeout(() => {
              if (htmlStrTemp != null) {
              api.closeFrame({
                name: htmlStrTemp
                });
              }
            }, 600);
        });
        //------
        //---------初始化vue
        vm = new Vue({
          el: '#app',
          data: {
            count: {
              allCount: 0,
              onlineCount: 0,
            },
            userType: Number(api.getPrefs({sync: true,key: 'userType'})),
          },
          created() {
            this.getCounts()
            this.insertProps()
            this.chooseTab('my_device','my_group')
            // this.chooseTab('my_group','my_device')
            that = this
          },
          mounted() {
            window.getCounts = this.getCounts;
            window.openDeviceDetailAlert = this.openDeviceDetailAlert;
          },
          methods: {
            chooseTab(newTab, oldTab) {
              $api.addCls($api.byId(newTab), 'tab-selected');
              $api.removeCls($api.byId(oldTab), 'tab-selected');
              let phoneType = api.getPrefs({sync: true,key: 'SYSTEMTYPE'})
              let animation_ = null;
              // if (phoneType === 'ios') {   //江总不喜欢
              //   animation_ = {
              //       type:"cube",                //动画类型(详见动画类型常量)
              //       subType:"from_left",       //动画子类型(详见动画子类型常量)
              //       duration:500                //动画过渡时间,默认300毫秒
              //   }
              // }else if (phoneType === 'android') {
                animation_ = {
                    type:"movein",                //动画类型(详见动画类型常量)
                    subType:"from_left",       //动画子类型(详见动画子类型常量)
                    duration:300                //动画过渡时间,默认300毫秒
                }
              // }

              if (newTab == 'my_device') {
                api.openFrame({
                    name: 'deviceListWin',
                    url: './deviceList_win.html',
                    rect: {
                        x: 0,
                        y: $api.byId("app").offsetHeight,
                        w: api.winWidth,
                        h: api.winHeight-49-$api.byId("app").offsetHeight-footerH
                    },
                    pageParam: {
                        // name: 'test'
                    },
                    reload: true,
                    bounces: true,
                    animation: animation_,
                    vScrollBarEnabled: true,
                });
                api.closeFrame({
                  name: 'deviceGroupWin'
                });
              }else if (newTab == 'my_group') {
                animation_.subType = "from_right"
                if (this.userType === 1) {
                  api.openFrame({
                      name: 'deviceGroupWin',
                      url: './deviceGroup_win.html',
                      rect: {
                          x: 0,
                          y: $api.byId("app").offsetHeight,
                          w: api.winWidth,
                          h: api.winHeight-49-$api.byId("app").offsetHeight-footerH
                      },
                      reload: true,
                      bounces: false,
                      animation: animation_,
                      vScrollBarEnabled: true,
                  });
                }else if (this.userType === 2) {
                  api.openFrame({
                      name: 'myEnterpriseWin',
                      url: './my_enterprise_win.html',
                      rect: {
                          x: 0,
                          y: $api.byId("app").offsetHeight,
                          w: api.winWidth,
                          h: api.winHeight-49-$api.byId("app").offsetHeight-footerH
                      },
                      reload: true,
                      bounces: false,
                      animation: animation_,
                      vScrollBarEnabled: true,
                  });
                }

                api.closeFrame({
                  name: 'deviceListWin'
                });
              }
              // api.hideProgress();
            },
            async getCounts() {
              const params = {
                user_id: api.getPrefs({sync: true,key: 'userID'}),
                token: api.getPrefs({sync: true,key: 'userToken'})
              }
              var result;
              if (this.userType === 1) {
                result = await get_bind_list_online_count(params)
              }else if (this.userType === 2) {
                  result = await get_enterprise_store_count(params)
              }
              if (result) {
                if (result.code === 0) {
                  this.count.allCount = result.data.count
                  this.count.onlineCount = result.data.online_count
                }  
              }
            },
            async insertProps() {
              var props = await getProductParams()
              const unitList = []
              props.data.List.forEach(d => {
                const prop = {type_id: d.type_id,
                  title: d.title,
                  unit: d.unit,
                  col_name: d.col_name,
                  id: d.id,
                }
                unitList.push(prop)
              });
              // api.alert({title: 'testtitle',msg: JSON.stringify(this.bind_list),}, function(ret, err) {});
              // $api.setStorage('props', unitList);
              api.setPrefs({
                key: 'props',
                value: unitList
              });
            },
            async openDeviceDetailAlert() {
              if (clickRow.storeType === '05001') {
                api.openWin({
                  name: 'dtu_list_win',
                  url: './dtu_list_win.html',
                  bounces: false,
                  pageParam: {row : clickRow}
                });
              }else {
                api.openFrame({
                  name: 'coverPage',
                  url: '../utils/coverPage_frm.html',
                  bounces: false,
                  rect: {
                    x: 0,
                    y: 0,
                    w: api.winWidth,
                    h: api.winHeight
                  },
                  bgColor: 'rgba(0, 0, 0, 0)',
                  pageParam: {
                    value: clickRow,
                  },
                  reload: true,
                });

                $("#app").bind('click',function(){
                  api.closeFrame({
                  name: 'detailAlertFrm',
                  });
                  $("#app").unbind();
                })
              }
            },
          }
        })
      };


  </script>
  </html>