index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import ColField from '@/components/col-field'
  2. import ColFieldGroup from '@/components/col-field-group'
  3. import ColHeader from '@/components/col-header'
  4. import request from '@/helpers/request'
  5. import { verifyIdCard } from '@/helpers/toolsValidate'
  6. import { state } from '@/state'
  7. import { Button, CellGroup, Checkbox, Field, Form, Icon, Toast } from 'vant'
  8. import { defineComponent } from 'vue'
  9. import activeButtonIcon from '@common/images/icon_checkbox.png'
  10. import inactiveButtonIcon from '@common/images/icon_checkbox_default.png'
  11. import styles from './index.module.less'
  12. export default defineComponent({
  13. name: 'UserAuth',
  14. props: {
  15. onSuccess: {
  16. // 实名成功
  17. type: Function,
  18. default: () => {}
  19. },
  20. exists: {
  21. type: Boolean,
  22. default: false
  23. }
  24. },
  25. data() {
  26. return {
  27. form: {
  28. realName: '',
  29. idCardNo: ''
  30. },
  31. checked: false
  32. }
  33. },
  34. mounted() {
  35. // exists
  36. this.checked = this.checked || this.exists
  37. },
  38. methods: {
  39. async onSubmit() {
  40. try {
  41. if (!this.checked) {
  42. Toast('请先阅读并同意《用户注册协议》')
  43. return
  44. }
  45. const url =
  46. state.platformType === 'STUDENT'
  47. ? '/api-student/student/realNameAuth'
  48. : '/api-teacher/teacher/realNameAuth'
  49. await request.post(url, {
  50. data: {
  51. ...this.form,
  52. contract: true,
  53. save: true
  54. }
  55. })
  56. Toast('实名成功')
  57. state.user.data.realName = this.form.realName
  58. state.user.data.idCardNo = this.form.idCardNo
  59. setTimeout(() => {
  60. this.onSuccess()
  61. }, 500)
  62. } catch {}
  63. },
  64. getContractDetail() {
  65. // 查看协议
  66. const client = state.platformType === 'STUDENT' ? 'student' : 'teacher'
  67. postMessage({
  68. api: 'openWebView',
  69. content: {
  70. url: `${location.origin}/${client}/#/previewProtocol`,
  71. orientation: 1,
  72. isHideTitle: false
  73. }
  74. })
  75. }
  76. },
  77. render() {
  78. return (
  79. <Form class={styles.userAuth} onSubmit={this.onSubmit}>
  80. <ColHeader title="实名认证" />
  81. <ColFieldGroup style={{ marginTop: '15px' }}>
  82. <ColField title="姓名" required>
  83. <Field
  84. name="lessonName"
  85. maxlength={20}
  86. v-model={this.form.realName}
  87. placeholder="请输入真实姓名"
  88. rules={[{ required: true, message: '请输入真实姓名' }]}
  89. />
  90. </ColField>
  91. <ColField title="证件号码" required>
  92. <Field
  93. name="lessonSubjectName"
  94. v-model={this.form.idCardNo}
  95. rules={[
  96. { required: true, message: '请输入身份证号' },
  97. {
  98. pattern:
  99. /^[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]$/,
  100. message: '请输入正确的身份证号'
  101. }
  102. ]}
  103. placeholder="请输入身份证号"
  104. />
  105. </ColField>
  106. </ColFieldGroup>
  107. <div class={styles.colProtocol}>
  108. {!this.exists && (
  109. <Checkbox
  110. v-model={this.checked}
  111. v-slots={{
  112. icon: (props: any) => (
  113. <Icon
  114. class={styles.boxStyle}
  115. name={props.checked ? activeButtonIcon : inactiveButtonIcon}
  116. size="15"
  117. />
  118. )
  119. }}
  120. >
  121. 我已阅读并同意
  122. </Checkbox>
  123. )}
  124. {this.exists && <>查看</>}
  125. <span onClick={this.getContractDetail} class={styles.protocolText}>
  126. 《用户注册协议》
  127. </span>
  128. </div>
  129. <div class={['btnGroup']}>
  130. <Button block round type="primary" native-type="submit">
  131. 确定
  132. </Button>
  133. </div>
  134. </Form>
  135. )
  136. }
  137. })