小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.3 KiB

  1. <template>
  2. <view class="ChangePassword">
  3. <view class="list">
  4. <view class="item">
  5. <input type="number" placeholder="填写手机号码" v-model="phone" />
  6. </view>
  7. <view class="item acea-row row-between-wrapper">
  8. <input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" />
  9. <button class="code font-color-red" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">{{ text }}</button>
  10. </view>
  11. </view>
  12. <view class="confirmBnt bg-color-red" @click="confirm">确认绑定</view>
  13. </view>
  14. </template>
  15. <script>
  16. import { mapGetters } from 'vuex'
  17. import sendVerifyCode from '@/mixins/SendVerifyCode'
  18. import { required, alpha_num, chs_phone } from '@/utils/validate'
  19. import { validatorDefaultCatch } from '@/utils/dialog'
  20. import { registerVerify, wxappBindingPhone } from '@/api/user'
  21. export default {
  22. name: 'BindingPhone',
  23. components: {},
  24. props: {},
  25. data: function () {
  26. return {
  27. captcha: '',
  28. phone: '', //手机号
  29. }
  30. },
  31. mixins: [sendVerifyCode],
  32. computed: mapGetters(['userInfo']),
  33. mounted: function () {},
  34. methods: {
  35. async confirm() {
  36. let that = this
  37. const { phone, captcha } = that
  38. try {
  39. await that
  40. .$validator({
  41. phone: [chs_phone(chs_phone.message('手机号码')), alpha_num(alpha_num.message())],
  42. captcha: [required(required.message('验证码')), alpha_num(alpha_num.message('验证码'))],
  43. })
  44. .validate({ phone, captcha })
  45. } catch (e) {
  46. return validatorDefaultCatch(e)
  47. }
  48. wxappBindingPhone({
  49. phone: this.phone,
  50. captcha: this.captcha,
  51. })
  52. .then(res => {
  53. if (res.data !== undefined && res.data.is_bind) {
  54. uni.showModal({
  55. title: '提示',
  56. content: '确认绑定?',
  57. success: function (res) {
  58. if (res.confirm) {
  59. wxappBindingPhone({
  60. phone: this.phone,
  61. captcha: this.captcha,
  62. step: 1,
  63. })
  64. .then(res => {
  65. uni.showToast({
  66. title: res.msg,
  67. icon: 'none',
  68. duration: 2000,
  69. })
  70. that.$yrouter.replace({
  71. path: '/pages/user/PersonalData/index',
  72. })
  73. })
  74. .catch(res => {
  75. uni.showToast({
  76. title: res.msg,
  77. icon: 'none',
  78. duration: 2000,
  79. })
  80. that.$yrouter.replace({
  81. path: '/pages/user/PersonalData/index',
  82. })
  83. })
  84. } else if (res.cancel) {
  85. uni.showToast({
  86. title: '已取消绑定',
  87. icon: 'none',
  88. duration: 2000,
  89. })
  90. that.$yrouter.replace({
  91. path: '/pages/user/PersonalData/index',
  92. })
  93. }
  94. },
  95. })
  96. } else {
  97. uni.showToast({
  98. title: res.msg,
  99. icon: 'none',
  100. duration: 2000,
  101. })
  102. that.$yrouter.replace({ path: '/pages/user/PersonalData/index' })
  103. }
  104. })
  105. .catch(res => {
  106. uni.showToast({
  107. title: res.msg,
  108. icon: 'none',
  109. duration: 2000,
  110. })
  111. })
  112. },
  113. async code() {
  114. let that = this
  115. const { phone } = that
  116. try {
  117. await that
  118. .$validator({
  119. phone: [required(required.message('手机号码')), chs_phone(chs_phone.message())],
  120. })
  121. .validate({ phone })
  122. } catch (e) {
  123. return validatorDefaultCatch(e)
  124. }
  125. registerVerify({ phone: phone })
  126. .then(res => {
  127. uni.showToast({
  128. title: res.msg,
  129. icon: 'none',
  130. duration: 2000,
  131. })
  132. that.sendCode()
  133. })
  134. .catch(res => {
  135. uni.showToast({
  136. title: res.msg,
  137. icon: 'none',
  138. duration: 2000,
  139. })
  140. })
  141. },
  142. },
  143. }
  144. </script>
  145. <style lang=""></style>