<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="所属公司ID" prop="companyId">-->
<!--        <el-input-->
<!--          v-model="queryParams.companyId"-->
<!--          placeholder="请输入所属公司ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属公司名" prop="companyName">-->
<!--        <el-input-->
<!--          v-model="queryParams.companyName"-->
<!--          placeholder="请输入所属公司名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属管理员ID" prop="userId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userId"-->
<!--          placeholder="请输入所属管理员ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属管理员名" prop="userName">-->
<!--        <el-input-->
<!--          v-model="queryParams.userName"-->
<!--          placeholder="请输入所属管理员名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="基站ID" prop="baseStationId">-->
<!--        <el-input-->
<!--          v-model="queryParams.baseStationId"-->
<!--          placeholder="请输入基站ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="序列号" prop="serialNumber">
        <el-input
          v-model="queryParams.serialNumber"
          placeholder="请输入序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类型" prop="deviceType">
        <el-select v-model="queryParams.deviceType" placeholder="请选择设备类型" clearable>
          <el-option
            v-for="dict in dict.type.mall_device_device_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备状态" prop="deviceStatus">
        <el-select v-model="queryParams.deviceStatus" placeholder="请选择设备状态" clearable>
          <el-option
            v-for="dict in dict.type.mall_device_device_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备开关" prop="deviceOpen">
        <el-select v-model="queryParams.deviceOpen" placeholder="请选择设备开关" clearable>
          <el-option
            v-for="dict in dict.type.mall_device_device_open"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备布防" prop="deviceDefence">
        <el-select v-model="queryParams.deviceDefence" placeholder="请选择设备布防" clearable>
          <el-option
            v-for="dict in dict.type.mall_device_device_defence"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="弹箱使用：0-未使用，1-已使用" prop="boxUse">-->
