<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="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入风险名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="楼宇名称" prop="buildingName">
        <el-input
          v-model="queryParams.buildingName"
          placeholder="请输入楼宇名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="楼层名称" prop="floorName">
        <el-input
          v-model="queryParams.floorName"
          placeholder="请输入楼层名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房间名称" prop="roomName">
        <el-input
          v-model="queryParams.roomName"
          placeholder="请输入房间名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="风险等级" prop="level">
        <el-select
          v-model="queryParams.level"
          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="factor">
        <el-input
          v-model="queryParams.factor"
          placeholder="请输入风险因素"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="准事故类型" prop="type">
        <el-input
          v-model="queryParams.type"
          placeholder="请输入准事故类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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>
        <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-table
      v-loading="loading"
      :data="inherentList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
        fixed="left"
      />
      <!-- <el-table-column label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column> -->

      <el-table-column
        label="风险名称"
        align="center"
        prop="name"
        fixed="left"
      />
      <el-table-column label="所属建筑" align="center" prop="buildingName">
        <template slot-scope="scope">
          <el-popover
            placement="top-start"
            title="所属建筑"
            width="200"
            trigger="hover"
            :content="scope.row.buildingName"
          >
            <span slot="reference">{{
              scope.row.buildingName.length > 10
                ? scope.row.buildingName.substring(0, 10) + "..."
                : scope.row.buildingName
            }}</span>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column label="所属楼层" align="center" prop="floorName" />
      <el-table-column label="所属房间" align="center" prop="roomName" />
      <el-table-column label="风险等级（系数）" align="center" prop="level" />
      <el-table-column label="风险因素" align="center" prop="factor">
        <template slot-scope="scope">
          <el-popover
            placement="top-start"
            title="风险因素"
            width="200"
            trigger="hover"
            :content="scope.row.factor"
          >
            <span slot="reference">{{
              scope.row.factor.length > 10
                ? scope.row.factor.substring(0, 10) + "..."
                : scope.row.factor
            }}</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="准事故类型" align="center" prop="type">
        <template slot-scope="scope">
          <el-popover
            placement="top-start"
            title="准事故类型"
            width="200"
            trigger="hover"
            :content="scope.row.type"
          >
            <span slot="reference">{{
              scope.row.type.length > 10
                ? scope.row.type.substring(0, 10) + "..."
                : scope.row.type
            }}</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="存在部位" align="center" prop="presenceLocation">
        <template slot-scope="scope">
          <el-popover
            placement="top-start"
            title="存在部位"
            width="200"
            trigger="hover"
            :content="scope.row.presenceLocation"
          >
            <span slot="reference">{{
              scope.row.presenceLocation.length > 10
                ? scope.row.presenceLocation.substring(0, 10) + "..."
                : scope.row.presenceLocation
            }}</span>
          </el-popover>
        </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 { listList } from "@/api/risk/existing";

export default {
  name: "inherent",
  dicts: ["risk_plan_level"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 固有风险清单库表格数据
      inherentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      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;
      listList(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,
        },
      });
    },
  },
};
</script>
