<!-- 硬件设备 -->
<template>
  <div class="app-container hardwareEquipment">
    <div class="page-container hardwareEquipmentPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="请输入名称/编号"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="hardwareTypeId">
            <el-select v-model="queryParams.hardwareTypeId" placeholder="请选择类型"
                       style="width: 160px">
              <el-option
                v-for="dict in typeList"
                :key="dict.hardwareTypeId"
                :label="dict.hardwareTypeName"
                :value="dict.hardwareTypeId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="schoolId">
            <el-select v-model="queryParams.schoolId" @change="changeSchool"
                       placeholder="请选择校区" style="width: 150px">
              <el-option v-for="(item,index) in schoolOption"
                         :key="item.id"
                         :label="item.name"
                         :value="item.id"/>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="buildId">
            <el-select v-model="queryParams.buildId" @change="buildSchool"
                       placeholder="请选择楼栋" style="width: 150px">
              <el-option v-for="(item,index) in buildOption"
                         :key="item.id"
                         :label="item.name"
                         :value="item.id"/>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="subjectId">
            <el-select v-model="queryParams.subjectId"
                       placeholder="请选择实验室" style="width: 150px">
              <el-option v-for="(item,index) in subjectOption"
                         :key="item.subId"
                         :label="item.subName"
                         :value="item.subId"/>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="operatingState">
            <el-select v-model="queryParams.operatingState" placeholder="请选择工作状态"
                       style="width: 160px">
              <el-option
                v-for="dict in operatingStateList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-select v-model="queryParams.state" placeholder="请选择状态"
                       style="width: 160px">
              <el-option
                v-for="dict in optionList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-add-common-style-button"
             style="float: right;"
             @click="dialogFormReset"
             v-hasPermiRouter="['iot:hardware:add']"
          >新增</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="设备名" prop="hardwareName" show-overflow-tooltip/>
          <el-table-column label="编号" prop="hardwareNo" width="200" show-overflow-tooltip/>
          <el-table-column label="设备类型" prop="hardwareTypeName" width="200" show-overflow-tooltip/>
          <el-table-column label="实验室" prop="subjectName" width="200" show-overflow-tooltip>
            <template slot-scope="scope">{{scope.row.subjectName?scope.row.subjectName:'-'}}</template>
          </el-table-column>
          <el-table-column label="物联编号" prop="relayNum" width="200" show-overflow-tooltip>
            <template slot-scope="scope">{{scope.row.deviceNo?scope.row.deviceNo:'-'}}</template>
          </el-table-column>
          <el-table-column label="工作状态" prop="operatingState" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.operatingState" style="color: #0183FA">运行中</span>
              <span v-if="!scope.row.operatingState">未运行</span>
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="state" width="100" show-overflow-tooltip
                           v-hasPermiRouter="['iot:hardware:edit']">
            <template slot-scope="scope">
              <el-switch
                @click.native="tableButton(5,scope.row)"
                class="switch captcha-img"
                :active-value="true"
                :inactive-value="false"
                active-color="#0183FA"
                inactive-color="#999"
                v-model="scope.row.state"
                active-text="启用"
                inactive-text="停用"
                disabled
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" prop="createTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,'{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(7,scope.row)"
                   v-hasPermiRouter="['iot:hardware:detail']"
                >详情</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['iot:hardware:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(4,scope.row)"
                   v-hasPermiRouter="['iot:hardware:del']"
                >删除</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <info-page v-if="pageType === 2" :propsData="propsData"></info-page>
    <!--新增弹窗-->
    <el-dialog class="iotClassification-dialog" :title='dialogTitle' width="540px" append-to-body
               :visible.sync="dialogType" v-if="dialogType" @close="dialogOff()"
               :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="dialogForm" ref="dialogForm" :inline="true"
               :rules="dialogRules" class="addCheckPage-min" label-width="120px">
        <el-form-item label="名称" prop="hardwareName">
          <el-input v-model="dialogForm.hardwareName" placeholder="请输入名称"
                    maxLength="10" style="width:320px;"/>
        </el-form-item>
        <el-form-item label="编号" prop="hardwareNo">
          <el-input v-model="dialogForm.hardwareNo" :disabled="!!dialogForm.id"
                    placeholder="请输入编号" maxLength="10" style="width:320px;"/>
        </el-form-item>
        <el-form-item label="类型" prop="hardwareTypeId">
          <el-select v-model="dialogForm.hardwareTypeId" placeholder="请选择类型"
                     style="width: 320px" @change="typeFun">
            <el-option
              v-for="dict in typeList"
              :key="dict.hardwareTypeId"
              :label="dict.hardwareTypeName"
              :value="dict.hardwareTypeId"
            />
          </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+'('+item.roomNum+')'" :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
              v-for="dict in relayList"
              :key="dict.id"
              :label="dict.deviceName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item :label="reservedNameOne" prop="reservedOne" v-if="reservedTypeOne">
          <el-input v-model="dialogForm.reservedOne" :placeholder="'请输入'+reservedNameOne"
                    maxLength="10" style="width:320px;"/>
        </el-form-item>
        <el-form-item :label="reservedNameTwo" prop="reservedTwo" v-if="reservedTypeTwo">
          <el-input v-model="dialogForm.reservedTwo" :placeholder="'请输入'+reservedNameTwo"
                    maxLength="10" style="width:320px;"/>
        </el-form-item>
        <el-form-item :label="reservedNameThree" prop="reservedThree" v-if="reservedTypeThree">
          <el-input v-model="dialogForm.reservedThree" :placeholder="'请输入'+reservedNameThree"
                    maxLength="10" style="width:320px;"/>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-radio-group v-model="dialogForm.state">
            <el-radio :label="true" style="margin-left:20px;">启用</el-radio>
            <el-radio :label="false">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
        <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    iotHardwareAdd,
    iotHardwareUpdate,
    iotHardwareList,
    iotHardwareDelete,
    iotHardwareTypeFindHardwareType,
    iotAttributeDetail
  } from '@/api/iotDevice/index'
  import { systemBuildingGetTreeList, laboratorySubRelInfoGetListByFloor,iotDeviceFindByType } from '@/api/commonality/permission'
  import infoPage from "./infoPage.vue";
  export default {
    name: 'index',
    components: {
      infoPage,
    },
    data() {
      return {
        tableButtonType: this.hasPermiDom(['iot:hardware:edit', 'iot:hardware:del']),
        //页面状态
        pageType: 1,
        //页面遮罩
        loading: false,
        //下拉列表数据
        optionList: [{ value: true, label: '启用' }, { value: false, label: '停用' }],
        operatingStateList: [{ value: true, label: '运行中' }, { value: false, label: '未运行' }],
        terminalList: [{ value: 1, label: '1' }, { value: 2, label: '2' }, { value: 3, label: '3' }, {
          value: 4,
          label: '4'
        }, { value: 5, label: '5' }, { value: 6, label: '6' }, { value: 7, label: '7' }, { value: 8, label: '8' }],
        //查询条件
        queryParams: {
          page: 1,
          pageSize: 20,
          searchValue: '',
          hardwareTypeId: null,
          schoolId: null,
          buildId: null,
          subjectId: null,
          operatingState: null,
          state: null
        },
        typeList: [],//类型
        relayList: [],//继电器
        //列表数据
        dataList: [],
        //数据数量
        total: 0,
        //组件传参
        propsData: {},
        //弹窗相关
        subOptions:[],
        treeOptions:[],
        dialogTitle: '',
        dialogType: false,
        dialogForm: {},
        dialogRules: {
          hardwareName: [
            { required: true, message: '请输入名称', trigger: 'blur' },
            { required: true, message: '请输入名称', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          hardwareNo: [
            { required: true, message: '请输入编号', trigger: 'blur' },
            { required: true, message: '请输入编号', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          hardwareTypeId: [
            { required: true, message: '请选择类型', trigger: 'blur' },
            { required: true, message: '请选择类型', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          deviceId: [
            { required: true, message: '请选择物联设备', trigger: 'blur' },
            { required: true, message: '请选择物联设备', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          subjectId: [
            { required: true, message: '请搜索选择实验室', trigger: 'blur' },
            { required: true, message: '请搜索选择实验室', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          relayId: [
            { required: true, message: '请选择继电器', trigger: 'blur' },
            { required: true, message: '请选择继电器', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          relayBit: [
            { required: true, message: '请选择继电器端子', trigger: 'blur' },
            { required: true, message: '请选择继电器端子', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          state: [
            { required: true, message: '请选择状态', trigger: 'blur' },
            { required: true, message: '请选择状态', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          reservedOne: [
            { required: true, message: '请输入参数', trigger: 'blur' },
            { required: true, message: '请输入参数', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          reservedTwo: [
            { required: true, message: '请输入参数', trigger: 'blur' },
            { required: true, message: '请输入参数', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          reservedThree: [
            { required: true, message: '请输入参数', trigger: 'blur' },
            { required: true, message: '请输入参数', validator: this.spaceJudgment, trigger: 'blur' }
          ],
          address: [
            { required: true, message: "请选择楼栋楼层", trigger: "blur" },
          ],
        },
        //校区楼栋原始数据
        addressList: [],
        //校区下拉列表
        schoolOption: [],
        //楼栋下拉列表
        buildOption: [],
        //实验室下拉列表
        subjectOption: [],
        //物联分类下拉列表
        iotTypeOptions:[],
        //硬件参数数据
        reservedNameOne:'',
        reservedTypeOne:false,
        reservedNameTwo:'',
        reservedTypeTwo:false,
        reservedNameThree:'',
        reservedTypeThree:false,
      }
    },
    created() {

    },
    mounted() {
      this.systemBuildingGetTreeList()
      this.iotHardwareTypeFindHardwareType()
      this.getList()
    },
    methods: {
      //查询按钮
      handleQuery() {
        this.$set(this.queryParams, 'page', 1)
        this.getList()
      },
      //重置按钮
      resetQuery() {
        this.$set(this, 'buildOption', [])
        this.$set(this, 'subjectOption', [])
        this.$set(this, 'queryParams', {
          page: 1,
          pageSize: 20,
          searchValue: '',
          hardwareTypeId: null,
          schoolId: null,
          buildId: null,
          subjectId: null,
          operatingState: null,
          state: null
        })
        this.getList()
      },
      //获取类型
      iotHardwareTypeFindHardwareType() {
        let obj = {
          searchValue: ''
        }
        iotHardwareTypeFindHardwareType(obj).then(response => {
          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;
        this.typeList.forEach((item) => {
          if(val == item.hardwareTypeId){
            self.$set(self.dialogForm, 'hardwareTypeKey', item.hardwareTypeKey)
            self.$set(self.dialogForm, 'hardwareTypeName', item.hardwareTypeName)
            self.$set(self.dialogForm, 'deviceTypeKey', item.deviceTypeKey)
            self.$set(self.dialogForm, 'deviceId', '')
            self.$set(self.dialogForm, 'deviceNo','')
            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();
            })
          }
        });
      },
      //属性选中
      deviceChange(val){
        let self = this;
        this.relayList.forEach((item) => {
          if(val == item.id){
            self.$set(self.dialogForm, 'deviceNo', item.deviceNo)
            self.$set(self.dialogForm, 'attributeId', item.attributeId)
            this.iotAttributeDetail(item.attributeId);
          }
        });
      },
      //查询物联分类属性详情
      iotAttributeDetail(attributeId){
        iotAttributeDetail({id:attributeId}).then(response => {
          let list = response.data.relateField?JSON.parse(response.data.relateField):[];
          list.forEach((item,index)=>{
            if(index == 0){
              if(item.state){
                this.$set(this, 'reservedNameOne', item.relateFieldName)
                this.$set(this, 'reservedTypeOne', true)
              }else{
                this.$set(this, 'reservedNameOne', '')
                this.$set(this, 'reservedTypeOne', false)
              }
            }else if(index == 1){
              if(item.state){
                this.$set(this, 'reservedNameTwo', item.relateFieldName)
                this.$set(this, 'reservedTypeTwo', true)
              }else{
                this.$set(this, 'reservedNameTwo', '')
                this.$set(this, 'reservedTypeTwo', false)
              }
            }else if(index == 2){
              if(item.state){
                this.$set(this, 'reservedNameThree', item.relateFieldName)
                this.$set(this, 'reservedTypeThree', true)
              }else{
                this.$set(this, 'reservedNameThree', '')
                this.$set(this, 'reservedTypeThree', false)
              }
            }
          })
        })
      },
      //根据类型查询物联设备
      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)
          })
        }
      },

      //获取数据列表
      getList() {
        this.$set(this, 'loading', true)
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        iotHardwareList(obj).then(response => {
          this.$set(this, 'loading', false)
          this.$set(this, 'dataList', response.data.records)
          this.$set(this, 'total', response.data.total)
        })
      },

      //操作按钮
      tableButton(type, row) {
        let self = this
        if (type == 3) {
          //编辑
          this.$set(this, 'dialogTitle', '编辑')
          let obj = JSON.parse(JSON.stringify(row))
          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.$nextTick(()=>{
            this.iotDeviceFindByType();
          })
          this.$set(this, 'dialogType', true)
        } else if (type == 4) {
          //删除
          this.$confirm('是否确认删除?', '警告', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(function() {
          }).then(() => {
            iotHardwareDelete({ id: row.id }).then(response => {
              self.msgSuccess(response.message)
              self.getList()
            })
          }).catch(() => {
          })
        } else if (type == 5) {
          //启用&停用
          let text = row.state ? '停用' : '启用'
          this.$confirm('是否确认' + text + '?', '警告', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(function() {
          }).then(() => {
            iotHardwareUpdate({ id: row.id, state: !row.state }).then(response => {
              self.msgSuccess(response.message)
              self.getList()
            })
          }).catch(() => {
          })
        } else if (type == 6) {
          //返回并刷新
          this.$set(this, 'pageType', 1)
          this.getList()
        }else if(type == 7){
          this.$set(this,'propsData',JSON.parse(JSON.stringify(row)));
          this.$set(this, 'pageType', 2)
        }
      },
      //**************************弹窗相关**************************
      //弹层关闭
      dialogOff() {
        this.$set(this, 'dialogType', false)
      },
      //弹层新增
      dialogFormReset() {
        this.$set(this, 'dialogTitle', '新增')
        this.$set(this, 'dialogForm', {
          hardwareName: '',
          hardwareNo: '',
          hardwareTypeId: '',
          hardwareTypeName: '',
          hardwareTypeKey: '',
          deviceTypeKey: '',
          deviceId: '',
          deviceNo: '',
          attributeId:'',
          address:[],
          subId:'',
          state: true,
          reservedOne:'',
          reservedTwo:'',
          reservedThree:'',
        })
        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.$set(this, 'relayList', [])
        this.$set(this, 'dialogType', true)
      },
      //dialog提交按钮
      dialogSubmit() {
        let self = this;
        this.$refs['dialogForm'].validate(valid => {
          if (valid) {
            let obj = {
              id: this.dialogForm.id,
              hardwareName: this.dialogForm.hardwareName,
              hardwareNo: this.dialogForm.hardwareNo,
              hardwareTypeId: this.dialogForm.hardwareTypeId,
              hardwareTypeName: this.dialogForm.hardwareTypeName,
              hardwareTypeKey: this.dialogForm.hardwareTypeKey,
              deviceTypeKey: this.dialogForm.deviceTypeKey,
              deviceId: this.dialogForm.deviceId,
              deviceNo: this.dialogForm.deviceNo,
              attributeId: this.dialogForm.attributeId,
              state: this.dialogForm.state,
              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 => {
                this.msgSuccess(response.message)
                this.dialogOff()
                this.getList()
              })
            } else {
              iotHardwareAdd(obj).then(response => {
                this.msgSuccess(response.message)
                this.dialogOff()
                this.getList()
              })
            }
          }
        })
      },

      //获取校区
      systemBuildingGetTreeList() {
        //楼栋楼层
        systemBuildingGetTreeList({}).then(response => {
          let listOne = []
          for (let i = 0; i < response.data.length; i++) {
            listOne.push({
              id: response.data[i].id,
              name: response.data[i].name
            })
          }
          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);
        })
      },
      //校区选中
      changeSchool(val) {
        let self = this
        let list = []
        for (let i = 0; i < self.addressList.length; i++) {
          if (val == self.addressList[i].id && self.addressList[i].buildFloorVoList[0]) {
            for (let o = 0; o < self.addressList[i].buildFloorVoList.length; o++) {
              list.push({
                id: self.addressList[i].buildFloorVoList[o].id,
                name: self.addressList[i].buildFloorVoList[o].name
              })
            }
          }
        }
        this.$set(this.queryParams, 'buildId', null)
        this.$set(this.queryParams, 'subjectId', null)
        this.$set(this, 'buildOption', list)
        this.$set(this, 'subjectOption', [])
      },
      //楼栋选中
      buildSchool(val) {
        laboratorySubRelInfoGetListByFloor({ buildId: val }).then(response => {
          this.$set(this.queryParams, 'subjectId', null)
          this.$set(this, 'subjectOption', response.data)
        })
      }
    }
  }
</script>
<style scoped lang="scss">
  .hardwareEquipment {
    .hardwareEquipmentPage {

    }
  }
</style>
