123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- import {
- computed,
- defineComponent,
- nextTick,
- onMounted,
- reactive,
- ref
- } from 'vue';
- import styles from './index.module.less';
- // import infoTitle from '../images/info-title.png';
- import {
- Button,
- CountDown,
- Field,
- Form,
- Picker,
- Popup,
- Radio,
- RadioGroup,
- Tag,
- showToast
- } from 'vant';
- import OWxTip from '@/components/m-wx-tip';
- import MProtocol from '@/components/m-protocol';
- import MImgCode from '@/components/m-img-code';
- import { browser, checkPhone } from '@/helpers/utils';
- import request from '@/helpers/request';
- import { useStudentRegisterStore } from '@/store/modules/student-register-store';
- import { setLoginInit, state } from '@/state';
- import iconGift from '../images/icon-gift.png';
- import { useRoute, useRouter } from 'vue-router';
- import MSticky from '@/components/m-sticky';
- const classList: any = [];
- for (let i = 1; i <= 40; i++) {
- classList.push({ text: i + '班', value: i });
- }
- export default defineComponent({
- name: 'register-modal',
- emits: ['close', 'submit'],
- setup(props, { emit }) {
- const route = useRoute();
- const router = useRouter();
- const studentRegisterStore = useStudentRegisterStore();
- // 初始化学校编号
- studentRegisterStore.setShoolId(route.query.sId as any);
- const countDownRef = ref();
- const gradeList = computed(() => {
- let tempList: any = [];
- const five = [
- { text: '一年级', value: 1 },
- { text: '二年级', value: 2 },
- { text: '三年级', value: 3 },
- { text: '四年级', value: 4 },
- { text: '五年级', value: 5 }
- ];
- const one = [{ text: '六年级', value: 6 }];
- const three = [
- { text: '七年级', value: 7 },
- { text: '八年级', value: 8 },
- { text: '九年级', value: 9 }
- ];
- if (forms.gradeYear === 'FIVE_YEAR_SYSTEM') {
- tempList.push([...five]);
- } else if (forms.gradeYear === 'SIX_YEAR_SYSTEM') {
- tempList.push([...five, ...one]);
- } else if (forms.gradeYear === 'THREE_YEAR_SYSTEM') {
- tempList.push([...three]);
- } else if (forms.gradeYear === 'FORE_YEAR_SYSTEM') {
- tempList.push([...one, ...three]);
- } else {
- tempList.push([...five, ...one, ...three]);
- }
- return tempList;
- });
- const forms = reactive({
- countDownStatus: true,
- countDownTime: 1000 * 120, // 倒计时时间
- modelValue: false, // 是否选中协议
- imgCodeStatus: false,
- gradeNumText: '',
- currentClassText: '',
- gradeStatus: false,
- classStatus: false,
- loading: false,
- schoolId: route.query.sId as any,
- gradeYear: null,
- schoolType: null,
- giftVipDay: null,
- showTips: false,
- showButton: false,
- showMessage: '请使用微信打开'
- });
- const studentInfo = reactive({
- autoRegister: true,
- client_id: 'cooleshow-student',
- client_secret: 'cooleshow-student',
- extra: {
- nickname: '',
- currentGradeNum: '',
- currentClass: '',
- gender: 1,
- registerType: '', // 报名类型
- giftVipDay: 0 // 赠送会员天数
- },
- grant_type: 'password',
- loginType: 'SMS',
- password: '',
- username: ''
- });
- const onCodeSend = () => {
- forms.countDownStatus = false;
- nextTick(() => {
- countDownRef.value.start();
- });
- };
- const onSendCode = () => {
- // 发送验证码
- if (!checkPhone(studentInfo.username)) {
- return showToast('请输入正确的手机号码');
- }
- forms.imgCodeStatus = true;
- };
- const validatePhone = computed(() => {
- return checkPhone(studentInfo.username) ? true : false;
- });
- const onFinished = () => {
- forms.countDownStatus = true;
- countDownRef.value.reset();
- };
- const onSubmit = async () => {
- try {
- if (checkForm()) return;
- forms.loading = true;
- await request.get('/edu-app/open/student/schoolQuery', {
- params: {
- schoolId: forms.schoolId,
- mobile: studentInfo.username
- }
- });
- const { extra, ...res } = studentInfo;
- const result = await request.post('/edu-app/userlogin', {
- hideLoading: false,
- requestType: 'form',
- data: {
- ...res,
- extra: JSON.stringify({
- ...extra,
- schoolId: forms.schoolId
- })
- }
- });
- if (result.code === 5436) {
- forms.showTips = true;
- forms.showMessage = '二维码已经失效,详情请咨询学校老师';
- forms.showButton = false;
- } else if (result.code === 5435) {
- forms.showTips = true;
- forms.showMessage = '报名信息更新,请刷新后重新提交';
- forms.showButton = true;
- } else {
- setTimeout(() => {
- showToast('报名成功');
- router.push('/download');
- }, 100);
- }
- } catch {
- } finally {
- forms.loading = false;
- }
- };
- const checkForm = () => {
- if (!studentInfo.extra.nickname) {
- showToast('请输入学生姓名');
- return true;
- } else if (!studentInfo.extra.currentGradeNum) {
- showToast('请选择所在年级');
- return true;
- } else if (!studentInfo.extra.currentClass) {
- showToast('请选择所在班级');
- return true;
- } else if (!checkPhone(studentInfo.username)) {
- showToast('请输入正确的手机号码');
- return true;
- } else if (!studentInfo.password) {
- showToast('请输入验证码');
- return true;
- }
- return false;
- };
- const getRegisterGoods = async () => {
- try {
- const { data } = await request.get('/edu-app/open/school/detail', {
- params: {
- id: forms.schoolId
- },
- noAuthorization: true // 是否请求接口的时候添加toekn
- });
- forms.giftVipDay = data.giftVipDay;
- forms.schoolType = data.schoolType;
- forms.gradeYear = data.gradeYear;
- studentInfo.extra.giftVipDay = data.giftVipDay;
- studentInfo.extra.registerType = data.registerType;
- if (browser().weixin) {
- if (data.registerType !== 'GIFT_VIP_DAY' || data.status === 0) {
- forms.showTips = true;
- forms.showMessage = '二维码已经失效,详情请咨询学校老师';
- forms.showButton = false;
- }
- } else {
- forms.showTips = true;
- }
- } catch {}
- };
- onMounted(() => {
- getRegisterGoods();
- });
- return () => (
- <div class={styles.registerModal}>
- {forms.giftVipDay ? (
- <div class={styles.memberNumer}>
- <img src={iconGift} class={styles.iconGift} />
- <p>
- 现在报名立即赠送乐器AI学练工具有效期{' '}
- <span>{forms.giftVipDay}</span> 天
- </p>
- </div>
- ) : (
- ''
- )}
- <Form labelAlign="top" class={styles.registerForm}>
- <Field
- clearable
- label="学生姓名"
- placeholder="请输入学生姓名"
- autocomplete="off"
- maxlength={14}
- v-model={studentInfo.extra.nickname}
- />
- <Field
- clearable
- label="学生性别"
- placeholder="请选择性别"
- autocomplete="off"
- // v-model={studentInfo.extra.nickname}
- >
- {{
- input: () => (
- <RadioGroup
- checked-color="#ffcb75"
- v-model={studentInfo.extra.gender}
- direction="horizontal">
- <Tag
- size="large"
- type="primary"
- color={
- !(studentInfo.extra.gender === 1) ? '#EAEAEA' : '#ffcb75'
- }
- textColor={
- !(studentInfo.extra.gender === 1) ? '#AAA' : '#5B2C03'
- }
- class={styles.radioSection}
- round>
- <Radio class={styles.radioItem} name={1}></Radio>男
- </Tag>
- <Tag
- size="large"
- type="primary"
- color={
- !(studentInfo.extra.gender === 0) ? '#EAEAEA' : '#ffcb75'
- }
- textColor={
- !(studentInfo.extra.gender === 0) ? '#AAA' : '#5B2C03'
- }
- class={styles.radioSection}
- round>
- <Radio class={styles.radioItem} name={0}></Radio>女
- </Tag>
- </RadioGroup>
- )
- }}
- </Field>
- <Field
- clearable
- label="所在年级"
- placeholder="请选择年级"
- isLink
- readonly
- clickable={false}
- modelValue={forms.gradeNumText}
- onClick={() => (forms.gradeStatus = true)}
- />
- <Field
- clearable
- label="所在班级"
- placeholder="请选择班级"
- isLink
- readonly
- clickable={false}
- modelValue={forms.currentClassText}
- onClick={() => (forms.classStatus = true)}
- />
- <Field
- clearable
- label="联系方式(直接监护人)"
- placeholder="请输入手机号码"
- type="tel"
- autocomplete="off"
- v-model={studentInfo.username}
- maxlength={11}>
- {{
- label: () => (
- <div>
- 联系方式
- {/* (直接监护人) */}
- <p class={styles.tips}>手机号是音乐数字课堂的唯一登录账户</p>
- </div>
- )
- }}
- </Field>
- <Field
- center
- clearable
- label="验证码"
- placeholder="请输入验证码"
- autocomplete="off"
- type="number"
- v-model={studentInfo.password}
- maxlength={6}>
- {{
- button: () =>
- forms.countDownStatus ? (
- <span
- class={[
- styles.codeText,
- !validatePhone.value ? styles.codeTextDisabled : ''
- ]}
- onClick={onSendCode}>
- 获取验证码
- </span>
- ) : (
- <CountDown
- ref={(el: any) => (countDownRef.value = el)}
- auto-start={false}
- time={forms.countDownTime}
- onFinish={onFinished}
- format="ss秒"
- />
- )
- }}
- </Field>
- </Form>
- {/* <MProtocol
- center
- v-model:modelValue={forms.modelValue}
- prototcolType="REGISTER"
- /> */}
- <MSticky position="bottom">
- <Button
- type="primary"
- class={styles.submitBtn}
- color="linear-gradient(121deg, #FFD892 0%, #FFCB75 100%)"
- block
- onClick={onSubmit}
- disabled={forms.loading}
- loading={forms.loading}>
- 确认
- </Button>
- </MSticky>
- {forms.imgCodeStatus ? (
- <MImgCode
- v-model:value={forms.imgCodeStatus}
- phone={studentInfo.username}
- onClose={() => {
- forms.imgCodeStatus = false;
- }}
- onSendCode={onCodeSend}
- />
- ) : null}
- {/* 年级 */}
- <Popup
- v-model:show={forms.gradeStatus}
- position="bottom"
- round
- safeAreaInsetBottom
- lazyRender={false}
- class={'popupBottomSearch'}>
- <Picker
- showToolbar
- columns={gradeList.value as any}
- onCancel={() => (forms.gradeStatus = false)}
- onConfirm={(val: any) => {
- const selectedOption = val.selectedOptions[0];
- studentInfo.extra.currentGradeNum = selectedOption.value;
- forms.gradeNumText = selectedOption.text;
- forms.gradeStatus = false;
- }}
- />
- </Popup>
- {/* 班级 */}
- <Popup
- v-model:show={forms.classStatus}
- position="bottom"
- round
- class={'popupBottomSearch'}>
- <Picker
- showToolbar
- columns={classList}
- onCancel={() => (forms.classStatus = false)}
- onConfirm={(val: any) => {
- const selectedOption = val.selectedOptions[0];
- studentInfo.extra.currentClass = selectedOption.value;
- forms.currentClassText = selectedOption.text;
- forms.classStatus = false;
- }}
- />
- </Popup>
- {/* 是否在微信中打开 */}
- <OWxTip
- v-model:show={forms.showTips}
- message={forms.showMessage}
- showButton={forms.showButton}
- buttonText="刷新"
- onConfirm={async () => {
- forms.showTips = false;
- await getRegisterGoods();
- studentInfo.password = '';
- window.scrollTo({
- top: 0,
- behavior: 'smooth'
- });
- }}
- />
- </div>
- );
- }
- });
|