<template>
  <ai-detail class="party-detail">
    <template slot="title">
      <ai-title
        title="党员信息详情"
        isShowBack
        isShowBottomBorder
        @onBackClick="cancel(true)"
      ></ai-title>
    </template>
    <template slot="content">
      <div>
        <ai-card title="基本信息">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-avatar
                class="party-avatar"
                v-model="info.avatarUrl"
                :editable="false"
              ></ai-avatar>
              <ai-info-item label="姓名">{{ info.name }}</ai-info-item>
              <ai-info-item
                label="性别"
                :value="dict.getLabel('sex', info.sex)"
              ></ai-info-item>
              <ai-info-item label="身份证号">
                <ai-id mode="show" :value="info.idNumber" rightBtn />
              </ai-info-item>
              <ai-info-item
                label="民族"
                :value="dict.getLabel('nation', info.nation)"
              ></ai-info-item>
              <ai-info-item
                label="出生日期"
                :value="info.birthday"
              ></ai-info-item>
              <ai-info-item label="年龄">{{ info.age }}</ai-info-item>
              <ai-info-item label="发展状态">{{ info.age }}</ai-info-item>
              <ai-info-item
                label="籍贯"
                isLine
                :value="info.birthplaceAreaName"
              ></ai-info-item>
              <ai-info-item
                label="户籍地"
                isLine
                :value="info.householdAreaName"
              ></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="联络信息">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-info-item label="联系方式">{{ info.name }}</ai-info-item>
              <ai-info-item
                label="现住址"
                isLine
                :value="info.householdAreaName"
              ></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="团籍信息">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-info-item label="入团日期">{{ info.name }}</ai-info-item>
              <ai-info-item label="文化程度">{{ info.name }}</ai-info-item>
              <ai-info-item label="学位职称">{{ info.name }}</ai-info-item>
              <ai-info-item label="奖励情况" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="处分情况" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="简历" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="附件" isLine>
                <ai-file-list v-if="info.files && info.files.length"
                  :fileList="info.files"
                  :fileOps="{ name: 'name', size: 'fileSizeStr' }"
                ></ai-file-list>
              </ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="申请入学">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-info-item label="申请入学时间">{{ info.name }}</ai-info-item>
              <ai-info-item
                label="申请入学形式"
                isLine
                :value="info.householdAreaName"
              ></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="入学积极分子的确定和教育培养">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-info-item label="确定为入学积极分子时间" isLine>{{ info.name }}</ai-info-item>
              <ai-info-item label="确定为积极分子的根据和意见" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="培养教育情况及鉴定意见" isLine :value="info.householdAreaName"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="入学介绍人/培养人">
          <template #content>
            <ai-table
              :border="true"
              :tableData="info.starList"
              :isShowPagination="false"
              :col-configs="colConfigs1"
              :stripe="false"
              @getList="() => {}"
              >
            </ai-table>
          </template>
        </ai-card>
        <ai-card title="发展对象的确定和考察">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-info-item label="确定为发展对象时间" isLine>{{ info.name }}</ai-info-item>
              <ai-info-item label="政治历史的考察及结论" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="社会关系考察及结论" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="现实考察及结论" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="学的基本知识考核及考试成绩" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="综合考察结论意见" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="学内讨论是否确定为发展对象的意见" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="确定为发展对象后的谈话记录" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="支委会研究意见" isLine :value="info.householdAreaName"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="预备学员的接收">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-info-item label="吸收入学时间" isLine>{{ info.name }}</ai-info-item>
              <ai-info-item label="吸收入学地点" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="吸收入学时支部大会上学员提的意见和要求及个人的态度" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="预备期间的教育情况" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="学小组对其转正的讨论意见" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="预备期间的考察情况" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="学支部对其转正的意见" isLine :value="info.householdAreaName"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="预备学员的教育考察和转正">
          <template #content>
            <ai-wrapper label-width="150px">
              <ai-info-item label="转正时间" isLine>{{ info.name }}</ai-info-item>
              <ai-info-item label="预备期间的教育情况" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="预备期间的考察情况" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="学小组对其转正的讨论意见" isLine :value="info.householdAreaName"></ai-info-item>
              <ai-info-item label="学支部对其转正的意见" isLine :value="info.householdAreaName"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
      </div>
    </template>
  </ai-detail>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "detail",

  props: {
    instance: Function,
    dict: Object,
    params: Object,
  },

  data() {
    return {
      info: {},
      isShowStarForm: false,
      isShowJobForm: false,
      jobForm: {
        date: [],
        company: "",
        position: "",
      },
      jobId: "",
      starForm: {
        starTime: "",
        level: 1,
      },
      disciplinaryId: "",
      isShowDisciplinaryForm: false,
      disciplinaryForm: {
        starTime: "",
        disciplinaryInfo: "",
        result: "",
      },
      starId: "",
      activeName: "五星党员",
      textlist: ["一星党员", "二星党员", "三星党员", "四星党员", "五星党员"],
      colConfigs1: [
        {
          prop: "starTime",
          label: "姓名",
          align: "center",
          formart: (v) => (v ? v.split(" ")[0] : "-"),
        },
        {
          prop: "starTime",
          label: "职位",
          align: "center",
          formart: (v) => (v ? v.split(" ")[0] : "-"),
        },
        
      ],
      colConfigs2: [
        { slot: "date" },
        { prop: "company", label: "单位", align: "center" },
        { prop: "position", label: "职务", align: "center" },
      ],
      colConfigs3: [
        {
          prop: "starTime",
          label: "时间",
          align: "center",
          formart: (v) => (v ? v.split(" ")[0] : "-"),
        },
        { prop: "disciplinaryInfo", label: "违纪原因", align: "center" },
        { prop: "result", label: "处理结果", align: "center" },
      ],
    };
  },

  computed: {
    ...mapState(["user"]),
  },

  created() {
    this.getInfo();
  },

  methods: {
    getInfo() {
      let { id } = this.$route.query;
      id &&
        this.instance
          .post(`/app/appparty/detail`, null, {
            params: { id },
          })
          .then((res) => {
            if (res?.data) {
              this.info = res.data;
              if (this.info.birthday) {
                this.info.birthday = this.info.birthday.substring(0, 10);
              }
            }
          });
    },
    remove(id, apiUrl) {
      this.$confirm("确定删除该数据？").then(() => {
        this.instance.post(`${apiUrl}?ids=${id}`).then((res) => {
          if (res.code == 0) {
            this.getInfo();
            this.$message.success("删除成功！");
          }
        });
      });
    },
    editJob(query) {
      this.jobForm = {
        ...query,
        date: [query.starTime, query.endTime],
      };
      this.jobId = query.id;

      this.isShowJobForm = true;
    },
    editStar(query) {
      this.starForm = {
        ...query,
      };
      this.starId = query.id;

      this.isShowStarForm = true;
    },

    editDisciplinary(query) {
      this.disciplinaryForm = {
        ...query,
      };
      this.disciplinaryId = query.id;

      this.isShowDisciplinaryForm = true;
    },

    onDisciplinarForm() {
      this.$refs.disciplinaryForm.validate((valid) => {
        if (valid) {
          this.instance
            .post(`/app/apppartydisciplinaryinfo/addOrUpdate`, {
              ...this.disciplinaryForm,
              partyId: this.params.id,
            })
            .then((res) => {
              if (res.code == 0) {
                this.isShowDisciplinaryForm = false;
                this.getInfo();
                this.$message.success(this.jobId ? "编辑成功" : "新增成功");
              }
            });
        }
      });
    },

    onJobForm() {
      this.$refs.jobForm.validate((valid) => {
        if (valid) {
          this.instance
            .post(`/app/apppartyworkinfo/addOrUpdate`, {
              ...this.jobForm,
              starTime: this.jobForm.date[0],
              endTime: this.jobForm.date[1],
              partyId: this.params.id,
            })
            .then((res) => {
              if (res.code == 0) {
                this.isShowJobForm = false;
                this.getInfo();
                this.$message.success(this.jobId ? "编辑成功" : "新增成功");
              }
            });
        }
      });
    },

    onStarForm() {
      this.$refs.starForm.validate((valid) => {
        if (valid) {
          this.instance
            .post(`/app/apppartyfivestar/addOrUpdate`, {
              ...this.starForm,
              idNumber: this.info.idNumber,
              partyId: this.params.id,
            })
            .then((res) => {
              if (res.code == 0) {
                this.isShowStarForm = false;
                this.getInfo();
                this.$message.success(this.starId ? "编辑成功" : "新增成功");
              }
            });
        }
      });
    },

    onClose() {
      this.starId = "";
      this.jobId = "";
      this.disciplinaryId = "";
      this.starForm.level = 0;
      this.starForm.id = "";
      this.starForm.starTime = "";
      this.jobForm.date = [];
      this.jobForm.company = "";
      this.jobForm.id = "";
      this.jobForm.position = "";
      this.disciplinaryForm.starTime = "";
      this.disciplinaryForm.id = "";
      this.disciplinaryForm.disciplinaryInfo = "";
      this.disciplinaryForm.result = "";
    },

    addForm(type) {
      if (type === "五星党员") {
        this.isShowStarForm = true;
      } else if (type === "工作信息") {
        this.isShowJobForm = true;
      } else {
        this.isShowDisciplinaryForm = true;
      }
    },

    cancel() {
      this.$router.push({});
    },
  },
};
</script>

<style scoped lang="scss">
.party-detail {
  ::v-deep .AiID {
    line-height: 1.4;
    color: #222;

    .el-button {
      height: auto;
      padding: 0 8px 0 0;
    }
  }

  .party-avatar {
    position: absolute;
    right: 100px;
  }
}

.audit-0 {
  color: #ff8822 !important;
}

.audit-1 {
  color: #2ea222 !important;
}

.add-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 20px;

  div {
    display: flex;
    align-items: center;
    color: #2266ff;
    font-size: 14px;

    &:hover {
      opacity: 0.6;
      cursor: pointer;
      user-select: none;
    }

    i {
      line-height: 1;
      margin-right: 4px;
    }
  }
}
</style>
