<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="140px"
    >
      <!-- <el-form-item label="设备ID" prop="deviceId">
        <el-input
          v-model="queryParams.deviceId"
          placeholder="请输入设备ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场馆ID" prop="venueId">
        <el-input
          v-model="queryParams.venueId"
          placeholder="请输入场馆ID"
          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="MAC地址" prop="bssid">
        <el-input
          v-model="queryParams.bssid"
          placeholder="请输入MAC地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="WIFI名称" prop="ssid">
        <el-input
          v-model="queryParams.ssid"
          placeholder="请输入WIFI名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="是否非法" prop="isIllegal">
        <el-select
          v-model="queryParams.isIllegal"
          placeholder="请选择是否非法"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="数据采集时间" prop="time">
        <el-date-picker
          clearable
          v-model="daterangeRegisterTime"
          style="width: 240px"
          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="['biz:wifiInfo: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="['biz:wifiInfo: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="['biz:wifiInfo: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="['biz:wifiInfo:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="wifiInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="信息ID" align="center" prop="wifiInfoId" /> -->
      <el-table-column label="设备ID" align="center" prop="deviceId" />
      <el-table-column label="场馆名称" align="center" prop="venueName" />
      <el-table-column label="区域名称" align="center" prop="areaName" />
      <el-table-column label="MAC地址" align="center" prop="bssid" />
      <el-table-column label="WIFI名称" align="center" prop="ssid" />
      <el-table-column label="是否非法" align="center" prop="isIllegal">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.isIllegal"
          />
        </template>
      </el-table-column>
      <el-table-column label="关键字类型" align="center" prop="keyType" />
      <el-table-column
        label="数据采集时间"
        align="center"
        prop="time"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="认证页面" align="center" prop="authPage">
        <template slot-scope="scope">
          <el-button
            type="primary"
            v-if="scope.row.authPage"
            plain
            size="mini"
            @click="handleAuth(scope.row.authPage)"
            >查看</el-button
          >
        </template>
      </el-table-column>
      <!-- <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="['biz:wifiInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:wifiInfo: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"
    />

    <!-- 添加或修改WIFI信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="auth-cls">
        <el-form-item label="设备ID" prop="deviceId">
          <el-input v-model="form.deviceId" placeholder="请输入设备ID" />
        </el-form-item>
        <el-form-item label="场馆名称" prop="venueName">
          <el-input v-model="form.venueName" placeholder="请输入场馆ID" />
        </el-form-item>
        <el-form-item label="区域名称" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入区域ID" />
        </el-form-item>
        <el-form-item label="MAC地址" prop="bssid">
          <el-input v-model="form.bssid" placeholder="请输入MAC地址" />
        </el-form-item>
        <el-form-item label="WIFI名称" prop="ssid">
          <el-input v-model="form.ssid" placeholder="请输入WIFI名称" />
        </el-form-item>
        <el-form-item label="认证页面" prop="authPage">
          <!-- <el-input
            v-model="form.authPage"
            type="textarea"
            placeholder="请输入内容"
          /> -->
          <div v-html="form.authPage"></div>
        </el-form-item>
        <el-form-item label="是否非法" prop="isIllegal">
          <el-select v-model="form.isIllegal" placeholder="请选择是否非法">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据采集时间" prop="time">
          <el-date-picker
            clearable
            v-model="form.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择数据采集时间"
          >
          </el-date-picker>
        </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>
    <el-dialog
      title="认证"
      :visible.sync="openAuth"
      width="800px"
      append-to-body
    >
      <div v-html="dataAuth" class="auth-cls"></div>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitFormAuth">确 定</el-button> -->
        <el-button @click="cancelAuth">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listWifiInfo,
  getWifiInfo,
  delWifiInfo,
  addWifiInfo,
  updateWifiInfo,
} from "@/api/biz/wifiInfo";

export default {
  name: "WifiInfo",
  dicts: ["sys_yes_no"],
  data() {
    return {
       // 注册时间时间范围
       daterangeRegisterTime: [],
      openAuth: false, //认证
      dataAuth: "", //认证数据
      rulesAuth: {},
      formAuth: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // WIFI信息表格数据
      wifiInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceId: null,
        venueName: null,
        areaName: null,
        bssid: null,
        ssid: null,
        authPage: null,
        isIllegal: null,
        keyType: null,
        time: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleAuth(item) {
      this.openAuth = true;
      this.dataAuth = item;
    },
    submitFormAuth() {
      this.openAuth = false;
    },
    cancelAuth() {
      this.openAuth = false;
    },
    /** 查询WIFI信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.time = {};
      if (null != this.daterangeRegisterTime && '' != this.daterangeRegisterTime) {
        this.queryParams.time["beginRegisterTime"] = this.daterangeRegisterTime[0];
        this.queryParams.time["endRegisterTime"] = this.daterangeRegisterTime[1];
      }
      listWifiInfo(this.queryParams).then((response) => {
        this.wifiInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wifiInfoId: null,
        deviceId: null,
        venueName: null,
        areaName: null,
        bssid: null,
        ssid: null,
        authPage: null,
        isIllegal: null,
        keyType: null,
        time: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRegisterTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.wifiInfoId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加WIFI信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const wifiInfoId = row.wifiInfoId || this.ids;
      getWifiInfo(wifiInfoId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改WIFI信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.wifiInfoId != null) {
            updateWifiInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWifiInfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const wifiInfoIds = row.wifiInfoId || this.ids;
      this.$modal
        .confirm('是否确认删除WIFI信息编号为"' + wifiInfoIds + '"的数据项？')
        .then(function () {
          return delWifiInfo(wifiInfoIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "biz/wifiInfo/export",
        {
          ...this.queryParams,
        },
        `wifiInfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.auth-cls{
  height: 500px;
  overflow-y: auto;
}
</style>
