<template>
  <div class="box-center">
    <!-- 头 -->
    <div class="app-top">
      <div class="app-titel" style="margin-left: 15px" v-if="orgType!=3">
          <el-select
          v-model="houseTypes"
          @change="sysChange"
          style="width: 100px; margin-right: 10px"
          placeholder="请选择"
        >
          <el-option
            v-for="item in options2"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-select
          v-model="selValue"
          @change="selChange1"
          style="width: 100px"
          placeholder="请选择"
        >
          <el-option label="代理商" v-if="orgType == 0" value="0"></el-option>
          <el-option label="公司" v-if="orgType != 2" value="1"></el-option>
          <el-option label="楼盘" value="2"></el-option>
        </el-select>
        <!--  -->
        <div style="margin-left: 26px" v-if="selValue == 1">
          <el-select
            v-model="choicValue"
            @change="valuechange"
            placeholder="默认为全部"
            clearable
            filterable
          >
            <el-option
              v-for="item in dataList"
              :key="item.orgCode"
              :label="item.name"
              :value="item.orgCode"
            >
            </el-option>
          </el-select>
        </div>
        <!-- 楼盘 -->
        <div style="margin-left: 26px" v-else-if="selValue == 2">
          <el-select
            v-model="choicValue"
            @change="valuechange"
            placeholder="默认为全部"
            clearable
            filterable
          >
            <el-option
              v-for="item in dataList"
              :key="item.id"
              :label="item.propertyName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div style="margin-left: 26px" v-else>
          <el-select
            v-model="choicValue"
            @change="valuechange"
            clearable
            filterable
            placeholder="默认为全部"
          >
            <el-option
              v-for="item in dataList"
              :key="item.id"
              :label="item.agentName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="app-titel" style="margin-top: 5px">
        <div class="div-lab">
          <div class="label">更新时间：</div>
          <el-date-picker
            v-model="time"
            type="daterange"
            class="div-inp"
            range-separator="-"
            start-placeholder="开始日期"
            :default-time="['00:00:00', '23:59:59']"
            value-format="yyyy-MM-dd"
            end-placeholder="结束日期"
            @change="timeChange"
          >
          </el-date-picker>
        </div>

        <div class="div-lab">
          <el-input
            v-model="changeValue"
            clearable
            placeholder="请输入"
            maxlength="20"
            @change="selectChange"
            style="width: 363px"
          >
            <el-select
              v-model="selflag"
              slot="prepend"
              class="input-with-select"
              style="width: 115px"
              placeholder="请选择"
              @change="selChange"
            >
              <el-option label="设备编号" value="1"></el-option>
              <!-- <el-option label="版本号" value="2"></el-option> -->
              <!-- <el-option label="批次号" value="3"></el-option>
              <el-option label="代理商名称" value="4"></el-option>
              <el-option label="公司名称" value="5"></el-option> -->
              <el-option label="楼盘名称" value="6"></el-option>
            </el-select>
          </el-input>
        </div>

        <!-- <div class="div-lab">
          <div class="label">售出状态</div>
          <el-select
            class="div-inp"
            multiple
            clearable
            collapse-tags
            v-model="searchForm.keywordsId"
            placeholder="请选择"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div> -->

        <div class="div-lab">
          <div class="label">领用状态：</div>
          <el-select
            class="div-inp"
            clearable
            filterable
            collapse-tags
            v-model="searchForm.receiveType"
            placeholder="请选择"
          >
            <el-option
              v-for="item in receiveTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <div class="div-lab">
          <div class="label">在线状态：</div>
          <el-select
            class="div-inp"
            clearable
            filterable
            collapse-tags
            v-model="searchForm.onLine"
            placeholder="请选择"
          >
            <el-option
              v-for="item in onlineList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <div class="div-lab">
          <div class="label">录音状态：</div>
          <el-select
            class="div-inp"
            clearable
            filterable
            collapse-tags
            v-model="searchForm.recCmd"
            placeholder="请选择"
          >
            <el-option
              v-for="item in audioStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <!--<div class="div-lab">
          <div class="label">上传状态：</div>
          <el-select
            class="div-inp"
            filterable
            clearable
            collapse-tags
            v-model="searchForm.simAudioUploadStatus"
            placeholder="请选择"
          >
            <el-option
              v-for="item in uploadStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>-->

        <div class="div-lab">
          <div class="label">关机状态：</div>
          <el-select
            class="div-inp"
            filterable
            clearable
            collapse-tags
            v-model="searchForm.offStatus"
            placeholder="请选择"
          >
            <el-option
              v-for="item in offStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="div-lab">
          <div class="label">领用人：</div>
          <el-input type="text" v-model="searchForm.userName"></el-input>
        </div>
        <div class="div-lab">
          <div class="label">设备电量：</div>
          <el-input type="text" v-model="searchForm.electricity"></el-input>
        </div>
      </div>

      <!-- <div class="app-titel" style="margin-top: 15px">
        <div class="label">设备电量：</div>
        <div>
          <el-input v-model="value"></el-input>
        </div>
        <div class="label">是否在线：</div>
        <div>
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </div> -->
      <div class="app-titel" style="margin-top: 15px">
        <!-- <div class="label" style="color: #ffffff">筛选相关：</div> -->
        <div style="margin-left: 20px">
          <el-button type="primary" @click="screen"
            >筛选</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button @click="reset">清空筛选条件</el-button>
        </div>
        <div style="margin-left: 20px">
          <el-button
            @click="openAllLight()"
            type="primary"
            v-if="equ_state_open"
            :disabled="multipleSelection.length == 0"
            >批量开启指示灯</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button
            @click="closeAllLight()"
            type="primary"
             v-if="equ_state_off"
            :disabled="multipleSelection.length == 0"
            >批量关闭指示灯</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button
            @click="Batchreturn()"
            type="primary"
            v-if="equ_state_back"
            :disabled="multipleSelection.length == 0"
            >批量归还</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button
            @click="infoMasstransfer()"
            type="primary"
            v-if="equ_state_tranfer"
            :disabled="multipleSelection.length == 0"
            >批量转移</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button
            @click="zkequipmentUnbind()"
            type="primary"
            v-if="equ_state_unbind"
            :disabled="multipleSelection.length == 0"
            >批量解绑</el-button
          >
        </div>
        <div style="margin-left: auto;margin-right:10px;" v-if="equ_state_downLoad">
          <el-button @click="downLoad">导出</el-button>
        </div>
      </div>
    </div>

    <!-- 表格 -->
    <div class="cen-tab">
      <div class="tongji">
        在线设备：{{ onLineCount || 0 }} 正在工作设备：{{
          workingCount || 0
        }}
        离线设备：{{ offLineCount || 0 }}
      </div>
      <el-table
        :data="tableData"
        stripe
        @selection-change="handleSelectionChange"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column type="index" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="imei" label="设备编号" align="center">
        </el-table-column>
        <el-table-column prop="houseName" label="楼盘" align="center">
        </el-table-column>
        <el-table-column prop="userName" label="领用人" align="center">
        </el-table-column>
        <el-table-column prop="onLine" label="在线状态" align="center">
          <template slot-scope="{ row }">
            {{ row.onLine == 1 ? "在线" : "离线" }}
          </template>
        </el-table-column>
        <el-table-column prop="date" label="离线天数" align="center">
        </el-table-column>
        <el-table-column prop="recCmd" label="录音状态" align="center">
          <template slot-scope="{ row }">
            {{ row.recCmd=='start' ? "开启" : "关闭" }}
          </template>
        </el-table-column>
        <!--<el-table-column
          prop="simAudioUploadStatus"
          label="上传状态"
          align="center"
        >
          <template slot-scope="{ row }">
            {{ row.simAudioUploadStatus=='true' ? "上传中" : "无上传" }}
          </template>
        </el-table-column>-->
        <el-table-column prop="lightStatus" label="开机指示灯" align="center">
          <template slot-scope="{ row }">
            {{ row.lightStatus == "on" ? "开启" : "关闭" }}
          </template>
        </el-table-column>

        <el-table-column
          prop="name"
          label="电池电量"
          width="200"
          align="center"
        >
          <template slot-scope="{ row }">
            <el-progress
              :percentage="row.electricity / 1"
              :color="customColors"
            ></el-progress>
          </template>
        </el-table-column>
        <el-table-column prop="signalDevice" label="信号强度" align="center">
        </el-table-column>
        <el-table-column prop="fileCount" label="待上传文件" align="center">
        </el-table-column>
        <el-table-column
          width="150"
          prop="updateTime"
          label="更新时间"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="openTime"
          width="150"
          label="开机时间"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="closeTime"
          width="150"
          label="关机时间"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="offStatus" label="关机类型" align="center">
          <template slot-scope="{ row }">
            {{
              row.offStatus == 1
                ? "正常关机": row.offStatus == 2
                ? "低电关机":row.offStatus == 3? "异常关机":''
            }}
          </template>
        </el-table-column>
        <!--  scope -->
        <el-table-column label="操作" align="center" fixed="right" width="200">
          <template slot-scope="{ row }">
            <!-- <div style="color: #2671e2" @click="toinifoThereturn()">
              修改指示灯状态
            </div> -->
            <el-dropdown v-if="(row.receiveType==2&&equ_state_take)||(row.houseName&&equ_state_take)||equ_state_open||equ_state_WiFi||equ_state_Voice" @command="handleCommand($event, row)" trigger="click">
              <span style="color: #409eff; font-size: 12px; margin-left: 10px;cursor: pointer;">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <!-- <el-dropdown-item command="toinifoThereturn" v-if="row.receiveType == 2" >归还</el-dropdown-item> -->
                <el-dropdown-item command="toinifoThereturn" v-if="row.receiveType==2  &&equ_state_take"
                  >归还</el-dropdown-item
                >
                <el-dropdown-item command="receive" v-if="row.houseName&&equ_state_take&&row.receiveType!=2"
                  >领用</el-dropdown-item
                >
                <el-dropdown-item command="lightStatusChange"
                v-if="equ_state_open"
                  >{{
                    row.lightStatus == "on" ? "关闭" : "开启"
                  }}指示灯</el-dropdown-item
                >
                <el-dropdown-item v-if="equ_state_WiFi" command="wifiShow">WiFi管理</el-dropdown-item>
                <el-dropdown-item v-if="equ_state_Voice" command="voiceOpen">录音{{row.recCmd=='start'?'关闭':'开启'}}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 30, 50]"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog
      title="领用"
      :visible.sync="receiveVisible"
      @close="resetReceive"
    >
      <el-form
        :model="receiveForm"
        label-position="labelPosition"
        ref="receiveForm"
        :rules="receiveRules"
        label-width="100px"
      >
        <el-form-item label="楼盘" prop="batchId">
          <el-input
            v-model="receiveForm.bindHouseName"
            style="width: 80%"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="顾问" prop="batchId">
          <el-select
            v-model="receiveForm.accountId"
            style="width: 80%"
            placeholder="请选择"
          >
            <el-option
              v-for="item in userList"
              :key="item.accountId"
              :label="item.name"
              :value="item.accountId"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="receiveVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveReceive()">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="批量转移"
      width="40%"
      :visible.sync="dialogVisible5"
      @close="resetBind"
    >
      <el-form
        :model="bindForm"
        label-position="labelPosition"
        ref="allbindForm"
        :rules="bindRules"
        label-width="140px"
      >
        <el-form-item label="楼盘" prop="houseId">
          <el-select
            filterable
            v-model="bindForm.houseId"
            style="width: 80%"
            placeholder="请选择"
            @change="houseChange"
          >
            <el-option
              v-for="item in houseList"
              :key="item.id"
              :label="item.propertyName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible5 = false">取 消</el-button>
        <el-button type="primary" @click="Masstransfer()">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="WiFi管理" width="40%" :visible.sync="wifiVisible">
      <el-form
        :model="wifiForm"
        :rules="wifiRule"
        ref="wifiForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="设备号" prop="imei">
          <el-input v-model="wifiForm.imei" disabled></el-input>
        </el-form-item>
        <div>主WiFi</div>
        <el-form-item label="wifi名称" prop="masterWifiName">
          <el-input v-model="wifiForm.masterWifiName" maxlength="20" clearable></el-input>
        </el-form-item>
        <el-form-item label="wifi密码" prop="masterWifiPassword">
          <el-input
            v-model="wifiForm.masterWifiPassword"
            show-password
          ></el-input>
        </el-form-item>
        <div>备用一</div>
        <el-form-item label="wifi名称" prop="spareOneWifiName">
          <el-input v-model="wifiForm.spareOneWifiName" maxlength="20" clearable></el-input>
        </el-form-item>
        <el-form-item label="wifi密码" prop="spareOneWifiPassword">
          <el-input
            v-model="wifiForm.spareOneWifiPassword"
            show-password
          ></el-input>
        </el-form-item>
        <div>备用二</div>
        <el-form-item label="wifi名称" prop="spareTwoWifiName">
          <el-input v-model="wifiForm.spareTwoWifiName" maxlength="20" clearable></el-input>
        </el-form-item>
        <el-form-item label="wifi密码" prop="spareTwoWifiPassword">
          <el-input
            v-model="wifiForm.spareTwoWifiPassword"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="wifiVisible = false" type="primary"
            >取消</el-button
          >
          <el-button @click="wifiEdit">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { exportMethodPost} from "@/util/util";
