<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item  prop="devTypeName">
        <el-select v-model="queryParams.devTypeName" placeholder="设备类型" clearable style="width: 100%;">
            <el-option
              v-for="dict in dict.type.sys_device_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item  prop="devName">
          <el-input
            v-model="queryParams.devName"
            placeholder="设备名称"
            clearable
            @keyup.enter.native="handleQuery"
            maxlength="20"
          />
        </el-form-item>
        <el-form-item  label="预警时间">
          <el-date-picker
          v-model="dateRange"
          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  prop="warnContent">
          <el-input
            v-model="queryParams.warnContent"
            placeholder="预警内容"
            clearable
            @keyup.enter.native="handleQuery"
            maxlength="20"
          />
        </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="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['basic:deviceLyRecord:export']"
        >导出数据</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="open" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableData" width="600px" height = "600px" >
      <el-table-column label="序号" align="center" width="80" type="index">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
        <el-table-column label="预警设备" align="center" prop="devTypeName" sortable/>
        <el-table-column label="设备名称" align="center" prop="devName" sortable/>
        <el-table-column label="预警时间" align="center" prop="warnTime" sortable/>
        <el-table-column label="预警内容" align="center" prop="warnContent" :show-overflow-tooltip='true' sortable/>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getListWarn"
      />

  </div>
</template>

<script>
import { ListWarn, exportWarnHistory} from "@/api/comprehensive/warnHistory";
import { downloadFile } from '@/utils/download'
import { getToken } from '@/utils/auth'
import uploadFile from '../../components/uploadFile.vue'
export default {
  name: "Post",
  dicts: ['sys_normal_disable','sys_device_type','sys_device_status'],
  components: {
    uploadFile
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备表格数据
      tableData: [],
      // 弹出层标题
      title: "",
      shxName:"shx",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        devTypeName:undefined,
        devName:undefined,
        warnContent:undefined,
      },
      // 表单参数
      form: {},
    };
  },
  computed: {

  },
  created() {
    this.getList();
    
  },
  mounted(){
    console.log(this.dict.type.sys_device_type)
  },
  methods: {

      /** 查询设备领用记录列表 */
      getList() {
          this.loading = true;
          ListWarn(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.tableData = response.rows;
            this.total = response.total;
            this.loading = false;
          });
      },

      // // 取消按钮
      // cancel() {
      //     this.open = false;
      //     this.reset();
      // },
      // // 表单重置
      // reset() {
      //     this.dateRange = [];
      //     // this.form = {};
      //     this.resetForm("form");
      //     this.handleQuery();
      // },
      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
          this.dateRange = [];
          this.resetForm("queryForm");
          this.handleQuery();
      },


     
      /** 导出按钮操作 */
      handleExport() {
        exportWarnHistory(this.queryParams).then(res => {
          downloadFile({ fileName: `预警历史记录_${new Date().getTime()}.xlsx`, fileData: res, fileType: 'application/vnd.ms-excel;charset=utf-8' })
        })
      },

  }
};
</script>

<style lang="scss" scoped>
::v-deep.el-table .fixed-width .el-button--mini {
    width: 60px !important;
    margin-bottom: 10px;
}
//隐藏图片上传框的css
::v-deep.disabled {
    .el-upload--picture-card {
        display: none;
    }
}
</style>