<template>
  <div class="div_form" v-loading="loading">
    <div class="form">
      <el-form :model="form" :rules="rules" label-width="105px" ref="editForm">
        <h5 style="margin-top: 6px">基础信息登记</h5>
        <div class="flex_box">
              <el-form-item
                label="姓名"
                prop="baseInfoDto.name"
                class="font-color-orange flex_item_width1"
              >
                <el-input
                  class="list_item_width_1"
                  v-model.trim="form.baseInfoDto.name"
                  placeholder="请输入内容"
                  size="small"
                  clearable
                ></el-input>
              </el-form-item>
            
              <el-form-item
                label="证件类型"
                prop="baseInfoDto.idType"
                class="font-color-orange flex_item_width1"
              >
                <el-select
                  v-model.trim="form.baseInfoDto.idType"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in idTypeList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
           
              <el-form-item
                label="证件号"
                prop="baseInfoDto.idNum"
                class="flex_item_width1"
              >
                <el-input
                  v-model.trim="form.baseInfoDto.idNum"
                  placeholder="请输入内容"
                  clearable
                  size="small"
                  class="list_item_width_1"
                  @blur="handleValidBlur"
                ></el-input>
              </el-form-item>
          
              <el-form-item
                label="国籍"
                prop="baseInfoDto.nationality"
                class="font-color-orange flex_item_width1"
              >
                <el-select
                  v-model.trim="form.baseInfoDto.nationality"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dicts.nationalityList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            
              <el-form-item
                label="联系电话"
                prop="baseInfoDto.mobile"
                class="font-color-orange flex_item_width1"
              >
                <el-input
                  class="list_item_width_1"
                  v-model.trim="form.baseInfoDto.mobile"
                  placeholder="请输入内容"
                  size="small"
                  clearable
                ></el-input>
              </el-form-item>
           
              <el-form-item label="性别" prop="baseInfoDto.gender" class="flex_item_width1">
                <el-select
                  v-model.trim="form.baseInfoDto.gender"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in genderList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
          
              <el-form-item label="出生日期" class="flex_item_width1" prop="baseInfoDto.birthday">
                <el-date-picker
                  v-model.trim="form.baseInfoDto.birthday"
                  class="list_item_width_1"
                  type="date"
                  size="small"
                  clearable
                  placeholder="选择日期"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
           </el-form-item>
              <el-form-item label="民族" class="flex_item_width1" prop="baseInfoDto.nation">
                <el-select
                  v-model.trim="form.baseInfoDto.nation"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dicts.nationList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
           
              <el-form-item label="文化程度" class="flex_item_width1" prop="eduInfoDto.cultureLevel">
                <el-select
                  v-model.trim="form.eduInfoDto.cultureLevel"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dicts.educationList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
           
              <el-form-item label="婚姻状况" class="flex_item_width1" prop="familyInfoDto.marriage">
                <el-select
                  v-model.trim="form.familyInfoDto.marriage"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dicts.marriageList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    @click.native="handelClickMarriage(item.value)"
                  ></el-option>
                </el-select>
              </el-form-item>
           
              <el-form-item
              class="flex_item_width1"
                label="配偶情况"
                prop="familyInfoDto.spouseSituation"  v-if="
                (form.familyInfoDto &&
                  form.familyInfoDto.marriage == 'chuhun') ||
                form.familyInfoDto.marriage == 'zaihun' ||
                form.familyInfoDto.marriage == 'fuhun'
              "
              >
                <el-select
                  v-model.trim="form.familyInfoDto.spouseSituation"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dicts.spouseSituationList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
          
              <el-form-item label="籍贯" class="flex_item_width1" prop="baseInfoDto.nativePlace">
                <el-input
                  v-model.trim="form.baseInfoDto.nativePlace"
                  placeholder="请输入内容"
                  clearable
                  size="small"
                  class="list_item_width_1"
                ></el-input>
                <el-radio-group v-model.trim="form.baseInfoDto.localResidenceFlag" style="margin-left: 10px;">
                  <el-radio
                    :label="1"
                    @click.native.prevent="handleLocalRadio($event, 1)"
                    >本地</el-radio
                  >
                  <el-radio
                    :label="0"
                    @click.native.prevent="handleLocalRadio($event, 0)"
                    v-show="false"
                    >非本地</el-radio
                  >
                </el-radio-group>
              </el-form-item>
          <el-form-item label="备注" prop="baseInfoDto.remark" class="flex_item_width2">
            <el-input
              type="textarea"
              class="item_width_1"
              :rows="3"
              placeholder="请输入内容"
              v-model.trim="form.baseInfoDto.remark"
              clearable
            >
            </el-input>
          </el-form-item>
        </div>
        <h5>居住信息登记</h5>
          <section
            v-for="(rowItem, index) in this.form.resideInfoDtos"
            :key="index"
          >
          <div class="flex_box">  
             <el-form-item
                  label="所属组织"
                  class="font-color-orange flex_item_width1"
                  :prop="`resideInfoDtos[${index}].gridId`"
                  :rules="[
                    {
                      required: true,
                      message: '请选择所属组织',
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-cascader
                    class="list_item_width_1"
                    ref="myCascader"
                    clearable
                    size="small"
                    v-model.trim="form.resideInfoDtos[index].gridId"
                    :options="form.resideInfoDtos[index].orgOptions"
                    :props="orgOptionProps"
                    @change="handleChangeAgency(index)"
                    :disabled="rowItem.accessable === 0"
                  ></el-cascader>
                </el-form-item>
            
                <el-form-item
                  :prop="`resideInfoDtos[${index}].villageId`"
                  label="所属房屋"
                  label-width="100px"
                  class="font-color-orange flex_item_width4"
                  :rules="[
                    { required: true, message: '请选择小区', trigger: 'blur' },
                  ]"
                >
                  <el-select
                    v-model.trim="form.resideInfoDtos[index].villageId"
                    placeholder="请选择小区"
                    size="small"
                    class=" f-bto0"
                    clearable
                    @change="handleChangeV(index)"
                    :disabled="rowItem.accessable === 0"
                  >
                    <el-option
                      v-for="item in rowItem.optionsV"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item
                  :prop="`resideInfoDtos[${index}].buildId`"
                  label-width="0"
                  style="margin: 0px"
                  :rules="[
                    { required: true, message: '请选择楼栋', trigger: 'blur' },
                  ]"
                >
                  <el-select
                    v-model.trim="form.resideInfoDtos[index].buildId"
                    placeholder="楼号"
                    size="small"
                    clearable
                    @change="handleChangeB(index)"
                    class="flex_item_width3 f-bto0"
                    :disabled="rowItem.accessable === 0"
                  >
                    <el-option
                      v-for="item in rowItem.optionsB"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item
                  :prop="`resideInfoDtos[${index}].unitId`"
                  label-width="0"
                  style="margin: 0px"
                  :rules="[
                    { required: true, message: '请选择单元', trigger: 'blur' },
                  ]"
                >
                  <el-select
                    v-model.trim="form.resideInfoDtos[index].unitId"
                    placeholder="单元"
                    size="small"
                    clearable
                    class="flex_item_width3 f-bto0"
                    @change="handleChangeD(index)"
                    :disabled="rowItem.accessable === 0"
                  >
                    <el-option
                      v-for="item in rowItem.optionsD"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item
                  :prop="`resideInfoDtos[${index}].homeId`"
                  label-width="0"
                  style="margin: 0px"
                  :rules="[
                    { required: true, message: '请选择房屋', trigger: 'blur' },
                  ]"
                  :disabled="rowItem.accessable === 0"
                >
                  <el-select
                    v-model.trim="form.resideInfoDtos[index].homeId"
                    placeholder="房号"
                    size="small"
                    clearable
                    class="flex_item_width3 f-bto0"
                    @change="handleChangeH(index)"
                    :disabled="rowItem.accessable === 0"
                  >
                    <el-option
                      v-for="item in rowItem.optionsH"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-button
                  type="primary"
                  size="mini"
                  icon="el-icon-plus"
                  circle
                  @click="handelClickAddHouse"
                  style="margin-left: 16px; height: 30px"
                ></el-button>
                <el-button
                  type="danger"
                  v-if="form.resideInfoDtos.length > 1 && rowItem.accessable !== 0"
                  size="small"
                  icon="el-icon-minus"
                  @click="handelClickDelHouse(index)"
                  style="height: 30px"
                  circle
                >
                </el-button>
              </div>
          <div class="flex_box">
            <el-form-item label="人房关系" class="font-color-blue flex_item_width1">
                  <el-select
                    v-model.trim="form.resideInfoDtos[index].resiHouseRel"
                    placeholder="请选择"
                    size="small"
                    class="list_item_width_1"
                    @change="handelChangeResiHouseRel($event, index)"
                    clearable
                    :disabled="rowItem.accessable === 0"
                  >
                    <el-option
                      v-for="(item, i) in dicts.resiHouseRelList"
                      :key="i"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="人户状况" class="font-color-blue flex_item_width1">
                  <el-select
                    v-model.trim="form.resideInfoDtos[index].householdSituation"
                    placeholder="请选择"
                    size="small"
                    class="list_item_width_1"
                    clearable
                    :disabled="rowItem.accessable === 0"
                  >
                    <el-option
                      v-for="(item, index) in dicts.householdSituationList"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item
                  label="与户主关系"
                  class="font-color-blue font-color-blue2 flex_item_width1"
                >
                  <el-select
                    v-model.trim="form.resideInfoDtos[index].houseHolderRel"
                    placeholder="请选择"
                    size="small"
                    class="list_item_width_1"
                    clearable
                    :disabled="rowItem.accessable === 0"
                  >
                    <el-option
                      v-for="(item, index) in dicts.houseHolderRelList"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
           
                <el-form-item label="户籍所在地" v-if="form.resideInfoDtos[index].householdSituation == 'rzhbz'" class="flex_item_width1">
                  <el-input
                    class="list_item_width_1"
                    v-model.trim="form.resideInfoDtos[index].placeOfDomicile"
                    placeholder="请输入内容"
                    size="small"
                    clearable
                    :disabled="rowItem.accessable === 0"
                  ></el-input>
                </el-form-item>
             
                <el-form-item label="现居住地址"   v-else-if="
                  form.resideInfoDtos[index].householdSituation == 'hzrbz'
                " class="flex_item_width1">
                  <el-input
                    class="list_item_width_1"
                    v-model.trim="form.resideInfoDtos[index].currentResidence"
                    placeholder="请输入内容"
                    size="small"
                    :disabled="rowItem.accessable === 0"
                    clearable
                  ></el-input>
                </el-form-item>
             
                <el-form-item label="迁出时间" 
                 class="flex_item_width1"  v-else-if="
                  form.resideInfoDtos[index].householdSituation == 'rhdbz'
                ">
                  <el-date-picker
                    v-model.trim="form.resideInfoDtos[index].outOfTime"
                    class="list_item_width_1"
                    type="date"
                    size="small"
                    clearable
                    placeholder="选择日期"
                    format="yyyy 年 MM 月 dd 日"
                    value-format="yyyy-MM-dd"
                    :disabled="rowItem.accessable === 0"
                  >
                  </el-date-picker>
                </el-form-item>
          </div> 
          </section>
        <h5>拓展信息登记</h5>
        <div class="flex_box">
         
              <el-form-item class="flex_item_width1" label="宗教信仰" prop="religionDto.religion">
                <el-input
                  class="list_item_width_1"
                  v-model.trim="form.religionDto.religion"
                  placeholder="请输入内容"
                  size="small"
                  clearable
                ></el-input>
              </el-form-item>
            
              <el-form-item
                label="就业状态"
                class="font-color-blue flex_item_width1"
                prop="workInfoDto.careerStatus"
              >
                <el-select
                  v-model.trim="form.workInfoDto.careerStatus"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dicts.careerStatusList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    @click.native="handelClickCareerStatus(item.value)"
                  ></el-option>
                </el-select>
              </el-form-item>
            
              <el-form-item label="工作单位" class="flex_item_width1" prop="workInfoDto.workUnit" v-if="
                form.workInfoDto.careerStatus >= 1 &&
                form.workInfoDto.careerStatus <= 5
              ">
                <el-input
                  class="list_item_width_1"
                  v-model.trim="form.workInfoDto.workUnit"
                  placeholder="请输入内容"
                  size="small"
                  clearable
                ></el-input>
              </el-form-item>
            
              <el-form-item  v-if="
                form.workInfoDto.careerStatus >= 1 &&
                form.workInfoDto.careerStatus <= 5
              " label="职业" class="flex_item_width1" prop="workInfoDto.occupation">
                <el-input
                  class="list_item_width_1"
                  v-model.trim="form.workInfoDto.occupation"
                  placeholder="请输入内容"
                  size="small"
                  clearable
                ></el-input>
              </el-form-item>
       
              <el-form-item label="月收入" class="flex_item_width1"  v-if="
              form.workInfoDto.careerStatus >= 1 &&
              form.workInfoDto.careerStatus <= 5
            " prop="economyDto.monthIncome">
                <el-input
                  class="list_item_width_1"
                  v-model.trim="form.economyDto.monthIncome"
                  placeholder="请输入内容"
                  size="small"
                  clearable
                ></el-input>
              </el-form-item>
           
              <el-form-item label="有无赡养人" class="flex_item_width1" prop="familyInfoDto.elderlyFlag">
                <el-radio-group v-model.trim="form.familyInfoDto.elderlyFlag">
                  <el-radio
                    :label="item.value"
                    v-for="item in hasOptions"
                    :key="item.value"
                    @click.native="handelClickelderly"
                    >{{ item.label }}</el-radio
                  >
                </el-radio-group>
              </el-form-item>
          
              <el-form-item
              v-if="form.familyInfoDto.elderlyFlag == 1" class="flex_item_width1"
                label="与赡养人关系"
                prop="familyInfoDto.elderlyRelation"
              >
                <el-select
                  v-model.trim="form.familyInfoDto.elderlyRelation"
                  placeholder="请选择"
                  size="small"
                  class="list_item_width_1"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dicts.houseHolderRelList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
              v-if="form.familyInfoDto.elderlyFlag == 1" class="flex_item_width1"
                label="赡养人联系电话"
                prop="familyInfoDto.dependantMobile"
              >
                <el-input
                  class="list_item_width_1"
                  v-model.trim="form.familyInfoDto.dependantMobile"
                  placeholder="请输入内容"
                  size="small"
                  clearable
                ></el-input>
              </el-form-item>
        </div>
        <h5>人员标签</h5>
        <div class="stafftag">
          <stafftag
            :formType="'edit'"
            ref="stafftag"
            :userInfo="form"
            @showDialog="showDialog"
          >
          </stafftag>
        </div>
        <resi-expand
          ref="resiExpand"
          @submitExpand="submitExpand"
        ></resi-expand>
        <el-row style="margin: 24px">
          <el-col :span="24" align="center">
            <el-button
              size="small"
              class="diy-button--white"
              @click="handlerCancle"
              plain
              >取消</el-button
            >
            <el-button
              type="primary"
              size="small"
              @click="handleClickSubmit"
              :loading="btnLoading"
              >保存</el-button
            >
            <el-button
              type="primary"
              size="small"
              @click="handleClickSubmit('house')"
              :loading="btnLoading"
              >提交并补充重点人员信息</el-button
            >
          </el-col>
        </el-row>
      </el-form>
      <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" destroy-on-close width="1028px">
            <add-expand ref="addExpand" @submitExpand="submitExpandAdd" @hideExpand="hideExpand"
                :operationType="'add'"></add-expand>
        </el-dialog>
    </div>
  </div>
