<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="区域公司" prop="deptName">
        <el-input v-model="queryParams.deptName" placeholder="请输入区域公司" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属城市" prop="city">
        <el-input v-model="queryParams.city" placeholder="请输入所属城市" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目业态" prop="businessFormat">
        <el-input v-model="queryParams.businessFormat" placeholder="请输入项目业态" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="固有风险危险源名称" prop="inherentName">
        <el-input v-model="queryParams.inherentName" placeholder="请输入固有风险危险源名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="固有风险风险等级" prop="inherentLevel">
        <el-select v-model="queryParams.inherentLevel" placeholder="请选择固有风险风险等级" clearable>
          <el-option v-for="dict in dict.type.risk_plan_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="现有风险危险源名称" prop="existingName">
        <el-input v-model="queryParams.existingName" placeholder="请输入现有风险危险源名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="现有风险风险等级" prop="existingLevel">
        <el-select v-model="queryParams.existingLevel" placeholder="请选择现有风险风险等级" clearable>
          <el-option v-for="dict in dict.type.risk_plan_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="风险点位置" prop="presenceLocation">
        <el-input v-model="queryParams.presenceLocation" placeholder="请输入风险点位置" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="可能导致的事故后果" prop="listType">
        <el-input v-model="queryParams.listType" placeholder="请输入可能导致的事故后果" clearable @keyup.enter.native="handleQuery" />
      </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 class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList">
      </right-toolbar>
    </el-row>
    <el-tabs v-model="activeName" type="border-card" style="margin-top: 10px">
      <el-tab-pane label="固有风险" name="1">
        <riskTable v-bind="inherent.data" @changePage="inherent.changePage" />
      </el-tab-pane>
      <el-tab-pane label="现状风险" name="2">
        <riskTable v-bind="existing.data" @changePage="existing.changePage" />
      </el-tab-pane>
    </el-tabs>

  </div>
</template>

<script>
import { inherentListList, existingList } from "@/api/risk/existing";
import riskTable from './component/table.vue'
export default {
  name: "inherent",
  dicts: ["risk_plan_level"],
  components: {
    riskTable
  },
  data() {
    return {
      activeName: '1',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 固有风险清单库表格数据
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        name: null,
        buildingName: null,
        floorName: null,
        roomName: null,
        level: null,
        factor: null,
        type: null,
        presenceLocation: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      inherent: {
        data: {
          loading: false,
          list: [],
          page: {
            pageNum: 1,
            pageSize: 10
          }
        },
        changePage: this.inherentChangePage
      },
      existing: {
        data: {
          loading: false,
          list: [],
          page: {
            pageNum: 1,
            pageSize: 10
          }
        },
        changePage: this.existingChangePage
      }
    };
  },
  created() {
    this.getList();
    this.getExitList()
  },
  methods: {
    existingChangePage(page) {
      this.existing.data.page.pageNum = page;
      this.getExitList()
    },
    inherentChangePage(page) {
      this.existing.data.page.pageNum = page;
      this.getList()
    },
    /** 查询固有风险清单库列表 */
    getList() {
      this.inherent.loading = true;
      inherentListList({ ...this.queryParams, ...this.existing.data.page }).then((response) => {
        // this.inherentList = response.rows;
        // this.total = response.total;
        // this.loading = false;
        this.inherent.data = {
          ...this.inherent.data,
          list: response.rows,
          loading: false,
          page: {
            ...this.inherent.page,
            total: response.total
          }
        }
      });
    },
    getExitList() {
      this.existing.loading = true
      existingList({ ...this.queryParams, ...this.existing.data.page }).then((response) => {
        this.existing.data = {
          ...this.existing,
          list: response.rows,
          loading: false,
          page: {
            ...this.existing.page,
            total: response.total
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        name: null,
        buildingName: null,
        floorName: null,
        roomName: null,
        level: null,
        factor: null,
        type: null,
        level: null,
        riskLikelihood: null,
        riskSeverity: null,
        presenceLocation: null,
        pictureFileIds: null,
        measuresProject: null,
        measuresProjectFileIds: null,
        measuresAdministration: null,
        measuresDeptName: null,
        measuresUserName: null,
        measuresUserPhone: null,
        measuresAdministrationFileIds: null,
        hazardSourceName: null,
        majorHazardSource: null,
        majorHazardSourceDescription: null,
        measuresEmergency: null,
        measuresEmergencyFileIds: null,
        referenceBasis: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    exportList(id) {
      this.download("system/risk/plan/exportWord/riskNotification/" + id, {});
    },
    showDrawCanvas(floorId) {
      this.$router.push({
        name: "drawCanvas",
        params: {
          floorId: floorId,
        },
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/system/risk/plan/exportExcel/InherentList",
        {
          ...this.queryParams,
        },
        `固有风险台账_${new Date().getTime()}.xls`
      );
    },
  },
};
</script>
