dedsudiyu 9 meses atrás
pai
commit
9772fc72e2

+ 161 - 20
src/views/iotDevice/hardwareManagement/hardwareEquipment/index.vue

@@ -177,6 +177,22 @@
             />
           </el-select>
         </el-form-item>
+        <el-form-item label="楼栋楼层:" prop="address">
+          <el-cascader
+            style="width:320px;"
+            v-model="dialogForm.address"
+            @change="cascaderChange"
+            placeholder="请选择楼栋楼层"
+            :props="{value: 'id', label: 'name',children:'buildFloorVoList'}"
+            :options="treeOptions" :show-all-levels="false"></el-cascader>
+        </el-form-item>
+        <el-form-item label="实验室:" prop="subId">
+          <el-select v-model="dialogForm.subId" placeholder="请选择实验室"
+                     @change="subChange"
+                     clearable style="width: 320px">
+            <el-option v-for="item in subOptions" :key="item.subId" :label="item.subName" :value="item.subId"/>
+          </el-select>
+        </el-form-item>
         <el-form-item label="物联设备" prop="deviceId">
           <el-select v-model="dialogForm.deviceId" @change="deviceChange" placeholder="请选择物联设备" style="width: 320px">
             <el-option
@@ -266,6 +282,8 @@
         //组件传参
         propsData: {},
         //弹窗相关
+        subOptions:[],
+        treeOptions:[],
         dialogTitle: '',
         dialogType: false,
         dialogForm: {},
@@ -313,7 +331,10 @@
           reservedThree: [
             { required: true, message: '请输入参数', trigger: 'blur' },
             { required: true, message: '请输入参数', validator: this.spaceJudgment, trigger: 'blur' }
-          ]
+          ],
+          address: [
+            { required: true, message: "请选择楼栋楼层", trigger: "blur" },
+          ],
         },
         //校区楼栋原始数据
         addressList: [],
@@ -374,6 +395,38 @@
           this.$set(this, 'typeList', response.data)
         })
       },
+      //楼栋楼层选中
+      cascaderChange(val){
+        laboratorySubRelInfoGetListByFloor({floorId:val[val.length-1]}).then(response => {
+          this.$set(this.dialogForm,'subId','');
+          this.$set(this,'subOptions',response.data);
+          this.$set(this.dialogForm, 'deviceId', '')
+          this.$set(this.dialogForm, 'deviceNo','')
+          this.$set(this, 'reservedNameOne', '')
+          this.$set(this, 'reservedTypeOne', false)
+          this.$set(this, 'reservedNameTwo', '')
+          this.$set(this, 'reservedTypeTwo', false)
+          this.$set(this, 'reservedNameThree', '')
+          this.$set(this, 'reservedTypeThree', false)
+          this.$nextTick(()=>{
+            this.iotDeviceFindByType();
+          })
+        })
+      },
+      //实验室选中
+      subChange(){
+        this.$set(this.dialogForm, 'deviceId', '')
+        this.$set(this.dialogForm, 'deviceNo','')
+        this.$set(this, 'reservedNameOne', '')
+        this.$set(this, 'reservedTypeOne', false)
+        this.$set(this, 'reservedNameTwo', '')
+        this.$set(this, 'reservedTypeTwo', false)
+        this.$set(this, 'reservedNameThree', '')
+        this.$set(this, 'reservedTypeThree', false)
+        this.$nextTick(()=>{
+          this.iotDeviceFindByType();
+        })
+      },
       //类型选中
       typeFun(val) {
         let self = this;
@@ -384,13 +437,15 @@
             self.$set(self.dialogForm, 'deviceTypeKey', item.deviceTypeKey)
             self.$set(self.dialogForm, 'deviceId', '')
             self.$set(self.dialogForm, 'deviceNo','')
-            this.$set(this, 'reservedNameOne', '')
-            this.$set(this, 'reservedTypeOne', false)
-            this.$set(this, 'reservedNameTwo', '')
-            this.$set(this, 'reservedTypeTwo', false)
-            this.$set(this, 'reservedNameThree', '')
-            this.$set(this, 'reservedTypeThree', false)
-            self.iotDeviceFindByType(item.deviceTypeKey);
+            self.$set(self, 'reservedNameOne', '')
+            self.$set(self, 'reservedTypeOne', false)
+            self.$set(self, 'reservedNameTwo', '')
+            self.$set(self, 'reservedTypeTwo', false)
+            self.$set(self, 'reservedNameThree', '')
+            self.$set(self, 'reservedTypeThree', false)
+            self.$nextTick(()=>{
+              self.iotDeviceFindByType();
+            })
           }
         });
       },
@@ -439,14 +494,17 @@
         })
       },
       //根据类型查询物联设备
