add_device_to_group.html 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">
      <meta name="referrer" content="no-referrer">
      <title>分组详情页</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-color: #F4F6F9;
          }
      </style>
  </head>
  <body>
    <div id="app">
      <template>
        <header class="aui-header-bar alarm-title" >
          <div class="aui-header-left" tapmode onclick="closeWin();">
              <i class="aui-iconfont aui-icon-left" style="color:#FFFFFF;font-size:16px;">返回</i>
          </div>
          <div class="aui-title title-font">添加设备</div>
          <div class="aui-header-right" tapmode @click="handleAdd">
              <div style="font-size: 14px;color:#FFFFFF;">确定</div>
          </div>
        </header>
        <div style="background:linear-gradient(90deg,rgba(91,127,248,1) 0%,rgba(75,175,239,1) 100%);height:50%;width:auto;"></div>
        <div class="search-view-inline" style="height: 2.5rem;margin-bottom: 0px;">
          <div class="select-list aui-ellipsis-1" tapmode  @click="selectCondition(0)">
              <span class="choose-device-title">{{ chooseModel }}</span>
              <i></i>
          </div>
        </div>
        <div class="search-view-inline" style="height: 2.5rem;">
          <div class="select-list aui-ellipsis-1" tapmode  @click="selectCondition(1)">
            <span class="choose-device-title">{{ chooseType }}</span>
            <i></i>
          </div>
        </div>
        <div class="group-panel">
          <div  v-for="(list_d, list_i) in newList">
            <div class="group-list-panel" tapmode @click="chooseList(list_d,list_i)" :id="'select_panel'+ list_i">
              <div class="group-list-inside-panel">
                  <el-row style="padding-bottom: 14px;">
                    <el-col :span=20>
                      <p style="font-size:14px;font-family:PingFang SC;font-weight:bold;color:rgba(55,57,78,1);">{{ list_d | filterStoreName }}</p>
                      <p style="font-size:12px;font-family:PingFang SC;font-weight:500;color:rgba(174,184,206,1);">设备编号: {{ list_d.imei }}</p>
                    </el-col>
                    <el-col :span=4>
                      <img v-show="!list_d.inGroup" src="../../image/alarm/icon-unselected.png" :id="'select_'+ list_i" class="group-choose-area" style="margin-top: 0.5rem;width:18px;height:18px;margin-left:15px;"  />
                      <img v-show="list_d.inGroup" src="../../image/icon_selected-gray.png" class="group-choose-area" style="margin-top: 0.5rem;width:18px;height:18px;margin-left:15px;"  />
                    </el-col>
                  </el-row>
              </div>
            </div>
          </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(){
        api.parseTapmode();
        $(function() {
          FastClick.attach(document.body);
        }); 

        //---------初始化vue
        vm = new Vue({
          el: '#app',
          data: {
            deviceList: api.pageParam.deviceList,
            modelList: [],
            chooseModel: "所有类型",
            chooseType: '所有型号',
            searchCondition: {
              storeModelId: '',
              type: '',
              params: {},
              user_id: api.getPrefs({sync: true,key: 'userID'}),
              limit: 10000,
              page: 1,
              token: api.getPrefs({sync: true,key: 'userToken'}),
            },
            newList: [],
            chooseArr: [],
          },
          mounted() {
          },
          filters: {
            filterStoreName(list) {
              if (list.storename != "" && list.storename != null) {
                return list.storename
              }else {
                return list.imei
              }
            }
          },
          created() {
            that = this

            api.addEventListener({
              name: 'change_group_device_model'
            }, function(ret, err){
              that.chooseModel = ret.value.name
              that.searchCondition.storeModelId = ret.value.model
              //改变类型时,重置型号
              that.chooseType = '所有型号'
              that.searchCondition.type = ''
              if (ret.value.name === '所有类型') {
                that.getPageList()
              }

            });
            api.addEventListener({
              name: 'change_group_device_type'
            }, function(ret, err){
              that.chooseType = ret.value.name
              that.searchCondition.type = ret.value.typeId
              that.getPageList()
            });

            this.initTypeList()
            // setTimeout(() => {
            //   this.selectCondition(0)
            // }, 2000);
            this.getPageList()
          },
          methods: {
            async handleAdd() {
              api.showProgress({
                  style: 'default',
                  animationType: 'fade',
                  title: '设备添加中...',
                  text: '',
                  modal: false
              });
              let groupId = api.pageParam.groupInfo.id
              this.chooseArr.forEach(async d => {
                let param = {
                  group_id: groupId,
                  imei: d
                }
                let addDeviceRes = await post_add_device_to_group(param)
              });
              api.hideProgress();
              api.sendEvent({
                name: 'addDeviceToGroupFinish',
              });
            },
            async initTypeList() {
              let res = await get_store_model();
              this.modelList = res.data
            },
            selectCondition(i) {
              switch (i) {
                case 0:
                api.openFrame({
                    name: 'alarmModelFooter',
                    url: '../alarm/alarm_model_footer.html',
                    bounces: false,
                    rect: {
                      x: 0,
                      y: 0,
                      w: api.winWidth,
                      h: api.winHeight
                    },
                    pageParam: {
                      list: this.modelList,
                      from: "add_device_to_group"
                    }
                  });
                  break;
                  case 1:
                    let list = []
                    if (this.chooseModel != '所有类型') {
                      this.modelList.forEach(d => {
                        if (d.name === this.chooseModel) {
                          list = d.data
                        }
                      });
                    }else {
                      this.modelList.forEach(d => {
                        d.data.forEach(e => {
                          list.push(e)
                        });
                      });
                    }
                    api.openFrame({
                      name: 'alarmTypeFooter',
                      url: '../alarm/alarm_type_footer.html',
                      bounces: false,
                      rect: {
                        x: 0,
                        y: 0,
                        w: api.winWidth,
                        h: api.winHeight
                      },
                      pageParam: {
                        list: list,
                        from: "add_device_to_group",
                      }
                    });
                  break;
              }
            },
            async getPageList() {
              api.showProgress({
                  style: 'default',
                  animationType: 'fade',
                  title: '列表加载中...',
                  text: '',
                  modal: false
              });
              if (this.searchCondition.storeModelId != '' &&this.searchCondition.type === '' ) {
                api.hideProgress();
                api.toast({
                  msg: '请选择型号!',
                  duration: 2000,
                  location: 'bottom'
                });
                return;
              }
              var user_perference = await get_product_perference(this.searchCondition.user_id)
              let userPreferenceList = user_perference.data
              
              for (let i = 0; i < userPreferenceList.length; i++) {
                const productPref = JSON.parse(userPreferenceList[i]);
                const prefList = []
                productPref.data_index.forEach(d => {
                  prefList.push('"'+d+'"')
                });
                eval('this.searchCondition.params["' + productPref.name +'"]=[' + prefList + ']')
              }
              let bind_list_data_res = await get_bind_list_data(this.searchCondition)
              let bind_list_data = bind_list_data_res.data.list.rows
              api.hideProgress();
              this.deviceList.forEach(d => {
                bind_list_data.forEach(e => {
                  if (d.imei === e.imei) {
                    console.log(d.imei);
                    e.inGroup = true //已经在组里的设备
                  }
                  
                })
              });
              this.newList = bind_list_data
            },
            chooseList(list_d, list_i) {
              if (list_d.inGroup) {
                return;
              }
              if ($api.byId('select_' + list_i).src.indexOf("unselected") != -1) {
                $api.byId('select_' + list_i).src = '../../image/alarm/icon-selected.png'
                $api.addCls($api.byId('select_panel' + list_i), 'add-border');
                this.chooseArr.push(list_d.imei)
              }else {
                $api.byId('select_' + list_i).src = '../../image/alarm/icon-unselected.png'
                //handle...
                let index = this.chooseArr.indexOf(list_d.imei)
                this.chooseArr.splice(index,1)
                $api.removeCls($api.byId('select_panel' + list_i), 'add-border');
              }
            },
            
          }
        })
      };
  </script>
</html>