<!--        <el-select v-model="queryParams.boxUse" placeholder="请选择弹箱使用：0-未使用，1-已使用" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.mall_device_box_use"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="弹箱语音提示：0-不提示，1-提示" prop="boxVoice">-->
<!--        <el-select v-model="queryParams.boxVoice" placeholder="请选择弹箱语音提示：0-不提示，1-提示" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.mall_device_box_voice"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="弹箱触发：0-不触发，1-触发" prop="boxTrigger">-->
<!--        <el-select v-model="queryParams.boxTrigger" placeholder="请选择弹箱触发：0-不触发，1-触发" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.mall_device_box_trigger"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="电源工作情况" prop="batteryWork">-->
<!--        <el-input-->
<!--          v-model="queryParams.batteryWork"-->
<!--          placeholder="请输入电源工作情况"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="电源目前使用类型：0-内部电池，1-外部电池48V，2-外部220V" prop="batteryUseType">-->
<!--        <el-select v-model="queryParams.batteryUseType" placeholder="请选择电源目前使用类型：0-内部电池，1-外部电池48V，2-外部220V" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.mall_device_battery_use_type"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="电源目前使用" prop="batteryUse">-->
<!--        <el-input-->
<!--          v-model="queryParams.batteryUse"-->
<!--          placeholder="请输入电源目前使用"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="省份ID" prop="provinceId">-->
<!--        <el-input-->
<!--          v-model="queryParams.provinceId"-->
<!--          placeholder="请输入省份ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="省份名" prop="provinceName">-->
<!--        <el-input-->
<!--          v-model="queryParams.provinceName"-->
<!--          placeholder="请输入省份名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="城市ID" prop="cityId">-->
<!--        <el-input-->
<!--          v-model="queryParams.cityId"-->
<!--          placeholder="请输入城市ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="城市名" prop="cityName">-->
<!--        <el-input-->
<!--          v-model="queryParams.cityName"-->
<!--          placeholder="请输入城市名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="区县ID" prop="areaId">-->
<!--        <el-input-->
<!--          v-model="queryParams.areaId"-->
<!--          placeholder="请输入区县ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="区县名" prop="areaName">-->
<!--        <el-input-->
<!--          v-model="queryParams.areaName"-->
<!--          placeholder="请输入区县名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="地址" prop="address">-->
<!--        <el-input-->
<!--          v-model="queryParams.address"-->
<!--          placeholder="请输入地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="相关ID" prop="resId">-->
<!--        <el-input-->
<!--          v-model="queryParams.resId"-->
<!--          placeholder="请输入相关ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <!-- 时间筛选 -->
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateAt"
          size="small"
          style="width: 215px !important"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始"
          end-placeholder="结束"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mall:mallDevice:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mall:mallDevice:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mall:mallDevice:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['mall:mallDevice:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallDeviceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="设备主键ID" align="center" prop="deviceId" />-->
<!--      <el-table-column label="所属公司ID" align="center" prop="companyId" />-->
<!--      <el-table-column label="所属公司名" align="center" prop="companyName" />-->
<!--      <el-table-column label="所属管理员ID" align="center" prop="userId" />-->
<!--      <el-table-column label="所属管理员名" align="center" prop="userName" />-->
<!--      <el-table-column label="基站ID" align="center" prop="baseStationId" />-->
      <el-table-column label="基站名" align="center" prop="baseStationName" />
      <el-table-column label="序列号" align="center" prop="serialNumber" />
      <el-table-column label="设备类型" align="center" prop="deviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mall_device_device_type" :value="scope.row.deviceType"/>
        </template>
      </el-table-column>
      <el-table-column label="设备状态" align="center" prop="deviceStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mall_device_device_status" :value="scope.row.deviceStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="设备开关" align="center" prop="deviceOpen">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mall_device_device_open" :value="scope.row.deviceOpen"/>
        </template>
      </el-table-column>
      <el-table-column label="设备布防" align="center" prop="deviceDefence">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mall_device_device_defence" :value="scope.row.deviceDefence"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="语音喇叭警报内容" align="center" prop="hornContent" />-->
<!--      <el-table-column label="弹箱使用" align="center" prop="boxUse">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.mall_device_box_use" :value="scope.row.boxUse"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="弹箱语音提示" align="center" prop="boxVoice">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.mall_device_box_voice" :value="scope.row.boxVoice"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="弹箱触发：0-不触发，1-触发" align="center" prop="boxTrigger">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.mall_device_box_trigger" :value="scope.row.boxTrigger"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="电源工作情况" align="center" prop="batteryWork" />-->
<!--      <el-table-column label="电源目前使用类型：0-内部电池，1-外部电池48V，2-外部220V" align="center" prop="batteryUseType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.mall_device_battery_use_type" :value="scope.row.batteryUseType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="电源目前使用" align="center" prop="batteryUse" />-->
<!--      <el-table-column label="省份ID" align="center" prop="provinceId" />-->
<!--      <el-table-column label="省份名" align="center" prop="provinceName" />-->
<!--      <el-table-column label="城市ID" align="center" prop="cityId" />-->
<!--      <el-table-column label="城市名" align="center" prop="cityName" />-->
<!--      <el-table-column label="区县ID" align="center" prop="areaId" />-->
<!--      <el-table-column label="区县名" align="center" prop="areaName" />-->
<!--      <el-table-column label="地址" align="center" prop="address" />-->
<!--      <el-table-column label="相关ID" align="center" prop="resId" />-->
      <el-table-column label="创建时间" align="center" prop="createAt" />
<!--      <el-table-column label="修改时间" align="center" prop="updateAt" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mall:mallDevice:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mall:mallDevice:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
<!--        <el-form-item label="所属公司ID" prop="companyId">-->
<!--          <el-input v-model="form.companyId" placeholder="请输入所属公司ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="所属公司名" prop="companyName">-->
<!--          <el-input v-model="form.companyName" placeholder="请输入所属公司名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="所属管理员ID" prop="userId">-->
<!--          <el-input v-model="form.userId" placeholder="请输入所属管理员ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="所属管理员名" prop="userName">-->
<!--          <el-input v-model="form.userName" placeholder="请输入所属管理员名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="基站ID" prop="baseStationId">-->
<!--          <el-input v-model="form.baseStationId" placeholder="请输入基站ID" />-->
<!--        </el-form-item>-->
        <el-form-item label="基站" prop="baseStationId">
          <el-select
            v-model="form.baseStationId"
            placeholder="请选择基站"
          >
            <el-option
              v-for="item in baseStationList"
              :key="item.baseStationId"
              :label="item.baseStationName"
              :value="item.baseStationId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="序列号" prop="serialNumber">
          <el-input v-model="form.serialNumber" placeholder="请输入序列号" />
        </el-form-item>
        <el-form-item label="设备类型" prop="deviceType">
          <el-select v-model="form.deviceType" placeholder="请选择设备类型">
            <el-option
              v-for="dict in dict.type.mall_device_device_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="设备状态">-->
<!--          <el-radio-group v-model="form.deviceStatus">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.mall_device_device_status"-->
<!--              :key="dict.value"-->
<!--              :label="dict.value"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="设备开关">-->
<!--          <el-radio-group v-model="form.deviceOpen">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.mall_device_device_open"-->
<!--              :key="dict.value"-->
<!--              :label="dict.value"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="设备布防">-->
<!--          <el-radio-group v-model="form.deviceDefence">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.mall_device_device_defence"-->
<!--              :key="dict.value"-->
<!--              :label="dict.value"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="语音喇叭警报内容" prop="hornContent">-->
<!--          <el-input v-model="form.hornContent" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="弹箱使用：0-未使用，1-已使用">-->
<!--          <el-radio-group v-model="form.boxUse">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.mall_device_box_use"-->
<!--              :key="dict.value"-->
<!--              :label="dict.value"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="弹箱语音提示：0-不提示，1-提示">-->
<!--          <el-radio-group v-model="form.boxVoice">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.mall_device_box_voice"-->
<!--              :key="dict.value"-->
<!--              :label="dict.value"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="弹箱触发：0-不触发，1-触发">-->
<!--          <el-radio-group v-model="form.boxTrigger">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.mall_device_box_trigger"-->
<!--              :key="dict.value"-->
<!--              :label="dict.value"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="电源工作情况" prop="batteryWork">-->
<!--          <el-input v-model="form.batteryWork" placeholder="请输入电源工作情况" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="电源目前使用类型：0-内部电池，1-外部电池48V，2-外部220V" prop="batteryUseType">-->
<!--          <el-select v-model="form.batteryUseType" placeholder="请选择电源目前使用类型：0-内部电池，1-外部电池48V，2-外部220V">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.mall_device_battery_use_type"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="电源目前使用" prop="batteryUse">-->
<!--          <el-input v-model="form.batteryUse" placeholder="请输入电源目前使用" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="省份ID" prop="provinceId">-->
<!--          <el-input v-model="form.provinceId" placeholder="请输入省份ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="省份名" prop="provinceName">-->
<!--          <el-input v-model="form.provinceName" placeholder="请输入省份名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="城市ID" prop="cityId">-->
<!--          <el-input v-model="form.cityId" placeholder="请输入城市ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="城市名" prop="cityName">-->
<!--          <el-input v-model="form.cityName" placeholder="请输入城市名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="区县ID" prop="areaId">-->
<!--          <el-input v-model="form.areaId" placeholder="请输入区县ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="区县名" prop="areaName">-->
<!--          <el-input v-model="form.areaName" placeholder="请输入区县名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="地址" prop="address">-->
<!--          <el-input v-model="form.address" placeholder="请输入地址" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="相关ID" prop="resId">-->
<!--          <el-input v-model="form.resId" placeholder="请输入相关ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="创建时间" prop="createAt">-->
<!--          <el-input v-model="form.createAt" placeholder="请输入创建时间" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="修改时间" prop="updateAt">-->
<!--          <el-input v-model="form.updateAt" placeholder="请输入修改时间" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="删除标记：0-正常，1-删除" prop="delFlag">-->
<!--          <el-input v-model="form.delFlag" placeholder="请输入删除标记：0-正常，1-删除" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMallDevice, getMallDevice, delMallDevice, addMallDevice, updateMallDevice } from "@/api/mall/mallDevice";
import {getCompany} from "@/api/mall/mallCompany";
import {getBaseStation} from "@/api/mall/mallBaseStation";

