<!--
 * @Author: ysh
 * @Date: 2024-07-09 11:13:55
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-07-09 14:27:31
-->
<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="128px">
      <el-form-item label="安全提示类型">
        <el-select v-model="queryParams.safeType" clearable placeholder="请选择" @change="handleQuery">
          <el-option label="环境管理要求" value="0"></el-option>
          <el-option label="安全生产与职业健康要求" value="1"></el-option>
          <el-option label="信息安全管理要求" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="safeRequestList" @selection-change="handleSelectionChange"
      :row-key="getRowKeys">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="安全提示类型" align="center" prop="safeType" :formatter="formatterLabel" width="120" />
      <el-table-column label="内容" prop="content" />
    </el-table>

    <div class="text-center mt20">
      <el-button type="primary" @click="confirm">确 定</el-button>
      <el-button @click="$emit('close')">取 消</el-button>
    </div>
    <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" /> -->
  </div>
</template>

<script>
import { listSafeRequest, getSafeRequest } from '@/api/oa/safe/safeRequest'
export default {
  props: {
    safeType: {
      type: String,
      default: ''
    }
  },
  watch: {
    safeType(val) {
      this.queryParams.safeType = val;
      this.handleQuery();
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // cmc安全要求表格数据
      safeRequestList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 99,
        safeType: null,
        content: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      chooseList: []
    }
  },
  created() {
    this.queryParams.safeType = this.safeType;
    this.getList();
  },
  mounted() {
  },
  methods: {
    /** 查询cmc安全要求列表 */
    getList() {
      this.loading = true;
      listSafeRequest(this.queryParams).then(response => {
        this.safeRequestList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleSelectionChange(val) {
      this.chooseList = val
    },
    getRowKeys(row) {
      return row.requestId;
    },
    formatterLabel(row) {
      switch (row.safeType) {
        case '0':
          return '环境管理要求'
        case '1':
          return '安全生产与职业健康要求'
        case '2':
          return '信息安全管理要求'
      }
    },
    formatterChooseList(arr){
      let contentList = [];
      arr.forEach(item => {
        contentList.push(item.content)
      })
      let str = contentList.join('\n')
      return str
    },
    confirm() {
      let confirmRequest = this.formatterChooseList(this.chooseList);
      this.$emit('confirm',confirmRequest)
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped></style>