<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    v-model="visible"
    append-to-body
    width="90%"
  >
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmit()"
             label-width="170px" size="mini">
      <el-row>
        <el-col :span="24">
          <el-form-item label="招生计划" prop="groupId">
            <el-select v-model="dataForm.groupId" filterable :disabled="!dataForm.id ? false : true"
                       placeholder="请选择招生计划" size="small" style="width: 100%">
              <el-option
                v-for="item in planList"
                :key="item.id"
                :label="item.groupName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="姓名" prop="name" >
            <el-input type="text" v-model="dataForm.name" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="曾用名" prop="oldName">
            <el-input type="text" v-model="dataForm.oldName" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="性别" prop="gender">
            <el-select v-model="dataForm.gender" style="width: 100%" :disabled="type==2 ? false : true" >
              <el-option
                v-for="item in sexyList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="民族" prop="nationality">
            <el-input type="text" v-model="dataForm.nationality" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="文化程度" prop="degreeOfEducation">
            <el-select v-model="dataForm.degreeOfEducation" filterable placeholder="请选择文化程度" size="small" :disabled="type==1 ? false : true" style="width: 100%" @change="changeEducation">
              <el-option
                v-for="item in eduList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否团员" prop="isLeagueMember">
            <el-select v-model="dataForm.isLeagueMember" filterable clearable placeholder="请选择是否团员" size="small" :disabled="type==1 ? false : true" style="width: 100%">
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="毕业学校" prop="schoolOfGraduation">
            <el-input type="text" v-model="dataForm.schoolOfGraduation" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否住宿" prop="isAccommodation">
            <el-select v-model="dataForm.isAccommodation" filterable clearable placeholder="请选择是否住宿" size="small" :disabled="type==1 ? false : true" style="width: 100%">
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="准考证号" prop="examRegistrationNumbers">
            <el-input type="text" v-model="dataForm.examRegistrationNumbers" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
<!--        <el-col :span="8">-->
<!--          <el-form-item label="是否低保" prop="isMinimumLivingSecurity">-->
<!--            <el-select v-model="dataForm.isMinimumLivingSecurity" filterable clearable placeholder="请选择是否低保"-->
<!--                       size="small" :disabled="type==1 ? false : true" style="width: 100%">-->
<!--              <el-option-->
<!--                v-for="item in yesNoList"-->
<!--                :key="item.value"-->
<!--                :label="item.label"-->
<!--                :value="item.value">-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="成绩" prop="score">
            <el-input type="text" v-model="dataForm.score" :disabled="type==1 ? false : true" @change="jsZSF"></el-input>
          </el-form-item>
        </el-col>
