index.tsx 4.3 KB

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