<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单位名称" prop="Dept">
        <el-input v-model="queryParams.Dept" placeholder="请输入单位名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <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="ShenFenZheng">
        <el-input v-model="queryParams.ShenFenZheng" placeholder="请输入身份证" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="RenCaiList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" type="index" :index="indexMethod">
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="Name">
        <template slot-scope="scope">
          <el-button type="text" @click="handleInfo(scope.row, false)">{{
            scope.row.Name
          }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="Sex" />
      <el-table-column label="身份证号" align="center" width="200" prop="ShenFenZheng" />
      <el-table-column label="单位名称" align="center" prop="Dept" width="400" />
      <el-table-column label="证书" width="220" align="center" prop="XueLi">
        <template slot-scope="scope"> <el-popover placement="left" width="180" trigger="hover"
            v-if="scope.row.JLYZhengHaoNum != '' && scope.row.JLYZhengHaoNum != null">
            <div>
              <div>
                证书编号：{{ scope.row.JLYZhengHaoNum }}
              </div>
              <div>
                发证日期：{{ scope.row.JLYfzrq }}
              </div>
            </div>
            <el-button type="text" slot="reference">监理员</el-button>
          </el-popover>
          <el-divider direction="vertical"
            v-if="scope.row.JLYZhengHaoNum != '' && scope.row.JLYZhengHaoNum != null && (scope.row.JLZhengHaoNum != '' && scope.row.JLZhengHaoNum != null || scope.row.ZJZhengHao != '' && scope.row.ZJZhengHao != null)"></el-divider>
          <el-popover placement="left" width="200" trigger="hover"
            v-if="scope.row.JLZhengHaoNum != '' && scope.row.JLZhengHaoNum != null">
            <div>
              <div>
                证书编号：{{ scope.row.JLZhengHaoNum }}
              </div>
              <div>
                证书有效期至：{{ scope.row.JLYxqz }}
              </div>
            </div>
            <el-button type="text" slot="reference">监理工程师</el-button>
          </el-popover>
          <el-divider direction="vertical"
            v-if="scope.row.JLZhengHaoNum != '' && scope.row.JLZhengHaoNum != null && scope.row.ZJZhengHao != '' && scope.row.ZJZhengHao != null"></el-divider>
          <el-popover placement="left" width="180" trigger="hover"
            v-if="scope.row.ZJZhengHao != '' && scope.row.ZJZhengHao != null">
            <div>
              <div>
                证书编号：{{ scope.row.ZJZhengHao }}
              </div>
              <div>
                发证日期：{{ scope.row.ZJfzrq }}
              </div>
            </div>
            <el-button type="text" slot="reference">总监理工程师</el-button>
          </el-popover>
        </template>
      </el-table-column>
      <!-- <el-table-column label="监理员证书号" align="center" width="300" prop="JLYZhengHao" />

      <el-table-column label="监理员发证日期" align="center" prop="JLYfzrq" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.JLYfzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="监理工程师证书号" align="center" width="200" prop="JLZhengHao" />
      <el-table-column label="监理工程师证书号(纯数字)" align="center" prop="JLZhengHaoNum" width="200" />
      <el-table-column label="监理工程师证书发证日期" align="center" prop="JLfzrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.JLfzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="监理工程师证书有效期至" align="center" prop="JLYxqz" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.JLYxqz, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总监证书号" align="center" width="200" prop="ZJZhengHao" />
      <el-table-column label="总监发证日期" align="center" prop="ZJfzrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ZJfzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="不良记录" align="center" prop="BljlFlg">
        <template slot-scope="scope">
          <el-popover placement="left" width="300" trigger="hover" v-if="scope.row.BljlFlg == 1">
            <div>
              <div>
                编号：{{ scope.row.BljlBianhao }}
              </div>
              <div>
                内容：{{ scope.row.BljlContent }}
              </div>
              <div>
                定性：{{ scope.row.BljlDingxing }}
              </div>
              <div>
                依据：{{ scope.row.BljlClyj }}
              </div>
              <div>
                开始：{{ scope.row.BljlGbStart }}
              </div>
              <div>
                结束：{{ scope.row.BljlGbEnd }}
              </div>
            </div>
            <el-button type="text" slot="reference">有</el-button>
          </el-popover>
          <el-button type="text" slot="reference" v-if="scope.row.BljlFlg == 0">无</el-button>
        </template>
      </el-table-column>
      <el-table-column label="处罚" align="center" prop="XueLi">
        <template slot-scope="scope">
          <el-popover placement="left" width="300" trigger="hover"
            v-if="scope.row.ChuFa != null && scope.row.ChuFa.length > 0 && scope.row.ChuFa !== '暂无'">
            <div>
              <div>
                内容：{{ scope.row.ChuFa }}
              </div>
              <div>
                时间：{{ scope.row.ChuFaTime }}
              </div>
            </div>
            <el-button type="text" slot="reference">有</el-button>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column label="业绩" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <el-dialog title="监理工程师业绩/简历" :visible.sync="viewDia" width="55%" :before-close="() => {
      viewDia = false;
    }
      ">
      <el-table :data="jianli" style="width: 100%">
        <el-table-column align="center" label="序号" width="100" type="index"> </el-table-column>
        <el-table-column align="center" prop="Nian" label="添加时间">
          <template slot-scope="scope">
            {{ parseTime(scope.row.Nian, "{y}-{m}-{d}") }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="QYLoginName" label="工作单位">
        </el-table-column>
        <el-table-column align="center" label="监理工程师业绩/简历">
          <template slot-scope="scope">
            <span v-html="content(scope.row)"></span>
            <!-- <el-popover placement="top" title="业绩:" width="400" trigger="click">
                  <div v-html="scope.row.zyJianSheYeJi"></div>
            <el-button @click="seeJianli(scope.row)" slot="reference">查看</el-button>
            </el-popover> -->
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="viewDia = false">关 闭</el-button>
      </span>
    </el-dialog>
    <el-dialog append-to-body title="监理工程师业绩/简历详情" :visible.sync="openJianli" width="50%">
      <Editor1 width="10vw" ref="editor" v-model="jianliInfo" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="openJianli = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog modal-append-to-body title="监理人员信息" height="75vh" :visible.sync="dialogVisibleInfo" top="3vh"
      width="1250px">
      <div style="
          height: 74vh;
          overflow-y: auto;
          overflow-x: hidden;
          padding-top: 0;
        " class="pd-10">
        <jianliInfo :IdInfo="IdInfo" :sfz="sfz"></jianliInfo>
      </div> <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleInfo = false">关闭</el-button>
        <!-- <el-button type="primary" @click="dialogVisible = false">确 定</el-button> -->
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listRenCai, getRenCai } from "@/api/xiehui/tjgl/supervisor";
import { handleTableIndex } from "@/utils/index";
import Editor1 from "../../../components/Editor1.vue";
import jianliInfo from "./../jianliInfo.vue"
import {
  getJianli
} from "@/api/xiehui/jlry/RenCai";
export default {
  name: "RenCai",
  components: { Editor1, jianliInfo },
  dicts: ["jxjy_sfkyjxjy", "jxjy_jlgcszfbz", "jxjy_bljl", "jxjy_jlyzfbz"],
  data() {
    return {
      jianli: [],
      yejiInfo: '',
      jianliInfo: '',
      openJianli: false,
      viewDia: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      activeView: {},
      // 监理人才管理表格数据
      RenCaiList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        Name: null,
        Dept: null,
        ShenFenZheng: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      IdInfo: null,
      sfz: null,
      dialogVisibleInfo: false,
    };
  },
  created() {
    this.getList();
  },
  computed: {
    content() {
      return (row) => {
        return row.zyJianSheYeJi
          .replaceAll("&lt;/p&gt;", "</p>")
          .replaceAll("&lt;br&gt;", "<br>")
          .replaceAll("&lt;/br&gt;", "</br>")
          .replaceAll("&lt;p&gt;", "<p>")
          .replaceAll("&nbsp;", " ")
          .replace(/&lt;/g, "<") // 替换 &lt; 为 <
          .replace(/&gt;/g, ">") // 替换 &gt; 为 >
          .replace(/&amp;nbsp;/g, " ") // 替换 &amp;nbsp; 为普通空格
          .replace(/\s+/g, " ") // 将多个空格替换为一个空格
          .trim(); // 去除首尾空格
      };
    },
  },
  methods: {
    handleInfo(row) {
      console.log("🚀 ~ handleInfo ~ row:", row.ID)
      this.IdInfo = row.ID
      this.sfz = row.ShenFenZheng
      this.dialogVisibleInfo = true
    },
    indexMethod(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + 1 + index
    },
    handleView(row) {
      this.activeView = row;
      this.viewDia = true;
      // this.jianliInfo=row.
      getJianli({ ShenFenZheng: row.ShenFenZheng }).then(response => {
        this.jianli = response.data;
      }
      )
    },
    seeJianli(row) {
      this.openJianli = true;
      this.jianliInfo = row.zyJianSheYeJi
    },
    /** 查询监理人才管理列表 */
    getList() {
      this.loading = true;
      listRenCai(this.queryParams).then((response) => {
        this.RenCaiList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange() { },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.ID || this.ids;
      getRenCai(ID).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改监理人才管理";
      });
    },
  },
};
</script>