export default {
  name: "MallDevice",
  dicts: ['mall_device_device_status','mall_device_device_open', 'mall_device_device_defence', 'mall_device_battery_use_type', 'mall_device_box_trigger', 'mall_device_box_use', 'mall_device_device_type', 'mall_device_box_voice'],
  data() {
    return {
      // 基站
      baseStationList: [],
      // 创建时间时间范围
      daterangeCreateAt: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备表格数据
      mallDeviceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        companyName: null,
        userId: null,
        userName: null,
        baseStationId: null,
        baseStationName: null,
        serialNumber: null,
        deviceType: null,
        deviceStatus: null,
        deviceOpen: null,
        deviceDefence: null,
        hornContent: null,
        boxUse: null,
        boxVoice: null,
        boxTrigger: null,
        batteryWork: null,
        batteryUseType: null,
        batteryUse: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        areaId: null,
        areaName: null,
        address: null,
        resId: null,
        createAt: null,
        updateAt: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getBaseStationList();
  },
  methods: {
    // 获取基站
    getBaseStationList() {
      getBaseStation().then((response) => {
        this.baseStationList = response.data.data;
      });
    },

    /** 查询设备列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateAt && "" != this.daterangeCreateAt) {
        this.queryParams.params["beginCreateAt"] = this.daterangeCreateAt[0];
        this.queryParams.params["endCreateAt"] = this.daterangeCreateAt[1];
      }
      listMallDevice(this.queryParams).then(response => {
        this.mallDeviceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deviceId: null,
        companyId: null,
        companyName: null,
        userId: null,
        userName: null,
        baseStationId: null,
        baseStationName: null,
        serialNumber: null,
        deviceType: null,
        deviceStatus: "0",
        deviceOpen: "0",
        deviceDefence: "0",
        hornContent: null,
        boxUse: "0",
        boxVoice: "0",
        boxTrigger: "0",
        batteryWork: null,
        batteryUseType: null,
        batteryUse: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        areaId: null,
        areaName: null,
        address: null,
        resId: null,
        createAt: null,
        updateAt: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateAt = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.deviceId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const deviceId = row.deviceId || this.ids
      getMallDevice(deviceId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.deviceId != null) {
            updateMallDevice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallDevice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const deviceIds = row.deviceId || this.ids;
      this.$modal.confirm('是否确认删除设备编号为"' + deviceIds + '"的数据项？').then(function() {
        return delMallDevice(deviceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mall/mallDevice/export', {
        ...this.queryParams
      }, `mallDevice_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
