import { defineComponent, onMounted, reactive } from 'vue'; import styles from './index.module.less'; import MHeader from '@/components/m-header'; import { Area, Button, CellGroup, Field, Form, Popup, showToast } from 'vant'; import icon_school from './images/icon_school.png'; import icon_person from './images/icon_person.png'; import icon_submit from './images/icon_submit.png'; import icon_logo from './images/logo.png'; import icon_p1 from './images/icon_p1.png'; import icon_p2 from './images/icon_p2.png'; import { api_openSendSms, api_schoolAdd, api_sysAreaQueryAllProvince } from './api'; import { useRoute } from 'vue-router'; import MImgCode from '@/components/m-img-code'; export default defineComponent({ name: 'SchoolRegister', setup() { const route = useRoute(); const formOptions = { /** 性质 */ nature: [ { label: '公立', value: 'PUBLIC' }, { label: '私立', value: 'PRIVATE' } ], types: [ { label: '小学', value: 'PRIMARY' }, { label: '初中', value: 'JUNIOR' }, { label: '小初一体', value: 'PRIMARY_JUNIOR' } ], grades: [ { label: '六年制', value: 'SIX_YEAR_SYSTEM' }, { label: '五年制', value: 'FIVE_YEAR_SYSTEM' } ], genaral: [ { label: '男', value: '1' }, { label: '女', value: '0' } ] }; const forms = reactive({ name: '', // 学校名称 regionCode: '', // 所属区域 cityCode: '', // 所属城市 provinceCode: '', // 所属省份 schoolNature: 'PUBLIC' as 'PUBLIC' | 'PRIVATE' | string, // 学校性质 schoolType: 'PRIMARY_JUNIOR' as 'PRIMARY' | 'JUNIOR' | 'PRIMARY_JUNIOR' | string, // 学校类型 gradeYear: 'SIX_YEAR_SYSTEM' as | 'FIVE_YEAR_SYSTEM' | 'SIX_YEAR_SYSTEM' | string, // 学年制 emergencyContact: '', // 校长姓名 emergencyContactPhone: '', // 校长联系方式 educationalAdministrationUsername: '', // 负责人姓名 educationalAdministrationPhone: '', // 负责人联系方式 genaral: '1', // 性别 code: '', // 验证码 buyGoods: true, // 是否购买商品 tenantId: route.query.id || '', // 机构 sourceForm: 'TEACHER' }); const data = reactive({ cityName: '', // 所属城市 showArea: false, success: false, areaList: {} as any, sendMsg: '发送验证码', imgCodeStatus: false }); const formateArea = (area: any[]) => { const province_list: { [_: string]: string } = {}; const city_list: { [_: string]: string } = {}; const county_list: { [_: string]: string } = {}; area.forEach((item: any) => { province_list[item.code] = item.name; }); area.forEach((item: any) => { item.areas?.forEach((city: any) => { city_list[city.code] = city.name; }); }); area.forEach((item: any) => { item.areas?.forEach((city: any) => { city.areas?.forEach((county: any) => { county_list[county.code] = county.name; }); }); }); return { province_list, city_list, county_list }; }; const getAreaList = () => { api_sysAreaQueryAllProvince().then(res => { if (res?.code === 200) { data.areaList = formateArea(res.data); console.log('🚀 ~ data.areaList:', data.areaList); } }); }; onMounted(() => { getAreaList(); }); /** 发送验证码 */ const onSendSms = async () => { try { await api_openSendSms({ clientId: 'cooleshow-student', type: 'REGISTER', mobile: forms.educationalAdministrationPhone }); onCountDown(); showToast('验证码已发送'); } catch { data.sendMsg = '重新发送'; } }; const onCountDown = () => { data.sendMsg = '30s'; let count = 30; setInterval(() => { count--; data.sendMsg = `${count}s后重新发送`; if (count <= 0) { data.sendMsg = '重新发送'; } }, 1000); }; const handleSubmit = async () => { const res = await api_schoolAdd({ ...forms }); if (res?.code === 200) { data.success = true; } }; return () => (