<template>
  <div class="box-center">
    <!-- 头 -->
    <div class="app-top">
      <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"
            clearable
            filterable
            collapse-tags
            v-model="searchForm.acceptanceStatus"
            placeholder="请选择"
          >
            <el-option
              v-for="item in equipmentStatusList"
              :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"
            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"
            multiple
            clearable
            collapse-tags
            v-model="searchForm.audioStatus"
            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"
            multiple
            clearable
            collapse-tags
            v-model="searchForm.uploadStatus"
            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"
            multiple
            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>
      <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>
      <div class="app-titel" style="margin-top: 15px">
        <!-- <div class="label" style="color: #ffffff">筛选相关：</div> -->
        <!-- <div style="margin-left: 20px">
          <el-button
            @click="Batchreturn()"
            type="primary"
            :disabled="multipleSelection.length == 0"
            >批量归还</el-button
          >
        </div> -->
        <div style="margin-left: 20px">
          <el-button
            @click="infoMasstransfer()"
            type="primary"
            v-if="equ_index_bind"
            :disabled="multipleSelection.length == 0"
            >批量绑定</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button
            @click="zkequipmentUnbind()"
            type="primary"
            v-if="equ_index_unbind"
            :disabled="multipleSelection.length == 0"
            >批量解绑</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button
            @click="infoBulkbinding()"
            v-if="euq_index_batch"
            type="primary"
            :disabled="multipleSelection.length == 0"
            >批量绑定批次号</el-button
          >
        </div>
        <div style="margin-left: 20px" v-if="equ_index_add">
          <el-button @click="infoadd()" type="primary">添加</el-button>
        </div>
        <div style="margin-left: auto;margin-right:10px;" v-if="euq_index_downLoad">
          <el-button @click="downLoad">导出</el-button>
        </div>
      </div>
    </div>

    <!-- 表格 -->
    <div class="cen-tab">
      <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="batchId" label="批次号" align="center">
        </el-table-column>
        <el-table-column prop="agentName" label="代理商" align="center">
        </el-table-column>
        <el-table-column prop="orgName" 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="userPhone" label="领用人手机" align="center">
        </el-table-column>
        <el-table-column prop="receiveType" label="领用状态" align="center">
          <template slot-scope="{ row }">
            {{
              row.receiveType == 1
                ? "未领用"
                : row.receiveType == 2
                ? "使用中"
                : "已归还"
            }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="date" label="在线状态" align="center">
        </el-table-column>
        <el-table-column prop="date" label="录音状态" align="center">
        </el-table-column>
        <el-table-column prop="name" label="上传状态" align="center">
        </el-table-column> -->
        <!-- <el-table-column
          prop="autoSwitch"
          label="自动转写开关"
          align="center"
          width="100"
        >
          <template slot-scope="{ row }">
            {{ row.autoSwitch == 0 ? "已关闭" : "已开启" }}
          </template>
        </el-table-column> -->
        <el-table-column
          prop="transliterationMethodName"
          label="转写方式"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="acceptanceStatus"
          label="设备状态"
          align="center"
        >
          <template slot-scope="{ row }">
            {{
              row.acceptanceStatus == 0
                ? "已验收"
                : row.acceptanceStatus == 1
                ? "未验收"
                : row.acceptanceStatus == 2
                ? "维修中"
                : row.acceptanceStatus == 3
                ? "更换中"
                : "已报损"
            }}
          </template>
        </el-table-column>

        <!-- <el-table-column prop="name" label="转写方式" align="center">
        </el-table-column> -->
        <!-- <el-table-column prop="name" label="开机指示灯" align="center">
        </el-table-column> -->
        <!-- <el-table-column
          prop="name"
          label="电池电量"
          width="200"
          align="center"
        >
          <template slot-scope="{ row }">
            <el-progress :percentage="80" :color="customColors"></el-progress>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="信号强度" align="center">
        </el-table-column>
        <el-table-column prop="name" label="待上传文件" align="center">
        </el-table-column>

        <el-table-column prop="name" label="更新时间" align="center">
        </el-table-column>
        <el-table-column prop="name" label="开机时间" align="center">
        </el-table-column>
        <el-table-column prop="name" label="关机时间" align="center">
        </el-table-column>
        <el-table-column prop="name" label="关机类型" align="center">
        </el-table-column> -->

        <el-table-column
          prop="createTime"
          label="添加时间"
          align="center"
          width="150"
        >
        </el-table-column>
        <!-- <el-table-column prop="name" label="购买时间" align="center">
        </el-table-column> -->
        <el-table-column
          prop="bindHouseTime"
          label="绑定项目时间"
          align="center"
          width="150"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="name"
          label="绑定代理时间"
          align="center"
          width="150"
        >
        </el-table-column> -->
        <!--  scope -->
        <el-table-column label="操作" align="center" fixed="right" width="200">
          <template slot-scope="{ row }">
            <!-- <el-button  v-if="row.receiveType == 2 && euq_index_back" type="text" @click="toinifoThereturn()">归还</el-button>
            <el-button  v-if="equ_index_change" type="text" @click="infotranscription()">转写方式</el-button>
            <el-button  v-if="equ_index_auto" type="text" @click="isAutoSwitch()">自动转写</el-button>
            <el-button  v-if="row.acceptanceStatus == 1 && equ_index_makeSure" type="text" @click="acceptance()">验收</el-button>
            <el-button  v-if="row.acceptanceStatus != (1 || 0) && euq_index_normal" type="text" @click="getRight()">恢复正常</el-button>
            <el-button  v-if="orgType == 0 && equ_index_bind&&row.receiveType!=2" type="text" @click="toinfobinding()">绑定</el-button>
            <el-button  v-if="equ_index_del&&row.receiveType!=2" type="text" @click="toinifodelete()">删除</el-button> -->

            <el-dropdown  v-if="(row.receiveType == 2 && euq_index_back)||equ_index_change||equ_index_auto||(row.acceptanceStatus == 1 && equ_index_makeSure)||(row.acceptanceStatus != (1 || 0) && euq_index_normal)||( equ_index_bind&&row.receiveType!=2)||(equ_index_del&&row.receiveType!=2)||(equ_index_ubind&&row.propertyId)" @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 && euq_index_back"
                  >归还</el-dropdown-item
                >

                  <el-dropdown-item
                  command="zhuanxeishezhi"
                  >转写设置</el-dropdown-item
                >
                <!-- <el-dropdown-item
                  command="infotranscription"
                  v-if="equ_index_change"
                  >转写方式</el-dropdown-item
                >
                <el-dropdown-item command="isAutoSwitch" v-if="equ_index_auto"
                  >自动转写</el-dropdown-item
                > -->
                <el-dropdown-item
                  command="acceptance"
                  v-if="row.acceptanceStatus == 1 && equ_index_makeSure"
                  >验收</el-dropdown-item
                >
                <!-- <el-dropdown-item
                  command="getRight"
                  v-if="row.acceptanceStatus != (1 || 0) && euq_index_normal"
                  >恢复正常</el-dropdown-item
                > -->
                <el-dropdown-item
                  command="toinfobinding"
                  v-if="equ_index_bind&&row.receiveType!=2&&!row.propertyId"
                  >绑定</el-dropdown-item
                >
                <el-dropdown-item
                  command="equipmentUnbind"
                  v-if="equ_index_ubind&&row.propertyId"
                  >解绑</el-dropdown-item
                >
                <!-- <el-dropdown-item command="infoeditor">修改</el-dropdown-item> -->
                <el-dropdown-item command="toinifodelete" v-if="equ_index_del&&row.receiveType!=2"
                  >删除</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="dialogVisible"
      @close="resetImei"
    >
      <el-form
        :model="addForm"
        label-position="labelPosition"
        ref="addForm"
        :rules="addRules"
        label-width="100px"
      >
        <el-form-item label="设备号" prop="imei">
          <el-input v-model="addForm.imei" style="width: 80%" maxlength="20" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="转写方式" prop="defaultTransliteration">
          <el-radio-group v-model="addForm.defaultTransliteration">
            <el-radio label="3">关闭转写</el-radio>
            <el-radio label="6">科大讯飞</el-radio>
            <el-radio label="9">思必驰</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <el-form-item label="批次号" prop="batchId">
          <el-select
            v-model="addForm.batchId"
            style="width: 80%"
            clearable
            filterable
            placeholder="请选择"
          >
            <el-option
              v-for="item in batchList"
              :key="item.id"
              :label="item.batchId"
              :value="item.batchId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            type="textarea"
            style="width: 80%"
            maxlength="50"
            show-word-limit
            v-model="addForm.remark"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" :loading="loadingFlag" @click="addEquipment()">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="编辑" :visible.sync="dialogVisible2">
      <el-form
        :model="editForm"
        label-position="labelPosition"
        ref="editForm"
        label-width="140px"
      >
        <el-form-item label="设备号" prop="imei">
          <el-input
            v-model="editForm.imei"
            maxlength="20"
            clearable
            style="width: 80%"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="设备状态" prop="acceptanceStatus">
          <el-radio-group v-model="editForm.acceptanceStatus">
            <el-radio label="0">正常</el-radio>
            <el-radio label="1">报损</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="报损原因"
          prop="desc"
          v-if="editForm.acceptanceStatus == 1"
        >
          <el-input
            type="textarea"
            style="width: 80%"
            v-model="editForm.desc"
            maxlength="50"
            show-word-limit
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="editor()">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="绑定" :visible.sync="dialogVisible3" @close="resetBind">
      <el-form
        :model="bindForm"
        label-position="labelPosition"
        ref="bindForm"
        :rules="bindRules"
        label-width="100px"
      >
        <!-- <el-form-item label="绑定" prop="choic">
          <el-radio-group v-model="bindForm.choic">
            <el-radio label="3">项目</el-radio>
            <el-radio label="6">代理商</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <el-form-item label="项目" prop="houseId">
          <el-select
            filterable
            clearable
            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-item label="备注：" prop="remark">
          <el-input
            type="textarea"
            style="width: 80%"
            v-model="bindForm.remark"
            maxlength="50"
            show-word-limit
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible3 = false">取 消</el-button>
        <el-button type="primary" @click="binding()">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="批量绑定批次号"
      width="40%"
      :visible.sync="dialogVisible4"
      @close="resetBatch"
    >
      <el-form
        :model="batchForm"
        label-position="labelPosition"
        ref="batchForm"
        label-width="140px"
        :rules="batchRules"
      >
        <el-form-item label="批次号" prop="batchId">
          <el-select
            v-model="batchForm.batchId"
            style="width: 80%"
            placeholder="请选择"
            filterable
            clearable

          >
            <el-option
              v-for="item in batchList"
              :key="item.id"
              :label="item.batchId"
              :value="item.batchId"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible4 = false">取 消</el-button>
        <el-button type="primary" @click="Bulkbinding()">保存</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="领用"
      :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-select
            v-model="receiveForm.batchId"
            style="width: 80%"
            placeholder="请选择"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.batchId"
              :value="item.batchId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="顾问" prop="batchId">
          <el-select
            v-model="receiveForm.houseList"
            style="width: 80%"
            placeholder="请选择"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.batchId"
              :value="item.batchId"
            >
            </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="转写设置"
      :visible.sync="receiveVisiblescd"
    >
     <div>
       <span>转写方式：</span>
        <el-radio-group v-model="radioindex" style="margin-left:30px;">
          <el-radio :label="0">关闭转写</el-radio>
          <el-radio :label="1">科大讯飞</el-radio>
          <el-radio :label="2">思必驰</el-radio>
        </el-radio-group>
     </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="receiveVisiblescd = false">取 消</el-button>
        <el-button type="primary" @click="shezhizhuanxei()">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { exportMethodPost} from "@/util/util";
export default {
  data() {
    return {
      time: [],
      changeValue: "",
      selflag: "1",
      searchForm: {
        name: "",
        imei: "", //设备号
        batchId: "", //批次号
        // equipmentType: "", //设备类型
        receiveType: "", //领用状态
        defaultTransliteration: "", //转写方式
        startDate: "", //开始时间
        endDate: "", //结束时间
        agentName: "", //代理商名称
        orgName: "", //公司名称
        houseName: "", //项目名称
        acceptanceStatus: "", //设备状态
        audioStatus: "", //录音状态
        uploadStatus: "", //上传状态
        offStatus: "", //关机状态
      },
      options: [],
      audioStatusList: [
        {
          value: true,
          label: "开启",
        },
        {
          value: false,
          label: "关闭",
        },
      ],
      uploadStatusList: [
        {
          value: true,
          label: "无上传",
        },
        {
          value: false,
          label: "上传中",
        },
      ],
      equipmentStatusList: [
        {
          value: "0",
          label: "已验收",
        },
        {
          value: "1",
          label: "未验收",
        },
      ],
      offStatusList: [
        {
          value: "1",
          label: "正常关机",
        },
        {
          value: "2",
          label: "低电关机",
        },
        {
          value: "3",
          label: "异常关机",
        },
      ],
      receiveTypeList: [
        {
          value: "1",
          label: "未领用",
        },
        {
          value: "2",
          label: "使用中",
        },
        {
          value: "3",
          label: "已归还",
        },
      ],
      currentPage: 1,
      size: 10,
      total: 10,
      value: "",
      input: "",
      orgType: localStorage.getItem("orgType"),
      tableData: [],
      houseList: [],
      batchList: [],
      dialogVisible: false,
      dialogVisible2: false,
      dialogVisible3: false,
      dialogVisible4: false,
      dialogVisible5: false,
      receiveVisible: false,
      loadingFlag:false,
      batchForm: {
        batchId: "",
        imeis: "",
      },
      ruleForm: {
        areaName: "",
        provinceItem: [],
      },
      addForm: {
        imei: "",
        // defaultTransliteration: "",
        batchId: "",
        remark: "",
      },
      bindForm: {
        remark: "",
        houseId: "",
        // choic: "3",
      },
      editForm: {
        imei: "123",
        desc: "",
        acceptanceStatus: "0",
      },
      receiveForm: {},
      receiveRules: {
        houseId: [{ required: true, message: "请选择项目", trigger: "blur" }],
        batchId: { required: true, message: "请选择顾问", trigger: "blur" },
      },
      batchRules: {
        batchId: { required: true, message: "请选择批次号", trigger: "blur" },
      },
      addRules: {
        imei: [{ required: true, message: "请填写设备号", trigger: "blur" }],
        batchId: { required: true, message: "请选择批次号", trigger: "blur" },
      },
      bindRules: {
        houseId: [{ required: true, message: "请选择项目", trigger: "blur" }],
      },
      multipleSelection: [],
      customColors: [
        { color: "#f56c6c", percentage: 20 },
        { color: "#e6a23c", percentage: 40 },
        { color: "#5cb87a", percentage: 60 },
        { color: "#1989fa", percentage: 80 },
        { color: "#6f7ad3", percentage: 100 },
      ],
      radioindex:'',
      radioindexid:'',
      receiveVisiblescd:false
    };
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  created() {
    this.equ_index_add = this.permissions["equ_index_add"];
    this.equ_index_bind = this.permissions["equ_index_bind"];
    this.equ_index_unbind = this.permissions["equ_index_unbind"];
    this.equ_index_ubind = this.permissions["equ_index_ubind"];
    this.equ_index_change = this.permissions["equ_index_change"];
    this.equ_index_auto = this.permissions["equ_index_auto"];
    this.equ_index_makeSure = this.permissions["equ_index_makeSure"];
    this.equ_index_del = this.permissions["equ_index_del"];
    this.euq_index_batch = this.permissions["euq_index_batch"];
    this.euq_index_back = this.permissions["euq_index_back"];
    this.euq_index_normal = this.permissions["euq_index_normal"];
    this.euq_index_downLoad = this.permissions["euq_index_downLoad"];
  },
  mounted() {
      if(this.$route.query.time){
      this.time=[this.$route.query.time,this.$route.query.time]
      this.searchForm.startDate = this.time[0];
      this.searchForm.endDate = this.time[1];
    }
    // 获取设备列表
    this.equipmentManagement();
    // 获取批次列表
    this.zkequipmentbatchList();
    // 获取列表
    this.zkhousePage();
  },
  methods: {
        downLoad(){
      let obj = {
         timeType:1,
          orgType: localStorage.getItem("orgType"),
          orgCode: localStorage.getItem("orgCode"),
          agentId: localStorage.getItem("agentId"),
          houseId: localStorage.getItem("houseId"),
          ...this.searchForm,
      };
      exportMethodPost('autoSR/zk/equipment/equipmentManagementExport','设备使用统计',obj)
    },
    //转写设置
    zhuanxeishezhi(row){
      this.radioindexid=row.id;
      this.radioindex=row.transliterationMethod;
      this.receiveVisiblescd=true;
    },
     //转写设置确认
    shezhizhuanxei(){
        this.$api.api.updateTranslationMethod({
          id:  this.radioindexid,
          transliterationMethod:this.radioindex,
        }).then((res) => {
          this.receiveVisiblescd=false;
          this.$message({
            type: "success",
            message: "修改成功!",
          });
          this.equipmentManagement();
        });
    },
    // 获取批次列表
    zkequipmentbatchList() {
      this.$api.api.zkequipmentbatchList().then((res) => {
        // console.log(res)
        this.batchList = res.data;
      });
    },
    handleCommand(e, row) {
      console.log(row);
      this[e](row);
    },
    receive(row) {
      this.receiveVisible = true;
      // this.bindForm.imeis = row.imei;
    },
    saveReceive() {},
    resetReceive() {},
    selChange() {
      this.changeValue = "";
      this.searchForm.imei = "";
      this.searchForm.batchId = "";
      this.searchForm.agentName = "";
      this.searchForm.orgName = "";
      this.searchForm.houseName = "";
    },
    selectChange(e) {
      this.searchForm.imei = "";
      this.searchForm.batchId = "";
      this.searchForm.agentName = "";
      this.searchForm.orgName = "";
      this.searchForm.houseName = "";
      if (!e) retun;
      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;
      }
    },
    reset() {
      this.changeValue = "";
      this.searchForm = {
        name: "",
        imei: "", //设备号
        batchId: "", //批次号
        // equipmentType: "", //设备类型
        receiveType: "", //领用状态
        defaultTransliteration: "", //转写方式
        startDate: "", //开始时间
        endDate: "", //结束时间
        agentName: "", //代理商名称
        orgName: "", //公司名称
        houseName: "", //项目名称
        acceptanceStatus: "", //设备状态
        audioStatus: "", //录音状态
        uploadStatus: "", //上传状态
        offStatus: "", //关机状态
      };
      this.currentPage = 1;
      this.equipmentManagement();
    },
    resetImei() {
      this.addForm = {
        imei: "",
        // defaultTransliteration: "",
        batchId: "",
        remark: "",
      };
     this.$refs.addForm.resetFields()
    },
    resetBind() {
      this.bindForm = {
        remark: "",
        houseId: "",
      };
    },
    houseChange(e) {
      console.log(e);
      let idx = this.houseList.findIndex((item) => item.id == e);
      if (idx != -1) {
        this.bindForm.orgCode = this.houseList[idx].orgCode;
      }
    },
    screen() {
      this.currentPage = 1;
      console.log(this.searchForm);
      this.equipmentManagement();
    },
    equipmentManagement() {
      this.$api.api
        .equipmentManagement({
          size: this.size,
          current: this.currentPage,
          timeType:1,
          orgType: localStorage.getItem("orgType"),
          orgCode: localStorage.getItem("orgCode"),
          agentId: localStorage.getItem("agentId"),
          houseId: localStorage.getItem("houseId"),
          ...this.searchForm,
        })
        .then((res) => {
          // console.log(res);
          this.tableData = res.data.records;
          this.total = res.data.total;
        });
    },
    //批量绑定
    infoBulkbinding() {
      this.dialogVisible4 = true;
    },
    resetBatch() {
      this.batchForm = {
        batchId: "",
        imeis: "",
      };
    },
    //批量绑定确认
    Bulkbinding() {
      this.$refs.batchForm.validate((valid) => {
        if (valid) {
          let arr = [];
          this.multipleSelection.map((item) => arr.push(item.imei));
          let obj = {
            batchId: this.batchForm.batchId,
            imeis: arr.join(","),
          };
          this.$api.api.zkequipmentBindBatchId(obj).then((res) => {
            console.log(res);
            this.$message.success("绑定成功");
            this.equipmentManagement();
            this.dialogVisible5 = false;
          });
        }
      });
      this.dialogVisible4 = false;
    },
    //批量转移
    infoMasstransfer() {
      this.dialogVisible5 = true;
    },
    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.equipmentManagement();
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消操作",
          // });
        });
    },
    equipmentUnbind(row){
      this.$confirm("确认解绑吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.api
            .zkequipmentUnbind({
              imeis: row.imei,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消操作",
          // });
        });
    },
    //批量转移确认
    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.equipmentbind(obj).then((res) => {
            console.log(res);
            this.$message.success("绑定成功");
            this.equipmentManagement();
            this.dialogVisible5 = false;
          });
        }
      });
    },
    timeChange(e) {
      if (e) {
        this.searchForm.startDate = e[0];
        this.searchForm.endDate = e[1];
      }
    },
    //批量归还
    Batchreturn() {
      this.$confirm("确认批量归还吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let str = [];
          this.multipleSelection.map((item) => {
            if (item.receiveType == 2) {
              str.push(item.imei);
            }
          });
          this.$api.api
            .equipmentUnbind({
              imeis: str.join(","),
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
    handleSelectionChange(val) {
      // this.multipleSelection = [];
      // val.map((item) => {
      //   this.multipleSelection.push(item.id);
      // });
      this.multipleSelection = val;
      console.log(this.multipleSelection);
    },
    //绑定
    toinfobinding(row) {
      if(row.receiveType==2){
        this.$message.warning('设备使用中不能删除')
        return
      }
      this.dialogVisible3 = true;
      this.bindForm.imeis = row.imei;
    },
    //确认绑定
    binding() {
      this.$refs.bindForm.validate((valid) => {
        if (valid) {
          console.log(this.bindForm);
          this.$api.api.equipmentbind(this.bindForm).then((res) => {
            console.log(res);
            this.$message.success("绑定成功");
            this.equipmentManagement();
            this.dialogVisible3 = false;
          });
        }
      });
    },
    //编辑
    infoeditor() {
      this.dialogVisible2 = true;
    },
    //确认编辑
    editor() {
      this.dialogVisible2 = false;
    },
    //新增
    infoadd() {
      this.dialogVisible = true;
    },
    zkhousePage() {
      this.$api.api
        .findHouseByUser({
          orgType: localStorage.getItem("orgType"),
          houseTypes:'0,1,2,3'
        })
        .then((res) => {
          // console.log(res)
          this.houseList = res.data;
          // this.searchForm.houseId = res.data[0].id;
          // 列表获取
          // this.correctFindbypage();
        });
    },
    //确认新增
    addEquipment() {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.loadingFlag=true
          console.log(this.addForm);
          this.$api.api.equipmentAdd(this.addForm).then((res) => {
            console.log(res);
            setTimeout(() => {
                  this.loadingFlag=false
                  console.log('防重')
                }, 1);
            this.$message.success("添加成功");
            this.dialogVisible = false;
            this.equipmentManagement();
          });
        }
      });
    },
    // 回复正常
    getRight(row) {
      this.$confirm("确认恢复么?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.api
            .backToNormal({
              id: row.id,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消",
          // });
        });
    },
    //验收
    acceptance(row) {
      this.$confirm("确认验收吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.api
            .equipmentAcceptance({
              imeis: row.imei,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "验收成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch((err) => {
          // this.$message({
          //   type: "info",
          //   message: "已取消验收",
          // });
          console.log(err);
        });
    },
    // 自动转写开关
    isAutoSwitch(row) {
      this.$confirm(
        `确认${row.autoSwitch == 0 ? "开启" : "关闭"}自动转写?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.$api.api
            .equipmentZxOn({
              id: row.id,
              autoSwitch: row.autoSwitch == 0 ? 1 : 0,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "修改成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消",
          // });
        });
    },
    // 转写开关
    infotranscription(row) {
      this.$confirm(
        `确认修改转写方式为${
          row.defaultTransliteration == 0 ? "思必驰" : "科大讯飞"
        }?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.$api.api.updateTranslationMethod({
              id: row.id,
              defaultTransliteration: row.defaultTransliteration == 0 ? 1 : 0,
            }).then((res) => {
              this.$message({
                type: "success",
                message: "修改成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消",
          // });
        });
    },
    //归还
    toinifoThereturn(row) {
      this.$confirm("确认归还吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.api
            .zkequipmentEquipmentBack({
              imeis: row.imei,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "归还成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消归还",
          // });
        });
    },
    //删除
    toinifodelete(row) {
      if(row.receiveType==2){
        this.$message.warning('设备使用中不能删除')
        return
      }
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.api
            .equipmentZxOnDelete({
              id: row.id,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.equipmentManagement();
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消删除",
          // });
        });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.size = val;
      this.equipmentManagement();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.equipmentManagement();
    },
  },
};
</script>

<style scoped="scoped" lang="scss" >
.box-center {
  width: 100%;
  padding: 15px;
  min-width: 1000px;
  padding-bottom: 100px;
}
.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>
