<!--
 * @Description: 
 * @Author: gcz
 * @Date: 2022-08-25 09:38:41
 * @LastEditors: gcz
 * @LastEditTime: 2022-08-26 16:08:25
 * @FilePath: \veterans_client_web\src\views\PersonalCenter\Resume\ResumeEdit.vue
 * @Copyright: Copyright (c) 2016~2022 by gcz, All Rights Reserved. 
-->
<template>
  <div class="app-main">
    <BannerBreadcrumb title="我的简历" :breadcrumb="false" />
    <div class="banner-breadcrumb-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/personalcenter' }"
          >我的</el-breadcrumb-item
        >
        <el-breadcrumb-item>我的简历</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="app-main-box">
      <div class="app-main-box-content resume">
        <div class="title">我的简历</div>
        <el-row>
          <el-col :span="16">
            <div class="name">{{ memberinfo.name }}</div>
            <div class="">
              {{ memberinfo.menSex === 1 ? "女" : "男" }} ·
              <!-- <span class="position" v-if="memberinfo.jobStatus !== 0">
                · <span class="c-yellow">入职中</span>
                <span>({{memberinfo.company}})</span>
              </span>
              <span class="c-yellow" v-else>未入职</span> -->
              <el-switch
                @change="updateJobStatus"
                v-model="jobStatus"
                active-text="已入职"
                active-color="#709078"
                :active-value="1"
                :inactive-value="0"
                inactive-text="未入职">
              </el-switch>
              <span v-if="jobStatus==1&&memberinfo.company" style="margin-left:10px">({{memberinfo.company}})</span>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="avatar hexagon">
              <div
                class="avatar-box hexagon-box"
                :style="{
                  backgroundImage: `url('${
                    memberinfo.avatar
                      ? memberinfo.avatar
                      : 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
                  }')`,
                }"
              ></div>
            </div>
          </el-col>
        </el-row>
        <el-row class="resumm-item">
          <el-col :span="24">
            <div class="item-title">基本信息</div>
            <p>
              退役军人 ·
              {{ memberinfo.menBirth ? getAge(memberinfo.menBirth) : "-" }}岁 ·
              {{ memberinfo.politOutlook || "-" }} ·
              {{ memberinfo.degrEduc || "-" }}
            </p>
            <p>电话：{{ memberinfo.mobile }}</p>
          </el-col>
        </el-row>
        <el-form ref="form" :model="form" label-width="80px">
          <div class="form-title">求职意向</div>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item
                label="最低工资"
                prop="expectedLowestSalary"
              >
                <el-col :span="8">
                  <el-select v-model="form.expectedLowestSalary" placeholder="请选择">
                    <el-option
                      v-for="item of 50"
                      :disabled="item >= form.expectedHighestSalary"
                      :key="item"
                      :label="item"
                      :value="item"
                    >
                    </el-option>
                  </el-select>
                </el-col>
                <el-col :span="4">
                  <div
                    :style="{
                      width: '100%',
                      fontSize: '50px',
                      textAlign: 'center',
                    }"
                  >
                    ~
                  </div>
                </el-col>
                <el-col :span="8">
                  <el-select v-model="form.expectedHighestSalary" placeholder="请选择">
                    <el-option
                      v-for="item of 50"
                      :disabled="item <= form.expectedLowestSalary"
                      :key="item"
                      :label="item"
                      :value="item"
                    >
                    </el-option>
                  </el-select>
                </el-col>
                <el-col :span="2">
                  <div
                    :style="{
                      width: '100%',
                      fontSize: '40px',
                      paddingLeft: '3px',
                      fontWeight: 1,
                    }"
                  >
                    K
                  </div>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="意向地区" prop="intentionArea">
                <el-cascader
                  filterable
                  size="large"
                  ref="addressSelect"
                  :options="addressOptions"
                  v-model="form.intentionArea"
                  :leafOnly="true"
                  @change="addrChange"
                >
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="期望行业">
                <el-input v-model="form.expectedIndustry"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="期望职位">
                <el-input v-model="form.expectedPost"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="btn-wrap">
            <span class="btn" @click="saveJobIntention">保存</span>
          </div>
        </el-form>
        <section class="resumm-item self-assessment">
          <div class="item-title">自我评价</div>
          <el-input
            class="textarea"
            type="textarea"
            :rows="5"
            placeholder="请输入自我评价"
            v-model="selfAssessment">
          </el-input>
          <div class="btn-wrap">
            <span class="btn" @click="saveSelfAssessment">保存</span>
          </div>
        </section>
      </div>
    </div>
  </div>
</template>