<!--        <el-col :span="8">-->
<!--          <el-form-item label="邮编" prop="postcode">-->
<!--            <el-input type="text" v-model="dataForm.postcode" :disabled="type==1 ? false : true"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
        <el-col :span="8">
          <el-form-item label="户口性质" prop="residenceType">
            <el-select v-model="dataForm.residenceType" filterable clearable placeholder="请选择户口性质" size="small" :disabled="type==1 ? false : true" style="width: 100%">
              <el-option
                v-for="item in residenceTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="this.dataForm.degreeOfEducation=='1'">
        <el-col :span="8">
          <el-form-item label="成绩折算分" prop="correctedScore">
            <el-input type="text" v-model="dataForm.correctedScore" :disabled="type==2 ? false : true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="当地总分" prop="fullScore">
            <el-input type="text" v-model="dataForm.fullScore" :disabled="isShow" @change="changePlaceScore"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="学校归属地" prop="schoolArea">
            <el-select v-model="dataForm.schoolArea" filterable  placeholder="请选择学校归属地" size="small" :disabled="type==1 ? false : true" @change="changeFrom" style="width: 100%">
              <el-option
                v-for="item in schoolFromList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="(this.dataForm.degreeOfEducation) && (dataForm.schoolArea=='2')">

        <el-col :span="24">
          <el-form-item label="学校所在省市" prop="jsOtherCity">
            <el-select v-model="dataForm.jsOtherCity" filterable  placeholder="请选择学校所在省市" size="small"
                       :disabled="type==1 ? false : true" @change="changeSchoolCode"
                      style="width: 100%"
            >
              <el-option
                v-for="item in schoolCodeList"
                :key="item.regionId"
                :label="item.regionName"
                :value="item.regionId">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="(this.dataForm.degreeOfEducation) && (dataForm.schoolArea=='3')">

        <el-col :span="24">
          <el-form-item label="外省" prop="otherProvince">
            <el-select v-model="dataForm.otherProvince" filterable  placeholder="请选择学校所在省市" size="small"
                       :disabled="type==1 ? false : true" @change="changeSchoolCode"
                       style="width: 100%"
            >
              <el-option
                v-for="item in areaHPList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="身份证号" prop="idNumber">
            <el-input type="text" v-model="dataForm.idNumber" :disabled="type==2 ? false : true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="户口所在地" prop="residenceProvince">
            <el-select v-model="dataForm.residenceProvince" filterable clearable placeholder="请选择户口所在地" size="small" :disabled="type==1 ? false : true"style="width: 100%" @change="changeR(1)">
              <el-option
                v-for="item in areaPList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="" prop="residenceCity">
            <el-select v-model="dataForm.residenceCity" filterable clearable placeholder="" size="small" :disabled="type==1 ? false : true" style="width: 100%" @change="changeR(2)">
              <el-option
                v-for="item in areaCList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="" prop="residenceArea">
            <el-select v-model="dataForm.residenceArea" filterable clearable placeholder="" size="small" :disabled="type==1 ? false : true" style="width: 100%">
              <el-option
                v-for="item in areaAList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
        <el-row>
        <el-col :span="24">
          <el-form-item label="" prop="residenceDetail">
            <el-input type="text" v-model="dataForm.residenceDetail" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="家庭地址" prop="homeAddressProvince">
            <el-select v-model="dataForm.homeAddressProvince" filterable clearable placeholder="" size="small" :disabled="type==1 ? false : true" style="width: 100%" @change="changeH(1)">
              <el-option
                v-for="item in areaHPList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="" prop="homeAddressCity">
            <el-select v-model="dataForm.homeAddressCity" filterable clearable placeholder="" size="small" :disabled="type==1 ? false : true" style="width: 100%" @change="changeH(2)">
              <el-option
                v-for="item in areaHCList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="" prop="homeAddressArea">
            <el-select v-model="dataForm.homeAddressArea" filterable clearable placeholder="" size="small" :disabled="type==1 ? false : true" style="width: 100%">
              <el-option
                v-for="item in areaHAList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="" prop="homeAddressDetail">
            <el-input type="text" v-model="dataForm.homeAddressDetail" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="家长姓名" prop="parentName">
            <el-input type="text" v-model="dataForm.parentName" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="手机" prop="parentTelOne">
            <el-input type="text" v-model="dataForm.parentTelOne" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="固话" prop="parentTelTwo">
            <el-input type="text" v-model="dataForm.parentTelTwo" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="本人联系电话" prop="selfTel">
            <el-input type="text" v-model="dataForm.selfTel" :disabled="type==1 ? false : true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="拟报专业1" prop="wishMajorOne">
            <el-select v-model="dataForm.wishMajorOne" filterable clearable placeholder="" size="small" style="width: 100%" >
              <el-option
                v-for="item in planMajorList"
                :key="item.zydm"
                :label="item.zymc"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="拟报专业2" prop="wishMajorTwo">
            <el-select v-model="dataForm.wishMajorTwo" filterable clearable placeholder="" size="small" style="width: 100%" >
              <el-option
                v-for="item in planMajorList"
                :key="item.zydm"
                :label="item.zymc"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="拟报专业3" prop="wishMajorThree">
            <el-select v-model="dataForm.wishMajorThree" filterable clearable placeholder="" size="small" style="width: 100%" >
              <el-option
                v-for="item in planMajorList"
                :key="item.zydm"
                :label="item.zymc"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="录取专业" prop="confirmedMajor">
            <el-select v-model="dataForm.confirmedMajor" filterable clearable placeholder="" size="small" style="width: 100%" :disabled="type==1 ? false : true" @change="changeM(dataForm.confirmedMajor)">
              <el-option
                v-for="item in planMajorList"
                :key="item.zydm"
                :label="item.zymc+' || '+item.xyNum"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="type==0 ? false : true">
        <el-col :span="24">
          <el-form-item label="两年制专业" prop="twoMajor" v-if="twoMajorList.length>0">
            <el-select v-model="dataForm.twoMajor" filterable clearable placeholder="" size="small" style="width: 100%" @change="changeM(dataForm.twoMajor)">
              <el-option
                v-for="item in twoMajorList"
                :key="item.zydm"
                :label="item.zymc+' || '+item.xyNum"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="三年制专业" prop="threeMajor" v-if="threeMajorList.length>0">
            <el-select v-model="dataForm.threeMajor" filterable clearable placeholder="" size="small" style="width: 100%" @change="changeM(dataForm.threeMajor)">
              <el-option
                v-for="item in threeMajorList"
                :key="item.zydm"
                :label="item.zymc+' || '+item.xyNum"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="四年制专业" prop="fourMajor" v-if="fourMajorList.length>0">
            <el-select v-model="dataForm.fourMajor" filterable clearable placeholder="" size="small" style="width: 100%" @change="changeM(dataForm.fourMajor)">
            <el-option
              v-for="item in fourMajorList"
              :key="item.zydm"
              :label="item.zymc+' || '+item.xyNum"
              :value="item.zydm">
            </el-option>
          </el-select>
          </el-form-item>
          <el-form-item label="五年制专业" prop="fiveMajor" v-if="fiveMajorList.length>0">
            <el-select v-model="dataForm.fiveMajor" filterable clearable placeholder="" size="small" style="width: 100%" @change="changeM(dataForm.fiveMajor)">
              <el-option
                v-for="item in fiveMajorList"
                :key="item.zydm"
                :label="item.zymc+' || '+item.xyNum"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="六年制专业" prop="sixMajor" v-if="sixMajorList.length>0">
            <el-select v-model="dataForm.sixMajor" filterable  clearable placeholder="" size="small" style="width: 100%" @change="changeM(dataForm.sixMajor)">
              <el-option
                v-for="item in sixMajorList"
                :key="item.zydm"
                :label="item.zymc+' || '+item.xyNum"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="七年制专业" prop="sevenMajor" v-if="sevenMajorList.length>0">
            <el-select v-model="dataForm.sevenMajor" filterable clearable placeholder="" size="small" style="width: 100%"  @change="changeM(dataForm.sevenMajor)">
              <el-option
                v-for="item in sevenMajorList"
                :key="item.zydm"
                :label="item.zymc+' || '+item.xyNum"
                :value="item.zydm">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="学费" prop="feeTuition">
            <el-input-number v-model="dataForm.feeTuition" controls-position="right" :min="0" :max="999999" :step-strictly="true" style="width:100%;"  :disabled="type==2?false:true"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="代办费" prop="feeAgency">
            <el-input-number v-model="dataForm.feeAgency" controls-position="right" :min="0" :max="999999" :step-strictly="true" style="width:100%;" :disabled="type==2?false:true"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="总费用" prop="allMoney">
            <span style="color: red">{{dataForm.feeTuition+dataForm.feeAgency}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row >
        <el-col :span="8">
          <el-form-item label="成绩单" prop="scorePhoto" >
            <viewer :images="dataForm.scorePhotoList" v-if="dataForm.scorePhoto !=''">
              <img v-for="src in dataForm.scorePhotoList" :src="src"  style="width:100px;height:100px;">
            </viewer>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="毕业证" prop="graPic">
            <viewer :images="dataForm.graPicList"  v-if="dataForm.graPic !=''">
              <img v-for="src in dataForm.graPicList" :src="src"  style="width:100px;height:100px;">
            </viewer>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="在常营业执照" prop="yyPic">
            <viewer :images="dataForm.yyPicList" v-if="dataForm.yyPic !=''">
              <img v-for="src in dataForm.yyPicList" :src="src"  style="width:100px;height:100px;">
            </viewer>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row >
        <el-col :span="8">
          <el-form-item label="在常租赁合同/房产证明" prop="housePic" >
            <viewer :images="dataForm.housePicList" v-if="dataForm.housePic !=''">
              <img v-for="src in dataForm.housePicList" :src="src"  style="width:100px;height:100px;">
            </viewer>

          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="在常就业社保证明" prop="sbPic"  >
            <viewer :images="dataForm.sbPicList" v-if="dataForm.sbPic !=''">
              <img v-for="src in dataForm.sbPicList" :src="src"  style="width:100px;height:100px;">
            </viewer>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="户口本" prop="householdPic"  >
            <viewer class="view" :images="dataForm.householdPicList" v-if="dataForm.householdPic !=''">
              <img v-for="src in dataForm.householdPicList" :src="src"  style="width:100px;height:100px;">
            </viewer>

          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="联系人" prop="contactName">
            <el-select v-model="dataForm.contactName" filterable clearable placeholder="" size="small" style="width: 100%" :disabled="type==1?false:true" >
              <el-option
                v-for="item in contactNameList"
                :key="item.teacherNo"
                :label="item.realName+'-'+item.deptCode"
                :value="item.teacherNo">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="原序号" prop="oldSerialNumber">
            <el-input type="text" v-model="dataForm.oldSerialNumber" :disabled="type==1?false:true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="辨色力" prop="colorDiscrimination">
            <el-select v-model="dataForm.colorDiscrimination" filterable clearable placeholder="" size="small" style="width: 100%" :disabled="type==1?false:true">
              <el-option
                v-for="item in colorDiscriminationList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="既往病史" prop="pastMedicalHistory">
            <el-input type="textarea" v-model="dataForm.pastMedicalHistory" placeholder="备注" :rows="2" :disabled="type==1?false:true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="remarks">
            <el-input type="textarea" v-model="dataForm.remarks" placeholder="备注" :rows="2" :disabled="type==1?false:true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="审核备注" prop="auditRemarks">
            <el-input type="textarea" v-model="dataForm.auditRemarks" placeholder="审核备注" :rows="2" :disabled="type==1?false:true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer v-if="type==1">
      <div class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="success" @click="dataFormSubmit(20)" v-if="canSubmit">确认录取</el-button>
        <el-button type="danger" @click="dataFormSubmit(-20)" v-if="canSubmit">驳回录取</el-button>
      </div>
    </template>

    <!--    图片预览-->
    <el-dialog title="图片预览" v-model="dialogUploadVisible" append-to-body >

    </el-dialog>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, nextTick } from 'vue'
