<template>
  <div class="subject">
    <div class="subject-page" v-if="pageType == 1">
      <div class="subject-page-min">
        <div :class="versionField() == 'xiBeiNongLinDaXue'?'left-subject-list-flex':''" class="left-subject-list" >
          <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" style="border-bottom:1px solid #D8D8D8">
            <el-form-item label="关键字" prop="searchValue" label-width="100px">
              <el-input
                v-model="queryParams.searchValue"
                placeholder="实验室/房间号"
                clearable
                style="width:150px;"
              />
            </el-form-item>
            <el-form-item label="学院" prop="deptId" label-width="50px">
              <el-select v-model="queryParams.deptId" placeholder="请选择学院" style="width:150px;">
                <el-option
                  v-for="dict in deptOptions"
                  :key="dict.deptId"
                  :label="dict.deptName"
                  :value="dict.deptId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="typeId" label-width="60px">
              <el-select v-model="queryParams.typeId" placeholder="安全分类" style="width:120px;margin-left:10px;">
                <el-option
                  v-for="dict in typeList"
                  :key="dict.typeName"
                  :label="dict.typeName"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="level" label-width="60px">
              <el-select v-model="queryParams.level" placeholder="安全分级" style="width:120px;margin-left:10px;">
                <el-option
                  v-for="dict in levelList"
                  :key="dict.id"
                  :label="dict.classifiedName"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="float: right;">
              <el-col :span="1.5" style="margin-bottom:26px;margin-right: 20px">
                <p class="add-button-one-90"
                   @click="clickPage(2)"
                   v-hasPermi="['laboratory:subject:add']"
                ><i class="el-icon-plus"></i>新增</p>
              </el-col>
            </el-form-item>
            <el-form-item style="float: right;margin-right:20px;" v-hasPermi="['laboratory:subject:import']">
              <el-dropdown @command="importButton">
                <div class="form-dropdown-box">
                  <img src="@/assets/ZDimages/personnelManagement/icon_jzgxx_dr.png">
                  <p>导入</p>
                  <img src="@/assets/ZDimages/personnelManagement/icon_jzggl_xljt.png">
                </div>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;color:#333;" :command="{command:1}">下载模板</el-dropdown-item>
                  <el-dropdown-item style="margin:0 10px;color:#333;" :command="{command:2}">导入数据</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-form-item>
            <el-form-item style="margin-right: 20px;">
              <p class="inquire-button-one" style="margin-left:20px;" @click="handleQuery">查询</p>
              <p class="reset-button-one" style="margin-left:20px;" @click="resetQuery">重置</p>
            </el-form-item>
          </el-form>
          <div class="table_border">
            <el-table ref="multipleTable" border :data="subjectList" highlight-current-row @current-change="handleCurrentChange" style="cursor: pointer;">

              <el-table-column label="排序" align="left" prop="id" width="80">
                <template slot-scope="scope">
                  <el-input maxlength="4" type="text" oninput ="value=value.replace(/[^0-9.]/g,'')" v-model="scope.row.diyOrder" @focus="liveSort(scope.row)" @blur="editSort(scope.row)"></el-input>
                </template>
              </el-table-column>
              <el-table-column label="实验室名称" align="left" prop="name"  show-overflow-tooltip/>
              <el-table-column label="房间号" align="left" prop="room" :width="versionField() == 'xiBeiNongLinDaXue'?250:150" show-overflow-tooltip/>
              <el-table-column label="学院" align="left" prop="deptName" :width="versionField() == 'xiBeiNongLinDaXue'?200:130"  show-overflow-tooltip/>
              <el-table-column label="分类/分级" align="left" prop="levelName" :width="versionField() == 'xiBeiNongLinDaXue'?200:150"  show-overflow-tooltip>
                <template slot-scope="scope">
                  <span >{{scope.row.typeName}}/</span>
                  <span :style="'color:'+scope.row.fiedColor+';'">{{scope.row.levelName}}</span>
                </template>
              </el-table-column>
              <el-table-column label="实验室责任人" align="left" prop="adminName" :width="versionField() == 'xiBeiNongLinDaXue'?180:130"  show-overflow-tooltip/>
              <el-table-column label="安全责任人" align="left" prop="safeUserName" :width="versionField() == 'xiBeiNongLinDaXue'?180:130"  show-overflow-tooltip/>
              <el-table-column label="操作" align="left" :width="versionField() == 'xiBeiNongLinDaXue'?180:140" >
                <template slot-scope="scope">
                  <div class="table-button-box">
                    <p class="table-button-null"></p>
                    <p class="table-button-p" v-hasPermi="['laboratory:subject:query']" @click="clickPage(7,scope.row)">详情</p>
                    <el-dropdown trigger="click" size="mini" @command="(command) => handleCommand(command, scope.row)">
                      <p class="table-button-p">更多>></p>
                      <el-dropdown-menu slot="dropdown" style="margin:0!important;">
                        <el-dropdown-item style="height:36px;line-height:36px;width:90px;text-align: center" command="1" v-hasPermiAnd="['laboratory:subject:query','laboratory:subject:edit']">关联配置</el-dropdown-item>
                        <el-dropdown-item v-if="versionField() != 'xiBeiNongLinDaXue'" style="height:36px;line-height:36px;width:90px;text-align: center" command="2">物联配置</el-dropdown-item>
                        <el-dropdown-item v-if="versionField() != 'xiBeiNongLinDaXue'" style="height:36px;line-height:36px;width:90px;text-align: center" command="3" v-hasPermi="['laboratory:subjectmaterial:add']">准入配置</el-dropdown-item>
                        <el-dropdown-item style="height:36px;line-height:36px;width:90px;text-align: center" command="4" v-hasPermiAnd="['laboratory:subject:query','laboratory:subject:edit']">编辑</el-dropdown-item>
                        <!--<el-dropdown-item style="height:36px;line-height:36px;width:90px;text-align: center" command="5"-->
                        <!--v-hasPermi="['laboratory:subject:remove']">删除</el-dropdown-item>-->
                      </el-dropdown-menu>
                    </el-dropdown>
                    <p class="table-button-null"></p>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <pagination
              style="margin-top:10px;"
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </div>
        </div>
        <div class="right-subject-box scrollbar-box" v-if="checkedSubject.id && versionField() != 'xiBeiNongLinDaXue'"
             :class="rightButtonType == 4?'overflow-box':''">
          <div class="top-button-box">
            <div :class="rightButtonType == 1 ? 'buttonColorA' : 'buttonColorB'" @click="rightButtonClick(1)">传感器监测</div>
            <div :class="rightButtonType == 2 ? 'buttonColorA' : 'buttonColorB'" @click="rightButtonClick(2)">物联控制</div>
            <div :class="rightButtonType == 3 ? 'buttonColorA' : 'buttonColorB'" @click="rightButtonClick(3)">视频监控</div>
            <div :class="rightButtonType == 4 ? 'buttonColorA' : 'buttonColorB'" @click="rightButtonClick(4)">声光报警</div>
            <div v-if="versionField() != 'suZhouDaXue'"
              :class="rightButtonType == 5 ? 'buttonColorA' : 'buttonColorB'" @click="rightButtonClick(5)">智能门禁</div>
          </div>
          <!--传感器-->
          <div class="bottom-max-box" :class="rightButtonType == 4?'overflow-box':''">
            <div class="bottom-sensor-box" v-if="rightButtonType == 1">
              <p class="top-title">
                <el-tooltip class="item" effect="dark" :content="checkedSubject.deptName" placement="bottom">
                  <i>{{checkedSubject.deptName}}</i>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" :content="checkedSubject.subAddrr.buildName+checkedSubject.subAddrr.floorName" placement="bottom">
                  <i>当前位置：{{checkedSubject.subAddrr.buildName}}{{checkedSubject.subAddrr.floorName}}</i>
                </el-tooltip>
              </p>
              <div class="sensor-for-max-box scrollbar-box" v-if="checkedSubject.sensorFunctionStatusList[0]">
                <div class="sensor-for-big-box"
                     :class="item.type == 1 ? 'sensor-color-a' : (item.type == 2 ? 'sensor-color-b' : 'sensor-color-c')"
                     v-if="item.funNum != 'huoyan'"
                     v-for="(item,index) in checkedSubject.sensorFunctionStatusList" :key="index">
                  <div class="sensor-for-min-box">
                    <img src="@/assets/ZDimages/subject/icon_bj_wd.png" v-if="item.funNum == 'wendu'">
                    <img src="@/assets/ZDimages/subject/icon_bj_wd.png" v-if="item.funNum == 'fbwendu'">
                    <img src="@/assets/ZDimages/subject/icon_bj_sd.png" v-if="item.funNum == 'shidu'">
                    <img src="@/assets/ZDimages/subject/icon_bj_sd.png" v-if="item.funNum == 'fbshidu'">
                    <img src="@/assets/ZDimages/subject/icon_bj_eyht.png" v-if="item.funNum == 'co'">
                    <img src="@/assets/ZDimages/subject/icon_bj_eyht.png" v-if="item.funNum == 'fbco'">
                    <img src="@/assets/ZDimages/subject/icon_bj_jwnd.png" v-if="item.funNum == 'jiawan'">
                    <img src="@/assets/ZDimages/subject/icon_sy_yqnd.png" v-if="item.funNum == 'o2'">
                    <img src="@/assets/ZDimages/subject/icon_sy_yqnd.png" v-if="item.funNum == 'fbo2'">
                    <img src="@/assets/ZDimages/subject/icon_bj_yg.png" v-if="item.funNum == 'yanwu'">
                    <img src="@/assets/ZDimages/subject/icon_sy_dqy.png" v-if="item.funNum == 'daqiya'">
                    <img src="@/assets/ZDimages/subject/icon_syspz_voc.png" v-if="item.funNum == 'voc'">
                    <img src="@/assets/ZDimages/subject/icon_syspz_voc.png" v-if="item.funNum == 'fbvoc'">
                    <img src="@/assets/ZDimages/subject/icon_syspz_tvoc.png" v-if="item.funNum == 'tvoc'">
                    <img src="@/assets/ZDimages/subject/icon_sy_mcnd.png" v-if="item.funNum == 'so2'">
                    <img src="@/assets/ZDimages/subject/icon_bj_yyhd.png" v-if="item.funNum == 'no1'">
                    <img src="@/assets/ZDimages/subject/icon_bj_dqy.png" v-if="item.funNum == 'fenchen'">
                    <img src="@/assets/ZDimages/subject/icon_bj_qq.png" v-if="item.funNum == 'H2'">
                    <img src="@/assets/ZDimages/subject/guangqi.png" v-if="item.funNum == 'guangqi'">
                    <img src="@/assets/ZDimages/subject/lvqi.png" v-if="item.funNum == 'lvqi'">
                    <img src="@/assets/ZDimages/subject/icon_syspz_jiaquan.png" v-if="item.funNum == 'jiaquan'">
                    <img src="@/assets/ZDimages/subject/icon_syspz_hwcw.png" v-if="item.funNum == 'hwcwy'">
                    <div>
                      <el-tooltip class="item" effect="dark" :content="item.describe" placement="bottom">
                        <p>{{item.describe|ellipsis}}</p>
                      </el-tooltip>
                      <p>{{item.formatVal}}</p>
                    </div>
                  </div>
                </div>
              </div>
              <img class="null-data-img" src="@/assets/ZDimages/null-data.png" v-if="!checkedSubject.sensorFunctionStatusList[0]">
              <p class="null-text-p" v-if="!checkedSubject.sensorFunctionStatusList[0]">暂无环境监测信息，请在更多操作-物联设备配置中进行添加</p>
              <p class="bottom-text" v-if="checkedSubject.sensorFunctionStatusList[0]">数据上报时间：{{checkedSubject.sensorFunctionStatusList[0].sendDate}}</p>
            </div>
            <div class="bottom-switch-box" v-if="rightButtonType == 2">
              <p class="top-title">
                <el-tooltip class="item" effect="dark" :content="checkedSubject.deptName" placement="bottom">
                  <i>{{checkedSubject.deptName}}</i>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" :content="checkedSubject.subAddrr.buildName+checkedSubject.subAddrr.floorName" placement="bottom">
                  <i>当前位置：{{checkedSubject.subAddrr.buildName}}{{checkedSubject.subAddrr.floorName}}</i>
                </el-tooltip>
              </p>
              <div class="switch-for-max-box scrollbar-box" v-show="checkedSubject.VOlist[0]" v-hasPermi="['laboratory:subcontrol:set']">
                <div class="switch-for-big-box" v-for="(item,index) in checkedSubject.VOlist" :key="index">
                  <div class="switch-for-min-box" v-if="item.hardwareTypeEnum.enumName == 'SWITCH'">
                    <div class="switch-for-min-box_t">
                      <p class="switch-for-min-title">{{item.hardwareName}}</p>
                      <p class="switch-null-p" v-if="item.state.code != 3 && item.state.code != 4" >{{item.state.name}}</p>
                    </div>
                    <div class="switch-for-min-box_b">
                      <el-switch
                        v-if="item.state.code == 3||item.state.code == 4"
                        class="switch"
                        @click.native="changeIsNeedCaptcha(item)"
                        v-model="item.state.code"
                        :active-value="3"
                        :inactive-value="4"
                        active-text="开启"
                        inactive-text="关闭"
                        disabled>
                      </el-switch>
                    </div>
                  </div>
                  <div class="switch-for-min-box" v-if="item.hardwareTypeEnum.enumName == 'AI_VENTILATION'">
                    <div class="switch-for-min-box_t">
                      <p class="switch-for-min-title">{{item.hardwareName}}</p>
                      <p class="switch-null-p" v-if="item.state.code != 3 && item.state.code != 4 && item.pcType == 0">{{item.state.name}}</p>
                      <p class="switch-pc-type-p" v-if="item.pcType == 1" @click="tableButton(item)">操作</p>
                    </div>
                    <div class="switch-for-min-box_b" v-if="item.pcType == 0">
                      <p class="switch-null-ventilate" v-if="item.hardwareTypeEnum.hardwareTypeCode==2 && item.state.code==3">{{item.dictLabel}}</p>
                      <el-switch
                        v-if="item.state.code == 3||item.state.code == 4"
                        class="switch"
                        @click.native="changeIsNeedCaptcha(item)"
                        v-model="item.state.code"
                        :active-value="3"
                        :inactive-value="4"
                        active-text="开启"
                        inactive-text="关闭"
                        disabled>
                      </el-switch>
                    </div>
                  </div>
                  <div class="switch-for-min-box" v-if="item.hardwareTypeEnum.enumName == 'ONE_MACHINE'">
                  <p class="switch-for-min-title">广播系统</p>
                  <p class="switch-for-min-button" @click="handleAdd(item.subId)">播放文字</p>
                  </div>
                </div>
              </div>
              <img class="null-data-img" src="@/assets/ZDimages/null-data.png" v-show="!checkedSubject.VOlist[0]">
              <p class="null-text-p" v-show="!checkedSubject.VOlist[0]">暂无物联控制信息，请在更多操作-物联设备配置中进行添加</p>
            </div>
            <div class="bottom-video-box" v-if="rightButtonType == 3">
              <p class="top-title">
                <el-tooltip class="item" effect="dark" :content="checkedSubject.deptName" placement="bottom">
                  <i>{{checkedSubject.deptName}}</i>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" :content="checkedSubject.subAddrr.buildName+checkedSubject.subAddrr.floorName" placement="bottom">
                  <i>当前位置：{{checkedSubject.subAddrr.buildName}}{{checkedSubject.subAddrr.floorName}}</i>
                </el-tooltip>
              </p>
              <div class="video-for-max-box scrollbar-box" v-if="checkedSubject.videoData[0]">
                <div class="switch-for-big-box" v-for="(item,index) in checkedSubject.videoData" :key="index">
                  <video :id="item.divId" ref="videoRef" autoplay controls  muted width="490px" height="262px"></video>
                  <p class="el-icon-full-screen position-p" @click="videoFullScreen(index)"></p>
                </div>
              </div>
              <img class="null-data-img" src="@/assets/ZDimages/null-data.png" v-if="!checkedSubject.videoData[0]">
              <p class="null-text-p" v-if="!checkedSubject.videoData[0]">暂无视频监控信息，请在更多操作-物联设备配置中进行添加</p>
            </div>
            <div class="bottom-alarm-box" v-if="rightButtonType == 4">
              <p class="top-title">
                <el-tooltip class="item" effect="dark" :content="checkedSubject.deptName" placement="bottom">
                  <i>{{checkedSubject.deptName}}</i>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" :content="checkedSubject.subAddrr.buildName+checkedSubject.subAddrr.floorName" placement="bottom">
                  <i>当前位置：{{checkedSubject.subAddrr.buildName}}{{checkedSubject.subAddrr.floorName}}</i>
                </el-tooltip>
              </p>
              <div class="alarm-max-box" :class="hardwareData[0]?hardwareData[0].status==3||hardwareData[0].status==4?'BGcolorTypeA':'BGcolorTypeB':''">
                <img  v-if="hardwareData[0]?hardwareData[0].status == 3:''" src="@/assets/ZDimages/medicUniversity-3_1/img_syslb_znsgbjzx.png" class="alarm-img">
                <div class="alarm-big-box" v-if="hardwareData[0]">
                  <p>报警器编号：{{hardwareData[0].hardwareNum}}</p>
                  <div class="alarm-position-box" >
                    <el-switch
                      v-if="hardwareData[0].status == 3"
                      @click.native="changeIsNeedCaptchaAlarm(hardwareData[0])"
                      class="switch captcha-img"
                      :active-value="3"
                      :inactive-value="4"
                      active-color="#FF9900"
                      inactive-color="#999"
                      v-model="hardwareData[0].status"
                      active-text="报警中"
                      inactive-text="未报警"
                      disabled
                    ></el-switch>
                  </div>
                  <p :class="hardwareData[0].status==3||hardwareData[0].status==4?'colorTypeA':'colorTypeB'">{{hardwareData[0].status==3||hardwareData[0].status==4?'在线':'离线'}}</p>
                </div>
                <div class="alarm-big-box" v-if="!hardwareData[0]">
                  <p>未绑定报警器</p>
                </div>

              </div>
              <div class="alarm-title-box">
                <p>报警记录</p>
                <p v-hasPermi="['chemical:hxpAlarmRecord:list']" @click="goAlarmRecord">更多>></p>
              </div>
              <el-table class="subject-alarm-time" style="margin-bottom:10px;" border :data="tableList" ref="multipleTable">
                <el-table-column label="报警时间" align="center" prop="alarmTime"/>
                <el-table-column label="处理状态" align="center" prop="operate" width="100"/>
                <el-table-column label="处理人" align="center" prop="handlingUserName" width="90"/>
              </el-table>
              <pagination
                v-show="totalTwo>0"
                :total="totalTwo"
                :page.sync="queryParamsTwo.pageNum"
                :limit.sync="queryParamsTwo.pageSize"
                @pagination="getHxpAlarmRecordNoAuthList"
              />
            </div>
            <div class="bottom-entrance-box" v-if="rightButtonType == 5">
              <p class="top-title">
                <el-tooltip class="item" effect="dark" :content="checkedSubject.deptName" placement="bottom">
                  <i>{{checkedSubject.deptName}}</i>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" :content="checkedSubject.subAddrr.buildName+checkedSubject.subAddrr.floorName" placement="bottom">
                  <i>当前位置：{{checkedSubject.subAddrr.buildName}}{{checkedSubject.subAddrr.floorName}}</i>
                </el-tooltip>
              </p>
              <div class="entrance" :class="item.operate.code==2?'BGentrance_l_yes':'BGentrance_l_no'" v-for="(item,index) in entranceList" v-if="item.operate">
                <img class="entrance_c" v-if="item.operate.code==2" src="@/assets/ZDimages/icon_znmj_zx.png">
                <img class="entrance_c" v-if="item.operate.code!=2"  src="@/assets/ZDimages/icon_znmj_lx.png">
                <div class="entrance_r">门禁编号：{{item.hardwareNum}}</div>
                <p :class="item.operate.code==2?'entrance_l_yes':'entrance_l_no'">{{item.operate.code==2?'在线':'离线'}}</p>
              </div>
              <img class="null-data-img" src="@/assets/ZDimages/null-data.png" v-if="entranceList.length<=0">
              <p class="null-text-p" v-if="entranceList.length<=0">暂无智能门禁信息，请在更多操作-物联设备配置中进行添加</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <add-subject v-if="pageType == 2" :subjectData="subjectData"></add-subject>
    <device-list v-if="pageType == 3" :subjectData="subjectData"></device-list>
    <admission-configuration v-if="pageType == 4" :subjectData="subjectData"></admission-configuration>
    <association-configuration v-if="pageType == 5" :subjectData="subjectData"></association-configuration>
    <info-page v-if="pageType == 6" :newData="newData"></info-page>
    <!--播放文字窗口-->
    <el-dialog title="广播系统" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="播放文字" prop="txt">
          <el-input v-model="form.txt" placeholder="请输入播放文字" />
        </el-form-item>
        <el-form-item label="播报方式" prop="type">
          <el-radio-group v-model="form.type">
            <el-radio :label="1">文字</el-radio>
            <el-radio :label="2">音频</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitFormOne">确 定</el-button>
      </div>
    </el-dialog>
    <!--导入窗口-->
    <el-dialog title="导入数据" :visible.sync="importOpen" @close="importOpenOff" width="600px" append-to-body class="checkItemLibrary-dialog-box">
      <el-upload
        class="teacher-import-dialog-upLoad-box"
        :drag="true"
        :data="upImportData"
        :action="uploadImgUrl"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :headers="headers"
        :before-upload="beforeAvatarUpload">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">仅允许导入xls、xlsx、格式文件。<span style="color:#0183FA;cursor: pointer" v-hasPermi="['system:user_teacher:exceltemplate']" @click="importTemplate">下载模板</span></div>
        <div class="el-upload-text-box" slot="tip" v-if="getImportData.downFile">
          <div class="img-text-box">
            <img src="@/assets/ZDimages/personnelManagement/icon_dr_wj.png">
            <p>{{getImportData.textName}}</p>
          </div>
          <p class="text-p">数据导入成功 <span style="color:#0183FA;">{{getImportData.successNum}}</span> 条，失败 <span style="color:#FF6464 ;">{{getImportData.failureNum}}</span> 条</p>
          <div class="img-text-box" v-if="getImportData.failureNum">
            <img src="@/assets/ZDimages/personnelManagement/icon_dr_sj.png">
            <p style="color:#0183FA;cursor: pointer;" @click="failureExcel">点击下载失败数据报表</p>
          </div>
        </div>
      </el-upload>
      <div slot="footer" class="teacher-import-dialog-button-box">
        <p class="inquire-button-one" @click="importOpenOff">确定</p>
      </div>
      <div class="teacher-import-dialog-position-box" v-if="loading"></div>
    </el-dialog>
  </div>
