<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="设备类型" prop="patrolType">
        <el-select v-model="queryParams.patrolType" placeholder="请选择设备类型"
                   @change="handleQuery">
          <el-option
            v-for="dict in dict.type.patrol_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="记录时间" prop="createdate">
        <el-date-picker v-model="queryParams.createdate"
                        clearable
                        placeholder="请选择记录时间"
                        type="month"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @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
          v-hasPermi="['patrol:issues:export']"
          icon="el-icon-download"
          plain
          size="mini"
          type="warning"
          @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="issuesList" :height="clientHeight" border>
      <el-table-column align="center" label="设备类型" prop="patrolType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.patrol_type" :value="scope.row.patrolType"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备描述" prop="devDescribe"/>
      <el-table-column align="center" label="处理状态" prop="status">
        <template slot-scope="scope">
          {{ getStatus(scope.row.status) }}
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['patrol:issues:edit']"
            icon="el-icon-top-right"
            size="mini"
            type="text"
            @click="toLink(scope.row.patrolType,scope.row.linkId)"
          >查看问题详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

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

  </div>
</template>

<script>
import {listIssues} from "@/api/patrol/patrol/issues";

export default {
  dicts: ['patrol_type'],
  name: "Issues",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 页面高度
      clientHeight: 300,
      // 总条数
      total: 0,
      // 检查问题记录表格数据
      issuesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        linkId: null,
        patrolType: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        remarks: null,
        deptId: null
      },
      // 表单校验
      rules: {}
    };
  },
  created() {
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = document.body.clientHeight - 270
    });
    this.getList();
  },
  methods: {
    toLink(patrolType, id) {
      switch (patrolType) {
        case '1':
          this.$router.push({
            path: '/record/fire/annihilator',
            query: {id: id}
          });
          break;
        case '2':
          this.$router.push({
            path: '/record/fire/cannon',
            query: {id: id}
          });
          break;
        case '3':
          this.$router.push({
            path: '/record/fire/postFire',
            query: {id: id}
          });
          break;
        case '4':
          this.$router.push({
            path: '/record/fire/hoseBox',
            query: {id: id}
          });
          break;
        case '5':
          this.$router.push({
            path: '/record/fire/standpipe',
            query: {id: id}
          });
          break;
        case '6':
          this.$router.push({
            path: '/record/fire/sprinkler',
            query: {id: id}
          });
          break;
        case '7':
          this.$router.push({
            path: '/record/emergency/cabinet',
            query: {id: id}
          });
          break;
        case '8':
          this.$router.push({
            path: '/record/fire/alarm',
            query: {id: id}
          });
          break;
        case '9':
          this.$router.push({
            path: '/record/fire/shield',
            query: {id: id}
          });
          break;
        case '10':
          this.$router.push({
            path: '/record/emergency/paga',
            query: {id: id}
          });
          break;
        case '11':
          this.$router.push({
            path: '/record/emergency/cctv',
            query: {id: id}
          });
          break;
        case '12':
          this.$router.push({
            path: '/record/emergency/eyewash',
            query: {id: id}
          });
          break;
        case '13':
          this.$router.push({
            path: '/record/fire/sandbox',
            query: {id: id}
          });
          break;
        case '14':
          this.$router.push({
            path: '/record/fire/door',
            query: {id: id}
          });
          break;
        case '15':
          this.$router.push({
            path: '/record/fire/weathervane',
            query: {id: id}
          });
          break;
        case '16':
          this.$router.push({
            path: '/record/fire/curtain',
            query: {id: id}
          });
          break;
        case '17':
          this.$router.push({
            path: '/record/emergency/cofferdam',
            query: {id: id}
          });
          break;
        case '18':
          this.$router.push({
            path: '/record/commonuse/tester',
            query: {id: id}
          });
          break;
        case '19':
          this.$router.push({
            path: '/record/commonuse/earplug',
            query: {id: id}
          });
          break;
        case '20':
          this.$router.push({
            path: '/record/commonuse/movement',
            query: {id: id}
          });
          break;
        case '21':
          this.$router.push({
            path: '/record/commonuse/bicycle',
            query: {id: id}
          });
          break;
        case '22':
          this.$router.push({
            path: '/record/commonuse/cover',
            query: {id: id}
          });
          break;
        case '23':
          this.$router.push({
            path: '/record/commonuse/walkitTalkie',
            query: {id: id}
          });
          break;
        case '24':
          this.$router.push({
            path: '/record/commonuse/safetyBelt',
            query: {id: id}
          });
          break;
        case '25':
          this.$router.push({
            path: '/record/commonuse/downspout',
            query: {id: id}
          });
          break;
        case '26':
          this.$router.push({
            path: '/record/commonuse/pump',
            query: {id: id}
          });
          break;
      }
    },
    getStatus(val) {
      return val == 0 ? '未处理' : '已处理';
    },
    /** 查询检查问题记录列表 */
    getList() {
      this.loading = true;
      listIssues(this.queryParams).then(response => {
        this.issuesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download2('/patrol/issues/export', {
        ...this.queryParams
      }, `issues_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