import { ElNotification } from 'element-plus'
import { useMessageBox } from '/@/hooks/message'
import { getObj, putObj } from '@/api/recruit/recruitstudentsignup'
import { list as listByGroupId } from '@/api/recruit/recruitstudentschool'
import { getDeptList } from "@/api/basic/basicclass"
import { list } from "@/api/recruit/recruitstudentplangroup"
import { listByEdu } from "@/api/recruit/recruitplanmajor"
import { getDictByType } from "@/api/contract/contract"
import { areaList, areaSonList } from "@/api/recruit/recruitstudentschool"
import { list as scoreList } from "@/api/recruit/recruitstudentplancorrectscoreconfig"
import { queryAllTeacher } from "@/api/professional/teacherbase"

const messageBox = useMessageBox()

// Emits
const emit = defineEmits<{
  (e: 'refreshDataList'): void
}>()

// 表单引用
const dataFormRef = ref()

// 响应式数据
const visible = ref(false)
const canSubmit = ref(false)
const title = ref("")
const eduList = ref<any[]>([])
const imgList = ref<string[]>([])
const type = ref<number | null>(null)
const isShow = ref(false)
const yesNoList = [{ label: "否", value: "0" }, { label: "是", value: "1" }]
const residenceTypeList = [{ label: "农村", value: "1" }, { label: "城市", value: "2" }]
const colorDiscriminationList = [{ label: "正常", value: "1" }, { label: "色弱", value: "2" }, { label: "色盲", value: "3" }]
const nutritionList = [{ label: "优", value: "1" }, { label: "良", value: "2" }, { label: "一般", value: "3" }, { label: "差", value: "4" }]
const schoolCodeList = ref<any[]>([])
const sexyList = [
  { label: '男', value: '1' },
  { label: '女', value: '2' }
]
const contactNameList = ref<any[]>([])
const planList = ref<any[]>([])
const planMajorList = ref<any[]>([])
const areaListData = ref<any[]>([])
const areaPList = ref<any[]>([])
const areaCList = ref<any[]>([])
const areaAList = ref<any[]>([])
const areaHPList = ref<any[]>([])
const areaHCList = ref<any[]>([])
const areaHAList = ref<any[]>([])
const deptList = ref<any[]>([])
const dialogImageUrl = ref("")
const dialogUploadVisible = ref(false)
const sevenMajorList = ref<any[]>([])
const sixMajorList = ref<any[]>([])
const fiveMajorList = ref<any[]>([])
const fourMajorList = ref<any[]>([])
const threeMajorList = ref<any[]>([])
const twoMajorList = ref<any[]>([])
const agencyFeeList = ref<any[]>([])
const tuitionFeeList = ref<any[]>([])
const schoolFromList = [{ label: "本省外市", value: "2" }, { label: "外省外市", value: "3" }]