-      iotDeviceFindByType(val) {
-        let obj = {
-          searchValue: '',
-          typeKeyList: [val]//(relay 继电器,sensor 传感器)
+      iotDeviceFindByType() {
+        if (this.dialogForm.address[0]&&this.dialogForm.deviceTypeKey){
+          let obj = {
+            floorId: this.dialogForm.address[this.dialogForm.address.length-1],
+            subjectId: this.dialogForm.subId,
+            typeKeyList: [this.dialogForm.deviceTypeKey]//(relay 继电器,sensor 传感器)
+          }
+          iotDeviceFindByType(obj).then(response => {
+            this.$set(this, 'relayList', response.data)
+          })
         }
-        iotDeviceFindByType(obj).then(response => {
-          this.$set(this, 'relayList', response.data)
-        })
       },
 
       //获取数据列表
@@ -467,9 +525,31 @@
           //编辑
           this.$set(this, 'dialogTitle', '编辑')
           let obj = JSON.parse(JSON.stringify(row))
-          this.iotDeviceFindByType(row.deviceTypeKey)
+          this.$set(this, 'dialogForm', {
+            id: obj.id,
+            hardwareName: obj.hardwareName,
+            hardwareNo: obj.hardwareNo,
+            hardwareTypeId: obj.hardwareTypeId,
+            hardwareTypeName: obj.hardwareTypeName,
+            hardwareTypeKey: obj.hardwareTypeKey,
+            deviceTypeKey: obj.deviceTypeKey,
+            deviceId: obj.deviceId,
+            deviceNo: obj.deviceNo,
+            attributeId:obj.attributeId,
+            address:[obj.schoolId,obj.buildId,obj.floorId],
+            subId:obj.subjectId,
+            state: obj.state,
+            reservedOne:obj.reservedOne,
+            reservedTwo:obj.reservedTwo,
+            reservedThree:obj.reservedThree,
+          })
+          laboratorySubRelInfoGetListByFloor({floorId:obj.floorId}).then(response => {
+            this.$set(this,'subOptions',response.data);
+          })
           this.iotAttributeDetail(row.attributeId);
-          this.$set(this, 'dialogForm', obj)
+          this.$nextTick(()=>{
+            this.iotDeviceFindByType();
+          })
           this.$set(this, 'dialogType', true)
         } else if (type == 4) {
           //删除
@@ -527,6 +607,8 @@
           deviceId: '',
           deviceNo: '',
           attributeId:'',
+          address:[],
+          subId:'',
           state: true,
           reservedOne:'',
           reservedTwo:'',
@@ -543,6 +625,7 @@
       },
       //dialog提交按钮
       dialogSubmit() {
+        let self = this;
         this.$refs['dialogForm'].validate(valid => {
           if (valid) {
             let obj = {
@@ -560,6 +643,47 @@
               reservedOne:this.reservedTypeOne?this.dialogForm.reservedOne:'',
               reservedTwo:this.reservedTypeTwo?this.dialogForm.reservedTwo:'',
               reservedThree:this.reservedTypeThree?this.dialogForm.reservedThree:'',
+            }//获取校区-楼栋-楼层数据
+            if(self.dialogForm.address[0]){
+              for(let i=0;i<self.treeOptions.length;i++){
+                if(self.treeOptions[i].id == self.dialogForm.address[0]){
+                  for(let o=0;o<self.treeOptions[i].buildFloorVoList.length;o++){
+                    if(self.treeOptions[i].buildFloorVoList[o].id == self.dialogForm.address[1]){
+                      for(let x=0;x<self.treeOptions[i].buildFloorVoList[o].buildFloorVoList.length;x++){
+                        if(self.treeOptions[i].buildFloorVoList[o].buildFloorVoList[x].id == self.dialogForm.address[2]){
+                          obj.schoolId = self.treeOptions[i].id;
+                          obj.schoolName = self.treeOptions[i].name;
+                          obj.buildId = self.treeOptions[i].buildFloorVoList[o].id;
+                          obj.buildName = self.treeOptions[i].buildFloorVoList[o].name;
+                          obj.floorId = self.treeOptions[i].buildFloorVoList[o].buildFloorVoList[x].id;
+                          obj.floorName = self.treeOptions[i].buildFloorVoList[o].buildFloorVoList[x].name;
+                        }
+                      }
+                    }
+                  }
+                }
+              }
+            }else{
+              obj.schoolId = '';
+              obj.schoolName = '';
+              obj.buildId = '';
+              obj.buildName = '';
+              obj.floorId = '';
+              obj.floorName = '';
+            }
+            //获取实验室数据
+            if(this.dialogForm.subId){
+              for(let i=0;i<self.subOptions.length;i++){
+                if(self.subOptions[i].subId == self.dialogForm.subId){
+                  obj.subjectId = self.subOptions[i].subId
+                  obj.subjectName = self.subOptions[i].subName
+                  obj.room = self.subOptions[i].roomNum
+                }
+              }
+            }else{
+              obj.subjectId = ''
+              obj.subjectName = ''
+              obj.room = ''
             }
             if (this.dialogForm.id) {
               iotHardwareUpdate(obj).then(response => {
@@ -577,18 +701,35 @@
           }
         })
       },
+
       //获取校区
       systemBuildingGetTreeList() {
+        //楼栋楼层
         systemBuildingGetTreeList({}).then(response => {
-          let list = []
+          let listOne = []
           for (let i = 0; i < response.data.length; i++) {
-            list.push({
+            listOne.push({
               id: response.data[i].id,
               name: response.data[i].name
             })
           }
-          this.$set(this, 'schoolOption', list)
+          this.$set(this, 'schoolOption', listOne)
           this.$set(this, 'addressList', response.data)
+          let list = JSON.parse(JSON.stringify(response.data));
+          pushNode(list)
+          function pushNode(list){
+            for(let i=0;i<list.length;i++){
+              if(list[i].type != 3 && !list[i].buildFloorVoList[0]){
+                list.splice(i,1)
+                i--
+              }else if(list[i].type == 3){
+                delete list[i].buildFloorVoList;
+              }else{
+                pushNode(list[i].buildFloorVoList)
+              }
+            }
+          }
+          this.$set(this,'treeOptions',list);
         })
       },
       //校区选中

+ 3 - 3
src/views/iotDevice/intelligenceIot/iotHardware/addPage.vue

@@ -112,9 +112,9 @@
           state: [
             { required: true, message: "请选择状态", trigger: "blur" },
           ],
-          // address: [
-          //   { required: true, message: "请选择楼栋楼层", trigger: "blur" },
-          // ],
+          address: [
+            { required: true, message: "请选择楼栋楼层", trigger: "blur" },
+          ],
         },
         noRules:{},
         modelList:[],