Index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <app-view class="g-form register">
  3. <template #header>
  4. <app-navbar :title="$t('user.register.title')" />
  5. </template>
  6. <Form ref="formRef" class="g-form__container register__form" @submit="formSubmit">
  7. <CellGroup inset>
  8. <Field v-model="formData.mobilephone" type="digit" name="mobilephone" :placeholder="$t('common.required')"
  9. :rules="formRules.mobilephone">
  10. <template #label>
  11. <span>{{ $t('user.register.mobile') }}</span>
  12. <span style="margin-left: 10px;" @click="show = true">
  13. {{ countryCode }}
  14. </span>
  15. <Popup v-model:show="show" position="bottom" teleport="body" round>
  16. <Picker :columns="datalist" @cancel="onCancel" @confirm="onConfirm"
  17. :confirm-button-text="$t('operation.confirm')" :cancel-button-text="$t('operation.cancel')">
  18. <template #option="{ text, index }">
  19. <slot name="option" :row="datalist[index]" :index="index">
  20. {{ text }}
  21. </slot>
  22. </template>
  23. </Picker>
  24. </Popup>
  25. </template>
  26. </Field>
  27. <Field v-model="formData.vcode" type="digit" name="vcode" :label="$t('user.register.vcode')"
  28. :placeholder="$t('common.required')" :rules="formRules.vcode">
  29. <template #button>
  30. <Button size="small" type="danger" :disabled="loading" @click="sendVerifyCode">
  31. <span v-if="isCountdown">{{ $t('user.register.sendagain') }}({{ currentTime }})</span>
  32. <span v-else>{{ $t('user.register.getsmscode') }}</span>
  33. </Button>
  34. </template>
  35. </Field>
  36. </CellGroup>
  37. <CellGroup inset>
  38. <Field v-model="formData.loginpwd" name="loginpwd" type="password" :label="$t('user.register.logipwd')"
  39. :placeholder="$t('common.required')" :rules="formRules.loginpwd" />
  40. <Field v-model="confirmpassword" name="confirmpassword" type="password" :label="$t('user.register.confirmpwd')"
  41. :placeholder="$t('common.required')" :rules="formRules.confirmpassword" />
  42. <Field v-model="formData.refernum" name="refernum" :label="$t('user.register.registercode')"
  43. :placeholder="registrationCodeRule ? $t('common.required') : $t('common.optional')"
  44. :rules="formRules.refernum" v-if="registrationCodeRule > -1">
  45. <!-- <template #button>
  46. <app-qrcode-scan @success="onScanSuccess">
  47. <Button size="small" type="danger">扫码</Button>
  48. </app-qrcode-scan>
  49. </template> -->
  50. </Field>
  51. </CellGroup>
  52. <CellGroup inset>
  53. <Cell>
  54. <template #title>
  55. <div style="display: flex;align-items: center;font-size: 12px;">
  56. <Checkbox shape="square" icon-size="16px" v-model="checked">
  57. {{ $t('user.register.checked') }}
  58. </Checkbox>
  59. <span @click="routerTo('rules-zcxy')" style="color:#E92020">
  60. {{ $t('user.register.ruleszcxy') }}
  61. </span>
  62. <span @click="routerTo('rules-yhkhfxgzs')" style="color:#E92020" v-if="showYhkhfxgzs">
  63. {{ $t('user.register.rulesfxgzs') }}
  64. </span>
  65. </div>
  66. </template>
  67. </Cell>
  68. </CellGroup>
  69. </Form>
  70. <template #footer>
  71. <div class="g-form__footer inset">
  72. <Button type="danger" @click="formRef?.submit" round block>{{ $t('user.register.freeregister') }}</Button>
  73. </div>
  74. <app-reward :show="showReward" :value="redEnvelope" :title="$t('user.register.registersuccess')"
  75. @click="router.back()" />
  76. </template>
  77. </app-view>
  78. </template>
  79. <script lang="ts" setup>
  80. import { reactive, shallowRef, ref, computed, onMounted } from 'vue'
  81. import { CellGroup, Cell, Button, Field, Form, FormInstance, Checkbox, showFailToast, showToast, FieldRule, Popup, Picker, PickerConfirmEventParams } from 'vant'
  82. import { useCountDown } from '@vant/use'
  83. import { fullloading, dialog } from '@/utils/vant'
  84. import { validateRules } from '@/constants/regex'
  85. import { useNavigation } from '@mobile/router/navigation'
  86. import { userRegister, sendRegisterVerifyCode, queryMyRegisterMoney } from '@/services/api/common'
  87. import { i18n, useGlobalStore, useUserStore } from '@/stores'
  88. import { getCountryCodeList } from '@/constants/unit'
  89. import cryptojs from 'crypto-js'
  90. import plus from '@/utils/h5plus'
  91. import AppReward from '@mobile/components/modules/reward/index.vue'
  92. // import AppQrcodeScan from '@mobile/components/base/qrcode-scan/index.vue'
  93. defineProps({
  94. showYhkhfxgzs: {
  95. type: Boolean,
  96. default: true
  97. }
  98. })
  99. const show = shallowRef(false) // 是否弹出选择器
  100. const datalist = computed(() => {
  101. return getCountryCodeList().map(e => {
  102. return { text: e.value, value: e.value }
  103. })
  104. })
  105. const countryCode = ref(datalist.value[0].value.toString())
  106. const onCancel = () => {
  107. show.value = false
  108. }
  109. const onConfirm = ({ selectedValues: [value] }: PickerConfirmEventParams) => {
  110. show.value = false
  111. countryCode.value = value.toString()
  112. }
  113. const { router, routerTo } = useNavigation()
  114. const globalStore = useGlobalStore()
  115. const registrationCodeRule = globalStore.getSystemInfo('registrationCodeRule')
  116. const formRef = ref<FormInstance>()
  117. const checked = ref(false) // 是否同意注册条款
  118. const loading = ref(false)
  119. const isCountdown = ref(false) // 是否正在倒计时
  120. const showReward = ref(false) // 显示红包
  121. const redEnvelope = ref(0) // 红包金额
  122. const { getSystemParamValue } = useUserStore()
  123. const param1010 = getSystemParamValue('1010') ?? '1'
  124. const param1013 = getSystemParamValue('1013') ?? '30'
  125. const { global: { t } } = i18n
  126. const confirmpassword = ref('') // 确认密码
  127. // 倒计时函数
  128. const countdown = useCountDown({
  129. time: +param1013 * 1000,
  130. onFinish: () => {
  131. countdown.reset()
  132. isCountdown.value = false
  133. loading.value = false
  134. }
  135. })
  136. // 倒计时剩余时间
  137. const currentTime = computed(() => {
  138. const { total } = countdown.current.value
  139. return (total / 1000).toFixed(0)
  140. })
  141. // 表单数据
  142. const formData = reactive<Model.RegisterReq>({
  143. mobilephone: '',
  144. loginpwd: '',
  145. vcode: '',
  146. refernum: '',
  147. isaudit: 1,
  148. userinfotype: 1,
  149. usertype: 5,
  150. openmode: 4,
  151. lsitAgreementID: []
  152. })
  153. // 表单验证规则
  154. const formRules: { [key: string]: FieldRule[] } = {
  155. mobilephone: [{
  156. required: true,
  157. message: t('user.register.tips1'),
  158. validator: (val) => {
  159. /// 值为”0“ 时 只校验长度20位,不限字符
  160. if (param1010 === '0') {
  161. if (val.length <= 20) {
  162. return true
  163. }
  164. return t('banksign.tips6')
  165. } else {
  166. if (validateRules.phone.validate(val)) {
  167. return true
  168. }
  169. return validateRules.phone.message
  170. }
  171. }
  172. }],
  173. loginpwd: [{
  174. required: true,
  175. message: t('user.register.tips2'),
  176. validator: (val) => {
  177. if (validateRules.password.validate(val)) {
  178. return true
  179. }
  180. return validateRules.password.message
  181. }
  182. }],
  183. confirmpassword: [{
  184. required: true,
  185. message: t('user.register.tips3'),
  186. validator: (val) => {
  187. if (formData.loginpwd === val) {
  188. return true
  189. }
  190. return t('user.register.tips4')
  191. }
  192. }],
  193. vcode: [{
  194. required: true,
  195. message: t('user.register.tips5'),
  196. }],
  197. refernum: [{
  198. validator: (val) => {
  199. if (!registrationCodeRule || val) {
  200. return true
  201. }
  202. return t('user.register.tips6')
  203. }
  204. }],
  205. }
  206. // 扫码成功
  207. // const onScanSuccess = (text: string) => {
  208. // formData.refernum = text
  209. // }
  210. // 发送手机验证码
  211. const sendVerifyCode = () => {
  212. formRef.value?.validate('mobilephone').then(() => {
  213. loading.value = true
  214. sendRegisterVerifyCode({
  215. data: {
  216. phonenumber: countryCode.value + formData.mobilephone
  217. }
  218. }).then(() => {
  219. isCountdown.value = true
  220. countdown.start()
  221. }).catch(() => {
  222. loading.value = false
  223. showFailToast(t('user.register.tips7'))
  224. })
  225. })
  226. }
  227. // 获取注册红包
  228. const getRegisterMoney = (accountid: number) => {
  229. const toggleDialog = () => {
  230. dialog(t('user.register.tips8')).then(() => {
  231. router.back()
  232. })
  233. }
  234. return queryMyRegisterMoney({
  235. data: {
  236. accountid
  237. }
  238. }).then((res) => {
  239. // 查询成功显示获得红包
  240. if (res.data.length) {
  241. redEnvelope.value = res.data[0].amount
  242. showReward.value = true
  243. } else {
  244. toggleDialog()
  245. }
  246. }).catch(() => {
  247. // 查询失败提示注册成功后返回登录页面
  248. toggleDialog()
  249. })
  250. }
  251. // 表单提交
  252. const formSubmit = () => {
  253. if (checked.value) {
  254. fullloading((hideLoading) => {
  255. const { Utf8, Base64 } = cryptojs.enc
  256. // 密码需进行两次base64加密
  257. const passwordData = Base64.stringify(Utf8.parse(formData.loginpwd))
  258. const loginpwd = Base64.stringify(Utf8.parse(passwordData))
  259. const mobilephone = countryCode.value + formData.mobilephone
  260. userRegister({
  261. data: {
  262. ...formData,
  263. loginpwd,
  264. mobilephone
  265. }
  266. }).then((res) => {
  267. if (res.code === 0) {
  268. // 等待3秒后查询注册红包
  269. setTimeout(() => {
  270. getRegisterMoney(res.taaccount[0].accountid).finally(() => {
  271. hideLoading()
  272. })
  273. }, 3000)
  274. } else {
  275. showFailToast(res.message)
  276. }
  277. }).catch((err) => {
  278. showFailToast(err)
  279. })
  280. }, t('user.register.tips9'))
  281. } else {
  282. showToast(t('user.register.tips10'))
  283. }
  284. }
  285. onMounted(() => {
  286. const os = plus.getSystemInfo('os')
  287. if (os === 'Android') {
  288. formData.openmode = 5
  289. }
  290. if (os === 'iOS') {
  291. formData.openmode = 6
  292. }
  293. })
  294. </script>