<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="危险源名称" prop="hazardSourceName">
        <el-input
          v-model="queryParams.hazardSourceName"
          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-table v-loading="loading" :data="inherentList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <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" />
              <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",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 固有风险清单库表格数据
      inherentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        roomId: null,
        planId: null,
        name: null,
        pointType: null,
        specialEquipment: null,
        factor: null,
        type: null,
        level: null,
        presenceLocation: null,
        measuresProject: null,
        measuresAdministration: null,
        measuresDeptName: null,
        measuresUserName: null,
        measuresAdministrationFileIds: null,
        hazardSourceName: null,
        majorHazardSource: null,
        majorHazardSourceDescription: null,
        measuresEmergency: 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 = {
        id: null,
        userId: null,
        roomId: null,
        planId: null,
        name: null,
        pointType: null,
        specialEquipment: null,
        safetyWarningSigns: 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>
