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.

206 lines
4.2 KiB

8 months ago
  1. <template>
  2. <view class="phone-detail">
  3. <mNavbar :title="phone ? '修改手机号' : '绑定手机号'"></mNavbar>
  4. <div class="phone-detail-content">
  5. <view class="item-line flex">
  6. <view class="label">手机号</view>
  7. <input v-model="phone" placeholder="请输入手机号" />
  8. </view>
  9. <view class="item-line flex">
  10. <view class="label">验证码</view>
  11. <input v-model="code" placeholder="请输入验证码" />
  12. <view @click.stop="sendValidate" class="button" :class="{ forbidden : forbidden }">{{ forbidden ? `${m}秒后重试` : '发送验证码'}}</view>
  13. </view>
  14. <view class="add-btn">
  15. <view @click="editPhone" class="btn">
  16. 立即绑定
  17. </view>
  18. </view>
  19. </div>
  20. </view>
  21. </template>
  22. <script>
  23. import mNavbar from '@/components/base/m-navbar.vue'
  24. export default {
  25. components: {
  26. mNavbar
  27. },
  28. data() {
  29. return {
  30. phone: '',
  31. code: '',
  32. setInterval : null,
  33. m : 60,
  34. forbidden : false
  35. }
  36. },
  37. destroyed() {
  38. clearInterval(this.setInterval)
  39. },
  40. methods: {
  41. editPhone() { //绑定手机号
  42. if (this.validateparams(true)) {
  43. let data = {
  44. phone: this.phone,
  45. code : this.code
  46. }
  47. this.$api('ChangePhone', data, res => {
  48. if (res.code == 200) {
  49. uni.showToast({
  50. title : '绑定成功',
  51. icon : 'none'
  52. })
  53. //更新本地存储
  54. if(localStorage.getItem("userInfo")){
  55. let userInfo = JSON.parse(localStorage.getItem("userInfo"))
  56. userInfo.phone = this.phone;
  57. localStorage.setItem('userInfo',userInfo)
  58. }
  59. uni.switchTab({
  60. url: '/pages/index/index'
  61. })
  62. }
  63. })
  64. }
  65. },
  66. validateparams(isSubmit) { //验证参数
  67. if (this.phone.trim() == '') {
  68. uni.showToast({
  69. title: '请填写手机号',
  70. icon: 'none'
  71. })
  72. return false;
  73. }
  74. if(!this.$utils.verificationPhone(this.phone)){
  75. uni.showToast({
  76. title: '手机号格式不合法',
  77. icon: 'none'
  78. })
  79. return false
  80. }
  81. if (isSubmit && this.code.trim() == '') {
  82. uni.showToast({
  83. title: '请填写验证码',
  84. icon: 'none'
  85. })
  86. return false
  87. }
  88. return true;
  89. },
  90. sendValidate() { //发送验证码
  91. if(this.forbidden){
  92. return;
  93. }
  94. if (this.validateparams()) {
  95. this.$api('getVipCode', {
  96. phone: this.phone
  97. }, res => {
  98. if (res.code == 200) {
  99. this.forbidden = true;
  100. this.setInterval = setInterval(()=>{
  101. if(this.m == 0){
  102. this.m = 60
  103. this.forbidden = false
  104. clearInterval(this.setInterval)
  105. }
  106. this.m--
  107. },1000)
  108. }
  109. })
  110. }
  111. },
  112. toUserCenter(){ //跳转用户中心
  113. uni.switchTab({
  114. url: '/pages/index/center'
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .phone-detail {
  122. width: 750rpx;
  123. margin: 0 auto;
  124. .phone-detail-content {
  125. width: calc(750rpx - 40rpx);
  126. margin: 0 20rpx;
  127. .item-line {
  128. position: relative;
  129. height: 80rpx;
  130. line-height: 80rpx;
  131. font-size: 28rpx;
  132. font-family: PingFang SC, PingFang SC-Bold;
  133. font-weight: 700;
  134. text-align: left;
  135. color: #333333;
  136. margin-top: 40rpx;
  137. .button {
  138. display: flex;
  139. align-items: center;
  140. position: absolute;
  141. right: 10rpx;
  142. top: 10rpx;
  143. height: 60rpx;
  144. border-radius: 30rpx;
  145. padding: 0rpx 30rpx;
  146. background: #5AC796;
  147. color: white;
  148. }
  149. .forbidden{
  150. background: #ccc;
  151. }
  152. }
  153. .item-line .label {
  154. width: 100rpx;
  155. height: 60rpx;
  156. }
  157. .item-line input {
  158. width: calc(100% - 100rpx);
  159. height: 80rpx;
  160. line-height: 80rpx;
  161. background: #f5f5f5;
  162. border-radius: 40rpx;
  163. font-size: 28rpx;
  164. font-family: PingFang SC, PingFang SC-Medium;
  165. font-weight: 500;
  166. text-align: left;
  167. color: #939393;
  168. padding: 0 20rpx;
  169. }
  170. .add-btn {
  171. display: flex;
  172. justify-content: center;
  173. align-items: center;
  174. width: 100%;
  175. height: 100rpx;
  176. margin: 60rpx 0rpx;
  177. .btn {
  178. width: 95%;
  179. height: 80rpx;
  180. border-radius: 40rpx;
  181. color: white;
  182. text-align: center;
  183. line-height: 80rpx;
  184. font-size: 28rpx;
  185. background: linear-gradient(180deg, #6FDFBE, #5AC796);
  186. }
  187. }
  188. }
  189. }
  190. </style>