<template>
  <div class="main">
    <div class="top">
      如档案有问题请联系HR小白
      <i>18821992017</i>
    </div>
    <div class="header">
      <div class="header_name">{{employee_name}}</div>
      <div class="header_info">{{employee_sex}}|{{employee_birthday}}</div>
    </div>
    <work-info :obj="obj" :query="query" />
    <person-info :isEdit="isEdit" />
    <contact-info :isEdit="isEdit" />
    <social-info :isEdit="isEdit" />
    <wage-card-info :isEdit="isEdit" />
    <edu-experience :isEdit="isEdit" />
    <work-experience :isEdit="isEdit" />
    <teachnology-experience :isEdit="isEdit" />
    <!-- <archive-question /> -->
    <div class="saveBtn" v-if="this.isEdit==0 || this.isEdit==-1">
      <van-button type="primary" block @click="handleSave">提交信息</van-button>
    </div>
  </div>
</template>

<script lang="ts">
import Vue from "vue";
import { Button,Toast } from "vant";
import { Component } from "vue-property-decorator";
import workInfo from "./archives/workInfo.vue";
import personInfo from "./archives/personInfo.vue";
import contactInfo from "./archives/contactInfo.vue";
import socialInfo from "./archives/socialInfo.vue";
import wageCardInfo from "./archives/wageCardInfo.vue";
import eduExperience from "./archives/eduExperience.vue";
import workExperience from "./archives/workExperience.vue";
import teachnologyExperience from "./archives/technologyExperience.vue";
import archiveQuestion from "./archives/archiveQuestion.vue";

@Component({
  name: "Archives",
  components: {
    workInfo,
    personInfo,
    contactInfo,
    socialInfo,
    wageCardInfo,
    eduExperience,
    workExperience,
    teachnologyExperience,
    archiveQuestion,
    [Button.name]: Button
  }
})
export default class archives extends Vue {
  private isEdit: string = "";
  private employee_name: any = "";
  private employee_birthday: any = "";
  private employee_sex: any = "";
  private obj: object = {};
  private query: object = {};
  created() {
    this.employee_name = localStorage.getItem("name") as string;
    this.employee_birthday = localStorage.getItem("birthday") as string;
    this.employee_sex = localStorage.getItem("sex") as string;
    this.handleInfo();
  }
  sortKey(array: any, key: any) {
    return array.sort(function(a: any, b: any) {
      var x = a[key];
      var y = b[key];
      return x > y ? -1 : x < y ? 1 : 0;
    });
  }
  handleInfo() {
    let params = {
      spId: this.$route.query.sp_id,
      idNo: this.$route.query.id_no
    };
    this.$server.EmployeeService.getDispatchInfo(params).then(res => {
      this.query = res;
      this.isEdit = res.auditInfoStatus;
      this.obj = this.sortKey(res.workData, "res.workData.workStartDate")[0];
    });
  }
  handleSave() {
    let params = {
      edId: this.$route.query.ed_id
    };
    this.$server.EmployeeService.updateBaseInfo(params).then(res => {
      if (res == true) {
        Toast.success("保存成功");
        setTimeout(() => {
          window.location.href=window.location.href
        }, 500);
      } else {
        Toast(res.message);
      }
    });
  }
}
</script>

<style lang="less" scoped>
.main {
  background: #f5f7fa;
  .top {
    font-size: 15px;
    color: rgba(149, 152, 158, 1);
    line-height: 15px;
    padding: 20px 20px 10px;
    i {
      color: #077aec;
    }
  }
  .header {
    margin-top: 10px;
    background: white;
    padding: 24px 20px;
    .header_name {
      height: 24px;
      font-size: 24px;
      font-weight: 500;
      color: rgba(61, 64, 71, 1);
      line-height: 24px;
    }
    .header_info {
      height: 14px;
      font-size: 14px;
      color: rgba(149, 152, 158, 1);
      line-height: 14px;
      margin-top: 16px;
    }
  }
  .saveBtn {
    margin-top: 10px;
    color: white !important;
    font-size: 18px;
  }
}
</style>