export default {
  data() {
    return {
      options: [
        {
          value: "1",
          label: "全部",
        },
        {
          value: "2",
          label: "在线",
        },
        {
          value: "3",
          label: "离线",
        },
      ],
      onlineList: [
        {
          value: "0",
          label: "离线",
        },
        {
          value: "1",
          label: "在线",
        },
      ],
      audioStatusList: [
        {
          value: 'start',
          label: "开启",
        },
        {
          value: 'stop',
          label: "关闭",
        },
      ],
      uploadStatusList: [
        {
          value: false,
          label: "无上传",
        },
        {
          value: true,
          label: "上传中",
        },
      ],
      equipmentStatusList: [
        {
          value: "0",
          label: "已验收",
        },
        {
          value: "1",
          label: "未验收",
        },
        {
          value: "2",
          label: "维修中",
        },
        {
          value: "3",
          label: "更换中",
        },
        {
          value: "4",
          label: "已报损",
        },
      ],
      offStatusList: [
        {
          value: "1",
          label: "正常关机",
        },
        {
          value: "2",
          label: "低电关机",
        },
        {
          value: "3",
          label: "异常关机",
        },
      ],
      receiveTypeList: [
        {
          value: "1",
          label: "未领用",
        },
        {
          value: "2",
          label: "使用中",
        },
        {
          value: "3",
          label: "已归还",
        },
      ],
      options1: [],
      houseList: [],
      selValue:  localStorage.getItem("orgType") == 0
          ? "0"
          : localStorage.getItem("orgType") == 1
          ? "1"
          : "2",
      choicValue:'',
      dataList:[],
      searchForm: {
        name: "",
        imei: "", //设备号
        batchId: "", //批次号
        // equipmentType: "", //设备类型
        receiveType: "", //领用状态
        defaultTransliteration: "", //转写方式
        startDate: "", //开始时间
        endDate: "", //结束时间
        agentName: "", //代理商名称
        orgName: "", //公司名称
        houseName: "", //楼盘名称
        acceptanceStatus: "", //设备状态
        recCmd: "", //录音状态
        simAudioUploadStatus: "", //上传状态
        offStatus: "", //关机状态
        onLine: "",
        userName:'',
        electricity:''
      },
      bindRules: {
        houseId: [{ required: true, message: "请选择楼盘", trigger: "blur" }],
      },
      bindForm: {
        remark: "",
        houseId: "",
        // choic: "3",
      },
      wifiForm: {
        // imei:"",
        // masterWifiName:"",
        // masterWifiPassword:'',
        // spareOneWifiName:"",
        // spareOneWifiPassword:'',
        // spareTwoWifiName:'',
        // spareTwoWifiPassword:'',
      },
      receiveForm: {
        houseId: "",
        bindHouseName: "",
        accountId: "",
      },
      receiveRules: {},
      wifiRule: {
        masterWifiPassword: [
          { min: 8, max: 16, message: "长度在 8 到 16 位", trigger: "blur" },
        ],
        spareOneWifiPassword: [
          { min: 8, max: 16, message: "长度在 8 到 16 位", trigger: "blur" },
        ],
        spareTwoWifiPassword: [
          { min: 8, max: 16, message: "长度在 8 到 16 位", trigger: "blur" },
        ],
      },
      addRules: {
        houseId: [{ required: true, message: "请选择楼盘", trigger: "blur" }],
        batchId: { required: true, message: "请选择顾问", trigger: "blur" },
      },
      receiveVisible: false,
      currentPage: 1,
      size: 10,
      total: 10,
      value: "",
      input: "",
      time: [],
      selflag: "1",
      changeValue: "",
      tableData: [],
      multipleSelection: [],
      userList: [],
      onLineCount: "",
      offLineCount: "",
      workingCount: "",
      orgType: localStorage.getItem("orgType"),
      dialogVisible5: false,
      wifiVisible: false,
      customColors: [
        { color: "red", percentage: 20 },
        // { color: "#e6a23c", percentage: 40 },
        // { color: "#5cb87a", percentage: 60 },
        // { color: "#1989fa", percentage: 80 },
        { color: "#6f7ad3", percentage: 100 },
      ],
      options2: [
        {
          label: "正式数据",
          value: "0,1",
        },
        {
          label: "测试数据",
          value: "2,3",
        },
      ],
      houseTypes:'0,1'
    };
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  created() {
    this.equ_state_open = this.permissions["equ_state_open"];
    this.equ_state_off = this.permissions["equ_state_off"];
    this.equ_state_back = this.permissions["equ_state_back"];
    this.equ_state_tranfer = this.permissions["equ_state_tranfer"];
    this.equ_state_unbind = this.permissions["equ_state_unbind"];
    this.equ_state_take = this.permissions["equ_state_take"];
    this.equ_state_WiFi = this.permissions["equ_state_WiFi"];
    this.equ_state_Voice = this.permissions["equ_state_Voice"];
    this.equ_state_downLoad = this.permissions["equ_state_downLoad"];
  },
  mounted() {
   if(this.$route.query.flag){
    if(this.$route.query.flag==1){
      this.searchForm.onLine='0';
    }else{
      this.searchForm.onLine='1';
       this.searchForm.electricity=this.$route.query.electricity
    }

   }
    // asd
    this.getList();
    // 获取列表
    this.zkhousePage();
  },
  methods: {
        downLoad(){
      let obj = {
          timeType:2,
          agentId: localStorage.getItem("orgType")==1?localStorage.getItem("agentId"):this.selValue == 0 ? this.choicValue : null,
          orgCode: localStorage.getItem("orgType")==2?localStorage.getItem("orgCode"):this.selValue == 1 ? this.choicValue : null,
          houseId: localStorage.getItem("orgType")==3?localStorage.getItem("houseId"):this.selValue == 2 ? this.choicValue : null,
          orgType: localStorage.getItem("orgType"),
          queryOrgType:this.selValue/1+1,
          ...this.searchForm,
          houseTypes: this.houseTypes,
      };
      exportMethodPost('autoSR/zk/equipment/pageExport','设备监控',obj)
    },
    sysChange(){
      this.choicValue=''
      this.selValue='0'
      this.getList()
    },
    selChange1() {
      this.choicValue = "";
      this.getList();
    },
        getList() {
      console.log(this.selValue);
      // 当为楼盘选择时
      if (this.selValue == 1) {
        this.$api.api
          .findMyOrg({
            orgType: localStorage.getItem("orgType"),
            agentId: localStorage.getItem("agentId"),
          })
          .then((res) => {
            this.dataList = res.data;
            this.getTableList();
          });
      } else if (this.selValue == 2) {
        this.$api.api
          .findHouseByUser({
            orgType: localStorage.getItem("orgType"),
            houseId: localStorage.getItem("houseId"),
            houseTypes: this.houseTypes,
          })
          .then((res) => {
            this.dataList = res.data;
            this.getTableList();
          });
      } else {
        this.$api.api
          .findMyAgent({
            orgType: localStorage.getItem("orgType"),
          })
          .then((res) => {
            this.dataList = res.data;
            this.getTableList();
          });
      }
    },
    // wifi
    wifiShow(row) {
      this.wifiVisible = true;
      // 获取wifi数据
      this.wifiFindById(row.id);
    },
    //
    wifiFindById(id) {
      this.$api.api
        .wifiFindById({
          id,
        })
        .then((res) => {
          this.wifiForm = {
            imei: res.data.imei,
            masterWifiName: res.data.masterWifiName,
            masterWifiPassword: res.data.masterWifiPassword,
            spareOneWifiName: res.data.spareOneWifiName,
            spareOneWifiPassword: res.data.spareOneWifiPassword,
            spareTwoWifiName: res.data.spareTwoWifiName,
            spareTwoWifiPassword: res.data.spareTwoWifiPassword,
          };
          if (!res.data.receiveType) {
            this.wifiForm.id = res.data.id;
          }
        });
    },
    wifiEdit() {
      // console.log(this.wifiForm);
      // return
      this.$refs.wifiForm.validate((valid) => {
        if (valid) {
          if (
            this.wifiForm.masterWifiName &&
            !this.wifiForm.masterWifiPassword
          ) {
            this.$message.warning("请检查主WiFi密码是否填写");
            return;
          }
          if (
            this.wifiForm.spareOneWifiName &&
            !this.wifiForm.spareOneWifiPassword
          ) {
            this.$message.warning("请检查备用一密码是否填写");
            return;
          }
          if (
            this.wifiForm.spareTwoWifiName &&
            !this.wifiForm.spareTwoWifiPassword
          ) {
            this.$message.warning("请检查备用二密码是否填写");
            return;
          }
          this.$api.api.wifiUpdate(this.wifiForm).then((res) => {
            // console.log(res);
            this.$message.success("修改成功");
            this.wifiVisible = false;
          });
        }
      });
    },
    resetWifi() {},
    getTableList() {
      this.$api.api
        .equipmentZxOnFindByPage({
          size: this.size,
          current: this.currentPage,
          timeType:2,
          // orgType: localStorage.getItem("orgType"),
          // orgCode: localStorage.getItem("orgCode"),
          // agentId: localStorage.getItem("agentId"),
          // houseId: localStorage.getItem("houseId"),
          agentId: localStorage.getItem("orgType")==1?localStorage.getItem("agentId"):this.selValue == 0 ? this.choicValue : null,
          orgCode: localStorage.getItem("orgType")==2?localStorage.getItem("orgCode"):this.selValue == 1 ? this.choicValue : null,
          houseId: localStorage.getItem("orgType")==3?localStorage.getItem("houseId"):this.selValue == 2 ? this.choicValue : null,
          orgType: localStorage.getItem("orgType"),
          queryOrgType:this.selValue/1+1,
          ...this.searchForm,
          houseTypes: this.houseTypes,
        })
        .then((res) => {
          // console.log(res);
          let newlist=res.data.list.records;
          newlist.map(item=>{
            let num=this.ascformatDate(item.updateTime)
							if(num>12){
								item.electricity=0;
                item.signalDevice=0;
							}
          })
          this.tableData = newlist;
          this.onLineCount = res.data.onLineCount;
          this.offLineCount = res.data.offLineCount;
          this.workingCount = res.data.workingCount;
          this.total = res.data.list.total;
        });
    },
    valuechange() {
      this.getTableList();
    },
    ascformatDate(dateTimeStamp){
				let newDate = new Date(dateTimeStamp.replace(/-/g, '/')).getTime();
				let minute = 1000 * 60;
				let hour = minute * 60;
				let day = hour * 24;
				let halfamonth = day * 15;
				let month = day * 30;
				let now = new Date().getTime();
				let diffValue = now - newDate;
				let result =diffValue/hour;
				return result;
			},
    //批量
    Batchreturn() {
      this.$confirm("确认批量归还吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let str = [];
          this.multipleSelection.map((item) => {
            str.push(item.imei);
          });
          this.$api.api
            .zkequipmentEquipmentBack({
              imeis: str.join(","),
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "批量归还成功!",
              });
              this.getTableList();
            });
        })
        .catch(() => {

        });
    },
    zkequipmentUnbind() {
      this.$confirm("确认批量解绑吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let str = [];
          this.multipleSelection.map((item) => {
            if (item.receiveType != 2) {
              str.push(item.imei);
            }
          });
          console.log(str);
          this.$api.api
            .zkequipmentUnbind({
              imeis: str.join(","),
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: res.msg,
              });
              this.getTableList();
            });
        })
        .catch(() => {

        });
    },
    zkhousePage() {
      this.$api.api
        .findHouseByUser({
          orgType: localStorage.getItem("orgType"),
        })
        .then((res) => {
          // console.log(res)
          this.houseList = res.data;
          // this.searchForm.houseId = res.data[0].id;
          // 列表获取
          // this.correctFindbypage();
        });
    },
    //批量转移
    infoMasstransfer() {
      this.dialogVisible5 = true;
    },
    houseChange(e) {
      console.log(e);
      let idx = this.houseList.findIndex((item) => item.id == e);
      if (idx != -1) {
        this.bindForm.orgCode = this.houseList[idx].orgCode;
      }
    },
    Masstransfer() {
      this.$refs.allbindForm.validate((valid) => {
        if (valid) {
          console.log(this.bindForm);
          let arr = [];
          this.multipleSelection.map((item) => arr.push(item.imei));
          let obj = {
            houseId: this.bindForm.houseId,
            orgCode: this.bindForm.orgCode,
            imeis: arr.join(","),
          };
          this.$api.api.zkequipmentBind(obj).then((res) => {
            console.log(res);
            this.$message.success("绑定成功");
            this.getTableList();
            this.dialogVisible5 = false;
          });
        }
      });
    },
    resetBind() {
      this.bindForm = {
        remark: "",
        houseId: "",
      };
    },
    screen() {
      this.currentPage = 1;
      // console.log(this.searchForm);
      this.getTableList();
    },
    reset() {
      this.changeValue = "";
      this.searchForm = {
        name: "",
        imei: "", //设备号
        batchId: "", //批次号
        // equipmentType: "", //设备类型
        receiveType: "", //领用状态
        defaultTransliteration: "", //转写方式
        startDate: "", //开始时间
        endDate: "", //结束时间
        agentName: "", //代理商名称
        orgName: "", //公司名称
        houseName: "", //楼盘名称
        acceptanceStatus: "", //设备状态
        recCmd: "", //录音状态
        simAudioUploadStatus: "", //上传状态
        offStatus: "", //关机状态
        onLine: "",
        userName:'',
        electricity:''
      };
      this.time=[]
      this.currentPage = 1;
      this.getTableList();
    },
    receive(row) {
      this.receiveVisible = true;
      // this.bindForm.imeis = row.imei;
      this.receiveForm.houseId = row.propertyId;
      this.receiveForm.bindHouseName = row.bindHouseName;
      this.receiveForm.imei = row.imei;
      this.getUserByHouseId(row.propertyId);
    },
    saveReceive() {
      this.$refs.receiveForm.validate((valid) => {
        if (valid) {
          this.$api.api.equipmentReceiving(this.receiveForm).then((res) => {
            // console.log(res);
            this.receiveVisible = false;
            this.getTableList();
            this.$message({
              type: "success",
              message: "领用成功!",
            });
          });
        }
      });
    },
    resetReceive() {
      this.receiveForm = {
        houseId: "",
        bindHouseName: "",
        accountId: "",
      };
    },
    handleCommand(e, row) {
      console.log(row);
      this[e](row);
    },
    // 顾问列表
    getUserByHouseId(houseId) {
      this.$api.api
        .getUserByHouseId({
          houseId,
        })
        .then((res) => {
          // console.log(res);
          this.userList = res.data;
        });
    },
    voiceOpen(row){
        this.$confirm(
        `确认${row.recCmd == "start" ? "关闭" : "开启"}录音吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.$api.api
            .audioStatusControl({
              imei: row.imei,
              recCmd: row.recCmd == "start" ? "stop" : "start",
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.getTableList();
            });
        })
        .catch(() => {
        });
    },
    // 指示灯开启关闭
    lightStatusChange(row) {
      this.$confirm(
        `确认${row.lightStatus == "on" ? "关闭" : "开启"}指示灯吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.$api.api
            .batchOperateIndicator({
              imeis: row.imei,
              lightStatus: row.lightStatus == "on" ? "off" : "on",
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.getTableList();
            });
        })
        .catch(() => {
        });
    },
    openAllLight() {
      this.$confirm(`确认开启指示灯吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let str = [];
          this.multipleSelection.map((item) => {
            str.push(item.imei);
          });
          this.$api.api
            .batchOperateIndicator({
              imeis: str.join(","),
              lightStatus: "on",
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.getTableList();
            });
        })
        .catch(() => {
        });
    },
    closeAllLight() {
      this.$confirm(`确认关闭指示灯吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let str = [];
          this.multipleSelection.map((item) => {
            str.push(item.imei);
          });
          this.$api.api
            .batchOperateIndicator({
              imeis: str.join(","),
              lightStatus: "off",
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.getTableList();
            });
        })
        .catch(() => {
        });
    },
    //归还
    toinifoThereturn(row) {
      this.$confirm("确认归还吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.api
            .zkequipmentEquipmentBack({
              imeis: row.imei,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "归还成功!",
              });
              this.getTableList();
            });
        })
        .catch(() => {

        });
    },
    timeChange(e) {
      if (e) {
        this.searchForm.startDate = e[0];
        this.searchForm.endDate = e[1];
      }else{
        this.searchForm.startDate = '';
        this.searchForm.endDate ='';
      }
    },
    selChange() {
      this.changeValue = "";
      this.searchForm.imei = "";
      this.searchForm.batchId = "";
      this.searchForm.agentName = "";
      this.searchForm.orgName = "";
      this.searchForm.houseName = "";
      this.searchForm.userName=''
    },
    selectChange(e) {
      this.searchForm.imei = "";
      this.searchForm.batchId = "";
      this.searchForm.agentName = "";
      this.searchForm.orgName = "";
      this.searchForm.houseName = "";
      this.searchForm.userName=''
      if (!e) return;
      if (this.selflag == 1) {
        // 设备编号
        this.searchForm.imei = e;
      }
      if (this.selflag == 3) {
        // 批次号
        this.searchForm.batchId = e;
      }
      if (this.selflag == 4) {
        // 代理商名称
        this.searchForm.agentName = e;
      }
      if (this.selflag == 5) {
        // 公司名称
        this.searchForm.orgName = e;
      }
      if (this.selflag == 6) {
        // 楼盘名称
        this.searchForm.houseName = e;
      }
    },
    // //批量归还
    // toinifoThereturn() {
    //   this.$confirm("确认更改吗?", "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //   })
    //     .then(() => {
    //       this.$message({
    //         type: "success",
    //         message: "更改成功!",
    //       });
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "更改归还",
    //       });
    //     });
    // },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.size = val;
      this.getTableList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getTableList();
    },
  },
};
</script>

