<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <!-- <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="mac">
        <el-input
          v-model="queryParams.mac"
          placeholder="请输入MAC地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="蓝牙名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入蓝牙名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件名" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="文件地址" prop="filePath">
        <el-input
          v-model="queryParams.filePath"
          placeholder="请输入文件地址"
          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:bluetoothINfo: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:bluetoothINfo: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:bluetoothINfo: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:bluetoothINfo:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="bluetoothINfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="信息ID" align="center" prop="bInfoId" /> -->
      <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="mac" />
      <el-table-column label="蓝牙名称" align="center" prop="name" />
      <el-table-column label="文件名" align="center" prop="fileName">
        <template slot-scope="scope">
        <a @click="fujian(scope.row.filePath,scope.row.fileName)" style="color: #46A6FF;" target="_blank">{{ scope.row.fileName }}</a>
      </template>
      </el-table-column>
      <!-- <el-table-column label="文件地址" align="center" prop="filePath" /> -->
      <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"
        class-name="small-padding fi下载ed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:bluetoothINfo:edit']"
            >修改</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:bluetoothINfo: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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <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="请输入场馆名称" />
        </el-form-item>
        <el-form-item label="区域名称" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入区域名称" />
        </el-form-item>
        <el-form-item label="MAC地址" prop="mac">
          <el-input v-model="form.mac" placeholder="请输入MAC地址" />
        </el-form-item>
        <el-form-item label="蓝牙名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入蓝牙名称" />
        </el-form-item>
        <el-form-item label="文件名" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名" />
        </el-form-item>
        <el-form-item label="文件地址" prop="filePath">
          <el-input v-model="form.filePath" placeholder="请输入文件地址" />
        </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>
  </div>
</template>

<script>
import {
  listBluetoothINfo,
  getBluetoothINfo,
  delBluetoothINfo,
  addBluetoothINfo,
  updateBluetoothINfo,
} from "@/api/biz/bluetoothINfo";

export default {
  name: "BluetoothINfo",
  dicts: ["sys_yes_no"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      daterangeRegisterTime: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 蓝牙信息表格数据
      bluetoothINfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceId: null,
        venueName: null,
        areaName: null,
        mac: null,
        name: null,
        fileName: null,
        filePath: null,
        isIllegal: 'Y',
        keyType: null,
        time: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        mac: [{ required: true, message: "MAC地址不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
     
  },
  mounted(){
  },
  methods: {
    fujian(dizhi,name){
      console.log('dizhi', dizhi)
      const link = document.createElement('a');
        link.href =dizhi?dizhi:''
        link.setAttribute('download',name);
        link.setAttribute('target', '_blank'); // 新增代码
        document.body.appendChild(link);
        link.click();
    },
    /** 查询蓝牙信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (
        null != this.daterangeRegisterTime &&
        "" != this.daterangeRegisterTime
      ) {
        this.queryParams.params["beginTime"] =
          this.daterangeRegisterTime[0];
        this.queryParams.params["endTime"] =
          this.daterangeRegisterTime[1];
      }
      listBluetoothINfo(this.queryParams).then((response) => {
        this.bluetoothINfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bInfoId: null,
        deviceId: null,
        venueName: null,
        areaName: null,
        mac: null,
        name: null,
        fileName: null,
        filePath: 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.bInfoId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加蓝牙信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const bInfoId = row.bInfoId || this.ids;
      getBluetoothINfo(bInfoId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改蓝牙信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.bInfoId != null) {
            updateBluetoothINfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBluetoothINfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const bInfoIds = row.bInfoId || this.ids;
      this.$modal
        .confirm('是否确认删除蓝牙信息编号为"' + bInfoIds + '"的数据项？')
        .then(function () {
          return delBluetoothINfo(bInfoIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "biz/bluetoothINfo/export",
        {
          ...this.queryParams,
        },
        `bluetoothINfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