const dataForm = reactive({
        id: "",
        groupId: "",
        name: "",
        oldName: "",
        gender: "",
        nationality: "",
        degreeOfEducation: "",
        isLeagueMember: "",
        schoolOfGraduation: "",
        isAccommodation: "",
        examRegistrationNumbers: "",
        isMinimumLivingSecurity: "",
        score: "",
        postcode: "",
        residenceType: "",
        correctedScore: 0,
        fullScore: "",
        schoolArea: "",
        idNumber: "",
        residenceProvince: "",
        residenceCity: "",
        residenceArea: "",
        residenceDetail: "",
        homeAddressProvince: "",
        homeAddressCity: "",
        homeAddressArea: "",
        homeAddressDetail: "",
        parentName: "",
        parentTelOne: "",
        parentTelTwo: "",
        selfTel: "",
        wishMajorOne: "",
        wishMajorTwo: "",
        wishMajorThree: "",
        confirmedMajor: "",
        sevenMajor:"",
        sixMajor:"",
        fiveMajor:"",
        fourMajor: "",
        threeMajor: "",
        twoMajor: "",
        feeTuition: 0,
        feeAgency: 0,
        feeContribute: 0,
        scorePhoto: "",
        graPic: "",
        yyPic: "",
        housePic: "",
        sbPic: "",
        contactName: "",
        oldSerialNumber: "",
        colorDiscrimination: "",
        nutrition: "",
        height: "",
        weight: "",
        pastMedicalHistory: "",
        eyesightLeft: "",
        eyesightRight: "",
        correctEyesightLeft: "",
        correctEyesightRight: "",
        remarks: "",
        auditRemarks: "",
        serialNumber: "",
        auditStatus:"",
        jsOtherCity:"",
        householdPic:"",
        otherProvince:"",
        scorePhotoList: [] as string[],
        graPicList: [] as string[],
        yyPicList: [] as string[],
        housePicList: [] as string[],
        sbPicList: [] as string[],
        householdPicList: [] as string[]
})

