manage-teacher-register.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. import { areas } from '@/helpers/area'
  2. import request from '@/helpers/request'
  3. import {
  4. CellGroup,
  5. Form,
  6. Field,
  7. RadioGroup,
  8. Tag,
  9. Icon,
  10. Checkbox,
  11. Radio,
  12. Button,
  13. showToast,
  14. showDialog,
  15. showLoadingToast,
  16. closeToast,
  17. Picker,
  18. Popup,
  19. CountDown
  20. } from 'vant'
  21. import { defineComponent, onMounted, reactive } from 'vue'
  22. import { useRoute } from 'vue-router'
  23. import styles from './manage-teacher-register.module.less'
  24. import ImgCode from '@/components/o-img-code'
  25. import schoolLogo from './images/school-logo.png'
  26. import iconClose from './images/icon-close.png'
  27. import topBanner1 from './images/top-banner.png'
  28. import { checkPhone } from '@/helpers/validate'
  29. export default defineComponent({
  30. name: 'companion-teacher-register',
  31. setup() {
  32. const route = useRoute()
  33. const state = reactive({
  34. showPicker: false,
  35. showSubject: false,
  36. submitStatus: false,
  37. id: route.query.id,
  38. name: route.query.name,
  39. pattern: /^1(3|4|5|6|7|8|9)\d{9}$/,
  40. columns: [] as any,
  41. pickerType: null, // 下拉类型
  42. forms: {
  43. realName: '',
  44. phone: null,
  45. gender: 1,
  46. idCardNo: null,
  47. smsValidCode: ''
  48. },
  49. btnLoading: false,
  50. checkPhone: false,
  51. checked: true,
  52. columnSubject: [] as any,
  53. countDownStatus: true, // 是否发送验证码
  54. countDownTime: 120, // 倒计时时间
  55. // countDownRef: null as any, // 倒计时实例
  56. imgCodeStatus: false
  57. })
  58. const onSubmit = async () => {
  59. if (!state.checked) {
  60. showToast('请阅读并同意协议')
  61. return
  62. }
  63. state.btnLoading = true
  64. try {
  65. const forms = state.forms
  66. await request.post('/api-school/open/schoolStaff/registerTeacher', {
  67. data: {
  68. ...forms,
  69. schoolId: state.id
  70. }
  71. })
  72. state.submitStatus = true
  73. } catch {
  74. //
  75. }
  76. state.btnLoading = false
  77. }
  78. const onSendCode = () => {
  79. // 发送验证码
  80. if (!checkPhone(state.forms.phone as any)) {
  81. return showToast('请输入正确的手机号码')
  82. }
  83. state.imgCodeStatus = true
  84. }
  85. const onCodeSend = () => {
  86. state.countDownStatus = false
  87. const clearTimer = setInterval(() => {
  88. state.countDownTime = state.countDownTime - 1
  89. if (state.countDownTime <= 0) {
  90. state.countDownTime = 120
  91. state.countDownStatus = true
  92. clearInterval(clearTimer)
  93. }
  94. }, 1000)
  95. }
  96. const onFinished = () => {
  97. state.countDownStatus = true
  98. // ;(this.$refs.countDownRef as any).reset()
  99. }
  100. onMounted(async () => {
  101. if (!state.id) {
  102. showToast('信息获取失败,请联系老师')
  103. }
  104. try {
  105. const tempareas: any = []
  106. areas.forEach((item) => {
  107. const temp = {
  108. name: item.name,
  109. code: item.code,
  110. areas: [] as any
  111. }
  112. if (item.areas && item.areas.length > 0) {
  113. item.areas.forEach((child) => {
  114. temp.areas.push({
  115. name: child.name,
  116. code: child.code
  117. })
  118. })
  119. }
  120. tempareas.push(temp)
  121. })
  122. state.columns = tempareas || []
  123. const { data } = await request.post('/api-school/open/subject/page', {
  124. data: {
  125. page: 1,
  126. rows: 50
  127. }
  128. })
  129. const rows = data.rows || []
  130. const tempSubjects: any = []
  131. rows.forEach((item) => {
  132. tempSubjects.push({
  133. text: item.name,
  134. value: item.id
  135. })
  136. })
  137. state.columnSubject = tempSubjects
  138. } catch {
  139. showDialog({
  140. message: '信息获取失败,请联系老师',
  141. theme: 'round-button',
  142. confirmButtonColor: '#64A9FF'
  143. })
  144. }
  145. })
  146. return () => (
  147. <div class={styles.register}>
  148. <div class={styles.title}>
  149. <p class={styles.tips}>
  150. <img src={schoolLogo} />
  151. <span>{state.name}</span>
  152. </p>
  153. </div>
  154. <Form validateFirst scrollToError onSubmit={onSubmit} ref="form" class={styles.form}>
  155. <CellGroup inset class={styles['cell-group']}>
  156. <Field
  157. required
  158. label="真实姓名"
  159. v-model={state.forms.realName}
  160. rules={[{ required: true, message: '请填写真实姓名' }]}
  161. name="realName"
  162. placeholder="请填写真实姓名"
  163. maxlength="50"
  164. ></Field>
  165. <Field
  166. required
  167. label="手机号码"
  168. v-model={state.forms.phone}
  169. rules={[
  170. { required: true, message: '请输入手机号码' },
  171. { pattern: state.pattern, message: '输入手机号码有误' }
  172. ]}
  173. name="phone"
  174. placeholder="请输入手机号码"
  175. maxlength={11}
  176. type="tel"
  177. ></Field>
  178. <Field
  179. required
  180. label="验证码"
  181. v-model={state.forms.smsValidCode}
  182. name="smsValidCode"
  183. rules={[{ required: true, message: '请输入验证码', trigger: 'onChange' }]}
  184. placeholder="请输入验证码"
  185. maxlength={6}
  186. type="tel"
  187. >
  188. {{
  189. button: () =>
  190. state.countDownStatus ? (
  191. <Button type="primary" round size="small" color="#64A9FF" onClick={onSendCode}>
  192. 发送验证码
  193. </Button>
  194. ) : (
  195. <Button
  196. type="default"
  197. round
  198. size="small"
  199. disabled
  200. style={{ minWidth: '60px' }}
  201. onClick={onSendCode}
  202. >
  203. {state.countDownTime + 's'}
  204. </Button>
  205. )
  206. }}
  207. </Field>
  208. <div class={styles.phoneTips}>
  209. <Icon name="warning" size="16" />
  210. 提示:手机号码将成为您管乐团管理端登录账号
  211. </div>
  212. <Field
  213. required
  214. label="身份证号码"
  215. v-model={state.forms.idCardNo}
  216. rules={[
  217. { required: true, message: '请输入身份证号' },
  218. {
  219. pattern:
  220. /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
  221. message: '请输入正确的身份证号'
  222. }
  223. ]}
  224. name="idCardNo"
  225. placeholder="请输入身份证号码"
  226. ></Field>
  227. <Field
  228. required
  229. label="性别"
  230. name="gender"
  231. rules={[{ required: true, message: '请选择性别' }]}
  232. >
  233. {{
  234. input: () => (
  235. <RadioGroup
  236. checked-color="#64A9FF"
  237. v-model={state.forms.gender}
  238. direction="horizontal"
  239. >
  240. <Tag
  241. size="large"
  242. type="primary"
  243. plain={!(state.forms.gender === 1)}
  244. color="#64A9FF"
  245. class={styles.radioSection}
  246. >
  247. <Radio class={styles.radioItem} name={1}></Radio>男
  248. </Tag>
  249. <Tag
  250. size="large"
  251. type="primary"
  252. plain={!(state.forms.gender === 0)}
  253. color="#64A9FF"
  254. class={styles.radioSection}
  255. >
  256. <Radio class={styles.radioItem} name={0}></Radio>女
  257. </Tag>
  258. </RadioGroup>
  259. )
  260. }}
  261. </Field>
  262. </CellGroup>
  263. <div class={styles.protocol}>
  264. <Checkbox
  265. v-model={state.checked}
  266. icon-size="16"
  267. style="margin-right: 6px"
  268. checked-color="#64A9FF"
  269. ></Checkbox>
  270. <span
  271. onClick={() => {
  272. state.checked = !state.checked
  273. }}
  274. >
  275. 请认真阅读并勾选
  276. </span>
  277. <span class={styles.c}>《乐团伴学老师注册协议》</span>
  278. </div>
  279. <Button
  280. size="large"
  281. block
  282. round
  283. class={styles['btn-submit']}
  284. color="#64A9FF"
  285. loading={state.btnLoading}
  286. native-type="submit"
  287. >
  288. 完成
  289. </Button>
  290. </Form>
  291. <Popup v-model:show={state.submitStatus} round style="width: 75%" closeOnClickOverlay>
  292. <div class={styles.stautsS}>
  293. <img
  294. class={styles['icon-close']}
  295. src={iconClose}
  296. onClick={() => {
  297. state.submitStatus = false
  298. window.location.href =
  299. window.location.origin + '/orchestra-student/#/download?type=manage'
  300. }}
  301. />
  302. <img src={topBanner1} class={styles['submit-img']} />
  303. <div class={styles['submit-container']}>
  304. <p class={styles['submit-title']}>恭喜您已成功登记为</p>
  305. <p class={styles['submit-o']}>
  306. {state.name} <span>【管理老师】</span>
  307. </p>
  308. <p class={styles['submit-tips']}>请下载管乐团管理端APP</p>
  309. <Button
  310. type="primary"
  311. color="#64A9FF"
  312. block
  313. round
  314. onClick={() => {
  315. state.submitStatus = false
  316. window.location.href =
  317. window.location.origin + '/orchestra-student/#/download?type=manage'
  318. }}
  319. >
  320. 立即下载
  321. </Button>
  322. </div>
  323. </div>
  324. </Popup>
  325. {state.imgCodeStatus ? (
  326. <ImgCode
  327. v-model:value={state.imgCodeStatus}
  328. phone={state.forms.phone as any}
  329. onClose={() => {
  330. state.imgCodeStatus = false
  331. }}
  332. onSendCode={onCodeSend}
  333. />
  334. ) : null}
  335. </div>
  336. )
  337. }
  338. })