<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"
             label-width="130px">
      <!-- 基本信息 -->
      <div class="form-section">
        <div class="section-title">基本信息</div>
        <el-row :gutter="20" class="form-row">
          <el-col :span="24">
            <el-form-item label="招生计划" prop="groupId">
              <el-select v-model="dataForm.groupId" filterable :disabled="!dataForm.id ? false : true"
                         placeholder="请选择招生计划" class="w-full">
                <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 :gutter="20" class="form-row">
        <el-col :span="6">
          <el-form-item label="姓名" prop="name" >
            <el-input type="text" v-model="dataForm.name" :disabled="!isEdit"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="曾用名" prop="oldName">
            <el-input type="text" v-model="dataForm.oldName" :disabled="!isEdit"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="证件类型" prop="idCardType">
            <el-radio-group v-model="dataForm.idCardType" :disabled="!isEdit" @change="handleIdCardTypeChange">
              <el-radio v-for="item in idCardTypeList" :key="item.value" :label="item.value">{{ item.label }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="身份证号" prop="idNumber">
            <el-input 
              v-model="dataForm.idNumber" 
              placeholder="身份证号"
              maxlength="20"
              v-input-filter="'idcard'">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="性别" prop="gender" :required="isGenderRequired">
            <el-select v-model="dataForm.gender" class="w-full" :disabled="!isEdit || dataForm.idCardType=='0'" >
              <el-option
                v-for="item in sexy"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="民族" prop="nationality">
            <el-select v-model="dataForm.nationality" filterable placeholder="请选择民族" class="w-full" :disabled="!isEdit">
              <el-option
                v-for="item in nationalityList"
                :key="item.nationCode"
                :label="item.nationName"
                :value="item.nationName">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="是否团员" prop="isLeagueMember">
            <el-select v-model="dataForm.isLeagueMember" filterable clearable placeholder="请选择是否团员" class="w-full" :disabled="!isEdit">
              <el-option
                v-for="item in yes_no_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="是否住宿" prop="isAccommodation">
            <el-select v-model="dataForm.isAccommodation" filterable clearable placeholder="请选择是否住宿" class="w-full" :disabled="!isEdit">
              <el-option
                v-for="item in yes_no_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
       
      </el-row>
      <el-row :gutter="20" class="form-row">
        <el-col :span="12">
          <el-form-item label="毕业学校" prop="schoolOfGraduation">
            <el-input type="text" v-model="dataForm.schoolOfGraduation" :disabled="!isEdit"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20" class="form-row">
        <el-col :span="6">
          <el-form-item label="准考证号" prop="examRegistrationNumbers">
            <el-input 
              v-model="dataForm.examRegistrationNumbers" 
              placeholder="准考证号"
              maxlength="20"
              :disabled="!isEdit"
              v-input-filter="'alphanumeric'">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="文化程度" prop="degreeOfEducation">
            <el-select v-model="dataForm.degreeOfEducation" filterable placeholder="请选择文化程度" class="w-full" :disabled="!isEdit" @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="6">
          <el-form-item label="成绩" prop="score">
            <el-input-number 
              v-model="dataForm.score" 
              placeholder="成绩"
              :min="0"
              :max="1000"
              :disabled="!isEdit" 
              @change="calculateCorrectedScore">
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="户口性质" prop="residenceType">
            <el-select v-model="dataForm.residenceType" filterable clearable placeholder="请选择户口性质" class="w-full" :disabled="!isEdit">
              <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="dataForm.degreeOfEducation=='1'" :gutter="20" class="form-row">
        <el-col :span="6">
          <el-form-item label="学校归属地" prop="schoolArea">
            <el-select v-model="dataForm.schoolArea" filterable placeholder="请选择学校归属地" class="w-full" :disabled="!isEdit" @change="changeFrom">
              <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-col v-if="(dataForm.degreeOfEducation) && (dataForm.schoolArea=='2')" :span="6">
          <el-form-item label="学校所在省市" prop="jsOtherCity">
            <el-select v-model="dataForm.jsOtherCity" filterable placeholder="请选择学校所在省市" class="w-full"
                       :disabled="!isEdit" @change="changeSchoolCode">
              <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-col v-if="(dataForm.degreeOfEducation) && (dataForm.schoolArea=='3')" :span="6">
          <el-form-item label="外省" prop="otherProvince">
            <el-select v-model="dataForm.otherProvince" filterable placeholder="请选择学校所在省市" class="w-full"
                       :disabled="!isEdit" @change="changeSchoolCode">
              <el-option
                v-for="item in areaHomeProvinceList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="当地总分" prop="fullScore">
            <el-input-number 
              v-model="dataForm.fullScore" 
              :min="0"
              :max="1000"
              :disabled="isShow" 
              @change="changePlaceScore">
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="成绩折算分" prop="correctedScore">
            <el-input-number 
              v-model="dataForm.correctedScore" 
              :min="0"
              :max="1000"
              disabled>
            </el-input-number>
          </el-form-item>
        </el-col>
       
       
      </el-row>
   
      <!-- 户口所在地 -->
      <el-row :gutter="20" class="form-row">
        <el-col :span="12">
          <el-form-item label="户口所在地" prop="residenceProvince">
            <div class="address-group">
              <el-select v-model="dataForm.residenceProvince" filterable clearable placeholder="省" class="address-select" :disabled="!isEdit" @change="changeR(1)">
                <el-option
                  v-for="item in areaProvinceList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                </el-option>
              </el-select>
              <span class="address-separator">-</span>
              <el-select v-model="dataForm.residenceCity" filterable clearable placeholder="市" class="address-select" :disabled="!isEdit" @change="changeR(2)">
                <el-option
                  v-for="item in areaCityList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                </el-option>
              </el-select>
              <span class="address-separator">-</span>
              <el-select v-model="dataForm.residenceArea" filterable clearable placeholder="区/县" class="address-select" :disabled="!isEdit">
                <el-option
                  v-for="item in areaAreaList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="详细地址" prop="residenceDetail">
            <el-input type="text" v-model="dataForm.residenceDetail" placeholder="请输入详细地址" :disabled="!isEdit"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 家庭地址 -->
      <el-row :gutter="20" class="form-row">
        <el-col :span="12">
          <el-form-item label="家庭地址" prop="homeAddressProvince">
            <div class="address-group">
              <el-select v-model="dataForm.homeAddressProvince" filterable clearable placeholder="省" class="address-select" :disabled="!isEdit" @change="changeH(1)">
                <el-option
                  v-for="item in areaHomeProvinceList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                </el-option>
              </el-select>
              <span class="address-separator">-</span>
              <el-select v-model="dataForm.homeAddressCity" filterable clearable placeholder="市" class="address-select" :disabled="!isEdit" @change="changeH(2)">
                <el-option
                  v-for="item in areaHomeCityList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                </el-option>
              </el-select>
              <span class="address-separator">-</span>
              <el-select v-model="dataForm.homeAddressArea" filterable clearable placeholder="区/县" class="address-select" :disabled="!isEdit">
                <el-option
                  v-for="item in areaHomeAreaList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="详细地址" prop="homeAddressDetail">
            <el-input type="text" v-model="dataForm.homeAddressDetail" placeholder="请输入详细地址" :disabled="!isEdit"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20" class="form-row">
        <el-col :span="6">
          <el-form-item label="家长姓名" prop="parentName">
            <el-input type="text" v-model="dataForm.parentName" :disabled="!isEdit"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="家长手机" prop="parentTelOne">
            <el-input 
              v-model="dataForm.parentTelOne" 
              type="tel"
              placeholder="家长手机"
              maxlength="11"
              :disabled="!isEdit"
              v-input-filter="'number'">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="家长固话" prop="parentTelTwo">
            <el-input 
              v-model="dataForm.parentTelTwo" 
              placeholder="家长固话"
              maxlength="20"
              :disabled="!isEdit"
              v-input-filter="'tel'">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="本人联系电话" prop="selfTel">
            <el-input 
              v-model="dataForm.selfTel" 
              type="tel"
              placeholder="本人联系电话"
              maxlength="11"
              :disabled="!isEdit"
              v-input-filter="'number'">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      </div>

      <!-- 专业信息 -->
      <div class="form-section">
        <div class="section-title">专业信息</div>
        <el-row v-if="dataForm.id" :gutter="20" class="form-row">
          <el-col :span="8">
            <el-form-item label="拟报专业1" prop="wishMajorOne">
            <el-select v-model="dataForm.wishMajorOne" filterable clearable placeholder="请选择专业" class="w-full">
              <el-option
                v-for="item in planMajorList"
                :key="item.majorCode"
                :label="item.majorName"
                :value="item.majorCode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="拟报专业2" prop="wishMajorTwo">
            <el-select v-model="dataForm.wishMajorTwo" filterable clearable placeholder="请选择专业" class="w-full">
              <el-option
                v-for="item in planMajorList"
                :key="item.majorCode"
                :label="item.majorName"
                :value="item.majorCode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="拟报专业3" prop="wishMajorThree">
            <el-select v-model="dataForm.wishMajorThree" filterable clearable placeholder="请选择专业" class="w-full">
              <el-option
                v-for="item in planMajorList"
                :key="item.majorCode"
                :label="item.majorName"
                :value="item.majorCode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
        <el-row :gutter="20" class="form-row">
          <el-col :span="24">
            <el-form-item label="录取专业" prop="confirmedMajor">
            <el-select v-model="dataForm.confirmedMajor" filterable clearable placeholder="" class="w-full" :disabled="!isEdit" @change="changeConfirmedMajor(dataForm.confirmedMajor)">
              <el-option
                v-for="item in planMajorList"
                :key="item.majorCode"
                :label="item.majorName+' || '+item.xyNum"
                :value="item.majorCode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
        <el-row v-if="isEdit" :gutter="20" class="form-row">
        <el-col :span="24">
          <el-form-item label="两年制专业" prop="twoMajor" v-if="twoMajorList.length>0">
            <el-select v-model="dataForm.twoMajor" filterable clearable placeholder="" class="w-full" @change="changeConfirmedMajor(dataForm.twoMajor)">
              <el-option
                v-for="item in twoMajorList"
                :key="item.majorCode"
                :label="item.majorName+' || '+item.xyNum"
                :value="item.majorCode">
              </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="" class="w-full" @change="changeConfirmedMajor(dataForm.threeMajor)">
              <el-option
                v-for="item in threeMajorList"
                :key="item.majorCode"
                :label="item.majorName+' || '+item.xyNum"
                :value="item.majorCode">
              </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="" class="w-full" @change="changeConfirmedMajor(dataForm.fourMajor)">
            <el-option
              v-for="item in fourMajorList"
              :key="item.majorCode"
              :label="item.majorName+' || '+item.xyNum"
              :value="item.majorCode">
            </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="" class="w-full" @change="changeConfirmedMajor(dataForm.fiveMajor)">
              <el-option
                v-for="item in fiveMajorList"
                :key="item.majorCode"
                :label="item.majorName+' || '+item.xyNum"
                :value="item.majorCode">
              </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="" class="w-full" @change="changeConfirmedMajor(dataForm.sixMajor)">
              <el-option
                v-for="item in sixMajorList"
                :key="item.majorCode"
                :label="item.majorName+' || '+item.xyNum"
                :value="item.majorCode">
              </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="" class="w-full" @change="changeConfirmedMajor(dataForm.sevenMajor)">
              <el-option
                v-for="item in sevenMajorList"
                :key="item.majorCode"
                :label="item.majorName+' || '+item.xyNum"
                :value="item.majorCode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
        <!-- 费用信息 -->
        <el-row :gutter="20" class="form-row">
          <el-col :span="6">
            <el-form-item label="学费" prop="feeTuition">
              <el-input-number v-model="dataForm.feeTuition" controls-position="right" :min="0" :max="999999" :step-strictly="true" disabled class="w-full"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="代办费" prop="feeAgency">
              <el-input-number v-model="dataForm.feeAgency" controls-position="right" :min="0" :max="999999" :step-strictly="true" disabled class="w-full"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="总费用" prop="allMoney">
              <span class="total-fee">{{Number(dataForm.feeTuition)+Number(dataForm.feeAgency)}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 附件材料 -->
        <el-row :gutter="20" class="form-row">
          <el-col :span="8">
            <el-form-item label="成绩单" prop="scorePhoto">
              <div class="image-preview-container">
                <viewer :images="dataForm.scorePhotoList" v-if="dataForm.scorePhoto && dataForm.scorePhotoList && dataForm.scorePhotoList.length > 0">
                  <div class="image-list">
                    <div v-for="(src, index) in dataForm.scorePhotoList" :key="index" class="image-item">
                      <img :src="src" class="preview-image" :alt="`成绩单-${index + 1}`">
                    </div>
                  </div>
                </viewer>
                <div v-else class="image-placeholder">
                  <el-icon><Picture /></el-icon>
                  <span>暂无图片</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="毕业证" prop="graPic">
              <div class="image-preview-container">
                <viewer :images="dataForm.graPicList" v-if="dataForm.graPic && dataForm.graPicList && dataForm.graPicList.length > 0">
                  <div class="image-list">
                    <div v-for="(src, index) in dataForm.graPicList" :key="index" class="image-item">
                      <img :src="src" class="preview-image" :alt="`毕业证-${index + 1}`">
                    </div>
                  </div>
                </viewer>
                <div v-else class="image-placeholder">
                  <el-icon><Picture /></el-icon>
                  <span>暂无图片</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="在常营业执照" prop="yyPic">
              <div class="image-preview-container">
                <viewer :images="dataForm.yyPicList" v-if="dataForm.yyPic && dataForm.yyPicList && dataForm.yyPicList.length > 0">
                  <div class="image-list">
                    <div v-for="(src, index) in dataForm.yyPicList" :key="index" class="image-item">
                      <img :src="src" class="preview-image" :alt="`在常营业执照-${index + 1}`">
                    </div>
                  </div>
                </viewer>
                <div v-else class="image-placeholder">
                  <el-icon><Picture /></el-icon>
                  <span>暂无图片</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" class="form-row">
          <el-col :span="8">
            <el-form-item label="在常租赁合同/房产证明" prop="housePic">
              <div class="image-preview-container">
                <viewer :images="dataForm.housePicList" v-if="dataForm.housePic && dataForm.housePicList && dataForm.housePicList.length > 0">
                  <div class="image-list">
                    <div v-for="(src, index) in dataForm.housePicList" :key="index" class="image-item">
                      <img :src="src" class="preview-image" :alt="`在常租赁合同/房产证明-${index + 1}`">
                    </div>
                  </div>
                </viewer>
                <div v-else class="image-placeholder">
                  <el-icon><Picture /></el-icon>
                  <span>暂无图片</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="在常就业社保证明" prop="sbPic">
              <div class="image-preview-container">
                <viewer :images="dataForm.sbPicList" v-if="dataForm.sbPic && dataForm.sbPicList && dataForm.sbPicList.length > 0">
                  <div class="image-list">
                    <div v-for="(src, index) in dataForm.sbPicList" :key="index" class="image-item">
                      <img :src="src" class="preview-image" :alt="`在常就业社保证明-${index + 1}`">
                    </div>
                  </div>
                </viewer>
                <div v-else class="image-placeholder">
                  <el-icon><Picture /></el-icon>
                  <span>暂无图片</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="户口本" prop="householdPic">
              <div class="image-preview-container">
                <viewer :images="dataForm.householdPicList" v-if="dataForm.householdPic && dataForm.householdPicList && dataForm.householdPicList.length > 0">
                  <div class="image-list">
                    <div v-for="(src, index) in dataForm.householdPicList" :key="index" class="image-item">
                      <img :src="src" class="preview-image" :alt="`户口本-${index + 1}`">
                    </div>
                  </div>
                </viewer>
                <div v-else class="image-placeholder">
                  <el-icon><Picture /></el-icon>
                  <span>暂无图片</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 其他信息 -->
        <el-row :gutter="20" class="form-row">
          <el-col :span="8">
            <el-form-item label="联系人" prop="contactName">
              <el-select v-model="dataForm.contactName" filterable clearable placeholder="请选择联系人" class="w-full" :disabled="!isEdit">
                <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="8">
            <el-form-item label="辨色力" prop="colorDiscrimination">
              <el-select v-model="dataForm.colorDiscrimination" filterable clearable placeholder="请选择辨色力" class="w-full" :disabled="!isEdit">
                <el-option
                  v-for="item in color_discrimination"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" class="form-row">
          <el-col :span="24">
            <el-form-item label="既往病史" prop="pastMedicalHistory">
              <el-input type="textarea" v-model="dataForm.pastMedicalHistory" placeholder="请输入既往病史" :rows="2" :disabled="!isEdit"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" class="form-row">
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input type="textarea" v-model="dataForm.remarks" placeholder="备注" :rows="2" :disabled="!isEdit"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <template #footer v-if="isEdit">
      <div class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit('0')" v-auth="'recruit_recruitstudentsignup_add'"  v-if="canSubmit&&!dataForm.id">保存并送审</el-button>
        <el-button type="primary" @click="dataFormSubmit('0')" v-auth="'recruit_recruitstudentsignup_edit'"  v-if="canSubmit&&dataForm.id">保存</el-button>
        <el-button type="primary" @click="dataFormSubmit('20')" v-auth="'signup_info_exam'" v-if="canSubmit&&dataForm.id">确认录取</el-button>
        <el-button type="danger" plain @click="dataFormSubmit('-20')" v-auth="'signup_info_exam'" v-if="canSubmit&&dataForm.id">驳回录取</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, watch, computed } from 'vue'
import { ElNotification } from 'element-plus'
import { Picture } from '@element-plus/icons-vue'
import { useMessage, useMessageBox } from '/@/hooks/message'
import { getObj, putObj, addObj ,makeCorrectScore} from '/@/api/recruit/recruitstudentsignup'
import { list as listByGroupId } from '/@/api/recruit/recruitstudentschool'
import { getList } from "/@/api/recruit/recruitstudentplangroup"
import { listByEdu } from "/@/api/recruit/recruitstudentplan"
import { getDictsByTypes } from "/@/api/admin/dict"
import { useDict } from '/@/hooks/dict'
import { areaList, areaSonList } from "/@/api/recruit/recruitstudentschool"
import { list as scoreList } from "/@/api/recruit/recruitstudentplancorrectscoreconfig"
import { queryAllTeacher } from "/@/api/professional/professionaluser/teacherbase"
import { getNationalList } from "/@/api/basic/basicnation"
import { verifyIdCardAll, verifyAdmissionNumber } from '/@/utils/toolsValidate'
import { AUDIT_STATUS_LIST, getStatusConfig } from '/@/config/global'

const message = useMessage()
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 { yes_no_type, sexy, color_discrimination } = useDict('yes_no_type', 'sexy', 'color_discrimination')

const eduList = ref<any[]>([])
const imgList = ref<string[]>([])
const type = ref<number | null>(null)
const isShow = ref(false)
const isEdit = ref(false)
// 性别是否必填（证件类型不是身份证时必填）
const isGenderRequired = computed(() => dataForm.idCardType !== '0')
// 录取状态
const auditStatusList = AUDIT_STATUS_LIST
// 户口性质
const residenceTypeList = ref<any[]>([])
const schoolCodeList = ref<any[]>([])
const contactNameList = ref<any[]>([])
const planList = ref<any[]>([])
const planMajorList = ref<any[]>([])
const areaProvinceList = ref<any[]>([])
const areaCityList = ref<any[]>([])
const areaAreaList = ref<any[]>([])
const areaHomeProvinceList = ref<any[]>([])
const areaHomeCityList = ref<any[]>([])
const areaHomeAreaList = ref<any[]>([])
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 = ref<any[]>([])
const nationalityList = ref<any[]>([])
const idCardTypeList = ref<any[]>([])
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:"",
        idCardType:"0",
        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: [
          {
            validator: (rule: any, value: any, callback: any) => {
              // 如果证件类型是身份证，性别可以不填（后台会根据身份证号自动获取）
              if (dataForm.idCardType === '0') {
                callback()
              } else if (!value) {
                callback(new Error('性别不能为空'))
              } else {
                callback()
              }
            },
            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'}
        ],
        idCardType: [
          {required: true, message: '证件类型不能为空', trigger: 'change'}
        ],
        idNumber: [
          {required: true, message: '身份证不能为空', trigger: 'change'},
          {
            validator: (rule: any, value: any, callback: any) => {
              if (value && !verifyIdCardAll(value)) {
                callback(new Error('请输入正确的身份证号码'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ],
        examRegistrationNumbers: [
          {required: true, message: '准考证号不能为空', trigger: 'change'},
          {
            validator: (rule: any, value: any, callback: any) => {
              if (value && !verifyAdmissionNumber(value)) {
                callback(new Error('请输入正确的准考证号'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ],
        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'}
        ],
        // wishMajorOne: [
        //   {
        //     validator: (rule: any, value: any, callback: any) => {
        //       // 新增时不需要验证，修改时需要验证
        //       if (!dataForm.id) {
        //         callback()
        //       } else if (!value) {
        //         callback(new Error('拟报专业不能为空'))
        //       } else {
        //         callback()
        //       }
        //     },
        //     trigger: 'change'
        //   }
        // ],
        contactName: [
          {required: true, message: '联系人不能为空', trigger: 'change'}
        ],
        colorDiscrimination: [
          {required: true, message: '辨色力不能为空', trigger: 'change'}
        ],
        correctedScore:[
          {required: true, message: '折算分不能为空', trigger: 'change'}
  ]
}

// 初始化
const init = (id: string | null, typeParam: number) => {
  dataForm.id = id || null
  type.value = typeParam
  isEdit.value = typeParam == 1 ? true : false
  visible.value = true
  canSubmit.value = true
  initData()
  isShow.value = true
  nextTick(() => {
    dataFormRef.value?.resetFields()
    // 初始化地区数据
    areaProvinceList.value = []
    areaCityList.value = []
    areaAreaList.value = []
    // 家庭地址数据
    areaHomeProvinceList.value = []
    areaHomeCityList.value = []
    areaHomeAreaList.value = []
    
    // 批量获取数据字典（新增和编辑都需要）  文化程度  学费 代办费  户口性质  学校归属地
    getDictsByTypes(['id_type','finance_student_source', 'agency_fee', 'tuition_fee','house_hold_properties','recruit_school_form']).then((res: any) => {
      idCardTypeList.value = res.data.id_type || []
      eduList.value = res.data.finance_student_source || []
      agencyFeeList.value = res.data.agency_fee || []
      tuitionFeeList.value = res.data.tuition_fee || []
      residenceTypeList.value = res.data.house_hold_properties || []
      schoolFromList.value = res.data.recruit_school_form || []
      // 加载地区数据（新增和编辑都需要）
      areaList({ type: 0 }).then((data: any) => {
        const areas = data.data
        // 加载省级数据
        areas.forEach((e: any) => {
          if (e.parentId == '1') {
            areaProvinceList.value.push(e)
            areaHomeProvinceList.value.push(e)
          }
        })
      })
      
      if (dataForm.id) {
        // 编辑模式：获取表单数据
        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
              // 获取文化程度对应的专业
              // 根据学历获取代办费（从字典获取）
              agencyFeeList.value.forEach((e: any) => {
                if (dataForm.degreeOfEducation == e.label) {
                  dataForm.feeAgency = e.value
                }
              })
              // 加载专业列表并分组
              loadMajorListAndGroup()
              // 获取招生计划下的学校所在城市（本省外市）
              scoreList({ groupId: dataForm.groupId }).then((data: any) => {
                schoolCodeList.value = data.data
              })
              
              // 根据已有数据加载市区数据
              if (dataForm.residenceProvince) {
                areaSonList({ code: dataForm.residenceProvince }).then((data: any) => {
                  areaCityList.value = data.data
                  if (dataForm.residenceCity) {
                    areaSonList({ code: dataForm.residenceCity }).then((data: any) => {
                      areaAreaList.value = data.data
                    })
                  }
                })
              }
              
              if (dataForm.homeAddressProvince) {
                areaSonList({ code: dataForm.homeAddressProvince }).then((data: any) => {
                  areaHomeCityList.value = data.data
                  if (dataForm.homeAddressCity) {
                    areaSonList({ code: dataForm.homeAddressCity }).then((data: any) => {
                      areaHomeAreaList.value = data.data
                    })
                  }
                })
              }
              // 根据文化程度添加前缀：初中(C)、高中(G)、技职校(J)
              const educationPrefixMap: Record<string, string> = {
                '1': 'C',  // 初中
                '2': 'G',  // 高中
                '3': 'J'   // 技职校
              }
              const prefix = educationPrefixMap[String(dataForm.degreeOfEducation)]
              if (prefix) {
                title.value = prefix + title.value
              }

              // 从字典数据获取录取状态标签
              const auditStatusConfig = getStatusConfig(auditStatusList, dataForm.auditStatus)
              if (auditStatusConfig && auditStatusConfig.label) {
                title.value = auditStatusConfig.label + " " + title.value
              }
        })
      } else {
        // 新增模式：设置默认标题
        title.value = "新增报名信息"
      }
    })
  })
}

// 证件类型变化处理
const handleIdCardTypeChange = () => {
  // 如果选择身份证，清空性别字段（后台会根据身份证号自动获取）
  if (dataForm.idCardType === '0') {
    dataForm.gender = ''
  }
}

// 加载专业列表并分组
const loadMajorListAndGroup = () => {
  // 清空专业列表
  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
    // 如果是初中生，则根据折算分匹配录取专业
    getGzAuditChange()
    // 根据年制分组
    planMajorList.value.forEach((item: any) => {
      if (item.learnYear == '2') {
        twoMajorList.value.push(item)
      } else if (item.learnYear == '3') {
        threeMajorList.value.push(item)
      } else if (item.learnYear == '4') {
        fourMajorList.value.push(item)
      } else if (item.learnYear == '5') {
        fiveMajorList.value.push(item)
      } else if (item.learnYear == '6') {
        sixMajorList.value.push(item)
      } else if (item.learnYear == '7') {
        sevenMajorList.value.push(item)
      }
    })
    
    // 如果已有录取专业，根据文化程度和专业更新学费
    if (dataForm.confirmedMajor) {
      updateTuitionByMajorAndEducation()
    }
  })
}

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
    }
  })

  // 加载专业列表并分组
  loadMajorListAndGroup()
}

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

const initData = () => {
  // 联系人(教职工)
  queryAllTeacher().then((res: any) => {
    contactNameList.value = res.data
  })
  // 获取招生计划列表
  getList().then((data: any) => {
    planList.value = data.data
  })
  // 获取民族列表
  getNationalList().then((res: any) => {
    nationalityList.value = res.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
  calculateCorrectedScore()
}

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

const getGzAuditChange = () => {
  // 如果是初中生 需要根据折算分匹配录取专业
  if (dataForm.degreeOfEducation == "1") {
    if (isEdit.value && (dataForm.confirmedMajor == undefined || dataForm.confirmedMajor == "")) {
      // 根据折算分匹配录取专业
      planMajorList.value.forEach((e: any) => {
        if (e.majorCode == dataForm.wishMajorOne && (parseFloat(e.xyNum) > 0)) {
          dataForm.confirmedMajor = dataForm.wishMajorOne
        }
      })
      if (dataForm.confirmedMajor) {
        planMajorList.value.forEach((e: any) => {
          if (e.majorCode == dataForm.wishMajorTwo && (parseFloat(e.xyNum) > 0)) {
            dataForm.confirmedMajor = dataForm.wishMajorOne
          }
        })
      }

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

// 计算成绩折算分
const calculateCorrectedScore = () => {
  // 验证必要字段是否存在
  const hasFullScore = dataForm.fullScore != undefined && dataForm.fullScore != ""
  const hasSchoolArea = dataForm.schoolArea != undefined && dataForm.schoolArea != ""
  
  // 验证外省或学校所在省市至少有一个存在
  const hasLocation = (dataForm.schoolArea === '2' && dataForm.jsOtherCity) || 
                     (dataForm.schoolArea === '3' && dataForm.otherProvince)
  
  // 只有成绩、当地总分、学校归属地、外省/学校所在省市都存在时才能计算
  if (!hasFullScore || !hasSchoolArea || !hasLocation) {
    return
  }
  
  dataForm.confirmedMajor = ""
  
  // 调用后端接口计算折算分
  makeCorrectScore({
    groupId: dataForm.groupId,
    schoolArea: dataForm.schoolArea,
    jsOtherCity: dataForm.jsOtherCity,
    otherProvince: dataForm.otherProvince,
    fullScore: dataForm.fullScore,
    score: dataForm.score,
    degreeOfEducation: dataForm.degreeOfEducation
  }).then(res => {
    if (res.code !== 0) {
      return
    }
    
    dataForm.correctedScore = res.data
    
    // 根据折算分匹配录取专业（按志愿顺序：专业1 -> 专业2 -> 专业3）
    const matchMajorByScore = (majorCode: string) => {
      return planMajorList.value.find((major: any) => 
        dataForm.correctedScore >= major.scoreLine && 
        major.majorCode == majorCode && 
        parseFloat(major.xyNum) > 0
      )
    }
    
    // 按志愿顺序匹配专业
    const matchedMajor = matchMajorByScore(dataForm.wishMajorOne) || 
                        matchMajorByScore(dataForm.wishMajorTwo) || 
                        matchMajorByScore(dataForm.wishMajorThree)
    
    if (matchedMajor) {
      dataForm.confirmedMajor = matchedMajor.majorCode
      changeConfirmedMajor(dataForm.confirmedMajor)
    }
  })
}

const changeR = (changeType: number) => {
  let code = ""
  // 清空区数据
  areaAreaList.value = []
  dataForm.residenceArea = ""
  if (changeType == 1) {
    // 选择省份时，清空市和区数据
    code = dataForm.residenceProvince
    areaCityList.value = []
    dataForm.residenceCity = ""
  } else {
    // 选择市时
    code = dataForm.residenceCity
  }
  // 获取市或区数据
  areaSonList({ code: code }).then((data: any) => {
    if (changeType == 1) {
      areaCityList.value = data.data
    } else {
      areaAreaList.value = data.data
    }
  })
}

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

// 改变录取专业
const changeConfirmedMajor = (id: string) => {
  if (id) {
    dataForm.confirmedMajor = id
    // 根据文化程度和录取专业更新学费
    updateTuitionByMajorAndEducation()
  }
}

// 根据文化程度和录取专业更新学费
const updateTuitionByMajorAndEducation = () => {
  if (!dataForm.confirmedMajor || !dataForm.degreeOfEducation) {
    return
  }
  
  // 查找选中的专业
  const selectedMajor = planMajorList.value.find((major: any) => major.majorCode === dataForm.confirmedMajor)
  if (!selectedMajor) {
    return
  }
  
  // 根据文化程度选择对应的学费字段
  // '1' = 初中 -> czFee
  // '2' = 高中 -> gzFee
  // '3' = 技职校 -> jzxFee
  if (dataForm.degreeOfEducation === '1' && selectedMajor.czFee !== undefined && selectedMajor.czFee !== null) {
    dataForm.feeTuition = selectedMajor.czFee
  } else if (dataForm.degreeOfEducation === '2' && selectedMajor.gzFee !== undefined && selectedMajor.gzFee !== null) {
    dataForm.feeTuition = selectedMajor.gzFee
  } else if (dataForm.degreeOfEducation === '3' && selectedMajor.jzxFee !== undefined && selectedMajor.jzxFee !== null) {
    dataForm.feeTuition = selectedMajor.jzxFee
  }
}

// 表单提交
const dataFormSubmit = (state: string) => {
  dataForm.auditStatus = state
  let submitTitle = "确认通过该学生的报名申请么?"
  
  // 新增模式
  if (!dataForm.id) {
    submitTitle = "确认保存并提交该学生的报名信息么？"
  } else {
    // 编辑模式
    if(state){
      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(() => {
            message.success('操作成功')
            visible.value = false
            emit('refreshDataList')
          }).finally(() => {
            canSubmit.value = true
          })
        } else {
          // 新增模式
          addObj(dataForm).then(() => {
            message.success('新增成功')
            visible.value = false
            emit('refreshDataList')
          }).finally(() => {
            canSubmit.value = true
          })
        }
      }
    })
  }).catch(() => {
    // 用户取消
  })
}

// 监听招生计划变化（新增模式下需要加载分数线数据）
watch(() => dataForm.groupId, (newVal) => {
  if (newVal && !dataForm.id) {
    // 新增模式下，加载招生计划对应的分数线数据
    scoreList({ groupId: newVal }).then((data: any) => {
      schoolCodeList.value = data.data
    })
  }
})

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

// 统一宽度样式
.w-full {
  width: 100%;
}

// 图片预览容器样式
.image-preview-container {
  min-height: 120px;
  width: 100%;
}

// 图片列表样式
.image-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

// 图片项样式
.image-item {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  
  &:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
  }
}

// 图片预览样式
.preview-image {
  width: 120px;
  height: 120px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: transform 0.3s ease;
  
  &:hover {
    transform: scale(1.1);
  }
}

// 图片占位符样式
.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  width: 100%;
  background: #f5f7fa;
  border: 1px dashed #dcdfe6;
  border-radius: 6px;
  color: #909399;
  font-size: 14px;
  
  .el-icon {
    font-size: 32px;
    margin-bottom: 8px;
    color: #c0c4cc;
  }
  
  span {
    color: #909399;
  }
}

// 总费用样式
.total-fee {
  color: #f56c6c;
  font-weight: 600;
  font-size: 16px;
}

// 表单布局优化
.el-form {
  // 所有表单项保持默认间距
  .el-form-item {
    margin-bottom: 18px;
  }
  
  // 覆盖全局样式：每行的最后一个表单项也需要间距
  .form-row .el-form-item:last-child {
    margin-bottom: 18px !important;
  }
  
  // 只有整个表单的最后一个表单项才不需要底部间距
  .form-row:last-of-type .el-form-item:last-child {
    margin-bottom: 0 !important;
  }
  
  // 统一输入框宽度
  .el-select,
  .el-input,
  .el-date-editor,
  .el-input-number {
    width: 100%;
  }
}

// 行布局优化
.form-row {
  margin-bottom: 0;
}

// 表单模块样式
.form-section {
  margin-bottom: 24px;
  padding: 20px;
  background: #fafbfc;
  border-radius: 8px;
  border: 1px solid #ebeef5;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  .section-title {
    font-size: 15px;
    font-weight: 600;
    color: #303133;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #e4e7ed;
  }
  
  .form-row {
    margin-bottom: 0;
  }
}

// 地址组样式 - 省市区紧凑排列，用分隔符连接
.address-group {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  
  :deep(.address-select) {
    flex: 1 1 0;
    min-width: 0px;
    width: 0; // 让 flex: 1 生效
  }
  
  .address-separator {
    color: #909399;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
    padding: 0 4px;
  }
}

// 弹窗内容区域优化
:deep(.el-dialog__body) {
  max-height: 75vh;
  overflow-y: auto;
  padding: 24px;
}


</style>
