<template>
  <div>
    <el-tabs type="border-card" style="min-height:70vh" v-model="activeName">
      <el-tab-pane label="基本信息" name="first">
        <el-form ref="ruleForm" style="height: 75vh;overflow: auto;overflow-x: hidden;" :model="form" :inline="true"
          label-position="center" label-width="170px">
          <el-row :gutter="40">
            <!-- <el-col :span="24">
              <div style="background-color: #eee;font-weight: bold;text-align: center;font-size: 15px;position: relative;"
                class="pd-10 m-b-10">
                {{ title }}</div>
            </el-col> -->
            <el-col :span="24">
              <div class="formTitle m-b-20">单位信息</div>
            </el-col>

            <el-form-item label="单位名称" prop="Dept">
              <div class="qiye" style="width: 27.5vw;">
                <el-select v-model="form.Dept" filterable remote reserve-keyword clearable disabled placeholder="请输入单位名称"
                  :remote-method="remoteMethod" :loading="loading" @change="chooseQy">
                  <el-option v-for="(item, index) in options" :key="item.id" :label="item.DeptName" :value="index">
                  </el-option>
                </el-select>
              </div>
            </el-form-item>

            <!-- <el-form-item label="网址">
              <el-input readonly v-model="form.wangzhi" placeholder="请输入网址" />
            </el-form-item> -->


            <!-- <el-form-item label="地址">
              <div style="width: 27.5vw;">
                <el-input readonly v-model="form.Address" placeholder="请输入地址" />
              </div>
            </el-form-item> -->



            <el-form-item label="负责人姓名">
              <el-input readonly v-model="form.LianXiRen" placeholder="请输入负责人姓名" />
            </el-form-item>

            <!-- <el-form-item label="联系方式">
              <el-input readonly v-model="form.Tel" placeholder="请输入联系方式" />
            </el-form-item> -->

            <el-form-item label="手机号码">
              <el-input readonly v-model="form.Phone" placeholder="请输入手机号码" />
            </el-form-item>
            <el-form-item label="邮政编码">
              <el-input readonly v-model="form.PostCode" placeholder="请输入邮政编码" />
            </el-form-item>
            <!--
            <el-form-item label="传真">
              <el-input v-model="form.Fax" placeholder="请输入传真" />
            </el-form-item> -->

            <el-form-item label="电子邮箱">
              <el-input readonly v-model="form.Email" placeholder="请输入电子邮箱" />
            </el-form-item>

            <el-col :span="24">
              <div class="formTitle m-b-20">个人信息</div>
            </el-col>
            <br>
            <el-form-item label="姓名" prop="Name">
              <el-input readonly type="text" auto-complete="off" v-model="form.Name" placeholder="请输入姓名" />
            </el-form-item>

            <el-form-item label="性别" prop="Sex">
              <el-select :disabled="type == 0 ? false : true" v-model="form.Sex" clearable placeholder="请选择性别">
                <el-option label="男" value="男"> 男 </el-option>
                <el-option label="女" value="女"> 女 </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="身份证号" prop="ShenFenZheng">
              <el-input readonly v-model="form.ShenFenZheng" placeholder="请输入身份证号" />
            </el-form-item>

            <el-form-item label="出生年月" prop="Birthday">
              <el-input readonly v-model="form.Birthday" placeholder="请输入出生年月" />
            </el-form-item>

            <el-form-item label="学历" prop="XueLi">
              <el-input readonly v-model="form.XueLi" placeholder="请输入学历" />
            </el-form-item>

            <el-form-item label="专业" prop="ZhuanYe">
              <el-input :readonly="type == 0 ? false : true" v-model="form.ZhuanYe" type="text" auto-complete="off"
                placeholder="请输入专业"></el-input>
            </el-form-item>

            <el-form-item label="职称" prop="ZhiCheng">
              <el-select v-model="form.ZhiCheng" placeholder="请选择职称" clearable
                :disabled="type == 1 && xiugai == false ? true : false">
                <el-option v-for="dict in dict.type.job_title" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>

            <el-form-item label="监理工作年限" prop="NianXian">
              <el-input :readonly="type == 0 ? false : true" v-model="form.NianXian" type="number" min="0"
                placeholder="请输入监理工作年限"></el-input>
            </el-form-item>

            <el-col :span="24">
              <div class="formTitle m-b-20">证书信息</div>
            </el-col>
            <br>
            <span v-if="form.JLYZhengHao != null && form.JLYZhengHao != ''">
              <el-form-item prop="JLYZhengHao" label="监理员证书号">
                <el-input readonly v-model="form.JLYZhengHao" type="text" auto-complete="off"
                  placeholder="请输入监理员证书号"></el-input>
              </el-form-item>

              <el-form-item prop="JLYZhengHaoNum" label="监理员证书编号">
                <el-input readonly style="width:110%" v-model="form.JLYZhengHaoNum" type="text" auto-complete="off"
                  placeholder="请输入监理员证书编号"></el-input>
              </el-form-item>

              <el-form-item prop="JLYfzrq" label-width="180px" style="margin-left:8px" label="发证日期">
                <el-date-picker style="width: 200px;" readonly v-model="form.JLYfzrq" value-format="yyyy-MM-dd"
                  type="date" placeholder="请选择发证日期">
                </el-date-picker>
              </el-form-item>
            </span>

            <br>
            <span v-if="form.JLZhengHao != null && form.JLZhengHao != ''">
              <el-form-item label="监理工程师证书号">
                <el-input readonly v-model="form.JLZhengHao" type="text" auto-complete="off"
                  placeholder=" 请输入监理工程师证书号"></el-input>
              </el-form-item>

              <el-form-item label="发证日期">
                <el-date-picker style="width: 200px;" readonly v-model="form.JLfzrq" value-format="yyyy-MM-dd" type="date"
                  placeholder=" 请选择发证日期">
                </el-date-picker>
              </el-form-item>

              <el-form-item label="有效期至">
                <el-date-picker readonly v-model="form.JLYxqz" value-format="yyyy-MM-dd" type="date"
                  placeholder=" 请选择有效期至">
                </el-date-picker>
              </el-form-item>

              <el-form-item label="监理工程师证书编号">
                <el-input readonly v-model="form.JlZhengHaoNum" type="text" auto-complete="off"
                  placeholder=" 请输入监理工程师证书编号"></el-input>
              </el-form-item>
            </span>

            <br>
            <span v-if="form.ZJZhengHao != null && form.ZJZhengHao != ''">
              <el-form-item label="总监理工程师证书号">
                <el-input readonly v-model="form.ZJZhengHao" type="text" auto-complete="off"
                  placeholder=" 请输入总监理工程师证书号"></el-input>
              </el-form-item>

              <el-form-item label="发证日期">
                <el-date-picker style="width: 200px;" readonly v-model="form.ZJfzrq" value-format="yyyy-MM-dd" type="date"
                  placeholder=" 请选择发证日期">
                </el-date-picker>
              </el-form-item>
            </span>


            <br>
            <span v-if="form.JSBZhengHao != null && form.JSBZhengHao != ''">
              <el-form-item label="建设部证书号">
                <el-input readonly v-model="form.JSBZhengHao" type="text" auto-complete="off"
                  placeholder=" 请输入建设部证书号"></el-input>
              </el-form-item>

              <el-form-item label="发证日期">
                <el-date-picker style="width: 200px;" readonly v-model="form.JSBfzrq" value-format="yyyy-MM-dd"
                  type="date" placeholder=" 请选择发证日期">
                </el-date-picker>
              </el-form-item>
            </span>

          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="个人业绩" name="second">
        <el-table style="width: 1200px;height: 55vh;overflow: auto;" :data="achievementTableData">
          <el-table-column label="序号" align="center" type="index"></el-table-column>
          <el-table-column label="工作单位" align="center" prop="QYLoginName"></el-table-column>
          <el-table-column width="100" label="添加时间" align="center">
            <template slot-scope="scope">
              {{ parseTime(scope.row.Nian, "{y}-{m}-{d} {h}:{i}:{s}") }}
            </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>
      </el-tab-pane>
      <el-tab-pane label="处罚信息" name="third">
        <div style="font-size: 16px;">
          处罚内容：{{ form.ChuFa }}
          <br>
          <br>
          处罚时间：{{ parseTime(form.ChuFaTime, "{y}-{m}-{d}") }}
        </div>
      </el-tab-pane>
      <el-tab-pane label="变更信息" name="fourth">
        <el-table :data="biangengInfo" style="height: 55vh;">
          <el-table-column label="序号" align="center" type="index"></el-table-column>
          <el-table-column align="center" label="变更内容" width="800">
            <template slot-scope="scope">
              {{ scope.row.CaoZuo }}
            </template>
          </el-table-column>
          <el-table-column width="150" label="变更时间" align="center" prop="WriteTime">
            <!-- <template slot-scope="scope">
              {{ scope.row.WriteTime }}
            </template> -->
          </el-table-column>
          <el-table-column label="操作人" align="center" prop="updateBy"></el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {
  getRenCai,
  getYeJi,
  getCurrRenCaiLogList
} from "@/api/xiehui/tjgl/supervisor";
export default {
  components: {},
  dicts: ['job_title', "jxjy_sfkyjxjy", 'talent_type', 'zhengshu_type', 'biangeng_type', 'zhengshu_status', 'chufa_type', "jxjy_jlgcszfbz", "jxjy_bljl", "jxjy_jlyzfbz"],

  props: {
    IdInfo: {
      type: String,
      default: null
    },
    sfz: {
      type: String,
      default: null
    }
  },
  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(); // 去除首尾空格
      };
    },
  },
  data() {
    return {
      biangengInfo: [],
      //企业列表
      options: [],
      type: 2,
      IDInfo: null,
      form: {},
      activeName: "first",
      achievementTableData: [],
      ShenFenZheng: '',
      loading: false,
    };
  },
  watch: {
    IdInfo: {
      handler(newVal, oldVal) {
        console.log("🚀 ~ handler ~ newVal:", newVal)
        this.IDInfo = newVal;
        this.getInfo();
      },
      deep: true,
      immediate: true,
    },
    sfz: {
      handler(newVal, oldVal) {
        console.log("🚀 ~ handler ~ newVal:", newVal)
        this.ShenFenZheng = newVal;
        this.getYeJi();
      },
      deep: true,
      immediate: true,
    },
  },

  created() { },

  computed: {},
  methods: {
    getInfo() {
      this.form = {}
      this.$modal.loading('加载中,请稍候...');
      getRenCai(this.IDInfo).then((response) => {
        this.form = response.data.renCai;
        this.$modal.closeLoading();
      }).catch(() => {
        this.$modal.closeLoading();
      })
      getCurrRenCaiLogList({ ID: this.IDInfo, leiBie: '监理人员执业变更撤回,监理人员执业变更' }).then(res => {
        console.log("🚀 ~ res人员:", res)
        this.biangengInfo = res.rows
      })
    },
    getYeJi() {
      getYeJi({
        XYusercord: this.ShenFenZheng,
      }).then((res) => {
        this.achievementTableData = res.rows;
      });
    },
    //查询企业0
    remoteMethod(query) {
      if (query !== "") {
        this.loading = true;
        zgksQySearch(query).then((res) => {
          this.options = res.data;
          this.loading = false;
        });
      } else {
        this.options = [];
      }
    },
    chooseJl(v) {
      this.deptID = this.options[v].BMdept
    },
    //选择企业
    chooseQy(v) {
      console.log("🚀 ~ chooseQy ~ v:", v)
      this.form.DeptID = this.options[v].BMdept;
      this.form = {
        ...this.form,
        ...getObj(this.options[v]),
      }
      // this.classForm.zigeperson = {
      //   ...this.classForm.zigeperson,
      //   ...getObj(this.options[v]),
      // };
    },

  },
  mounted() { }
};
</script>
<style lang="scss" scoped>
.formTitle {
  color: #409eff;
  border-bottom: 1px solid #409eff;
  padding: 10px;
  font-size: 15px;
  font-weight: bold;
}

::v-deep .qiye .el-select>.el-input {
  display: block;
  width: 583px !important;
}

::v-deep .el-select>.el-input {
  display: block;
  width: 203px !important;
}
</style>