<script>
import BannerBreadcrumb from "@/components/BannerBreadcrumb";
import { getPersonInfoData ,saveJobIntention,saveSelfAssessment ,updateJobStatus} from "@/api/PersonalCenter";
import { regionDataPlus,regionData, CodeToText,TextToCode  } from "element-china-area-data";
export default {
  name: "Resume",
  components: {
    BannerBreadcrumb,
  },
  data() {
    return {
      addressOptions: regionDataPlus,
      memberinfo: {},
      jobStatus:null,
      form: {
        intentionArea:[],
        expectedPost:'',
        expectedIndustry:'',
        expectedLowestSalary:null,
        expectedHighestSalary:null,
      },
      selfAssessment:''
    };
  },
  created() {
    this.getPersonInfo();
  },
  methods: {
    /**
     * 获取个人信息
     * @date 2022-08-15
     * @returns {any}
     */
    getPersonInfo() {
      getPersonInfoData().then((res) => {
        if (res.code === 200) {
          this.memberinfo = res?.data;
          // this.form.provinceId = res?.data?.provinceId;
          // this.form.provinceName = res?.data?.provinceName;
          // this.form.cityId = res?.data?.cityId;
          // this.form.cityName = res?.data?.cityName;
          // this.form.areaId = res?.data?.areaId;
          // this.form.areaName  = res?.data?.areaName ;
          this.form.expectedPost = res?.data?.expectedPost||'';
          this.form.expectedIndustry = res?.data?.expectedIndustry||'';
          this.form.expectedLowestSalary = Number( res?.data?.expectedLowestSalary );
          this.form.expectedHighestSalary = Number( res?.data?.expectedHighestSalary );

          this.form.intentionArea = [];
          this.form.intentionArea.push(res?.data?.provinceId.toString())
          this.form.intentionArea.push(res?.data?.cityId.toString())
          this.form.intentionArea.push(res?.data?.areaId.toString())

          this.jobStatus = res?.data?.jobStatus;
          console.log('this.jobStatus',this.jobStatus);

          this.selfAssessment = res?.data?.selfAssessment||'';
          console.log("this.form", this.form);
        }
      });
    },
    /**
     * 通过出生年月计算年龄
     * @param { String } date
     */
    getAge(date) {
      const birth = new Date(date).valueOf();
      const now = new Date().valueOf();
      const age = (now - birth) / 1000 / 60 / 60 / 24 / 365;
      return parseInt(age);
    },
    addrChange(value) {
        this.form.provinceId =value[0];
        this.form.cityId = value[1];
        this.form.areaId = value[2];
        this.form.provinceName = CodeToText[value[0]];
        this.form.cityName = CodeToText[value[1]];
        this.form.areaName = CodeToText[value[2]];
      console.log("this.provinceName", this.provinceName);
      console.log("addrChange", value);
    },
    saveJobIntention(){
      saveJobIntention(this.form).then(res=>{
        this.$message.success(res.msg)
        // console.log('saveJobIntention',res);
      })
    },
    saveSelfAssessment(){
      saveSelfAssessment({selfAssessment:this.selfAssessment}).then(res=>{
        this.$message.success(res.msg)
      })
    },
    updateJobStatus(){
      console.log('updateJobStatusupdateJobStatus');
      updateJobStatus({jobStatus:this.jobStatus}).then(res=>{
        this.$message.success(res.msg)
      })
    }
  },
};
</script>

<style lang='scss' scoped>
.c-yellow {
  color: #ff6901;
}

.app-main-box-content {
  min-height: calc(100vh - 73px - 104px - 64px - 100px - 23px - 40px);
}
.banner-breadcrumb-breadcrumb {
  background-color: #fff;
  :deep(.el-breadcrumb) {
    width: 70%;
    height: 64px;
    line-height: 64px;
    min-width: 600px;
    margin: 0 auto;
    font-size: 20px;
  }
  :deep(.el-breadcrumb__inner.is-link) {
    color: #7e7e7e;
    font-weight: normal;
  }
  :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
    color: #ff0000;
  }
}
.resume {
  color: #666;
  .title {
    text-align: center;
    color: #222;
    font-weight: 400;
    font-size: 24px;
    letter-spacing: 1.55px;
    padding-bottom: 30px;
    border-bottom: 1px solid #d7d7d7;
    margin-bottom: 40px;
  }
  .name {
    color: #222;
    font-size: 30px;
    margin-bottom: 10px;
  }
  .avatar {
    width: 138px;
    height: 138px;
    background-color: rgba($color: #fff, $alpha: 0.7);
    padding: 7px;
    margin-right: 0;
    margin-left: auto;
  }
  .resumm-item {
    margin-bottom: 50px;
    .item-title {
      font-size: 20px;
      color: #222;
      margin-bottom: 14px;
      position: relative;
      padding-left: 10px;
      &::before{
        content:'';
        width: 5px;
        height: 5px;
        border-radius: 50%;
        position: absolute;
        left: 0;
        top: 50%;
        margin-top: -2.5px;
        background: #709078;
      }
    }
    p {
      margin-bottom: 10px;
    }
    .link-page {
      padding-top: 24px;
      text-align: right;
      cursor: pointer;
    }
  }
}
.el-form {
  background: #f4f4f4;
  margin-left: -20px;
  margin-right: -20px;
  padding: 20px;
  .form-title {
    font-size: 20px;
    color: #222;
    margin-bottom: 14px;
  }
}
.btn-wrap{
    text-align: right;
    .btn{
      display: inline-block;
      padding: 0 20px;
      cursor: pointer;
      height: 30px;
      line-height: 30px;
      background: #709078;
      color: #fff;
      font-size: 16px;
      border-radius: 5px;
      margin-left: 10px;
    }
  }
.resumm-item.self-assessment{
  padding-top: 24px;
  margin-bottom: 0;
  .textarea{
    margin-bottom: 24px;
  }
}
:deep(.el-switch){
  .el-switch__label.is-active{
    color: #ff6901;
  }
}
</style>
