deviceGroup_win.html 7.11 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>我的分组_win</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"/>
      <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
      <style>
          html,
          body{
            background: #F4F6F9;
            height: 100%;
            width: 100%;
          }
      </style>
  </head>
  <body>
    <div id="app">
      <template>
        <div v-if="groupList.length > 0">
          <div  class="group-panel" v-for="(list_d, list_i) in groupList">
            <div class="group-list-panel" tapmode @click="chooseToHandle(list_d, list_i)">
              <div class="group-list-inside-panel">
                <el-row>
                  <el-col :span=12>
                    <span class="group-list-panel-title">{{ list_d.group_name }}</span>
                  </el-col>
                  <el-col :span=11>
                    <div class="group-list-panel-subtitle">{{ list_d.total }}个设备</div>
                  </el-col>
                  <el-col :span=1>
                    <i class="aui-iconfont aui-icon-right"></i>
                  </el-col>
                </el-row>
                <div class="group-list-line"></div>
                <el-row style="padding-bottom: 10px;">
                  <el-col :span=1>
                    <img src="../../image/icon_badgeDot_green.png" style="height: 6px;" />
                  </el-col>
                  <el-col :span=6><span class="group-normal-span">在线: {{ list_d.on_line }}</span></el-col>
                  <el-col :span=2>&nbsp;</el-col>
                  <el-col :span=1>
                    <img src="../../image/icon_badgeDot_red.png" style="height: 6px;" />
                  </el-col>
                  <el-col :span=6><span class="group-normal-span">离线: {{ list_d.off_line }}</span></el-col>
                </el-row>
              </div>
            </div>
          </div>
          <div class="group-panel group-manage-btn" tapmode @click="groupManage()">分组管理</div>
        </div>
        <div v-if="groupList.length <= 0">
          <div class="no-list-data" style="top: 2rem;">
            <img src="../../image/img-nullInfo.png" />
            <!-- <p style="font-size:16px;font-weight:500;color:rgba(55,57,78,1);">这里还没有内容</p> -->
            <p><div class="aui-btn add-device-btn" tapmode @click="addGroup">添加分组</div></p>
            
          </div>
        </div>
      </template>
    </div>
  </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,
        that;
    apiready = function(){
      $(function() {
        FastClick.attach(document.body);
      }); 
      //---------初始化vue
      vm = new Vue({
        el: '#app',
        data: {
          userId: api.getPrefs({sync: true,key: 'userID'}),
          token: api.getPrefs({sync: true,key: 'userToken'}),
          groupList: [],
        },
        created() {
          that = this
          api.setRefreshHeaderInfo({
            bgColor: '#F4F6F9',
            textColor: 'rgba(55,57,78,1)',
            textDown: '下拉刷新设备列表...',
            textUp: '松开刷新...'
          }, function(ret, err) {
            that.initUserGroups()
          });      
          api.addEventListener({
            name: 'init_group_list'
          }, function(ret, err){
            that.initUserGroups()
          });
          api.addEventListener({
            name: 'addDeviceToGroupFinish'
          }, function(ret, err){
            that.initUserGroups()
          });
          api.addEventListener({
            name: 'delDeviceToGroupFinish'
          }, function(ret, err){
            that.initUserGroups()
          });
          
          this.initUserGroups()
          // this.chooseToHandle({"id":18,"user_id":"45e3019e-b22f-401c-92b4-03363aae0291","group_name":"2020-06-23","created_at":"2020-06-23 09:53:12","total":0,"on_line":0,"off_line":0}, 1)
        },

        methods: {
          async initUserGroups() {
            let dataRes = await get_user_groups(this.userId)
            console.log(JSON.stringify(dataRes));
            if (dataRes.data.List != null) {
              this.groupList = dataRes.data.List  
            }else {
              this.groupList = []
            }
            
            api.refreshHeaderLoadDone();
          },
          chooseToHandle(d, i) {
            // console.log(JSON.stringify(d));
            
            api.openWin({
              name: 'group_device_info_win.html',
              url: './group_device_info_win.html',
              bounces: false,
              pageParam: {row: d},
            });
          },
          groupManage() {
            api.openWin({
              name: 'groupManage_win',
              url: './groupManage_win.html',
              bounces: false
            });
          },
          addGroup() {
            let text_ = parseTime(new Date(),'{y}-{m}-{d}')
            api.prompt({
                title: '新建分组',
                text: text_,
                buttons: ['取消', '创建']
            },async function(ret, err) {
                var index = ret.buttonIndex;
                var text = ret.text;
                if (index == 2) {
                  if (text.length <= 15 && text != '') {
                    that.groupList.forEach(d => {
                      if (d.group_name === text) {
                        api.toast({msg: '当前组名已存在!'});
                        return;
                      }
                    });
                    let params = {
                      user_id: that.userId,
                      group_name: text
                    }
                    let result = await post_create_user_groups(params)
                    if (result && result.message === '成功') {
                      api.toast({msg: '创建成功!'});  
                    }
                    that.initUserGroups()
                  }else if (text == '') {
                    api.toast({msg: '设备名称不可为空'});
                  }else if (text.length > 15) {
                    api.toast({msg: '设备名称最多15个字符!'});
                  }
                }
            });
          }
        }
      })
    };
  </script>
</html>