</template>

<script>
import { requestGet, requestPost } from "@/js/dai/request";
import {
  isCard,
  isPassport,
  isMobile,
  isPhone,
  isHKPassport,
  isTwPassport,
  isSoldier,
} from "@/utils/validate";
import { computedCard } from "@/utils/index";
import {
  idTypeList,
  genderList,
  hasOptions,
  disabilityFlagList,
} from "@/js/columns/constants";
import stafftag from "@/views/modules/portrayal/jumin/cpts/staffTag.vue";
import resiExpand from "@/views/components/resiExpand/editExpand.vue";
import addExpand from "@/views/components/resiExpand/index.vue";

export default {
  name: 'editKeyPersonnel',
  data() {
    return {
      loading: false,
      dialogTitle:null,
      dialogVisible:false,
      houseType: true,
      formList: [],
      orgOptions: [],
      orgOptionProps: {
        value: "agencyId",
        label: "agencyName",
        children: "subAgencyList",
        emitPath: false,
        multiple: false,
        checkStrictly: true,
      },

      resiId: this.$route.query.id,
      form: {
        baseInfoDto: {
          name: null, //姓名
          idType: null, //证件类型
          idNum: null, //身份证号
          nationality: null, //国籍
          mobile: null, //手机号
          gender: null, //性别
          birthday: null, //出生日期
          nation: null, //民族
          localResidenceFlag: 0, //是否本地户籍
          nativePlace: null, //籍贯,
          remark: null, //备注,
          deathFlag:0,//死亡
          deathDate:null,//死亡日期
          categoryInfo: {
            partyFlag: 0,
            subsistenceAllowanceFlag: 0,
            ensureHouseFlag: 0,
            unemployedFlag: 0,
            fertileWomanFlag: 0,
            veteranFlag: 0,
            unitedFrontFlag: 0,
            petitionOfficerFlag: 0,
            volunteerFlag: 0,
            oldPeopleFlag: 0,
            emptyNesterFlag: 0,
            specialSupportFlag: 0,
            disabledFlag: 0,
            dementedFlag: 0,
            disabilityFlag: 0,
            seriousIllnessFlag: 0,
            chronicDiseaseFlag: 0,
            specialCrowdFlag: 0,
            tenantFlag: 0,
            floatingFlag: 0,
            liveAloneFlag: 0,
            publicWelfareFlag: 0,
            buildingChiefFlag: 0,
            unitChiefFlag: 0,
            riskyFlag: 0,
            delFlag: 0,
            aidsFlag:0,
            lbcFlag:0,
            negFlag :0
          },
        },
        eduInfoDto: {
          cultureLevel: null, //文化程度
        },
        familyInfoDto: {
          marriage: null, //婚姻状况
          spouseSituation: null, //配偶情况
          elderlyFlag: null, //有无赡养人
          elderlyRelation: null, //与赡养人关系
          dependantMobile: null, //赡养人联系电话
        },
        resideInfoDtos: [
          {
            agencyName: this.$store.state.user.agencyName,
            agencyId: this.$store.state.user.agencyId,
            gridId: null, //所属网格id
            villageId: null, //小区id
            buildId: null, //楼栋id
            unitId: null, //单元id
            moveOutFlag: null,
            outOfTime: null, //迁出时间
            homeId: null, //房屋id
            placeOfDomicile: null, //户籍所在地
            currentResidence: null, //现居住地
            householdSituation: null, //人户状况
            houseHolderRel: null, //与户主关系
            resiHouseRel: null, //人房关系
            optionsV: [],
            optionsB: [],
            optionsH: [],
            optionsD: [],
            orgOptions: [],
          },
        ],
        religionDto: {
          religion: null, //宗教信仰
        },
        workInfoDto: {
          careerStatus: null, //就业状况
          workUnit: null, //工作单位
          occupation: null, //职业
        },
        specialDto: {
          specialCategoryCodes: [],
        },
        unemployedDto: {
          originWorkUnit: null, //原工作单位
          unemploymentTime: null, //失业时间yyyy-MM-dd
          unemploymentNum: null, //失业证号
          employmentNum: null, //再就业优惠证号
          specialSkill: null, //技术特长
          unempCompensationFlag: null, //是否领取失业补助金
          unemploymentReason: null, //失业原因【字典表】code
          employmentHardFlag: null, //是否就业困难对象；1是0不是
          employmentWish: null, //劳动能力就业愿望
        },
        economyDto: {
          monthIncome: null, //月收入
        },
      },
      orgOption: [],
      footerInputList: [
        {
          id: "healthDto",

          children: [
            {
              label: "残疾类别",
              check:'fourFont',
              itemType: "select1",
              pformName: "healthDto",
              formName: "disabilityCategoryCode",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "disability_category_code" },
              opction: [],
            },
            {
              label: "残疾等级",
              itemType: "select1",
              check:'fourFont',
              pformName: "healthDto",
              formName: "disabilityLevel",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "disability_level" },
              opction: [],
            },
            {
              label: "残疾证号",
              pformName: "healthDto",
              itemType: "input1",
              check:'fourFont',
              formName: "disabilityNum",
            },
            {
              label: "残疾说明",
              pformName: "healthDto",
              itemType: "input1",
              formName: "disabilityDesc",
            },
            {
              label: "监护人",
              itemType: "radio1",
              pformName: "healthDto",
              formName: "guardianFlag",
              opction: [
                { label: "有", formName: "", value: 1 },
                { label: "无", formName: "", value: 0 },
              ],
            },
            {
              label: "监护人姓名",
              pformName: "healthDto",
              itemType: "input1",
              formName: "guardianName",
            },
            {
              label: "监护人联系电话",
              pformName: "healthDto",
              itemType: "input1",
              formName: "guardianMobile",
            },
            {
              label: "技能特长",
              pformName: "healthDto",
              itemType: "radio1",
              formName: "specialSkillFlag",
              opction: [
                { label: "有", formName: "", value: 1 },
                { label: "无", formName: "", value: 0 },
              ],
            },
            {
              label: "劳动能力",
              pformName: "healthDto",
              itemType: "radio1",
              formName: "workCapacityFlag",
              opction: [
                { label: "有", formName: "", value: 1 },
                { label: "无", formName: "", value: 0 },
              ],
            },
          ],
        },
        {
          id: "seriousIllnessDto",
          children: [
            {
              label: "所患大病",
              itemType: "checkbox",
              check:'fourFont',
              formName: "illnessCodes",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "illness_code" },
              opction: [],
              pformName: "seriousIllnessDto",
            },
          ],
        },
        {
          id: "chronicDiseaseDto",
          children: [
            {
              label: "所患慢病",
              itemType: "checkbox",
              check:'fourFont',
              formName: "chronicDiseaseCodes",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "chronic_disease_code" },
              opction: [],
              pformName: "chronicDiseaseDto",
            },
          ],
        },
        {
          id: "baseInfoDto",
          children: [
            {
              label: "死亡时间",
              itemType: "datepicker1",
              formName: "deathDate",
              check:'fourFont',
              pformName: "baseInfoDto",
            },
          ],
        },
        {
          id: "oldPeopleDto",
          children: [
            {
              label: "老年人分类",
              itemType: "checkbox",
              check:'fiveFont',
              formName: "oldPeopleCategories",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "oldPeople_categories" },
              pformName: "oldPeopleDto",
              opction:[]
            },
            {
              label: "居住情况",
              itemType: "select1",
              check:'fourFont',
              formName: "resideSituation",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "reside_situation" },
              pformName: "oldPeopleDto",
              opction:[]
            },
            {
              label: "高龄补助",
              itemType: "inputNum",
              formName: "oldSubsidy",
              // check:'fourFont',
              pformName: "oldPeopleDto",
            },
          ],
        },
        {
          id: "subsistenceAllowanceDto",
          children: [
            {
              label: "低保类别",
              itemType: "select1",
              check:'fourFont',
              formName: "category",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "subsistence_allowance_category" },
              pformName: "subsistenceAllowanceDto",
              opction: [],
            },
            {
              label: "低保享受原因",
              itemType: "checkbox",
              check:'sixFont',
              formName: "reasons",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "subsistence_allowance_reasons" },
              opction: [],
              pformName: "subsistenceAllowanceDto",
            },
          ],
        },
        {
          id: "parymemberInfoDto",
          children: [
            {
              check:'fourFont',
              label: "入党时间",
              itemType: "datepicker1",
              formName: "joinTime",
              pformName: "parymemberInfoDto",
              opction: [],
            },
            {
              label: "转正时间",
              itemType: "datepicker1",
              formName: "positiveTime",
              pformName: "parymemberInfoDto",
              opction: [],
            },
            {
              check:'fiveFont',
              label: "所属党组织",
              itemType: "cascader1",
              formName: "partyOrgId",
              pformName: "parymemberInfoDto",
              opction: [],
            },
            {
              label: "流动党员",
              itemType: "radio1",
              formName: "flowFlag",
              pformName: "parymemberInfoDto",
              opction: [
                { label: "是", value: 1 },
                { label: "否", value: 0 },
              ],
            },
            {
              label: "流动党员活动证号",
              itemType: "input1",
              formName: "flowActNum",
              pformName: "parymemberInfoDto",
            },
            {
              label: "党组织职务",
              itemType: "select1",
              formName: "partyJob",
              check:'fiveFont',
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "party_job" },
              pformName: "parymemberInfoDto",
              opction: [],
            },
            {
              label: "工作职责",
              itemType: "input1",
              formName: "duty",
              pformName: "parymemberInfoDto",
            },
            {
              label: "是否退休",
              itemType: "radio1",
              formName: "retiredFlag",
              pformName: "parymemberInfoDto",
              opction: [
                { label: "是", value: 1 },
                { label: "否", value: 0 },
              ],
            },
            {
              label: "党员中心户",
              itemType: "radio1",
              check:'fiveFont',
              formName: "centerFlag",
              pformName: "parymemberInfoDto",
              opction: [
                { label: "是", value: 1 },
                { label: "否", value: 0 },
              ],
            },
            {
              label: "免学习",
              itemType: "radio1",
              formName: "studyNotNeed",
              pformName: "parymemberInfoDto",
              opction: [
                { label: "是", value: 1 },
                { label: "否", value: 0 },
              ],
            },
            {
              label: "入党时所在党支部",
              itemType: "input1",
              formName: "joinBranchName",
              pformName: "parymemberInfoDto",
            },
            {
              label: "组织关系转入社区时间",
              itemType: "datepicker1",
              formName: "joinCommunityTime",
              pformName: "parymemberInfoDto",
              opction: [],
            },
          ],
        },
        {
          id: "ensureHouseDto",
          children: [
            {
              label: "所在社区",
              itemType: "input1",
              check:'fourFont',
              formName: "liveCommunity",
              pformName: "ensureHouseDto",
            },
            {
              label: "住房性质",
              itemType: "select1",
              check:'fourFont',
              formName: "housingNature",
              opctionUrl: "sys/dict/data/house",
              opctionParams: { formCode: "resi_base_info" },
              pformName: "ensureHouseDto",
              opction: [],
            },
          ],
        },
        {
          id: "veteranDto",
          children: [
            {
              label: "入伍日期",
              itemType: "datepicker1",
              check:'fourFont',
              formName: "joinArmyTime",
              pformName: "veteranDto",
              opction: [],
            },
            {
              label: "退伍日期",
              check:'fourFont',
              itemType: "datepicker1",
              formName: "leaveArmyTime",
              pformName: "veteranDto",
              opction: [],
            },
            {
              label: "服役单位",
              itemType: "input1",
              formName: "serviceUnit",
              pformName: "veteranDto",
            },
            {
              label: "接收单位",
              itemType: "input1",
              formName: "receiveUnit",
              pformName: "veteranDto",
            },
            {
              label: "待安置补助金",
              itemType: "inputNum",
              formName: "settlementAmount",
              pformName: "veteranDto",
              opction: [],
            },
            {
              label: "培训状况",
              itemType: "input1",
              formName: "trainDesc",
              pformName: "veteranDto",
            },
            {
              label: "现就业情况",
              itemType: "input1",
              formName: "employmentSituation",
              pformName: "veteranDto",
            },
            {
              label: "是否办理公益性岗位",
              check:'nineFont',
              itemType: "radio1",
              formName: "pubWelfareJobFlag",
              pformName: "veteranDto",
              opction: [
                { label: "是", value: 1 },
                { label: "否", value: 0 },
              ],
            },
          ],
        },
        {
          id: "unitedFrontDto",
          children: [
            {
              label: "统战类型",
              check:'fourFont',
              itemType: "input1",
              pformName: "unitedFrontDto",
              formName: "unitedFrontType",
            },
          ],
        },
        {
          id: "volunteerDto",
          children: [
            {
              label: "志愿者类别",
              itemType: "checkbox",
              formName: "volunteerCategory",
              pformName: "volunteerDto",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "VOLUNTEER_CATEGORY" },
              opction: [],
            },
          ],
        },
        {
          id: "specialSupportDto",
          children: [
            {
              label: "特扶类别",
              check:'fourFont',
              itemType: "select1",
              formName: "specialSupportType",
              pformName: "specialSupportDto",
              opction: [
                {
                  value: "1",
                  label: "失独",
                },
                {
                  value: "2",
                  label: "伤残",
                },
              ],
            },
            {
              //1
              label: "子女姓名",
              // check:'fourFont',
              itemType: "input1",
              formName: "childName",
              pformName: "specialSupportDto",
              opction: [],
            },
            {
              //2
              label: "子女性别",
              itemType: "select1",
              formName: "childGender",
              pformName: "specialSupportDto",
              opction: [
                {
                  value: "1",
                  label: "男",
                },
                {
                  value: "2",
                  label: "女",
                },
              ],
            },
            {
              label: "子女死亡日期",
              itemType: "datepicker1",
              formName: "childDeathDate",
              pformName: "specialSupportDto",
              opction: [],
            },
            {
              label: "子女伤残类别",
              itemType: "select1",
              formName: "childDisabilityCategoryCode",
              opctionUrl: "sys/dict/data/dictlist",
              pformName: "specialSupportDto",
              opctionParams: { dictType: "disability_category_code" },
              opction: [],
            },
            {
              label: "子女伤残等级",
              itemType: "select1",
              pformName: "specialSupportDto",
              formName: "childDisabilityLevel",
              opctionUrl: "sys/dict/data/dictlist",
              opctionParams: { dictType: "disability_level" },
              opction: [],
            },
          ],
        }, 
        {
                   id:'unemployedDto',
                   children:[
                        {
                            label: "原工作单位",
                            itemType: "input1",
                            formName: "originWorkUnit",
                            pformName: "unemployedDto",
                            opction: []
                        },
                        {
                            label: "失业时间",
                            itemType: "datepicker1",
                            formName: "unemploymentTime",
                            pformName: "unemployedDto",
                            opction: []
                        }, 
                        {
                            label: "失业证号",
                            itemType: "input1",
                            formName: "unemploymentNum",
                            pformName: "unemployedDto",
                            opction: []
                        },
                        {
                            label: "失业原因",
                            itemType: "select1",
                            formName: "unemploymentReason",
                            pformName: "unemployedDto",
                            opctionUrl: 'sys/dict/data/dictlist',
                            opctionParams: { dictType: 'unemployment_reason' },
                            opction: []
                        },
                        {
                            label: "再就业优惠证号",
                            itemType: "input1",
                            pformName: "unemployedDto",
                            formName: "employmentNum",
                            opction: []
                        },
                        {
                            label: "技术特长",
                            itemType: "input1",
                            pformName: "unemployedDto",
                            formName: "specialSkill",
                            opction: []
                        },
                        {
                            label: "是否领取失业金",
                            itemType: "radio1",
                            pformName: "unemployedDto",
                            formName: "unempCompensationFlag",
                            opction: [
                                { label: '是', value: 1 },
                                { label: '否', value: 0 },
                            ]
                        },
                        {
                            label: "是否就业困难对象",
                            itemType: "radio1",
                            pformName: "unemployedDto",
                            formName: "employmentHardFlag",
                            opction: [
                                { label: '是', value: 1 },
                                { label: '否', value: 0 },
                            ]
                        },
                        {
                            label: "劳动就业愿望",
                            itemType: "select1",
                            formName: "employmentWish",
                            pformName: "unemployedDto",
                            opctionUrl: 'sys/dict/data/dictlist',
                            opctionParams: { dictType: 'career_goals' },
                            opction: []
                        }
                        
                   ]
        }
      ],
      workInfoDtoId: null,
      idTypeList,
      genderList,
      hasOptions,
      disabilityFlagList,

      btnLoading: false,
      rules: {
        "baseInfoDto.name": [
          { required: true, message: "请输入姓名", trigger: "blur" },
        ],
        "baseInfoDto.idType": [
          { required: true, message: "请选择证件类型", trigger: "blur" },
        ],
        "baseInfoDto.idNum": [
          { required: true, message: "请输入证件号码", trigger: "blur" },
        ],
        "baseInfoDto.mobile": [
          { required: true, message: "请输入电话", trigger: "blur" },
        ],
        "baseInfoDto.nationality": [
          { required: true, message: "请选择国籍", trigger: "blur" },
        ],
      },
      dicts: {
        educationList: [], //文化程度
        nationList: [], //民族
        nationalityList: [], //国籍
        marriageList: [], //婚姻状况
        householdSituationList: [], //人户状况
        houseHolderRelList: [], //与户主关系
        careerStatusList: [], //就业状况
        spouseSituationList: [], //配偶情况
        unemploymentReasonList: [], //失业原因
        resiHouseRelList: [
          {
            label: "自住",
            value: 0,
          },
          {
            label: "租住",
            value: 1,
          },
        ],
      },
      incidence: {
        parymemberInfoDto: {
          formId: "parymemberInfoDto",
          formType: "parymemberInfoDto",
          title: "党员信息",
        },
        disabilityFlag: {
          formId: "healthDto",
          formType: "healthDto",
          title: "残疾信息",
        },
        seriousIllnessFlag: {
          formId: "seriousIllnessDto",
          formType: "seriousIllnessDto",
          title: "大病信息",
        },
        chronicDiseaseFlag: {
          formId: "chronicDiseaseDto",
          formType: "chronicDiseaseDto",
          title: "慢病信息",
        },
        deathFlag: { formId: "baseInfoDto", formType: "baseInfoDto", title: "死亡信息" },
        oldPeopleFlag: {
          formId: "oldPeopleDto",
          formType: "oldPeopleDto",
          title: "老年人信息",
        },
        subsistenceAllowanceFlag: {
          formId: "subsistenceAllowanceDto",
          formType: "subsistenceAllowanceDto",
          title: "低保人员信息",
        },
        veteranFlag: {
          formId: "veteranDto",
          formType: "veteranDto",
          title: "退役军人信息",
        },
        ensureHouseFlag: {
          formId: "ensureHouseDto",
          formType: "ensureHouseDto",
          title: "保障性住房信息",
        },
        specialSupportFlag: {
          formId: "specialSupportDto",
          formType: "specialSupportDto",
          title: "特扶人员",
        },
        unitedFrontFlag: {
          formId: "unitedFrontDto",
          formType: "unitedFrontDto",
          title: "统战人员",
        },
        volunteerFlag: {
          formId: "volunteerDto",
          formType: "volunteerDto",
          title: "志愿者",
        },
        unemployedFlag: {
          formId: "unemployedDto",
          formType: "unemployedDto",
          title: "失业人员",
        },
      },
      formCopy: null,
    };
  },
  async created() {
    this.formCopy = JSON.parse(JSON.stringify(this.form));
  },
  async activated() {
    this.resiId = this.$route.query.id;
    this.loading = true;
    await this.getDicts();
    await this.getOrgTreeListAll();
    await this.getResiDetail();
  },
  methods: {
    getResiDetail() {
      this.$http
        .get(`/actual/base/residentIntegratedInfo/detail/masked/${this.resiId}`)
        .then((res) => {
          if (res.data.code == 0) {
            this.form = {};
            this.form.resideInfoDtos = res.data.data.resideInfoDtos;
            const promises = [];
            this.$refs["resiExpand"].formList = [];
            for (let i in this.form.resideInfoDtos) {
              promises.push(this.getValiheList(i));
              promises.push(this.getBuildList(i));
              promises.push(this.getHouseList(i));
              promises.push(this.getUniList(i));
              this.form.resideInfoDtos[i].orgOptions = [];
              this.getOrgTreeList(this.form.resideInfoDtos[i].agencyId, i);
            }
            this.form = { ...res.data.data };
            this.form.baseInfoDto.idNum = this.$route.params.idNum;
            this.form.baseInfoDto.mobile = this.$route.params.mobile;
            this.form.baseInfoDto.name = this.$route.params.name;
            if (!res.data.data.familyInfoDto) {
              this.form.familyInfoDto = {
                marriage: null, //婚姻状况
                spouseSituation: null, //配偶情况
                elderlyFlag: null, //有无赡养人
                elderlyRelation: null, //与赡养人关系
                dependantMobile: null, //赡养人联系电话
              };
            }
            if (!res.data.data.religionDto) {
              this.form.religionDto = {
                religion: null, //宗教信仰
              };
            }
            if (!res.data.data.workInfoDto) {
              this.form.workInfoDto = {
                careerStatus: null, //就业状况
                workUnit: null, //工作单位
                occupation: null, //职业
              };
            }
            if (!res.data.data.eduInfoDto) {
              this.form.eduInfoDto = {
                cultureLevel: null,
              };
            }
            if (!res.data.data.specialDto) {
              this.form.specialDto = {
                specialCategoryCodes: [],
              };
            }
            if (!res.data.data.subsistenceAllowanceDto) {
              this.form.subsistenceAllowanceDto = {
                reasons: [],
                category: null,
              };
            }
            if (!res.data.data.unemployedDto) {
              this.form.unemployedDto = {
                originWorkUnit: null, //原工作单位
                unemploymentTime: null, //失业时间yyyy-MM-dd
                unemploymentNum: null, //失业证号
                employmentNum: null, //再就业优惠证号
                specialSkill: null, //技术特长
                unempCompensationFlag: null, //是否领取失业补助金
                unemploymentReason: null, //失业原因【字典表】code
                employmentHardFlag: null, //是否就业困难对象；1是0不是
                employmentWish: null, //劳动能力就业愿望
              };
            }
            if (!res.data.data.oldPeopleDto) {
              this.form.oldPeopleDto = {
                    oldPeopleCategories: [],
                    resideSituation: null,
                    oldSubsidy: null
                };
            }
            for (const key in this.form.baseInfoDto.categoryInfo) {
              if (
                (this.form.baseInfoDto.categoryInfo[key] === 1 &&
                  this.incidence[key]) ||
                (this.form.baseInfoDto.categoryInfo.partyFlag == 1 &&
                  key === "partyFlag")
              ) {
                const formId = key === "partyFlag" ? "parymemberInfoDto" : key;
                this.loadExpand({ index: key, value: formId }, true);
                for (let i in this.footerInputList) {
                  const incidenceFormId = this.incidence[formId].formId;
                  if (this.footerInputList[i].id === incidenceFormId) {
                    for (let index in this.footerInputList[i].children) {
                      const formName =
                        this.footerInputList[i].children[index].formName;
                      const formData = this.form[incidenceFormId];
                      if (
                        formData &&
                        Object.keys(formData).includes(formName)
                      ) {
                        if (
                          this.footerInputList[i].children[index].itemType ==
                          "cascader1"
                        ) {
                          this.footerInputList[i].children[index].orgPath =
                            formData.partyOrgIdPath || null;
                        }
                        this.footerInputList[i].children[index].value =
                          formData[formName] != null
                            ? formData[formName]
                            : null;
                        this.footerInputList[i].children[index].id =
                          formData.id;
                      }
                    }
                  }
                }
              }
            }
            this.workInfoDtoId = this.form.workInfoDto.id;
            this.loading = false;
            return Promise.all(promises);
          } else if (res.data.code >= 8000) {
            this.$message.error(res.data.msg);
            this.loading = false;
          }
        })
        .then(() => {})
        .catch((err) => {
          console.log(err);
        });
    },
    async getDicts() {
      try {
        const requests = [
          this.$http.post("sys/dict/data/dictlist", {
            dictType: "nationality",
          }),
          this.$http.post("sys/dict/data/nation", {
            formCode: "resi_base_info",
          }),
          this.$http.post("sys/dict/data/education", {
            formCode: "resi_base_info",
          }),
          this.$http.post("sys/dict/data/dictlist", {
            dictType: "marriage",
          }),
          this.$http.post("sys/dict/data/dictlist", {
            dictType: "household_situation",
          }),
          this.$http.post("sys/dict/data/relationship", {
            formCode: "resi_base_info",
          }),
          this.$http.post("sys/dict/data/dictlist", {
            dictType: "career_status",
          }),
          this.$http.post("sys/dict/data/dictlist", {
            dictType: "spouse_situation",
          }),
          this.$http.post("sys/dict/data/dictlist", {
            dictType: "unemployment_reason",
          }),
        ];
        const dictKeys = [
          "nationalityList",
          "nationList",
          "educationList",
          "marriageList",
          "householdSituationList",
          "houseHolderRelList",
          "careerStatusList",
          "spouseSituationList",
          "unemploymentReasonList",
        ]; // 对应的键名

        const results = await Promise.all(requests);
        results.forEach((result, index) => {
          if (result.data.code === 0) {
            this.dicts[dictKeys[index]].push(...result.data.data);
          } else {
            console.log(`获取${dictKeys[index]}失败: ${result.data.msg}`);
          }
        });
      } catch (error) {
        console.log("获取字典失败: ", error);
      }
    },
    getOrgTreeList(id, i) {
      this.$http
        .post("/gov/org/customeragency/rootagencygridtree", { agencyId: id })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.form.resideInfoDtos[i].orgOptions.push(res.data);
          }
        })
        .catch((err) => {
          console.log(err);
          return this.$message.error("网络错误");
        });
    },
    getOrgTreeListAll() {
      this.$http
        .post("/gov/org/customeragency/agencygridtree", {})
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.orgOption.push(res.data);
          }
        })
        .catch(() => {
          return this.$message.error("网络错误");
        });
    },
    handelChangeResiHouseRel(val, index) {
      this.form.resideInfoDtos[index].householdSituation =
        val == 0 ? "rhyz" : "rzhbz";
    },
    handleChangeAgency(index) {
      let obj = this.$refs[`myCascader`][index].getCheckedNodes()[0]
        ? this.$refs["myCascader"][index].getCheckedNodes()[0].data
        : null;
      if (obj) {
        if (obj.level === "grid") {
          this.form.resideInfoDtos[index].gridId = obj.agencyId;
          this.form.resideInfoDtos[index].agencyId = obj.pid;

          this.form.resideInfoDtos[index].villageId = "";
          this.form.resideInfoDtos[index].buildId = "";
          this.form.resideInfoDtos[index].unitId = "";
          this.form.resideInfoDtos[index].homeId = "";
          this.form.resideInfoDtos[index].optionsV = [];
          this.form.resideInfoDtos[index].optionsB = [];
          this.form.resideInfoDtos[index].optionsD = [];
          this.form.resideInfoDtos[index].optionsH = [];
          this.getValiheList(index);
        } else {
          // this.selGridId = []
          this.form.resideInfoDtos[index].gridId = "";
          this.form.resideInfoDtos[index].agencyId = "";
          this.$message.info("请选择网格");
          return false;
        }
      }
    },
    handleChangeV(index) {
      this.form.resideInfoDtos[index].buildId = "";
      this.form.resideInfoDtos[index].unitId = "";
      this.form.resideInfoDtos[index].homeId = "";
      this.form.resideInfoDtos[index].optionsB = [];
      this.form.resideInfoDtos[index].optionsD = [];
      this.form.resideInfoDtos[index].optionsH = [];
      this.getBuildList(index);
      this.getUniList(index);
      this.getHouseList(index);
    },
    handleChangeB(index) {
      this.form.resideInfoDtos[index].unitId = "";
      this.form.resideInfoDtos[index].homeId = "";
      this.form.resideInfoDtos[index].optionsD = [];
      this.form.resideInfoDtos[index].optionsH = [];
      this.getUniList(index);
      this.getHouseList(index);
    },
    handleChangeD(index) {
      this.form.resideInfoDtos[index].homeId = "";
      this.form.resideInfoDtos[index].optionsH = [];
      this.getHouseList(index);
    },
    handleChangeH(i) {},
    getValiheList(index) {
      const { user } = this.$store.state;
      this.$http
        .post("/actual/base/communityQuarters/listQuartersOptions", {
          gridId: this.form.resideInfoDtos[index].gridId,
          agencyId: this.form.resideInfoDtos[index].agencyId || user.agencyId,
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            // this.form.resideInfoDtos[index].optionsV.push(...res.data)
            this.$set(this.form.resideInfoDtos[index], "optionsV", res.data);
          }
        })
        .catch((err) => {
          console.log(err);
          return this.$message.error("网络错误");
        });
    },
    getBuildList(index) {
      this.$http
        .post("/actual/base/communityBuilding/buildingoption", {
          quartersId: this.form.resideInfoDtos[index].villageId,
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.$set(this.form.resideInfoDtos[index], "optionsB", res.data);
          }
        })
        .catch(() => {
          return this.$message.error("网络错误");
        });
    },
    getUniList(index) {
      this.$http
        .post("/actual/base/communityBuildingUnit/unitoption", {
          buildingId: this.form.resideInfoDtos[index].buildId,
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.$set(this.form.resideInfoDtos[index], "optionsD", res.data);
          }
        })
        .catch(() => {
          return this.$message.error("网络错误");
        });
    },
    getHouseList(index) {
      this.$http
        .post("/actual/base/communityHouse/houseoption", {
          unitId: this.form.resideInfoDtos[index].unitId,
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.$set(this.form.resideInfoDtos[index], "optionsH", res.data);
          }
        })
        .catch(() => {
          return this.$message.error("网络错误");
        });
    },
    handelClickAddHouse() {
      this.form.resideInfoDtos.push({
        agencyName: this.$store.state.user.agencyName,
        agencyId: this.$store.state.user.agencyId,
        gridId: null, //所属网格id
        villageId: null, //小区id
        buildId: null, //楼栋id
        unitId: null, //单元id
        moveOutFlag: null,
        outOfTime: null, //迁出时间
        homeId: null, //房屋id
        placeOfDomicile: null, //户籍所在地
        currentResidence: null, //现居住地
        householdSituation: null, //人户状况
        houseHolderRel: null, //与户主关系
        resiHouseRel: null, //人房关系
        optionsV: [],
        optionsB: [],
        optionsH: [],
        optionsD: [],
        orgOptions: this.orgOption,
      });
    },
    handelClickDelHouse(i) {
      this.form.resideInfoDtos = this.form.resideInfoDtos.filter(
        (item, index) => index != i
      );
    },
    handleValidBlur() {
      if (this.form.baseInfoDto.idType != 1) return;
      if (
        !isCard(this.form.baseInfoDto.idNum) &&
        !isPassport(this.form.baseInfoDto.idNum)
      )
        return;
      const { user } = this.$store.state;
      let huji = "",
        i = 0;
      if (user.areaCodePath && user.areaCodePath.length > 0) {
        i = user.areaCodePath.length - 1;
        huji =
          user.areaCodePath[i].length > 6
            ? user.areaCodePath[i].substr(0, 6)
            : user.areaCodePath[i];
      }

      if (
        this.form.baseInfoDto.idNum.length === 18 ||
        this.form.baseInfoDto.idNum.length === 15
      ) {
        const _id = this.form.baseInfoDto.idNum.substr(0, 6);
        const { sex, birth, age } = computedCard(this.form.baseInfoDto.idNum);
        this.form.baseInfoDto.birthday = birth;
        this.form.baseInfoDto.gender = sex == 1 ? "1" : "2";
        this.form.baseInfoDto.categoryInfo.oldPeopleFlag = age >= 60 ? 1 : 0;
        this.form.baseInfoDto.categoryInfo.fertileWomanFlag = this.form.baseInfoDto.gender == 2 && (age >= 18 && age < 49)? 1 : 0;
        let obj = {oldPeopleFlag:age >= 60 ? 1 : 0,fertileWomanFlag:this.form.baseInfoDto.gender == 2 && (age >= 18 && age < 49)? 1 : 0,sex,age}
        this.$refs['stafftag'].updatedForm(obj);
        this.form.oldPeopleDto.oldPeopleCategories = ['oldPeopleFlag'];
        // this.form.IS_BDHJ = huji == _id ? '1' : ''
        // 身份证前端验证角色方法 因原型没有注释
        // this.validateIdcard(this.form.idNum)
      }
    },
    handleLocalRadio(e, value) {
      if (e.target.type === "radio") return;
      this.form.baseInfoDto.localResidenceFlag =
      this.form.baseInfoDto.localResidenceFlag === value ? 0 : 1;
    },
    handelClickMarriage() {
      this.form.familyInfoDto.spouseSituation = null;
    },
    handelClickelderly() {
      this.form.familyInfoDto.elderlyRelation = null;
      this.form.familyInfoDto.dependantMobile = null;
    },
    handelClickCareerStatus(val) {
      this.form.workInfoDto = {
        careerStatus: val, //就业状况
        workUnit: null, //工作单位
        occupation: null, //职业
        id: this.workInfoDtoId || null,
      };
      if (!this.workInfoDtoId) {
        delete this.form.workInfoDto.id;
      }
    },
    handlerCancle() {
      this.$store.state.contentTabs = this.$store.state.contentTabs.filter(
        (item) => item.name !== "edit-elderly-database"
      );
      let tab =
        this.$store.state.contentTabs[this.$store.state.contentTabs.length - 1];
      this.$router.push({
        name: tab.name,
        params: { ...tab.params },
        query: { ...tab.query },
      });
    },
    handleClickSubmit(house) {
      this.$refs["editForm"].validate((valid) => {
        if (valid) {
          this.form.resideInfoDtos.forEach((item) => {
            delete item.optionsV;
            delete item.optionsB;
            delete item.optionsH;
            delete item.optionsD;
            delete item.orgOptions;
          });
          delete this.form.integrityData;
          this.submitForm(house);
        }
      });
    },
    async submitForm(house) {
      this.btnLoading = true;
      try {
        let url = this.houseType
          ? "/actual/base/residentBaseInfo/update"
          : "/actual/base/residentBaseInfo/save";
        let parm = {
          ...this.form,
        };
        let { code, data, msg } = await requestPost(url, parm);
        if (code == 0) {
          if (house != "house") {
            this.$message.success("保存成功");
            this.$refs["editForm"].resetFields();
            this.handlerCancle();
          } else {
            this.$message.success("保存成功");
            let homeArr = JSON.parse(JSON.stringify(this.form.resideInfoDtos));
            this.$refs["editForm"].resetFields();
            this.form = this.formCopy;
            this.form.resideInfoDtos = homeArr;
            for (let key in this.form.baseInfoDto.categoryInfo) {
              if (this.form.baseInfoDto.categoryInfo[key] === 1) {
                this.form.baseInfoDto.categoryInfo[key] = 0;
              }
            }
            this.$refs["resiExpand"].formList = [];
            this.footerInputList.forEach((item) => {
              item.children.forEach((child) => {
                child.value = child.itemType === "checkbox" ? [] : null;
              });
            });
            this.houseType = false;
          }
        } else if (code >= 8000) {
          this.$message.error(msg);
        }
        this.btnLoading = false;
      } catch (error) {
        this.$message.error(msg);
        this.btnLoading = false;
      }
    },

    loadExpand({ index, value }, event,) {
      // 设置 partyFlag
      if (value === 1 || value === 0 || value === 2) {
        this.form.baseInfoDto.categoryInfo.partyFlag = value;
        value = value === 1 ? "parymemberInfoDto" : value;
        if (value === 0 || value === 2) {
          this.form.parymemberInfoDto = null;
          this.footerInputList.forEach((item) => {
            if (item.id === "parymemberInfoDto") {
              item.children.forEach((child) => {
                child.value = child.itemType === "checkbox" ? [] : null;
              });
            }
          });

          this.$nextTick(() => {
            this.$refs["resiExpand"].formList = this.$refs[
              "resiExpand"
            ].formList.filter((item) => item.formId !== "parymemberInfoDto");
          });
        }
      }

      // 设置特殊处理逻辑
      if (index !== 3 && index) {
        this.form.baseInfoDto.categoryInfo[value] = event ? 1 : 0;
      } else if (index === 3) {
        if (event) {
          this.form.baseInfoDto.categoryInfo.specialCrowdFlag = 1;
          this.form.specialDto.specialCategoryCodes.push(value);
        } else {
          this.form.specialDto.specialCategoryCodes =
            this.form.specialDto.specialCategoryCodes.filter(
              (item) => item !== value
            );
        }
      }
      // 处理 incidence
      if (this.incidence[value]) {
        if (event) {
          this.$nextTick(() => {
            this.$refs["resiExpand"].formList.push({
              form: [
                this.footerInputList.find(
                  (item) => item.id === this.incidence[value].formId
                ),
              ],
              title: this.incidence[value].title,
              formId: this.incidence[value].formId,
            });
            this.$refs["resiExpand"].formType = this.incidence[value].formType;
            this.$refs["resiExpand"].showForm();
          });
        } else {
          this.$refs["resiExpand"].formList = this.$refs[
            "resiExpand"
          ].formList.filter(
            (item) => item.formId !== this.incidence[value].formId
          );

          this.footerInputList.forEach((item) => {
            if (item.id === this.incidence[value].formId) {
              item.children.forEach((child) => {
                child.value = child.itemType === "checkbox" ? [] : null;
              });
            }
          });
          delete this.form[this.incidence[value].formType];
        }
      }
    },
    showDialog({ index, value }, event) {
            if (value === 1) {
                value = 'parymemberInfoDto'
                this.form.baseInfoDto.categoryInfo.partyFlag = 1;
            } else if (value === 0) {
                value = 'parymemberInfoDto'
                this.form.baseInfoDto.categoryInfo.partyFlag = 0;
            } else if (value === 2) {
                value = 'parymemberInfoDto'
                this.form.baseInfoDto.categoryInfo.partyFlag = 2;
            }
            if (index != 3 && index) {
                if(value === 'deathFlag'){
                  this.form.baseInfoDto.deathFlag = event?1:0
                }else{
                  this.form.baseInfoDto.categoryInfo[value] = event ? 1 : 0;
                }

            } else if (index == 3) {
                if (event) {
                    this.form.baseInfoDto.categoryInfo.specialCrowdFlag = 1;
                    if (value == 'unitedFrontFlag' || value == 'petitionOfficerFlag') {
                        this.form.baseInfoDto.categoryInfo[value] = 1
                    }
                    this.form.specialDto.specialCategoryCodes.push(value);
                } else {
                    this.form.specialDto.specialCategoryCodes = this.form.specialDto.specialCategoryCodes.filter(item => item != value);
                    if (value == 'unitedFrontFlag' || value == 'petitionOfficerFlag') {
                        this.form.baseInfoDto.categoryInfo[value] = 0
                    }
                }
            }
            const map = {
                'parymemberInfoDto': { formId: 'parymemberInfoDto', formType: 'parymemberInfoDto', title: '党员信息' },
                'disabilityFlag': { formId: 'healthDto', formType: 'healthDto', title: '残疾信息' },
                'seriousIllnessFlag': { formId: 'seriousIllnessDto', formType: 'seriousIllnessDto', title: '大病信息' },
                'chronicDiseaseFlag': { formId: 'chronicDiseaseDto', formType: 'chronicDiseaseDto', title: '慢病信息' },
                'deathFlag': { formId: 'baseInfoDto', formType: 'baseInfoDto', title: '死亡' },
                'oldPeopleFlag': { formId: 'oldPeopleDto', formType: 'oldPeopleDto', title: '老年人信息' },
                'subsistenceAllowanceFlag': { formId: 'subsistenceAllowanceDto', formType: 'subsistenceAllowanceDto', title: '低保人员信息' },
                'veteranFlag': { formId: 'veteranDto', formType: 'veteranDto', title: '退役军人信息' },
                'ensureHouseFlag': { formId: 'ensureHouseDto', formType: 'ensureHouseDto', title: '保障性住房信息' },
                'specialSupportFlag': { formId: 'specialSupportDto', formType: 'specialSupportDto', title: '特扶人员' },
                'unitedFrontFlag': { formId: 'unitedFrontDto', formType: 'unitedFrontDto', title: '统战人员' },
                'volunteerFlag': { formId: 'volunteerDto', formType: 'volunteerDto', title: '志愿者' },
                'unemployedFlag': { formId: 'unemployedDto', formType: 'unemployedDto', title: '失业人员' }
            };
      if (map[value] && event == true) {
        this.dialogTitle = map[value].title;
        this.dialogVisible = (event == true || value == "parymemberInfoDto") && this.dialogTitle != "";
          this.$nextTick(() => {
            this.$refs["addExpand"].formList = [
              this.footerInputList.find((item) => item.id === map[value].formId),
            ];
            this.$refs["addExpand"].formType = map[value].formType;
            this.$refs["addExpand"].showForm();
          });
      }else{
        this.$refs["resiExpand"].formList = this.$refs[
            "resiExpand"
          ].formList.filter(
            (item) => item.formId !== this.incidence[value].formId
          );

          this.footerInputList.forEach((item) => {
            if (item.id === this.incidence[value].formId) {
              item.children.forEach((child) => {
                child.value = child.itemType === "checkbox" ? [] : null;
              });
            }
          });
          if(value === 'deathFlag'){
                  this.form.baseInfoDto.deathFlag = 0;
                  this.form.baseInfoDto.deathDate = null;
          }else{
                  delete this.form[this.incidence[value].formType];
          }
      }
    },
    submitExpandAdd(form, formType) {
      if(formType === 'baseInfoDto' ){
        this.form.baseInfoDto.deathDate = form[formType].deathDate;
        this.form.baseInfoDto.deathFlag = 1;
      }else{
        this.form[formType] = form[formType];
      }
      this.dialogVisible = false;
    },
    hideExpand(formType) {
      if(formType!= 'baseInfoDto'){
        delete this.form[formType];
      }else{
        this.form['baseInfoDto'].deathFlag = 0;
      }
      this.dialogVisible = false;
    },
    // 提交扩展信息
    submitExpand(_form, { changId, changPid, changType }) {
      if (changType == "checkbox") {
        this.form[changPid][changId] = [];
        this.form[changPid][changId].push(..._form[changPid][changId]);
      } else {
        if (!this.form[changPid]) {
          this.$set(this.form, changPid, {});
        }
        if (changPid) {
          this.$set(this.form[changPid], changId, _form[changPid][changId]);
        }
      }
      for (let i in this.footerInputList) {
        if (this.footerInputList[i].id === changPid) {
          for (let index in this.footerInputList[i].children) {
            const formName = this.footerInputList[i].children[index].formName;
            const formData = this.form[changPid];
            if (formData && Object.keys(formData).includes(formName)) {
              this.footerInputList[i].children[index].value =
                formData[formName] || null;
            }
          }
        }
      }
    },
  },
  components: { stafftag, resiExpand ,addExpand},
  computed: {},
  watch: {},
};
</script>

<style lang='scss' scoped>
@import "@/assets/scss/modules/management/form-main.scss";
@import "@/assets/scss/pages/resiAdd.scss";
</style>