const dataRule = {
        groupId: [
          {required: true, message: '招生计划不能为空', trigger: 'change'}
        ],
        name: [
          {required: true, message: '姓名不能为空', trigger: 'change'}
        ],
        gender: [
          {required: true, message: '性别不能为空', trigger: 'change'}
        ],
        nationality: [
          {required: true, message: '民族不能为空', trigger: 'change'}
        ],
        degreeOfEducation: [
          {required: true, message: '文化程度不能为空', trigger: 'change'}
        ],
        isLeagueMember: [
          {required: true, message: '是否团员不能为空', trigger: 'change'}
        ],
        schoolOfGraduation: [
          {required: true, message: '毕业学校不能为空', trigger: 'change'}
        ],
        isAccommodation: [
          {required: true, message: '是否住宿不能为空', trigger: 'change'}
        ],
        residenceType: [
          {required: true, message: '户口性质不能为空', trigger: 'change'}
        ],
        idNumber: [
          {required: true, message: '身份证不能为空', trigger: 'change'}
        ],
        otherProvince: [
          {required: true, message: '外省不能为空', trigger: 'change'}
        ],
        residenceProvince: [
          {required: true, message: '户口所在地不能为空', trigger: 'change'}
        ],
        residenceCity: [
          {required: true, message: '户口所在地不能为空', trigger: 'change'}
        ],
        residenceArea: [
          {required: true, message: '户口所在地不能为空', trigger: 'change'}
        ],
        residenceDetail: [
          {required: true, message: '户口所在地不能为空', trigger: 'change'}
        ],
        homeAddressProvince: [
          {required: true, message: '家庭地址不能为空', trigger: 'change'}
        ],
        homeAddressCity: [
          {required: true, message: '家庭地址不能为空', trigger: 'change'}
        ],
        homeAddressArea: [
          {required: true, message: '家庭地址不能为空', trigger: 'change'}
        ],
        homeAddressDetail: [
          {required: true, message: '家庭地址不能为空', trigger: 'change'}
        ],
        parentName: [
          {required: true, message: '家长姓名不能为空', trigger: 'change'}
        ],
        parentTel_1: [
          {required: true, message: '家长手机不能为空', trigger: 'change'}
        ],
        wishMajor_1: [
          {required: true, message: '拟报专业不能为空', trigger: 'change'}
        ],
        nutrition: [
          {required: true, message: '辨色力不能为空', trigger: 'change'}
        ],
        height: [
          {required: true, message: '身高cm不能为空', trigger: 'change'}
        ],
        weight: [
          {required: true, message: '体重kg不能为空', trigger: 'change'}
        ],
        correctedScore:[
          {required: true, message: '折算分不能为空', trigger: 'change'}
  ]
}

