<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">
        <template slot-scope="scope">
          <span>{{ handleTableIndex(scope.$index, queryParams) }}</span>
        </template>
      </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 width="50" label="性别" align="center" prop="Sex" />
      <el-table-column label="身份证号" align="center" width="250" prop="ShenFenZheng" />
      <el-table-column label="单位名称" align="center" prop="Dept" width="400" />
      <!-- <el-table-column label="监理员证书号" align="center" width="300" prop="JLYZhengHao">
        <template slot-scope="scope">
          <div>
            {{ scope.row.JLYZhengHao }}

            <span class="supervision" v-if="scope.row.JLYzfFlg == '0'">（作废）</span>
          </div>
        </template>
      </el-table-column>

      <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">
        <template slot-scope="scope">
          <div>
            {{ scope.row.JLZhengHao }}
            <span v-if="scope.row.ShenHe == '0'" class="supervision">（禁用）</span>
          </div>
        </template>
      </el-table-column>

      <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">
        <template slot-scope="scope">
          <div>
            {{ scope.row.ZJZhengHao }}
            <span v-if="scope.row.ZJzfFlg == '0'" class="supervision">（禁用）</span>
          </div>
        </template>
      </el-table-column>

      <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 width="220" label="证书" 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 align="center" prop="BljlFlg" label="不良记录">
        <template slot-scope="scope">
          <el-popover v-if="scope.row.BljlFlg == '1'" placement="left" width="380" trigger="hover">
            <template slot="reference">
              <el-tag type="danger">有</el-tag>
            </template>
            <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-popover>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="ChuFa" label="处罚">
        <template slot-scope="scope">
          <div v-if="scope.row.ChuFa == '暂无'"></div>
          <el-popover v-else placement="left" width="250" trigger="hover">
            <template slot="reference">
              <el-tag type="danger">有</el-tag>
            </template>
            <div>
              处罚
              <div>内容：{{ scope.row.ChuFa }}</div>
              <div>时间：{{ scope.row.ChuFaTime }}</div>
            </div>
          </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="1000px" :before-close="() => {
      viewDia = false;
    }
      ">
      <el-table style="width: 1000px" :data="achievementTableData">
        <el-table-column label="序号" align="center" type="index"></el-table-column>
        <el-table-column label="工作单位" width="300" align="center" prop="QYLoginName"></el-table-column>
        <el-table-column width="200" label="添加时间" align="center">
          <template slot-scope="scope">
            {{ parseTime(scope.row.Nian, "{y}-{m}-{d}") }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="内容" width="500">
          <template slot-scope="scope">
            <span v-html="content(scope.row)"></span>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="viewDia = false">关 闭</el-button>
      </span>
    </el-dialog>
    <el-dialog title="监理人员信息" height="75vh" modal-append-to-body :visible.sync="dialogVisibleInfo" top="3vh"
      :append-to-body="true" 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, getYeJi } from "@/api/xiehui/tjgl/supervisor";
import { handleTableIndex } from "@/utils/index";
import jianliInfo from "./../jianliInfo.vue"
export default {
  name: "RenCai",
  components: { jianliInfo },
  dicts: ["jxjy_sfkyjxjy", "jxjy_jlgcszfbz", "jxjy_bljl", "jxjy_jlyzfbz"],
  data() {
    return {
      achievementTableData: [],
      viewDia: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      activeView: {},
      // 监理人才管理表格数据
      RenCaiList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      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: {
    handleSelectionChange() { },
    handleInfo(row) {
      console.log("🚀 ~ handleInfo ~ row:", row.ID)
      this.IdInfo = row.ID
      this.sfz = row.ShenFenZheng
      this.dialogVisibleInfo = true
    },
    handleTableIndex,
    handleView(row) {
      getYeJi({
        XYusercord: row.ShenFenZheng,
      }).then((res) => {
        this.achievementTableData = res.rows;
      });
      this.viewDia = true;
    },
    /** 查询监理人才管理列表 */
    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();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.ID || this.ids;
      getRenCai(ID).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改监理人才管理";
      });
    },
  },
};
</script>
<style scoped lang="scss">
.supervision {
  color: red;
}
</style>
