<template>
  <basic-container>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="基础信息" name="first"></el-tab-pane>
      <el-tab-pane label="退伍军人信息" name="second"></el-tab-pane>
    </el-tabs>
    <avue-form v-show="activeName=='first'" :option="optionBasic" v-model="formBasic">
      <template slot-scope="scope" slot="menuForm">
        <el-button type="primary" @click="nextStep">下一步</el-button>
      </template>
    </avue-form>
    <avue-form v-show="activeName=='second'" :option="optionVeterans" v-model="formVeterans" @submit="addEntity"></avue-form>
  </basic-container>
</template>

<script>
  import {DIC} from "@/api/util/nation"
  import {update} from "@/api/person/basicinfo";
  import {update as veteransUpdate,addVeterans} from "@/api/person/veterans";
  import {validatePhone} from "../../util/validator";
  export default {
    name: "veterans-form",
    props:{
      closeFn:{type:Function},
      tag:{type:Number},
      formBasic:{type:Object},
      formVeterans:{type:Object},
    },
    data(){
      return{
        activeName:'first',
        formBasic:{},
        formVeterans:{},
        loading:false,
        query: {},
        optionBasic:{
          tip: false,
          submitBtn:false,
          emptyBtn:false,
          column:[
            {
              label: "身份证号",
              prop: "idCard",
              search:true,
              hide: true,
              rules: [{
                required: false,
                message: "请输入身份证号码",
                trigger: "blur"
              }]
            },
            {
              label: "姓名",
              prop: "name",
              search:true,
              rules: [{
                required: true,
                message: "请输入姓名",
                trigger: "blur"
              }]
            },
            {
              label: "性别",
              prop: "sex",
              type: 'select',
              dataType:"number",
              search:true,
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=sex",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请选择性别",
                trigger: "blur"
              }]
            },
            {
              label: "所属社区",
              prop: "agencyId",
              search: true,
              cascaderItem: ['residentialId'],
              type: "select",
              remote: true,
              dicUrl: "/api/cyzh-community/agency/list?size=100",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择所属社区",
                trigger: "blur"
              }]
            },
            {
              label: "所属小区",
              prop: "residentialId",
              type: "select",
              search: true,
              cascaderItem: ['buildingId'],
              dicUrl: "/api/cyzh-community/residential/list?agencyId={{key}}&size=100",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择所属小区",
                trigger: "blur"
              }]
            },
            {
              label: "所属楼栋",
              prop: "buildingId",
              type: "select",
              // slot:true,
              search: true,
              cascaderItem: ['unitId'],
              dicUrl: "/api/cyzh-community/building/list?residentialId={{key}}&size=100",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: true,
              // filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择楼栋",
                trigger: "blur"
              }]
            },
            {
              label: "所属单元",
              prop: "unitId",
              type: "select",
              // slot:true,
              search: true,
              cascaderItem: ['floorId'],
              dicUrl: "/api/cyzh-community/unit/list?buildingId={{key}}&size=100",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择单元",
                trigger: "blur"
              }]
            },
            {
              label: "所属楼层",
              prop: "floorId",
              type: "select",
              // slot:true,
              search: true,
              cascaderItem: ['roomId'],
              dicUrl: "/api/cyzh-community/floor/list?unitId={{key}}&size=50",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择楼层d",
                trigger: "blur"
              }]
            },
            {
              label: "所属房间",
              prop: "roomId",
              type: "select",
              // slot:true,
              search: true,
              dicUrl: "/api/cyzh-community/room/list?floorId={{key}}&size=100",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择房间",
                trigger: "blur"
              }]
            },
            {
              label:'手机号码',
              prop:'phone',
              width:120,
              rules: [{
                required: true,
                message: "请输入手机号码",
              },{
                validator: validatePhone,
                trigger: "blur"
              },{
                validator: validatePhone,
                trigger: "blur"
              }]
            },
            {
              label: "邮箱",
              prop: "email",
              hide:true,
              rules: [{
                required: false,
                message: "请输入邮箱",
                trigger: "blur"
              }]
            },
            {
              label: "生日",
              prop: "birthday",
              type:'date',
              valueFormat:"yyyy-MM-dd",
              hide: true,
              rules: [{
                required: false,
                message: "请输入生日",
                trigger: "blur"
              }]
            },
            {
              label: "民族",
              prop: "nation",
              type:'select',
              dicData:DIC.VALUE,
              filterable:true,
              // searchFilterable:true,
              hide:true,
              rules: [{
                required: true,
                message: "请输入民族",
                trigger: "blur"
              }]
            },
            {
              label: "籍贯",
              prop: "nativePlace",
              hide:true,
              rules: [{
                required: false,
                message: "请输入籍贯",
                trigger: "blur"
              }]
            },
            {
              label: "国籍",
              prop: "nationality",
              hide:true,
              type:'select',
              dataType:'number',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=nationality",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请输入国籍",
                trigger: "blur"
              }]
            },
            {
              label: "政治面貌",
              prop: "political",
              hide:true,
              type: 'select',
              dataType:"number",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=political",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请选择政治面貌",
                trigger: "blur"
              }]
            },
            {
              label: "婚姻状况",
              prop: "maritalStatus",
              type: 'select',
              dataType:"number",
              hide:true,
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=marital-status",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请选择婚姻状况",
                trigger: "blur"
              }]
            },
            {
              label: "教育水平",
              prop: "educationalLevel",
              hide:true,
              type: 'select',
              dataType:"number",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=educational-level",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请选择教育水平",
                trigger: "blur"
              }]
            },
            {
              label: "工作单位",
              prop: "workplace",
              hide:true,
              rules: [{
                required: false,
                message: "请输入工作单位",
                trigger: "blur"
              }]
            },
            {
              label:"是否会员",
              prop:'isMember',
              type:"select",
              hide:true,
              dataType:'number',
              dicData:[
                {
                  label:'是',
                  value:1
                },{
                  label:'否',
                  value:0
                },{
                  label:'暂无',
                  value:-1
                }
              ],
            },
            {
              label: "照片",
              prop: "imageUri",
              type: 'upload',
              hide:true,
              listType: 'picture-img',
              propsHttp: {
                res: "data",
                url: "link"
              },
              action: "/api/blade-resource/oss/endpoint/put-file",
              tip: '只能生产jpg/png图片，且不超过500kb',
              rules: [{
                required: false,
                message: "请上传入境证明url",
                trigger: "blur"
              }]
            },
            {
              label: "备注",
              prop: "remark",
              type:'textarea',
              hide:true,
              rules: [{
                required: false,
                message: "请输入备注",
                trigger: "blur"
              }]
            },
          ]
        },
        optionVeterans:{
          emptyBtn:false,
          submitText:"提交",
          column: [
            {
              label: "姓名",
              prop: "name",
              search:true,
              display:false,
              rules: [{
                required: true,
                message: "请输入姓名",
                trigger: "blur"
              }]
            },
            {
              label: "是否独生子女",
              prop: "onlyChild",
              type: 'select',
              hide:true,
              dataType:'number',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=yes_no",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请选择是否独生子女",
                trigger: "blur"
              }]
            },
            {
              label: "身体状况",
              prop: "physicalCondition",
              hide:true,
              rules: [{
                required: false,
                message: "请输入身体状况",
                trigger: "blur"
              }]
            },
            {
              label: "可编方向",
              prop: "programmableDirection",
              hide: true,
              rules: [{
                required: false,
                message: "请输入可编方向",
                trigger: "blur"
              }]
            },
            {
              label: "服役地点",
              prop: "servicePlace",
              hide: true,
              rules: [{
                required: true,
                message: "请输入服役地点",
                trigger: "blur"
              }]
            },
            {
              label: "入伍日期",
              prop: "enlistmentTime",
              type: 'date',
              hide:true,
              format: 'yyyy-MM-dd',
              rules: [{
                required: true,
                message: "请输入入伍日期",
                trigger: "blur"
              }]
            },
            {
              label: "退伍日期",
              prop: "dischargeTime",
              type: 'date',
              format: 'yyyy-MM-dd',
              rules: [{
                required: true,
                message: "请输入退伍日期",
                trigger: "blur"
              }]
            },
            {
              label: "服役军种",
              prop: "services",
              hide:true,
              rules: [{
                required: false,
                message: "请输入服役军种",
                trigger: "blur"
              }]
            },
            {
              label: "转业退伍时职务",
              prop: "postOfDischarge",
              hide: true,
              rules: [{
                required: false,
                message: "请输入转业退伍时职务",
                trigger: "blur"
              }]
            },
            {
              label: "退役证件名称",
              prop: "retirementCertificate",
              hide: true,
              rules: [{
                required: false,
                message: "请输入退役证件名称",
                trigger: "blur"
              }]
            },
            {
              label: "退役证件编号",
              prop: "retirementCertificateCode",
              hide: true,
              rules: [{
                required: false,
                message: "请输入退役证件编号",
                trigger: "blur"
              }]
            },
            {
              label: "优抚证书",
              prop: "specialCareCertificate",
              type: "upload",
              hide: true,
              row: true,
              listType: 'picture-img',
              action: "/api/blade-resource/oss/endpoint/put-file",
              propsHttp: {
                res: "data",
                url: "link"
              },
              tip: '只能生产jpg/png图片，且不超过500kb',
              rules: [{
                required: false,
                message: "请输入优抚证书",
                trigger: "blur"
              }]
            },
            {
              label: "奖励或处分",
              prop: "rewardAndPunishment",
              hide:true,
              rules: [{
                required: false,
                message: "请输入在部队由何原因受过何种奖励、处分",
                trigger: "blur"
              }]
            },
          ]
        },
      }
    },
    methods:{
      nextStep(){
        if (!this.validatenull(this.formBasic.name) && !this.validatenull(this.formBasic.sex) && !this.validatenull(this.formBasic.agencyId) && !this.validatenull(this.formBasic.residentialId)
          && !this.validatenull(this.formBasic.buildingId) && !this.validatenull(this.formBasic.floorId) && !this.validatenull(this.formBasic.unitId)
          && !this.validatenull(this.formBasic.roomId) && !this.validatenull(this.formBasic.phone)){
          this.activeName='second';
        }else {
          this.$message({
            type: "warning",
            message: "请先完善当前界面信息!"
          })
        }
      },
      addEntity(){
        //新增
        if (this.tag==1){
          var ObjectList = new Array();
          ObjectList.push(this.formVeterans);
          ObjectList.push(this.formBasic);
          addVeterans(ObjectList).then(()=>{
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$emit('refreshChange');
            this.closeFn();
          }, error => {
            // loading();
            window.console.log(error);
          });
        }else {
          //修改基本信息
          update(this.formBasic).then(() => {}, error => {
            window.console.log(error);
          });
          //修改退伍军人信息
          veteransUpdate(this.formVeterans).then(() => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$emit('refreshChange');
            this.closeFn();
          }, error => {
            window.console.log(error);
          });
        }
      },
      handleClick(tab, event){
        console.log(tab,event)
      },
    }
  }
</script>

<style scoped>

</style>