// 初始化
const init = (id: string | null, typeParam: number) => {
  dataForm.id = id || ""
  type.value = typeParam
  visible.value = true
  canSubmit.value = true
  initData()
  isShow.value = true
  nextTick(() => {
    dataFormRef.value?.resetFields()
    if (dataForm.id) {
      areaPList.value = []
      areaCList.value = []
      areaAList.value = []
      areaHPList.value = []
      areaHCList.value = []
      areaHAList.value = []
      // 获取数据字典
      getDictByType("finance_student_source").then((edu: any) => {
        eduList.value = edu.data
        // 获取数据字典代办费
        getDictByType("agency_fee").then((fee: any) => {
          agencyFeeList.value = fee.data
          // 获取数据字典学费
          getDictByType("tuition_fee").then((res: any) => {
            tuitionFeeList.value = res.data
            getObj(dataForm.id).then((response: any) => {
              Object.assign(dataForm, response.data)
              dataForm.scorePhotoList = []
              dataForm.graPicList = []
              dataForm.yyPicList = []
              dataForm.housePicList = []
              dataForm.sbPicList = []
              dataForm.householdPicList = []

              if (dataForm.scorePhoto) {
                dataForm.scorePhotoList = dataForm.scorePhoto.split(",")
              }
              if (dataForm.graPic) {
                dataForm.graPicList = dataForm.graPic.split(",")
              }
              if (dataForm.yyPic) {
                dataForm.yyPicList = dataForm.yyPic.split(",")
              }
              if (dataForm.housePic) {
                dataForm.housePicList = dataForm.housePic.split(",")
              }
              if (dataForm.householdPic) {
                dataForm.householdPicList = dataForm.householdPic.split(",")
              }
              if (dataForm.sbPic) {
                dataForm.sbPicList = dataForm.sbPic.split(",")
              }

              title.value = dataForm.serialNumber
              // 获取文化程度对应的专业
              planMajorList.value = []
              twoMajorList.value = []
              threeMajorList.value = []
              fiveMajorList.value = []
              sixMajorList.value = []
              sevenMajorList.value = []
              fourMajorList.value = []
              agencyFeeList.value.forEach((e: any) => {
                if (dataForm.degreeOfEducation == e.label) {
                  dataForm.feeAgency = e.value
                }
              })
              tuitionFeeList.value.forEach((e: any) => {
                if (dataForm.degreeOfEducation == e.label && (dataForm.degreeOfEducation != 1)) {
                  dataForm.feeTuition = e.value
                }
              })
              listByEdu({ groupId: dataForm.groupId, degreeOfEducation: dataForm.degreeOfEducation }).then((e: any) => {
                planMajorList.value = e.data
                if (1 != Number(dataForm.degreeOfEducation)) {
                  gzAuditChange()
                }
                // 根据年制分组
                planMajorList.value.forEach((item: any) => {
                  if (item.xz == '2') {
                    twoMajorList.value.push(item)
                  } else if (item.xz == '3') {
                    threeMajorList.value.push(item)
                  } else if (item.xz == '4') {
                    fourMajorList.value.push(item)
                  } else if (item.xz == '5') {
                    fiveMajorList.value.push(item)
                  } else if (item.xz == '6') {
                    sixMajorList.value.push(item)
                  } else if (item.xz == '7') {
                    sevenMajorList.value.push(item)
                  }
                })
              })
              // 获取招生计划下的学校和分数线
              scoreList({ groupId: dataForm.groupId }).then((data: any) => {
                schoolCodeList.value = data.data
              })
              let areas: any[] = []
              // 获取户口所在 省市区
              areaList({ type: 0 }).then((data: any) => {
                areas = data.data
                // 省
                let pid = ""
                areas.forEach((e: any) => {
                  if (e.parentId == '1') {
                    areaPList.value.push(e)
                    if (e.code == dataForm.residenceProvince) {
                      pid = e.id
                    }
                  }
                })
                // 市
                let cid = ""
                areas.forEach((e: any) => {
                  if (e.parentId == pid) {
                    areaCList.value.push(e)
                    if (e.code == dataForm.residenceCity) {
                      cid = e.id
                    }
                  }
                })
                // 区
                areas.forEach((e: any) => {
                  if (e.parentId == cid) {
                    areaAList.value.push(e)
                  }
                })

                // 省
                let hpid = ""
                areas.forEach((e: any) => {
                  if (e.parentId == '1') {
                    areaHPList.value.push(e)
                    if (e.code == dataForm.homeAddressProvince) {
                      hpid = e.id
                    }
                  }
                })
                // 市
                let hcid = ""
                areas.forEach((e: any) => {
                  if (e.parentId == hpid) {
                    areaHCList.value.push(e)
                    if (e.code == dataForm.homeAddressCity) {
                      hcid = e.id
                    }
                  }
                })
                // 区
                areas.forEach((e: any) => {
                  if (e.parentId == hcid) {
                    areaHAList.value.push(e)
                  }
                })
              })
              if ("1" == String(dataForm.degreeOfEducation)) {
                title.value = "C" + title.value
              } else if ("2" == String(dataForm.degreeOfEducation)) {
                title.value = "G" + title.value
              } else if ("3" == String(dataForm.degreeOfEducation)) {
                title.value = "J" + title.value
              }

              if ("-20" == String(dataForm.auditStatus)) {
                title.value = "未录取 " + title.value
              } else if ("0" == String(dataForm.auditStatus)) {
                title.value = "待审核 " + title.value
              } else if ("20" == String(dataForm.auditStatus)) {
                title.value = "已录取 " + title.value
              }
            })
          })
        })
      })
    }
  })
}

