phoneUpdate.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <zj-page-layout bgColor="#ffffff">
  3. <view class="all-container">
  4. <view class="input">
  5. <u-input clearable border="bottom" placeholder="" :value="mobile" :disabled="true">
  6. <view class="" style="" slot="prefix">
  7. <text class="kakkslakldsj">当前手机号码</text>
  8. </view>
  9. </u-input>
  10. </view>
  11. <view class="input">
  12. <u-input clearable border="bottom" placeholder="请输入手机号" v-model="phone">
  13. <view class="" style="" slot="prefix">
  14. <text class="kakkslakldsj">*新手机号码</text>
  15. </view>
  16. </u-input>
  17. </view>
  18. <view class="input">
  19. <u-input clearable border="bottom" placeholder="请输入验证码" v-model="code">
  20. <view class="" style="" slot="prefix">
  21. <text class="kakkslakldsj">*验证码</text>
  22. </view>
  23. <view class="" slot="suffix" @click="getCode">
  24. <text class="text">{{ countDown ? countDown + 'S' : '获取验证码' }}</text>
  25. </view>
  26. </u-input>
  27. </view>
  28. <u-button type="primary" text="确定" :disabled="!phone || !code" @click="submitForm"></u-button>
  29. <zjDialogVerification
  30. ref="verification"
  31. :isShow="isShowCodeDialog"
  32. :top="codeObj.yHeight"
  33. :bgImg="codeObj.bigImage"
  34. :maskImg="codeObj.smallImage"
  35. :isSuccess="codeObj.isSuccess"
  36. :isFail="codeObj.isFail"
  37. @close="isShowCodeDialog = false"
  38. @refresh="refresh"
  39. @finish="finish"
  40. >
  41. </zjDialogVerification>
  42. </view>
  43. </zj-page-layout>
  44. </template>
  45. <script>
  46. import zjDialogVerification from '@/components/zj-dialog/zj-dialog-verification.vue'
  47. import { getStorage } from '@/common/utils/storage.js'
  48. export default {
  49. components: {
  50. zjDialogVerification
  51. },
  52. data() {
  53. return {
  54. phone: '',
  55. code: '',
  56. getCodeText: '获取验证码',
  57. countDown: 0,
  58. timer: null,
  59. isShowCodeDialog: false,
  60. codeObj: {
  61. bigImage: '',
  62. smallImage: '',
  63. key: '',
  64. yHeight: '',
  65. isSuccess: false,
  66. isFail: false
  67. }
  68. }
  69. },
  70. computed: {
  71. userInfo() {
  72. return getStorage('user')
  73. },
  74. mobile() {
  75. return this?.userInfo?.mobile
  76. }
  77. },
  78. methods: {
  79. // 获取验证码
  80. getCode() {
  81. if (!this.phone) {
  82. this.$toast('请先填写手机号码')
  83. return false
  84. }
  85. if (this.countDown != 0) {
  86. this.$toast('请勿频繁获取验证码')
  87. return false
  88. }
  89. if (!/^1[3456789]\d{9}$/.test(this.phone)) {
  90. this.$toast('请填写正确的手机号码')
  91. return false
  92. }
  93. // this.init();
  94. this.isShowCodeDialog = true
  95. this.$refs.verification.refresh()
  96. },
  97. // 提交表单
  98. submitForm() {
  99. if (!this.phone) {
  100. this.$toast('请先填写手机号码')
  101. return false
  102. }
  103. if (!/^1[3456789]\d{9}$/.test(this.phone)) {
  104. this.$toast('请填写正确的手机号码')
  105. return false
  106. }
  107. if (this.phone == this.mobile) {
  108. this.$toast('不能和原号码一样')
  109. return false
  110. }
  111. if (!this.code) {
  112. this.$toast('请先填写验证码')
  113. return false
  114. }
  115. this.$api
  116. .post('/user/phone/upBind', {
  117. phone: this.phone,
  118. code: this.code
  119. })
  120. .then(res => {
  121. this.$successToast('申请成功')
  122. setTimeout(() => {
  123. this.$navToPage(
  124. {
  125. delta: 1
  126. },
  127. 'navigateBack'
  128. )
  129. }, 1000)
  130. })
  131. },
  132. // 获取图片验证码
  133. init() {
  134. this.$api.get('/common/getVerifi').then(res => {
  135. this.codeObj = res.data
  136. })
  137. },
  138. // 刷新验证码
  139. refresh() {
  140. this.init()
  141. },
  142. // 验证结束
  143. finish(value) {
  144. this.$api
  145. .post('/user/sms/send', {
  146. phone: this.phone,
  147. key: this.codeObj.key,
  148. vrifyCode: Math.round(value)
  149. })
  150. .then(res => {
  151. this.countDown = 60
  152. this.codeObj.isSuccess = true
  153. this.codeObj.isFail = false
  154. setTimeout(() => {
  155. this.isShowCodeDialog = false
  156. this.$toast('短信发送成功')
  157. }, 1500)
  158. this.countDown--
  159. this.timer = setInterval(() => {
  160. this.countDown--
  161. if (this.countDown == 0) {
  162. this.getCodeText = '重新获取'
  163. clearInterval(this.timer)
  164. }
  165. }, 1000)
  166. })
  167. .catch(res => {
  168. this.isShowCodeDialog = false
  169. this.codeObj.isSuccess = false
  170. this.codeObj.isFail = false
  171. // setTimeout(() => {
  172. // this.$refs.verification.refresh()
  173. // }, 1500)
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .kakkslakldsj {
  181. display: inline-block;
  182. width: 220rpx;
  183. }
  184. .all-container {
  185. padding: 0 30rpx;
  186. .input {
  187. margin-top: 30rpx;
  188. ::v-deep .u-input {
  189. .iconfont {
  190. font-size: 36rpx;
  191. color: $theme-color;
  192. font-weight: 600;
  193. margin-right: 12rpx;
  194. }
  195. .text {
  196. color: $theme-color;
  197. }
  198. }
  199. }
  200. ::v-deep .u-button {
  201. margin-top: 60rpx;
  202. }
  203. }
  204. </style>