</template>

<script>
import { controlSwitch } from "@/api/laboratory/hardware";
import mqtt from 'mqtt'
import flvjs from 'flv.js'
import { hardWareControl,alarmControl } from "@/api/laboratory/hardware";
import {
  authListSubject,
  subjectInfo,
  updateSubject,
  mangerVoice,
  startUrl,
  queryHardByTypeList, getHaikangUserList, subjectTriggerModes, subjectEditSort, laboratorySubjectEditSort
} from '@/api/laboratory/subject'
import { listData} from "@/api/system/dict/data";
import { filterDept } from "@/api/medicUniversity-3_1/index";
import addSubject from "./addSubject.vue";
import deviceList from "./deviceList.vue";
import admissionConfiguration from "./admissionConfiguration.vue";
import associationConfiguration from "./associationConfiguration.vue";
import infoPage from "./infoPage.vue";
import { getHxpAlarmRecordNoAuthList,getEnablelist} from "@/api/medicUniversity-3_1/index";
import { listClassifiedAll } from "@/api/laboratory/classified";
import { listClasstypeAll } from "@/api/laboratory/classtype";
import { getToken } from "@/utils/auth";
import store from '@/store'
export default {
  filters:{
    ellipsis(value){
      if (!value) return '';
      if (value.length > 6) {
        return value.slice(0,6) + '...'
      }
      return value
    }
  },
  name: "subject",
  components: {
    addSubject,
    deviceList,
    admissionConfiguration,
    associationConfiguration,
    infoPage
  },
  data(){
    return{
      uploadImgUrl: window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + "/laboratory/subject/importSubData", // 上传地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      //导入弹层开关
      importOpen:false,
      //导入数据
      upImportData:{
        sysUserEnable:true,
        upDate:false,
      },
      getImportData:{
        downFile:false,
        successNum:0,
        failureNum:0,
        textName:"",
      },
      pageType:1,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        name: null,
        floorId: null,
        room: null,
        deptId: null,
        deptName: null,
        adminId: null,
        isDel: null,
        userId: null,
        diyOrder: null
      },
      // 实验室表格数据
      subjectList: [],
      //学院列表
      deptOptions:[],
      //当前选中实验室
      checkedSubject:{},
      //当前选中右侧按钮
      rightButtonType:1,
      //编辑实验室数据
      subjectData:{},
      // 临时保存排序
      sort:"",
      //播放文字的实验室id
      subId:"",
      open:false,
      form:{},
      //智能门禁
      entranceList:[
        {
          status:1,
          name:'门禁名称',
          num:'XD12345678912'
        },
        {
          status:0,
          name:'门禁名称',
          num:'XD12345678912'
        }
      ],
      rules:{
        txt:[
          {required: true, message: '请输入播放文字', trigger: 'blur'},
          { required: true, message: "请输入播放文字", validator: this.spaceJudgment, trigger: "blur" }
        ],
        type:[
          {required: true, message: '请选择播报方式', trigger: 'blur'}
        ],
      },
      newData:{

      },
      //MQTT请求参数-传感器
      mtopic:"lab/function/data",
      //MQTT请求参数-硬件
      mtopicOne:"lab/hardware/data",
      //MQTT请求参数-传感器-预案
      mtopicTow:"lab/riskPlan/trigger/notice",
      msg:"",
      client:{},
      videoList:[],
      //警报数据
      totalTwo:0,
      tableList:[],
      queryParamsTwo:{
        pageNum:1,
        pageSize:20,
      },
      hardwareData:[],
      //mqtt实验室id
      mqttIdList:[],
      //字典排风扇数组
      fanList:[],
      selectTriggerList:[],//预案触发下,预案数据存储
      //分类数据
      typeList:[],
      //分级数据
      levelList:[],
    }
  },
  created() {
  },
  mounted(){
    this.getListClasstypeAll();
    this.getListClassifiedAll();
    this.getDeptList();
    // this.subscriptionMQTT();
    this.getList();
    this.getlistData();
    // this.queryHardByTypeList();
  },
  methods:{
    tableButton(row){
      let self = this;
      this.$confirm(`是否确认操作此设备`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        controlSwitch({id:row.id}).then(response => {
          self.msgSuccess(response.msg);
        });
      }).catch(() => {

      })
    },
    //查询当前用户下的预案触发数据
    selectTriggerFun(data){
      let self = this;
      let dataArr=data;
      let list=JSON.parse(localStorage.getItem('selectTriggerList'));
      for(let i=0;i<list.length;i++){
        if(self.subId==list[i].subId){//如果当前选中的实验室和预案触发的实验室id
          for(let b=0;b<dataArr.length;b++){
            if(list[i].funNum==dataArr[b].funNum){

              if(list[i].minMonitor<dataArr[b].roundVlue<list[i].maxMonitor){//传感器值正常
                dataArr[b].type=1
              }else{//传感器值异常

              }
            }
          }
        }
      }
      return dataArr;
    },
    /** 查询字典数据列表 */
    getlistData() {
      this.loading = true;
      listData({pageNum:1,pageSize:20,dictType:'trigger_modes'}).then(response => {
        this.fanList=response.rows
      });
    },
    goAlarmRecord(){
      this.$router.push({
        path: `/chemicalLibrary/alarmRecord`,
      })
    },
    //智能门禁
    queryHardByTypeList(){
      let _this=this;
      let obj={
        subjectId:this.subId,
        type:'HK_DOOR',
      }
      queryHardByTypeList(obj).then( response => {
        let res=response.data;
        _this.entranceList=res;
      });
    },
    //报警器开启关闭方法
    changeIsNeedCaptchaAlarm(row){
      let self = this;
      console.log(row.status)
      if(row.status!=3 && row.status!=4){
        return
      }
      let text = row.status==3?'关闭':(row.status==4?'开启':'')
      this.$confirm(`是否`+text+`此设备`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        self.alarmControl(row)
      }).catch(() => {

      })
    },
    //开关按钮
    alarmControl(row){
      let switchData = {
        id:row.id,
        switchVal:row.status==3?'close':(row.status==4?'open':'')
      };
      alarmControl(switchData).then(response => {
        if(response.code==200){
          row.status = row.status==3?4:(row.status==4?3:'')
        }
      });
    },
    //获取实验室绑定报警器设备数据
    getEnablelist(){
      let obj = {
        subjectId:this.subId,
        type:"AI_ALARM"
      }
      getEnablelist(obj).then(response => {
        this.hardwareData = response.rows;
      });
    },
    //获取实验室报警列表数据
    getHxpAlarmRecordNoAuthList(){
      this.queryParamsTwo.subId = this.subId;
      getHxpAlarmRecordNoAuthList(this.queryParamsTwo).then(response => {
        this.totalTwo = response.total;
        this.tableList = response.rows;
      });
    },
    //播放文字
    handleAdd(id) {
      this.open = true;
      this.subId = id;
    },
    // 取消按钮
    cancel() {
      this.form = {};
      this.open = false;
    },
    /*播放文字*/
    submitFormOne(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          let id = this.subId;
          mangerVoice(this.form,id).then(response => {
            this.msgSuccess("播放成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    // 页面切换
    clickPage(type,row){
      if(this.pageType != type){
        if(type == 1){
          //列表页面
          this.pageType = type;
          this.getList();
          this.$set(this,'subjectData',{})
        }else if(type == 2){
          //新增页面
          this.pageType = type;
        }else if(type == 3){
          //编辑页面
          //this.pageType = 2;
          this.editFun(row);
          //this.$set(this,'subjectData',row)
        }else if(type == 4){
          this.pageType = 3;
          this.$set(this,'subjectData',row)
        }else if(type == 5){
          this.pageType = 4;
          this.$set(this,'subjectData',row)
        }else if(type == 6){
          this.pageType = 5;
          this.$set(this,'subjectData',row)
        }else if(type == 7){
          this.subjectInfoTwo(row);
          // this.$set(this,'subjectData',row)
        }
      }
    },
    //实验室编辑
    editFun(row){
      let self = this;
      let type = 0; //硬件 //0全部
      subjectInfo(row.id,type).then(response => {
        console.log(response.data)
        this.$set(this,'subjectData',response.data)
        this.pageType = 2;
      })
    },
    //获取实验室详情
    subjectInfoTwo(row){
      let self = this;
      let type = 0; //硬件 //0全部
      subjectInfo(row.id,type).then(response => {
        let classifyList = [];
        for(let i=0;i<response.data.classifyList.length;i++){
          if(response.data.classifyList[i].privateList.length>0 && (response.data.classifyList[i].classifyType==1||response.data.classifyList[i].classifyType==2)){
            classifyList.push(response.data.classifyList[i]);
          }
        }
        response.data.classifyList = classifyList;
        // console.log("获取实验室详情",response.data)
        this.$set(this,'newData',response.data);
        if(response.data.safeUserName){
          this.$set(this.newData,'safeUserName',response.data.safeUserName.split(','));
        }
        if(response.data.safeUserPhone){
          this.$set(this.newData,'safeUserPhone',response.data.safeUserPhone.split(','));
        }
        if(response.data.safeSigns){
          this.$set(this.newData,'safeSigns',response.data.safeSigns.split(','));
        }
        if(response.data.hazardCategory){
          this.$set(this.newData,'hazardCategory',response.data.hazardCategory.split(','));
        }
        if(response.data.outfire){
          this.$set(this.newData,'outfire',response.data.outfire.split(','));
        }
        if(response.data.riskMeasure){
          this.$set(this.newData,'riskMeasure',response.data.riskMeasure.split(','));
        }
        let list = [];
        let listTwo = [];
        if (response.data.labHardwareVOList){
          for(let i=0;i<response.data.labHardwareVOList.length;i++){
            if(response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'VIDEO_MONITOR'){
              list.push(response.data.labHardwareVOList[i].hardwareNUM);
            }
            // if(response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'SWITCH' || response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'AI_VENTILATION' || response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'ONE_MACHINE'){
            if(response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'SWITCH' || response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'AI_VENTILATION'){
              listTwo.push(response.data.labHardwareVOList[i])
            }
          }
        }
        this.$set(this.newData,'labHardwareVOListTwo',listTwo);
        if(this.versionField() == 'xiBeiNongLinDaXue'){
          this.$set(this.newData,'videoData',[]);
          this.pageType = 6;
          return
        }
        if(list[0]){
          let obj = {
            count:"100",
            deviceIds:list.join(),
            page:"1",
          };
          let urlText = window.location.href;
          if(urlText.indexOf(localStorage.getItem('ipIdentify')) != -1){
            startUrl(obj).then(res => {
              if(res.code == 200){
                if(!res.data[0]){
                  this.msgError("视频配置异常请联系管理员")
                  this.newData.videoData = [];
                  this.pageType = 6;
                }else{
                  let newData = res.data;
                  let videoList = [];
                  for(let i=0;i<newData.length;i++){
                    let obj = {
                      name:response.data.name + response.data.subAddrr.room,
                      videoType:"flv",
                      divId:'divId'+i,
                      url:newData[i].ws_flv,
                    }
                    videoList.push(obj)
                  }
                  this.$set(this.newData,'videoData',videoList);
                  this.pageType = 6;
                }
              }
            });
          }else{
            startUrl(obj).then(res => {
              if(res.code == 200){
                if(!res.data[0]){
                  this.msgError("视频配置异常请联系管理员")
                  this.newData.videoData = [];
                  this.pageType = 6;
                }else{
                  let newData = res.data;
                  let videoList = [];
                  for(let i=0;i<newData.length;i++){
                    let text = localStorage.getItem('cameraUrl');
                    let url = newData[i].ws_flv;
                    url = url.split("rtp/");
                    let newUrl = text+'rtp/'+url[1];
                    let obj = {
                      name:response.data.name + response.data.subAddrr.room,
                      videoType:"flv",
                      divId:'divId'+i,
                      url:newUrl,
                    }
                    videoList.push(obj)
                  }
                  this.$set(this.newData,'videoData',videoList);
                  this.pageType = 6;
                }
              }
            });
          }
        }else{
          this.$set(this.newData,'videoData',[]);
          this.pageType = 6;
        }
      })
    },
    // 开启关闭验证
    async changeIsNeedCaptcha (row) {
      let self = this;
      console.log(row)
      if(row.state.code!=3 && row.state.code!=4){
        return
      }
      let text = row.state.code==3?'关闭':(row.state.code==4?'开启':'')
      this.$confirm(`是否`+text+`此设备`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        self.switchChange(row)

      }).catch(() => {

      })
    },
    //点击开关按钮开启的时候充电调用硬件状态
    subjectTriggerModes(row){
      let self=this;
      subjectTriggerModes(row.id).then(response => {
        if(response.code==200){
          for(let b=0;b<self.fanList.length;b++){
            if(self.fanList[b].dictValue==response.data.triggerModes){
              for(let i=0;i<self.checkedSubject.VOlist.length;i++){
                if(row.id == self.checkedSubject.VOlist[i].id){
                  this.$set(self.checkedSubject.VOlist[i],'dictLabel',self.fanList[b].dictLabel);
                  this.$set(self.checkedSubject.VOlist[i],'triggerModes',response.data.triggerModes);
                }
              }
            }
          }
        }
      });
    },
    //开关按钮
    switchChange(row){
      let switchData = {
        id:row.id,
        switchVal:row.state.code==3?'close':(row.state.code==4?'open':'')
      };
      hardWareControl(switchData).then(response => {
        if(response.code==200){
          this.msgSuccess("操作成功")
        }
      });

    },
    //切换实验室展示数据
    rightButtonClick(type){
      let self = this;
      if(this.rightButtonType != type){
        this.rightButtonType = type;
        this.videoOff();
        if(type == 3){
          let self = this;
          let list = [];
          if(self.checkedSubject.labHardwareVOList){
            for(let i=0;i<self.checkedSubject.labHardwareVOList.length;i++){
              if(self.checkedSubject.labHardwareVOList[i].hardwareTypeEnum.enumName == 'VIDEO_MONITOR'){
                list.push(self.checkedSubject.labHardwareVOList[i].hardwareNUM);
              }
            }
            if(list[0]){
              let obj = {
                count:"100",
                deviceIds:list+'',
                page:"1",
              };
              let urlText = window.location.href;
              if(urlText.indexOf(localStorage.getItem('ipIdentify')) != -1){
                startUrl(obj).then(res => {
                  if(res.code == 200){
                    if(!res.data[0]){
                      this.msgError("视频配置异常请联系管理员")
                      return
                    }
                    let newData = res.data;
                    let videoList = [];
                    for(let i=0;i<newData.length;i++){
                      let obj = {
                        name:self.checkedSubject.name + self.checkedSubject.subAddrr.room,
                        videoType:"flv",
                        divId:'divId'+i,
                        url:newData[i].ws_flv,
                      }
                      videoList.push(obj)
                    }
                    this.$set(this.checkedSubject,'videoData',videoList);
                    if(this.rightButtonType == 3){
                      setTimeout(function(){
                        self.videoFunction();
                      },1000);
                    }
                  }
                });
              }else{
                startUrl(obj).then(res => {
                  if(res.code == 200){
                    if(!res.data[0]){
                      this.msgError("视频配置异常请联系管理员")
                      return
                    }
                    let newData = res.data;
                    let videoList = [];
                    for(let i=0;i<newData.length;i++){
                      let text = localStorage.getItem('cameraUrl');
                      let url = newData[i].ws_flv;
                      url = url.split("rtp/");
                      let newUrl = text+'rtp/'+url[1];
                      let obj = {
                        name:self.checkedSubject.name + self.checkedSubject.subAddrr.room,
                        videoType:"flv",
                        divId:'divId'+i,
                        url:newUrl,
                      }
                      videoList.push(obj)
                    }
                    this.$set(this.checkedSubject,'videoData',videoList);
                    if(this.rightButtonType == 3){
                      setTimeout(function(){
                        self.videoFunction();
                      },1000);
                    }
                  }
                });
              }
            }else{
              this.$set(this.checkedSubject,'videoData',[]);
            }
          }else{
            this.$set(this.checkedSubject,'videoData',[]);
          }
        }else if(type==2){
          for(let i=0;i<self.checkedSubject.VOlist.length;i++){
            if(self.checkedSubject.VOlist[i].hardwareTypeEnum.hardwareTypeCode == '2'){
              for(let b=0;b<self.fanList.length;b++){
                if(self.fanList[b].dictValue==self.checkedSubject.VOlist[i].triggerModes){
                  self.checkedSubject.VOlist[i].dictLabel=self.fanList[b].dictLabel
                }
              }
            }
          }
        }else if(type==5){
          this.queryHardByTypeList();
        }
      }
    },
    //选中实验室
    handleCurrentChange(val){
      let self = this;
      if(this.versionField() == 'xiBeiNongLinDaXue'){
        return
      }
      if(val.id != this.checkedSubject.id){
        this.videoOff();
        this.offMQTT();
        this.subjectInfo(val.id);
        this.subId = val.id;
        this.$set(this,'queryParamsTwo',{
          pageNum:1,
          pageSize:20,
        });
        this.getEnablelist();
        this.getHxpAlarmRecordNoAuthList();
        this.subscriptionMQTT();
      }
    },
    //获取实验室详情
    subjectInfo(id){
      let type = 1; //硬件 //0全部
      subjectInfo(id,type).then(response => {
        let obj = JSON.parse(JSON.stringify(response.data));
        obj.VOlist = [];
        if(response.data.labHardwareVOList){
          for(let i=0;i<response.data.labHardwareVOList.length;i++){
            if(response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'SWITCH'||
              response.data.labHardwareVOList[i].hardwareTypeEnum.enumName == 'AI_VENTILATION'){
              if( response.data.labHardwareVOList[i].isPcfire == 0 ){
                obj.VOlist.push(response.data.labHardwareVOList[i]);
              }
            }
          }
        }
        //判断传感器是否在线如果不在线type为2
        if(response.data.sensorFunctionStatusList){
          obj.sensorFunctionStatusList.forEach(function(item) {
            if(item.formatVal.indexOf("--") != -1){
              item.type=2
            }
          })
          obj.sensorFunctionStatusList=this.selectTriggerFun(obj.sensorFunctionStatusList)
        }
        this.$set(this,'checkedSubject',obj);
        this.$set(this.checkedSubject,'videoData',[]);
        this.rightButtonType = 1;
      })
    },
    //编辑按钮
    handleCommand(command, row){
      switch (command) {
        case "1":
          console.log('关联配置');
          this.clickPage(6,row);
          break;
        case "2":
          console.log('物联配置');
          this.clickPage(4,row);
          break;
        case "3":
          console.log('准入配置');
          this.clickPage(5,row);
          break;
        case "4":
          console.log('编辑');
          this.clickPage(3,row);
          break;
        case "5":
          console.log('删除');
          break;
        default:
          break;
      }
    },
    //保存当前排序
    liveSort(row){
      let obj = {
        sort:row.diyOrder
      }
      this.sort = JSON.parse(JSON.stringify(obj));
    },
    //编辑排序
    editSort(row){
      let self = this;
      if(row.diyOrder != this.sort.sort){
        self.$confirm('是否确认修改排序?', "", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          let obj = {
            id:row.id,
            diyOrder:row.diyOrder,
          };
          laboratorySubjectEditSort(obj).then(response => {
            self.msgSuccess("修改成功");
            self.getList();
          });
        }).then(() => {}).catch(() => {
          let obj = JSON.parse(JSON.stringify(self.sort));
          row.diyOrder = obj.sort
        });
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize:20,
        deptId:"",
        name: '',
      });

      // this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询实验室列表 */
    getList() {
      this.loading = true;
      // this.offMQTT();
      authListSubject(this.queryParams).then(response => {
        this.subjectList = response.rows;
        this.total = response.total;
        this.loading = false;
        if(response.rows[0]){
          this.$refs.multipleTable.setCurrentRow(response.rows[0]);
          this.subjectInfo(response.rows[0].id);
        }
        let idList = [];
        for(let i=0;i<response.rows.length;i++){
          idList.push(response.rows[i].id)
        }
        this.$set(this,'mqttIdList',idList);
        // this.subscriptionMQTT();
      });
    },
    /** 查询学院列表 */
    getDeptList() {
      filterDept().then(response => {
        this.$set(this, 'deptOptions', response.data)
      });
    },
    //MQTT订阅
    subscriptionMQTT(){
      let self = this;
      this.client = mqtt.connect(localStorage.getItem('mqttUrl'), {
        username: localStorage.getItem('mqttUser'),
        password:localStorage.getItem('mqttPassword')
      });
      this.client.on("connect", e =>{
        console.log("连接成功");
        this.client.subscribe(this.mtopic+self.subId, (err) => {
          if (!err) {
            console.log("订阅成功:" + this.mtopic+self.subId);
          }
        });
        this.client.subscribe(this.mtopicOne+self.subId, (err) => {
          if (!err) {
            console.log("订阅成功:" + this.mtopicOne+self.subId);
          }
        });
        // for(let i = 0; i< self.mqttIdList.length;i++){
        //   this.client.subscribe(this.mtopic+self.mqttIdList[i], (err) => {
        //     if (!err) {
        //       console.log("订阅成功:" + this.mtopic+self.mqttIdList[i]);
        //     }
        //   });
        //   this.client.subscribe(this.mtopicOne+self.mqttIdList[i], (err) => {
        //     if (!err) {
        //       console.log("订阅成功:" + this.mtopicOne+self.mqttIdList[i]);
        //     }
        //   });
        // }
      });
      this.client.on("message", (topic, message) => {
        // console.log('message',message)
        if (message){
          let data = JSON.parse(message)
           //console.log("MQTT----message",data)
          if(data.data.subId){
            //传感器
            // console.log("传感器",data.data.subId,'---------',data);
            if(self.checkedSubject.id){
              if(data.data.subId&&data.data.subId == self.checkedSubject.id){
                self.$set(self.checkedSubject,'sensorFunctionStatusList',data.data.functionStatuses);
                self.$set(self.checkedSubject.sensorFunctionStatusList[0],'sendDate',data.sendDate);
                //判断传感器是否在线如果不在线type为2
                self.checkedSubject.sensorFunctionStatusList.forEach(function(item) {
                  if(item.formatVal.indexOf("--") != -1){
                    item.type=2
                  }
                })
                self.checkedSubject.sensorFunctionStatusList=self.selectTriggerFun(self.checkedSubject.sensorFunctionStatusList)
              }
            }
            if(self.newData.id){
              if(data.data.subId&&data.data.subId == self.newData.id){
                self.$set(self.newData,'sensorFunctionStatusList',data.data.functionStatuses);
                self.$set(self.newData.sensorFunctionStatusList[0],'sendDate',data.sendDate);
              }
            }
          }else{
            //硬件
             console.log("硬件",data);
            for (let i = 0; i < data.data.length; i++) {
              if (self.checkedSubject.VOlist) {
                for (let k = 0; k < self.checkedSubject.VOlist.length; k++) {
                  if (self.checkedSubject.VOlist[k].id == data.data[i].num) {
                    if (data.data[i].hardwareOperate == 'CLOSE') {
                      self.checkedSubject.VOlist[k].state.code = 4;
                    } else if (data.data[i].hardwareOperate == 'OPEN') {
                      self.checkedSubject.VOlist[k].state.code = 3;
                    } else if (data.data[i].hardwareOperate == 'OFFLINE') {
                      self.checkedSubject.VOlist[k].state.code = 0;
                    }
                    if(self.checkedSubject.VOlist[k].hardwareTypeEnum.hardwareTypeCode == '2'&&
                      self.checkedSubject.VOlist[k].pcType == '0'){
                      self.subjectTriggerModes(self.checkedSubject.VOlist[k])
                    }
                  }
                }
              }
              if(self.newData.labHardwareVOList){
                for(let k=0;k<self.newData.labHardwareVOList.length;k++){
                  if(self.newData.labHardwareVOList[k].id == data.data[i].num){
                    if(data.data[i].hardwareOperate == 'CLOSE'){
                      self.newData.labHardwareVOList[k].state.code = 4;
                    }else if(data.data[i].hardwareOperate == 'OPEN'){
                      self.newData.labHardwareVOList[k].state.code = 3;
                    }else if(data.data[i].hardwareOperate == 'OFFLINE'){
                      self.newData.labHardwareVOList[k].state.code = 0;
                    }
                  }
                }
              }
            }
          }
        }
      });
    },
    //取消订阅关闭MQTT连接
    offMQTT(){
      let self = this;
      if (self.mqttIdList[0]){
        // for(let i=0;i<self.mqttIdList.length;i++){
        //   self.client.unsubscribe(self.mtopic+self.mqttIdList[i], error => {
        //     if (error) {
        //       console.log('Unsubscribe error', error)
        //     }
        //   })
        //   self.client.unsubscribe(self.mtopicOne+self.mqttIdList[i], error => {
        //     if (error) {
        //       console.log('Unsubscribe error', error)
        //     }
        //   })
        // }
        self.client.unsubscribe(self.mtopic+self.subId, error => {
          if (error) {
            console.log('Unsubscribe error', error)
          }
        })
        self.client.unsubscribe(self.mtopicOne+self.subId, error => {
          if (error) {
            console.log('Unsubscribe error', error)
          }
        })
        self.client.end();
        self.client = {};
      }
    },
    //视频方法
    videoFunction(){
      let self = this;
      // self.videoList = [];
      for(let i=0;i<self.checkedSubject.videoData.length;i++){
        let obj = {
          player :{},
          flvPlayer:{}
        };
        obj.player = document.getElementById(self.checkedSubject.videoData[i].divId);
        // if (flvjs.isSupported()) {
        obj.flvPlayer = flvjs.createPlayer(
          {
            // isLive: true, //=> 是否为直播流
            // hasAudio: false, //=> 是否开启声音
            type: self.checkedSubject.videoData[i].videoType, //媒体类型 flv 或 mp4
            url: self.checkedSubject.videoData[i].url //视频流地址
          },
          {
            enableStashBuffer: true,//启用 IO 存储缓冲区。 如果您需要实时流播放（最小延迟），请设置为 false，但如果存在网络抖动，则可能会停止。
            stashInitialSize: 128,//IO 存储缓冲区初始大小。 默认值为 384KB。 指示合适的大小可以改善视频加载/搜索时间。
            isLive: true,//是否是直播
            lazyLoadRecoverDuration: 30,//指示以秒为单位的lazyLoad 恢复时间边界。
            autoCleanupSourceBuffer: true,//进行自动清理
            autoCleanupMaxBackwardDuration: 3 * 60,//3 * 60 当向后缓冲持续时间超过这个值（以秒为单位）时，对 SourceBuffer 进行自动清理
            autoCleanupMinBackwardDuration: 2 * 60,//2 * 60 指示在执行自动清理时为后向缓冲区保留的持续时间（以秒为单位）。
          }
        );
        self.videoList.push(obj);
        // }
        console.log("i",i)
      }

      for(let i=0;i<self.videoList.length;i++){
        self.videoList[i].flvPlayer.attachMediaElement(self.videoList[i].player);
        self.videoList[i].flvPlayer.load(); //加载
        self.videoList[i].flvPlayer.play(); //加载
      }
    },
    //视屏全屏方法
    videoFullScreen(index){
      this.$refs.videoRef[index].webkitRequestFullScreen();
    },
    //断开视频流
    videoOff(){
      let self = this;
      if(self.videoList[0]){
        for(let i=0;i<self.videoList.length;i++){
          self.videoList[i].flvPlayer.pause();
          self.videoList[i].flvPlayer.unload();
          self.videoList[i].flvPlayer.detachMediaElement();
          self.videoList[i].flvPlayer.destroy();
          self.videoList[i].flvPlayer = null;
        }
        self.videoList = [];
      }
    },
    //查询安全分级
    getListClassifiedAll(){
      listClassifiedAll().then(response=>{
        if(response.code==200){
          console.log(response)
          this.levelList=response.data
        }
      })
    },
    //查询安全分类
    getListClasstypeAll(){
      listClasstypeAll().then(response=>{
        if(response.code==200){
          this.typeList=response.data;
        }
      });
    },
    //****************************************导入功能**************************************
    handleAvatarSuccess(res, file) {
      if(res.code == 200){
        this.getImportData.downFile = true
        this.getImportData.successNum = res.data.successNum
        this.getImportData.failureNum = res.data.failureNum
        // this.importOpen = false;
        // this.getList();
      }else{
        this.msgError(res.msg);
      }
      this.loading = false;
    },
    beforeAvatarUpload(file) {
      let type = false;
      console.log('file',file);
      if (file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || file.type == 'application/vnd.ms-excel') {
        if(file.size> 5250000){
          this.msgError('上传大小不能超过5M')
          return false
        }
        this.getImportData.textName = file.name;
        type = true;
        this.loading = true;
      }else{
        this.$message.error('只能上传xls/xlsx格式文件');
        type = false;
      }
      return type;
    },
    //导入页面关闭
    importOpenOff(){
      this.importOpen = false;
      this.getImportData.downFile = false;
      this.getImportData.successNum = 0;
      this.getImportData.failureNum = 0;
      this.getImportData.textName = "";
    },
    /** 导入按钮操作 */
    importButton(item){
      if(item.command == 1){
        //  下载模板
        this.download('/laboratory/subject/exportSubTemplate', {}, `实验室导入模板.xlsx`)
      }else if(item.command == 2){
        //  导入数据
        console.log('导入数据');
        this.importOpen = true;
      }
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('/laboratory/subject/exportSubTemplate', {}, `实验室导入模板.xlsx`)
    },
    /*下载失败列表*/
    failureExcel(){
      this.download('/laboratory/subject/exportProblemData', {}, `实验室导入模板失败报表.xlsx`)
    },
  },
  beforeDestroy() {
    //清除定时器
    let self = this;
    self.videoOff();
    self.offMQTT();
  },
}
</script>