const changeEducation = () => {
  // 清空拟报专业 录取专业 学费和代办费
  dataForm.wishMajorOne = ""
  dataForm.wishMajorTwo = ""
  dataForm.wishMajorThree = ""
  dataForm.confirmedMajor = ""
  dataForm.twoMajor = ""
  dataForm.threeMajor = ""
  dataForm.fourMajor = ""
  dataForm.fiveMajor = ""
  dataForm.sixMajor = ""
  dataForm.sevenMajor = ""

  dataForm.feeTuition = 0
  dataForm.feeAgency = 0

  // 重新根据学历 获取学费和代办费
  agencyFeeList.value.forEach((e: any) => {
    if (dataForm.degreeOfEducation == e.label) {
      dataForm.feeAgency = e.value
    }
  })
  tuitionFeeList.value.forEach((e: any) => {
    if (dataForm.degreeOfEducation == e.label && (dataForm.degreeOfEducation != 1)) {
      dataForm.feeTuition = e.value
    }
  })
  // 根据学历获取快捷专业选择
  planMajorList.value = []
  twoMajorList.value = []
  threeMajorList.value = []
  fiveMajorList.value = []
  sixMajorList.value = []
  sevenMajorList.value = []
  fourMajorList.value = []
  listByEdu({ groupId: dataForm.groupId, degreeOfEducation: dataForm.degreeOfEducation }).then((e: any) => {
    planMajorList.value = e.data
    if (1 != Number(dataForm.degreeOfEducation)) {
      gzAuditChange()
    }
    // 根据年制分组
    planMajorList.value.forEach((item: any) => {
      if (item.xz == '2') {
        twoMajorList.value.push(item)
      } else if (item.xz == '3') {
        threeMajorList.value.push(item)
      } else if (item.xz == '4') {
        fourMajorList.value.push(item)
      } else if (item.xz == '5') {
        fiveMajorList.value.push(item)
      } else if (item.xz == '6') {
        sixMajorList.value.push(item)
      } else if (item.xz == '7') {
        sevenMajorList.value.push(item)
      }
    })
  })
}

const handlePicCardPreview = (file: string) => {
  const array = file.split(",")
  imgList.value = array
  dialogUploadVisible.value = true
}

const initData = () => {
  // 联系人(教职工)
  queryAllTeacher().then((res: any) => {
    contactNameList.value = res.data
  })
  // 查询二级学院信息
  getDeptList().then((data: any) => {
    deptList.value = data.data
  })
  list().then((data: any) => {
    planList.value = data.data
  })
}

const changeFrom = () => {
  dataForm.fullScore = ""
  dataForm.correctedScore = 0
  if (dataForm.schoolArea == "2") {
    isShow.value = true
  } else {
    isShow.value = false
  }
}

const changeSchoolCode = () => {
  dataForm.fullScore = ""
  schoolCodeList.value.forEach((e: any) => {
    if (e.regionId == dataForm.jsOtherCity) {
      dataForm.fullScore = e.fullScore
    }
  })
  if (dataForm.fullScore == "" && dataForm.schoolArea != "3") {
    ElNotification.error({
      title: '错误',
      message: '当前省市未匹配到分数线,请检查'
    })
    return
  }

  dataForm.correctedScore = 0
  jsZSF()
}

const changePlaceScore = () => {
  jsZSF()
}

const gzAuditChange = () => {
  if (type.value != 0 && (dataForm.confirmedMajor == undefined || dataForm.confirmedMajor == "")) {
    // 根据折算分匹配录取专业
    planMajorList.value.forEach((e: any) => {
      if (e.zydm == dataForm.wishMajorOne && (parseFloat(e.xyNum) > 0)) {
        dataForm.confirmedMajor = dataForm.wishMajorOne
      }
    })
    if (dataForm.confirmedMajor) {
      planMajorList.value.forEach((e: any) => {
        if (e.zydm == dataForm.wishMajorTwo && (parseFloat(e.xyNum) > 0)) {
          dataForm.confirmedMajor = dataForm.wishMajorOne
        }
      })
    }

    if (dataForm.confirmedMajor) {
      planMajorList.value.forEach((e: any) => {
        if (e.zydm == dataForm.wishMajorThree && (parseFloat(e.xyNum) > 0)) {
          dataForm.confirmedMajor = dataForm.wishMajorOne
        }
      })
    }
  }
}

const jsZSF = () => {
  if (dataForm.score != undefined && dataForm.fullScore != undefined && dataForm.correctedScore != undefined && !isNaN(Number(dataForm.correctedScore))) {
    dataForm.confirmedMajor = ""
    let fjf = 20

    if (dataForm.schoolArea == "3") {
      fjf = 30
    }
    const score = (parseFloat(String(dataForm.score)) * parseFloat("700"))
    dataForm.correctedScore = String(Math.floor(score / parseFloat(String(dataForm.fullScore)) + fjf))
    // 根据折算分匹配录取专业
    planMajorList.value.forEach((e: any) => {
      if (dataForm.correctedScore >= e.scoreLine && e.zydm == dataForm.wishMajorOne && (parseFloat(e.xyNum) > 0)) {
        dataForm.confirmedMajor = dataForm.wishMajorOne
      }
    })
    if (dataForm.confirmedMajor == "") {
      planMajorList.value.forEach((e: any) => {
        if (dataForm.correctedScore >= e.scoreLine && e.zydm == dataForm.wishMajorTwo && (parseFloat(e.xyNum) > 0)) {
          dataForm.confirmedMajor = dataForm.wishMajorTwo
        }
      })
    }

    if (dataForm.confirmedMajor == "") {
      planMajorList.value.forEach((e: any) => {
        if (dataForm.correctedScore >= e.scoreLine && e.zydm == dataForm.wishMajorThree && (parseFloat(e.xyNum) > 0)) {
          dataForm.confirmedMajor = dataForm.wishMajorThree
        }
      })
    }
    if (dataForm.confirmedMajor) {
      changeM(dataForm.confirmedMajor)
    }
  }
}

