editphone.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="main bg-white margin-top padding-tb-sm">
  3. <view class="flex justify-between align-center padding-lr-sm">
  4. <view class="flex-sub margin-right-sm">
  5. <u-input v-model="value" :type="type" placeholder="请输入原绑定电话验证码" :border="border" />
  6. </view>
  7. <u-verification-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-verification-code>
  8. <u-button @click="getCode">{{tips}}</u-button>
  9. </view>
  10. <view class="flex justify-between align-center margin-top-sm padding-lr-sm">
  11. <view class="flex-sub margin-right-sm">
  12. <u-input v-model="newphone" :type="type" placeholder="请输入新号码" :border="border" />
  13. </view>
  14. </view>
  15. <view class="flex justify-between align-center margin-top-sm padding-lr-sm">
  16. <view class="flex-sub margin-right-sm">
  17. <u-input v-model="newcode" :type="type" placeholder="请输入新号码验证码" :border="border" />
  18. </view>
  19. <u-verification-code :seconds="newseconds" @end="newend" @start="newstart" ref="newuCode" @change="codeChange1"></u-verification-code>
  20. <u-button @click="getnewCode">{{newtips}}</u-button>
  21. </view>
  22. <view class="cu-bar bg-white tabbar" style="position: fixed;bottom: 0;width: 100%;">
  23. <view class="submit" style="background-color: #0B73B9;color: white;" @click="savephone">
  24. 立即保存
  25. </view>
  26. </view>
  27. <view class="cu-tabbar-height"></view>
  28. <view class="cu-tabbar-height"></view>
  29. <u-no-network></u-no-network>
  30. </view>
  31. </template>
  32. <script>
  33. import store from '@/store'
  34. export default {
  35. onLoad(options) {
  36. },
  37. mounted() {
  38. this.info = store.getters['getusers']
  39. },
  40. data() {
  41. return {
  42. value: '',
  43. newphone: "",
  44. newcode: "",
  45. type: 'number',
  46. border: true,
  47. tips: '',
  48. newtips: "",
  49. seconds: 60,
  50. newseconds: 60,
  51. info: {}
  52. }
  53. },
  54. methods: {
  55. codeChange(text) {
  56. this.tips = text;
  57. },
  58. codeChange1(text) {
  59. this.newtips = text;
  60. },
  61. getCode() {
  62. if (this.$refs.uCode.canGetCode) {
  63. this.$refs.uCode.start();
  64. } else {
  65. uni.showToast({
  66. title: "结束后再发送",
  67. icon: "none"
  68. })
  69. }
  70. },
  71. getnewCode() {
  72. if (!this.$util.isNum(this.newphone)) {
  73. uni.showToast({
  74. title: "手机号不正确",
  75. icon: "none",
  76. })
  77. return false
  78. }
  79. if (!this.$util.isPhoneNumber(this.newphone)) {
  80. uni.showToast({
  81. title: "手机号不正确",
  82. icon: "none"
  83. })
  84. return false
  85. }
  86. if (this.$refs.newuCode.canGetCode) {
  87. this.newstart()
  88. } else {
  89. uni.showToast({
  90. title: "结束后再发送",
  91. icon: "none"
  92. })
  93. }
  94. },
  95. end() {
  96. },
  97. start: async function() {
  98. let res = await this.$request.post("/api/v1/common/sendVerifyCode", {
  99. phone: this.info.phone,
  100. type: 4
  101. })
  102. },
  103. newend() {
  104. },
  105. newstart: async function() {
  106. let res = await this.$request.post("/api/v1/common/sendVerifyCode", {
  107. phone: this.newphone,
  108. type: 5
  109. })
  110. if (res.status == 0) {
  111. } else {
  112. uni.showToast({
  113. title: res.message,
  114. icon:"none"
  115. })
  116. this.$refs.newuCode.reset()
  117. }
  118. },
  119. savephone: async function() {
  120. if (this.value == "" || this.newphone == "" || this.newcode == "") {
  121. uni.showToast({
  122. title: "请填写完整",
  123. icon: "none"
  124. })
  125. return false
  126. }
  127. let res = await this.$request.post("/api/v1/user/changeUserPhone", {
  128. old_verify_code: this.value,
  129. new_verify_code: this.newcode,
  130. new_phone: this.newphone
  131. })
  132. console.log(res)
  133. if (res.status == 0) {
  134. uni.showToast({
  135. title: "保存成功",
  136. duration: 1000
  137. })
  138. setTimeout(() => {
  139. uni.navigateBack({
  140. delta: 1
  141. })
  142. }, 1000)
  143. } else {
  144. uni.showToast({
  145. title: res.message,
  146. icon: "none",
  147. duration: 1500
  148. })
  149. }
  150. }
  151. }
  152. };
  153. </script>
  154. <style lang="scss">
  155. page {
  156. background-color: #fff;
  157. }
  158. .main {}
  159. </style>