<style scoped lang="scss">
.subject{
  flex:1;
  display: flex!important;
  flex-direction: column;
  overflow: hidden;
  *{
    margin:0;
  }
  ::v-deep .el-table__row{
    td:nth-child(1){
      padding:0;
    }
  }
  .subject-page{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius:10px;
    margin:5px 0 0 0;
    //box-shadow: 0 0 8px 1px rgba(0, 0, 0, 0.1);
    .subject-page-min{
      flex:1;
      display: flex;
      overflow: hidden;
      padding: 2px 0 10px 10px;
      box-sizing: border-box;
      .form-dropdown-box{
        display: flex;
        margin:0;
        padding:0 10px;
        cursor: pointer;
        height:40px;
        img:nth-child(1){
          width:16px;
          height:16px;
          margin-top:12px;
        }
        p{
          width:47px;
          text-align: center;
          font-size:14px;
          margin:0;
          line-height:40px;
        }
        img:nth-child(3){
          width:10px;
          height:6px;
          margin-top:17px;
        }
      }
    }
    .left-subject-list-flex{
      flex:1;
    }
    .left-subject-list{
      /*flex:1;*/
      width:1143px;
      display: flex;
      flex-direction: column;
      margin-right:6px;
      overflow: hidden ;
      box-shadow: 0px 2px 6px 0px rgba(0,0,0,0.2);
      border-radius: 20px 20px 20px 20px;
      padding-top: 24px;
      margin-bottom:10px;
      .table_border{
        flex:1;
        display: flex;
        flex-direction: column;
        padding: 20px 20px 10px;
        box-sizing: border-box;
        overflow: hidden;
      }
    }
    .overflow-box{
      overflow: hidden;
    }
    .right-subject-box{
      /*width:440px;*/
      display: flex;
      flex-direction: column;
      .top-button-box{
        display: flex;
        margin-left:6px;
        div{
          padding:0 10px;
          height:40px;
          line-height:40px;
          font-size:14px;
          text-align: center;
          border-top-right-radius: 10px;
          border-top-left-radius: 10px;
          margin-right:1px;
          cursor: pointer;
          font-weight: 500;
        }
        .buttonColorA{
          color:#0045AF;
          background:#fff ;
          border: 1px solid #E0E0E0;
          border-bottom: 1px solid rgba(224,224,224,0.3);
        }
        .buttonColorB{
          color:#333;
          background:#E0E0E0 ;
          border: 1px solid #E0E0E0;
          border-bottom:none;
        }
      }
      .bottom-max-box{
        width:428px;
        box-shadow: 0px 2px 6px 0px rgba(0,0,0,0.2);
        border-radius: 0px 0px 20px 20px;
        font-weight:500;
        flex:1;
        display: flex;
        flex-direction: column;
        margin-left:6px;
        overflow: hidden;
        margin-bottom:10px;
        .bottom-sensor-box{
          overflow: hidden;
          display: flex;
          flex-direction: column;
          background: #fff;
          width:424px;
          flex:1;
          position: relative;
         // border: 1px solid #E0E0E0;
          //border-radius: 0 10px 10px 10px;
          .top-title{
            margin:16px 26px;
            display: flex;
            justify-content: space-between;
            >i{
              font-style: normal;
              line-height:18px;
              font-size:16px;
              color: #333;
              overflow:hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
          .null-text-p{
            text-align: center;
            font-size:16px;
            color:#999;
            line-height:50px;
            margin:0 30px;
          }
          .sensor-for-max-box{
            .sensor-for-big-box{
              display: inline-block;
              width:180px;
              height:60px;
              margin:0 0 11px 22px;
              border-radius: 10px;
              .sensor-for-min-box{
                display: flex;
                img{
                  width:26px;
                  height:26px;
                  margin:17px 11px;
                }
                div{
                  margin:9px 0;
                  p{
                    color:#fff;
                  }
                  p:nth-child(1){
                    font-size:14px;
                    line-height:20px;
                  }
                  p:nth-child(2){
                    font-size:16px;
                    line-height:22px;
                  }
                }
              }
            }
            .sensor-color-a{
              background: #FF7272;
              color:#fff;
            }
            .sensor-color-b{
              background: #E0E0E0;
              color:#999999;
            }
            .sensor-color-c{
              background: #80D164;
              color:#fff;

            }
          }
          .bottom-text{
            line-height:18px;
            font-size:14px;
            color:#999999;
            margin:0 0px 0px 26px;
            position: absolute;
            bottom: 22px;
          }
        }
        .bottom-switch-box{
          overflow: hidden;
          display: flex;
          flex-direction: column;
          background: #fff;
          width:424px;
          flex: 1;
          .top-title{
            margin:16px 26px;
            display: flex;
            justify-content: space-between;
            >i{
              font-style: normal;
              line-height:18px;
              font-size:16px;
              color: #333;
              overflow:hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
          .null-text-p{
            text-align: center;
            font-size:16px;
            color:#999;
            line-height:50px;
            margin:0 30px;
          }
          .switch-for-max-box{
            width: 424px;
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            .switch-for-big-box{
              .switch-for-min-box{
                width:180px;
                height:70px;
                margin:0 0 14px 20px;
                background: rgba(1,131,250,0.1);
                border-radius: 10px 10px 10px 10px;
                padding: 10px;
                box-sizing: border-box;
                .switch-for-min-box_t{
                  width: 100%;
                  display: flex;
                  justify-content: space-between;
                  .switch-for-min-title{
                    font-size:14px;
                    line-height:24px;
                    width: 84px;
                    color: #333333;
                    display:block;
                    overflow:hidden;
                    text-overflow:ellipsis;
                    white-space:nowrap;
                  }
                  .switch-null-p{
                    font-size:14px;
                    line-height:24px;
                    color:#999;
                  }
                  .switch-pc-type-p{
                    font-size:14px;
                    line-height:24px;
                    color:#0183fa;
                    cursor: pointer;
                  }
                }
                .switch-for-min-box_b{
                  margin-top: 10px;
                  .switch-null-ventilate{
                    width: 62px;
                    height: 18px;
                    border-radius: 10px 10px 10px 10px;
                    opacity: 1;
                    border: 1px solid #0183FA;
                    font-size: 12px;
                    font-weight: 400;
                    color: #0183FA;
                    line-height: 15px;
                    text-align: center;
                    float: left;
                  }
                  .switch{
                    float: right;
                  }
                }



                .switch-for-min-button{
                  width:70px;
                  height:30px;
                  line-height:30px;
                  font-size:14px;
                  color:#0045AF;
                  border-radius:6px;
                  border: 1px solid #0045AF;
                  margin-top:14px;
                  text-align: center;
                  cursor: pointer;
                }
              }
            }
          }
        }
        .bottom-video-box{
          overflow: hidden;
          display: flex;
          flex-direction: column;
          background: #fff;
          width:424px;
          border-radius: 0 10px 10px 10px;
          flex: 1;
          .top-title{
            margin:16px 26px;
            display: flex;
            justify-content: space-between;
            >i{
              font-style: normal;
              line-height:18px;
              font-size:16px;
              color: #333;
              overflow:hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
          .null-text-p{
            text-align: center;
            font-size:16px;
            color:#999;
            line-height:50px;
            margin:0 30px;
          }
          .video-for-max-box{
            .switch-for-big-box{
              width:374px;
              height:262px;
              margin:0 auto 14px;
              position: relative;
              .position-p{
                width:42px;
                height:42px;
                text-align: center;
                line-height:42px;
                font-size:18px;
                position: absolute;
                top:0;
                right:0;
                color:#fff;
                cursor: pointer;
              }
            }
          }
        }
        .bottom-alarm-box{
          flex:1;
          display: flex;
          flex-direction: column;
          background: #fff;
          width:424px;
          overflow-x: hidden;
          padding: 0 27px 0 23px;
          box-sizing: border-box;
          .top-title{
            margin:16px 0px;
            display: flex;
            justify-content: space-between;
            >i{
              font-style: normal;
              line-height:18px;
              font-size:16px;
              color: #333;
              overflow:hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
          .alarm-max-box{
            width:374px;
            height:60px;
            display: flex;
            position:relative;
            background: #f5f5f5;
            border-radius: 10px 10px 10px 10px;
            margin: 10px 0 0 0;
            .alarm-img{
              width:30px;
              height:30px;
              margin:14px;
            }
            .alarm-big-box{
              p:nth-of-type(1){
                position:absolute;
                top:18px;
                left:64px;
                font-size: 14px;
                font-weight: 400;
                color: #333333;
              }
              .alarm-position-box{
                position:absolute;
                top:8px;
                left:260px;
              }
              p:nth-of-type(2){
                position:absolute;
                top:0px;
                right:0px;
                width: 50px;
                height: 20px;
                font-size:12px;
                font-weight:700;
                line-height:20px;
                border-radius: 0px 10px 0px 10px;
                text-align: center;
              }
              .colorTypeA{
                background: rgba(1,131,250,0.2);
                color:#0183FA;
              }
              .colorTypeB{
                background: #ECECEC;
                color:#A2A2A2;
              }
            }

          }
          .BGcolorTypeA{
            width:374px;
            height:60px;
            display: flex;
            position:relative;
            background: rgba(1,131,250,0.1);
            border-radius: 10px 10px 10px 10px;
            margin: 10px 0 0 0;
          }
          .BGcolorTypeB{
            width:374px;
            height:60px;
            display: flex;
            position:relative;
            background: #F5F5F5;
            border-radius: 10px 10px 10px 10px;
            margin: 10px 0 0 0;

          }
          .alarm-title-box{
            display: flex;
            p{
              line-height:60px;
              font-size:14px;
            }
            p:nth-child(1){
              flex:1;
            }
            p:nth-child(2){
              cursor: pointer;
            }
          }
        }
        /*智能门禁*/
        .bottom-entrance-box{
          flex: 1;
          background: #fff;
          width:424px;
          border-radius: 0 10px 10px 10px;
          .top-title{
            margin:16px 26px;
            display: flex;
            justify-content: space-between;
            >i{
              font-style: normal;
              line-height:18px;
              font-size:16px;
              color: #333;
              overflow:hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
          .entrance{
            width: 374px;
            height: 60px;
            display: flex;
            justify-content: flex-start;
            border-radius: 10px 10px 10px 10px;
            margin: 10px 0 0 26px;
            position: relative;
            .entrance_c{
              width: 30px;
              height: 30px;
              margin: 14px 20px 0px 14px;
            }
            .entrance_r{
              font-size: 14px;
              font-family: Microsoft YaHei-Regular, Microsoft YaHei;
              font-weight: 400;
              color: #333333;
              line-height: 60px;
            }
            .entrance_l_yes{
              width: 60px;
              height: 30px;
              background: #0183FA;
              border-radius: 0px 10px 0px 10px;
              font-size: 14px;
              font-weight: 400;
              color: #fff;
              line-height: 30px;
              text-align: center;
              position: absolute;
              top: 0;
              right: 0;
            }
            .entrance_l_no{
              width: 60px;
              height: 30px;
              background: #A2A2A2;
              border-radius: 0px 10px 0px 10px;
              font-size: 14px;
              font-weight: 400;
              color: #fff;
              line-height: 30px;
              text-align: center;
              position: absolute;
              top: 0;
              right: 0;
            }
          }
          .BGentrance_l_yes{
            background: rgba(1,131,250,0.1);
          }
          .BGentrance_l_no{
            background: #F5F5F5;
          }

        }
        .null-data-img{
          width:137px;
          height:137px;
          display: block;
          margin:10px auto;
        }
        .null-text-p{
          text-align: center;
          font-size:16px;
          color:#999;
          line-height:50px;
          margin:0 30px;
        }
      }
    }
  }
}
</style>
<style lang="scss">
.alarm-position-box{
  .switch .el-switch__label {
    position: absolute;
    display: none;
    color: #fff !important;
  }
  .switch .el-switch__label--right {
    z-index: 1;
  }
  .switch .el-switch__label--right span{
    margin-right: 9px;
  }
  .switch .el-switch__label--left {
    z-index: 1;
  }
  .switch .el-switch__label--left span{
    margin-left: 9px;
  }
  .switch .el-switch__label.is-active {
    display: block;
  }
  .switch.el-switch .el-switch__core{
    background-color: rgba(255,196,124)!important;
    border-color: rgba(255,196,124)!important;
  }
  .switch.el-switch .el-switch__core,
  .el-switch .el-switch__label {
    width: 68px !important;
    height:20px!important;
    line-height:30px!important;
    -webkit-border-radius: 20px!important;
    -moz-border-radius: 20px!important;
    border-radius: 20px!important;
    margin: 0;
    position: absolute;
    top: 0;

  }
  .switch .el-switch__label--left span{
    margin-left:22px!important;
    font-size: 12px;
    color: #fff;
    line-height: 20px;
    position: relative;
    top: -5px;
  }
  .switch .el-switch__label--right span{
    margin-left:5px!important;
    font-size: 12px;
    position: relative;
    top: -5px;
  }
  .el-switch__core:after{
    background: #FA8A01 !important;
    height:16px!important;
    width:16px!important;
    top:1px!important;
  }
  .el-switch.is-checked .el-switch__core::after{
    margin-left: -20px!important;
  }
  .el-switch{
    margin:10px auto 0;
    display: block;
    width:80px!important;
    height:4px!important;
  }
}

.subject-alarm-time{
  .el-table__empty-text{
    background-size: 45%;
  }
}

.checkItemLibrary-dialog-box{
  .teacher-import-dialog-upLoad-box{
    .el-upload{
      width:450px;
      margin:0 55px;
      .el-upload-dragger{
        width:450px;
        .el-icon-upload{
          font-size:100px;
          color:#CBE6FE;
        }
        .el-upload__text{
          margin-top:20px;
        }
      }
    }
    .el-upload__tip{
      margin-left:60px;
      font-size:14px;
      margin-top:10px;
    }
    .el-upload-text-box{
      background: #F5F5F5;
      border-radius: 10px;
      margin:15px 30px 0;
      padding:0 20px 15px;
      overflow: hidden;
      *{
        margin:0;
      }
      .img-text-box{
        display: flex;
        margin-top:15px;
        img{
          width:16px;
          height:16px;
          margin-right:13px;
        }
        p{
          height:16px;
          line-height:16px;
          font-size:12px;
        }
      }
      .text-p{
        margin-top:15px;
        margin-left:29px;
        height:16px;
        line-height:16px;
        font-size:12px;
      }
    }
  }
  .teacher-import-dialog-button-box{
    display: flex;
    width:190px;
    margin:0 auto;
    p{
      width:70px;
      height:30px;
      line-height:30px;
      font-size:14px;
      margin:0 auto;
    }
  }
  .teacher-import-dialog-position-box{
    width:100%;
    height:100%;
    position: absolute;
    top:0;
    left:0;
    z-index: 999;
    background: rgba(255,255,255,0.4);
    border-radius:20px;
  }
  .code-max-box{
    display: flex;
    .code-button-box{
      display: flex;
      flex-direction: column;
      margin-left:8px;
      p{
        width:40px;
        text-align: center;
        line-height:19px;
        font-size:14px;
        cursor: pointer;
        color:#d8d8d8;
      }
      p:nth-child(1){
        border:1px solid #d8d8d8;
        border-top-left-radius: 4px;
        border-top-right-radius: 4px;
      }
      p:nth-child(2){
        border-bottom:1px solid #d8d8d8;
        border-left:1px solid #d8d8d8;
        border-right:1px solid #d8d8d8;
        border-bottom-left-radius: 4px;
        border-bottom-right-radius: 4px;
      }
      p:hover{
        color:#fff;
        background-color: #d8d8d8;
      }
    }
  }
}
</style>