<style scoped="scoped" lang="scss" >
.box-center {
  width: 100%;
  padding: 15px;
  min-width: 1000px;
  padding-bottom: 100px;
}
.tongji {
  padding-bottom: 10px;
  font-size: 16px;
  color: red;
}
.cen-tab {
  width: 100%;
  padding: 15px;
  background: #ffffff;
  margin-top: 15px;
}
.tophove {
  color: #ffffff;
  background: #2671e2;
}
.app-top {
  width: 100%;
  background: #ffffff;
  box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  padding-top: 15px;
  padding-bottom: 15px;
  .app-titel {
    width: 100%;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    .label {
      font-size: 14px;
      font-weight: 400;
      color: #32363d;
      line-height: 32px;
      margin-left: 15px;
      min-width: 78px;
    }
    .toptimeqhuan {
      height: 30px;
      background: #ffffff;
      display: flex;
      align-items: center;
    }
    .toptimeqhuan div {
      padding-left: 20px;
      padding-right: 20px;
      text-align: center;
      line-height: 30px;
      font-size: 14px;
      margin-right: 15px;
      border-radius: 4px;
      border: 1px solid #e0e0e0;
    }
  }
}
.div-lab {
  display: flex;
  margin: 5px;
}
.div-inp {
  width: 250px;
}
</style>