const changeR = (changeType: number) => {
  let code = ""
  areaAList.value = []
  dataForm.residenceArea = ""
  if (changeType == 1) {
    code = dataForm.residenceProvince
    areaCList.value = []
    dataForm.residenceCity = ""
  } else {
    code = dataForm.residenceCity
  }
  areaSonList({ code: code }).then((data: any) => {
    if (changeType == 1) {
      areaCList.value = data.data
    } else {
      areaAList.value = data.data
    }
  })
}

const changeH = (changeType: number) => {
  let code = ""
  areaHAList.value = []
  dataForm.homeAddressArea = ""
  if (changeType == 1) {
    code = dataForm.homeAddressProvince
    areaHCList.value = []
    dataForm.homeAddressCity = ""
  } else {
    code = dataForm.homeAddressCity
  }
  areaSonList({ code: code }).then((data: any) => {
    if (changeType == 1) {
      areaHCList.value = data.data
    } else {
      areaHAList.value = data.data
    }
  })
}

const changeM = (id: string) => {
  if (id) {
    let flag = false
    dataForm.confirmedMajor = id
    // 是初中生并且是中德班
    planMajorList.value.forEach((e: any) => {
      if (dataForm.confirmedMajor == e.zydm && e.isZd == "1" && dataForm.degreeOfEducation == "1") {
        flag = true
      }
    })
    if (dataForm.degreeOfEducation == "1") {
      dataForm.feeTuition = 0
      tuitionFeeList.value.forEach((e: any) => {
        if (e.label == "0" && flag) {
          dataForm.feeTuition = e.value
        }
      })
    }
  }
}

// 表单提交
const dataFormSubmit = (state: number) => {
  dataForm.auditStatus = String(state)
  let submitTitle = "确认通过该学生的报名申请么?"
  if (state == -20) {
    submitTitle = "确认驳回该学生的报名申请么？"
  } else {
    if (!dataForm.confirmedMajor) {
      ElNotification.error({
        title: '错误',
        message: '请选择录取专业'
      })
      return
    }
  }
  if (dataForm.degreeOfEducation == '1' && (dataForm.score == undefined || dataForm.score == '')) {
    ElNotification.error({
      title: '错误',
      message: '初中生报名请填写成绩'
    })
    return
  }
  if (dataForm.degreeOfEducation == '1' && dataForm.schoolArea == '3' && (dataForm.fullScore == undefined || dataForm.fullScore == '')) {
    ElNotification.error({
      title: '错误',
      message: '外地初中生报名请填写当地总分'
    })
    return
  }
  if (dataForm.degreeOfEducation == '1' && dataForm.schoolArea == '2' && (dataForm.schoolArea == undefined || dataForm.jsOtherCity == undefined) && state == 20) {
    ElNotification.error({
      title: '错误',
      message: '初中生审核请选择学校归属地和所在省市'
    })
    return
  }
  if (dataForm.degreeOfEducation == '1' && dataForm.schoolArea == '3' && (dataForm.schoolArea == undefined || dataForm.otherProvince == undefined) && state == 20) {
    ElNotification.error({
      title: '错误',
      message: '初中生审核请选择学校归属地和所在省市'
    })
    return
  }

  messageBox.confirm(submitTitle, '提示').then(() => {
    dataFormRef.value?.validate((valid: boolean) => {
      if (valid) {
        canSubmit.value = false
        if (dataForm.id) {
          putObj(dataForm).then(() => {
            ElNotification.success({
              title: '成功',
              message: '操作成功'
            })
            visible.value = false
            emit('refreshDataList')
          }).catch((e: any) => {
            ElNotification.error({
              title: '错误',
              message: e || '操作失败'
            })
          }).finally(() => {
            canSubmit.value = true
          })
        } else {
          canSubmit.value = true
        }
      }
    })
  }).catch(() => {
    // 用户取消
  })
}

// 暴露方法给父组件
defineExpose({
  init
})
</script>
<style lang="scss" scoped>
.viewer-container{
  z-index: 9999;
}
</style>
