index.tsx 4.5 KB

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