<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="businessArr" placeholder="请输入项目业态" clearable @keyup.enter.native="handleQuery" /> -->
        <el-select v-model="businessArr" placeholder="请选择项目业态" clearable multiple>
          <el-option v-for="dict in dict.type.risk_project_business" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </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">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList">
      </right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="inherentList" @selection-change="handleSelectionChange">
      <el-table-column label="项目信息" align="center" fixed width="500">
        <el-table-column label="区域公司" align="center" prop="deptName" width="100" />
        <el-table-column label="项目名称" align="center" prop="projectName" width="100">
          <template slot-scope="scope">
            <el-popover placement="top-start" title="项目名称" width="200" trigger="hover" :content="scope.row.projectName">
              <span slot="reference">{{
      scope.row.projectName.length > 10
        ? scope.row.projectName.substring(0, 10) + "..."
        : scope.row.projectName
    }}</span>
            </el-popover>
          </template>
        </el-table-column>

        <el-table-column label="所属城市" align="center" prop="city" width="100" />
        <el-table-column label="项目业态" align="center" prop="businessFormat" width="100" />
        <el-table-column label="项目类型" align="center" prop="type" width="100" />
      </el-table-column>

      <el-table-column label="项目风险清单" align="center">
        <el-table-column label="固有风险" align="center">
          <el-table-column label="危险源名称" align="center" prop="inherentName" width="100" />
          <el-table-column label="风险等级" align="center" prop="inherentLevel" width="100" />
        </el-table-column>
        <el-table-column label="现有风险" align="center">
          <el-table-column label="危险源名称" align="center" prop="existingName" width="100" />
          <el-table-column label="风险等级" align="center" prop="existingLevel" width="100" />
        </el-table-column>
        <el-table-column label="风险点位置" align="center" prop="presenceLocation" width="100" />
        <el-table-column label="可能导致的事故后果" align="center" prop="listType" width="100">

          <template slot-scope="scope">
            <el-popover placement="top-start" title="项目名称" width="200" trigger="hover" :content="scope.row.listType">
              <span slot="reference">{{
      scope.row.listType.length > 10
        ? scope.row.listType.substring(0, 10) + "..."
        : scope.row.listType
    }}</span>
            </el-popover>
          </template>
        </el-table-column>
      </el-table-column>

      <el-table-column label="项目整体风险等级" align="center">
        <el-table-column label="固有风险" align="center" prop="inherentProjectLevel" width="100" />
        <el-table-column label="现状风险" align="center" prop="existingProjectLevel" width="100" />
      </el-table-column>

      <el-table-column label="风险管控" align="center">
        <el-table-column label="应采取的管控措施" align="center" prop="inherentMeasuresAdministration" width="100">

          <template slot-scope="scope">
            <el-popover placement="top-start" title="应采取的管控措施" width="200" trigger="hover"
              :content="scope.row.inherentMeasuresAdministration">
              <span slot="reference">{{
      scope.row.inherentMeasuresAdministration &&
        scope.row.inherentMeasuresAdministration.length > 10
        ? scope.row.inherentMeasuresAdministration.substring(0, 10) +
        "..."
        : scope.row.inherentMeasuresAdministration
    }}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="已采取的管控措施" align="center" prop="existingMeasuresAdministration" width="100">

          <template slot-scope="scope">
            <el-popover placement="top-start" title="已采取的管控措施" width="200" trigger="hover"
              :content="scope.row.existingMeasuresAdministration">
              <span slot="reference">{{
      scope.row.existingMeasuresAdministration &&
        scope.row.existingMeasuresAdministration.length > 10
        ? scope.row.existingMeasuresAdministration.substring(0, 10) +
        "..."
        : scope.row.existingMeasuresAdministration
    }}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="分级管控" align="center">
          <el-table-column label="管控责任单位" align="center" prop="measuresDeptName" width="100" />
          <el-table-column label="管控责任人" align="center" prop="measuresUserName" width="100" />
          <el-table-column label="人员联系方式" align="center" prop="measuresUserPhone" width="100" />
        </el-table-column>
      </el-table-column>

      <el-table-column label="重大危险源管理" align="center">
        <el-table-column label="是否存在重大危险源" align="center" prop="majorHazardSource" width="100" />
        <el-table-column label="重大危险源名称" align="center" prop="hazardSourceName" width="100" />
        <el-table-column label="重大危险源描述" align="center" prop="majorHazardDescription" width="100" />
      </el-table-column>

      <el-table-column label="判定依据" align="center" prop="referenceBasis" width="100">

        <template slot-scope="scope">
          {{ scope.row.referenceBasis === 'null' ? '' : scope.row.referenceBasis }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" prop="describe">

        <template slot-scope="scope">
          <div>
            <router-link :to="'/risk/plan/inherentdata/index/' + scope.row.id" class="link-type">
              <el-button size="mini" type="text" icon="el-icon-view">详情</el-button>
            </router-link>
          </div>
        </template>
      </el-table-column>
    </el-table>

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

<script>
import { inherentListList } from "@/api/risk/existing";

export default {
  name: "inherent",
  dicts: ["risk_plan_level", "risk_project_business"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 固有风险清单库表格数据
      inherentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      businessArr: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        buildingName: null,
        floorName: null,
        roomName: null,
        level: null,
        factor: null,
        type: null,
        presenceLocation: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询固有风险清单库列表 */
    getList() {
      this.loading = true;
      if (this.businessArr) {
        this.queryParams.businessFormat = this.businessArr.join(',');
      }
      inherentListList(this.queryParams).then((response) => {
        this.inherentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    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();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    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>
