index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <view>
  3. <!-- #ifdef H5 -->
  4. <view style="color: #fff;">
  5. <tn-nav-bar :bottomShadow="false" backgroundColor="#26B3A0">更换手机号</tn-nav-bar>
  6. <view :style="{height: tobheight+'px'}"></view>
  7. </view>
  8. <!-- #endif -->
  9. <view class="container">
  10. <view class="textl_ogin">更换手机号</view>
  11. <!-- 账号密码登录 -->
  12. <view class="login">
  13. <view class="input u-flex align-center">
  14. <u-icon name="phone-fill" color="#26B3A0" size="24"></u-icon>
  15. <input class="vs-flex-item" v-model="parmas.phone" :maxlength="11" placeholder="原手机号" />
  16. </view>
  17. <view class="input u-flex align-center">
  18. <i class="iconfont icon-yanzhengma" style="color:#26B3A0"></i>
  19. <input class="vs-flex-item" v-model="parmas.code" :maxlength="11" placeholder="原手机验证码" />
  20. <view class="" style="width: 250rpx;">
  21. <u-button style="width: 250rpx;" color='#26B3A0' class="custom-style"
  22. @tap="getCode">{{tips}}</u-button>
  23. </view>
  24. </view>
  25. <view class="input u-flex align-center">
  26. <u-icon name="phone-fill" color="#26B3A0" size="24"></u-icon>
  27. <input class="vs-flex-item" v-model="parmas.newPhone" :maxlength="11" placeholder="新手机号" />
  28. </view>
  29. <view class="input u-flex align-center">
  30. <i class="iconfont icon-yanzhengma" style="color:#26B3A0"></i>
  31. <input class="vs-flex-item" v-model="parmas.newCode" :maxlength="11" placeholder="新手机验证码" />
  32. <view class="" style="width: 250rpx;">
  33. <u-button style="width: 250rpx;" color='#26B3A0' class="custom-style"
  34. @tap="getCode1">{{tips1}}</u-button>
  35. </view>
  36. </view>
  37. </view>
  38. <view @click="handleChangePhone()" hover-class="hoversubmit" class="signinnow">修改
  39. </view>
  40. </view>
  41. <view class="wrap">
  42. <u-toast ref="uToast"></u-toast>
  43. <u-code :seconds="seconds" @end="" @start="" ref="uCode" @change="codeChange"></u-code>
  44. <u-code :seconds="seconds1" @end="" @start="" ref="uCode1" @change="codeChange1"></u-code>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. mapMutations,
  51. mapActions,
  52. mapState,
  53. mapGetters
  54. } from 'vuex';
  55. import {
  56. sendCode,
  57. changePhone
  58. } from '@/api/my/index.js'
  59. export default {
  60. data() {
  61. return {
  62. tips: '',
  63. seconds: 60,
  64. tips1: '',
  65. seconds1: 60,
  66. password: true,
  67. twopassword: true,
  68. parmas: {
  69. phone: '',
  70. newPhone: '',
  71. code: '',
  72. newCode: ''
  73. },
  74. password2: '',
  75. tobheight: 45,
  76. platform: this.$platform.get(),
  77. userList: [{
  78. title: '更换手机号',
  79. icon: 'account-fill',
  80. path: 'collect-list',
  81. url: '/pages/user/public/agreement?type=aboutus',
  82. },
  83. {
  84. title: '修改密码',
  85. icon: 'question-circle-fill',
  86. path: 'collect-list',
  87. url: '/pages/user/public/agreement?type=use'
  88. }
  89. ],
  90. }
  91. },
  92. computed: {
  93. ...mapGetters(['appInfo'])
  94. },
  95. onLoad() {
  96. },
  97. methods: {
  98. async handleChangePhone() {
  99. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  100. if (!this.parmas.phone) {
  101. uni.showToast({
  102. title: '请输入旧手机号',
  103. icon: 'none'
  104. })
  105. return;
  106. }
  107. if (!phoneReg.test(this.parmas.phone)) {
  108. uni.showToast({
  109. title: '旧手机号不合法',
  110. icon: 'none'
  111. })
  112. return
  113. }
  114. if (!this.parmas.code) {
  115. uni.showToast({
  116. title: '请输入原手机验证码',
  117. icon: 'none'
  118. })
  119. return
  120. }
  121. if (!this.parmas.newPhone) {
  122. uni.showToast({
  123. title: '请输入新手机号',
  124. icon: 'none'
  125. })
  126. return;
  127. }
  128. if (!phoneReg.test(this.parmas.newPhone)) {
  129. uni.showToast({
  130. title: '新手机号不合法',
  131. icon: 'none'
  132. })
  133. return
  134. }
  135. if (!this.parmas.newCode) {
  136. uni.showToast({
  137. title: '请输入新手机验证码',
  138. icon: 'none'
  139. })
  140. return
  141. }
  142. console.log('修改手机号参数', {
  143. mobile: this.parmas.phone,
  144. new_mobile: this.parmas.newPhone,
  145. code: this.parmas.code,
  146. new_code: this.parmas.newCode
  147. });
  148. let res = await changePhone({
  149. mobile: this.parmas.phone,
  150. new_mobile: this.parmas.newPhone,
  151. code: this.parmas.code,
  152. new_code: this.parmas.newCode
  153. })
  154. console.log('修改手机号返回值', res);
  155. if (res.code == 0) {
  156. uni.showToast({
  157. title: '更换手机号成功',
  158. icon: 'none'
  159. })
  160. setTimeout(function() {
  161. uni.navigateBack()
  162. }, 1000);
  163. } else {
  164. uni.$u.toast(res.msg);
  165. }
  166. },
  167. codeChange(text) {
  168. this.tips = text;
  169. },
  170. codeChange1(text) {
  171. this.tips1 = text;
  172. },
  173. async getCode() {
  174. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  175. if (!this.parmas.phone) {
  176. uni.showToast({
  177. title: '请输入原手机号',
  178. icon: 'none'
  179. })
  180. return;
  181. }
  182. if (!phoneReg.test(this.parmas.phone)) {
  183. uni.showToast({
  184. title: '原手机号不合法',
  185. icon: 'none'
  186. })
  187. return
  188. }
  189. if (!this.$refs.uCode.canGetCode) {
  190. return
  191. }
  192. let res = await sendCode({
  193. mobile: this.parmas.phone
  194. })
  195. console.log('验证码返回值', res);
  196. if (res.code == 0) {
  197. if (this.$refs.uCode.canGetCode) {
  198. // 模拟向后端请求验证码
  199. uni.showLoading({
  200. title: '正在获取验证码'
  201. })
  202. setTimeout(() => {
  203. uni.hideLoading();
  204. // 这里此提示会被this.start()方法中的提示覆盖
  205. uni.$u.toast('验证码已发送');
  206. // 通知验证码组件内部开始倒计时
  207. this.$refs.uCode.start();
  208. }, 2000);
  209. } else {
  210. uni.$u.toast('倒计时结束后再发送');
  211. }
  212. } else {
  213. uni.hideLoading();
  214. uni.$u.toast(res.msg);
  215. }
  216. },
  217. async getCode1() {
  218. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  219. if (!this.parmas.newPhone) {
  220. uni.showToast({
  221. title: '请输入新手机号',
  222. icon: 'none'
  223. })
  224. return;
  225. }
  226. if (!phoneReg.test(this.parmas.newPhone)) {
  227. uni.showToast({
  228. title: '新手机号不合法',
  229. icon: 'none'
  230. })
  231. return
  232. }
  233. if (!this.$refs.uCode1.canGetCode) {
  234. return
  235. }
  236. let res = await sendCode({
  237. mobile: this.parmas.newPhone
  238. })
  239. console.log('新--验证码返回值', res);
  240. if (res.code == 0) {
  241. if (this.$refs.uCode1.canGetCode) {
  242. // 模拟向后端请求验证码
  243. uni.showLoading({
  244. title: '正在获取验证码'
  245. })
  246. setTimeout(() => {
  247. uni.hideLoading();
  248. // 这里此提示会被this.start()方法中的提示覆盖
  249. uni.$u.toast('验证码已发送');
  250. // 通知验证码组件内部开始倒计时
  251. this.$refs.uCode1.start();
  252. }, 2000);
  253. } else {
  254. uni.$u.toast('倒计时结束后再发送');
  255. }
  256. } else {
  257. uni.hideLoading();
  258. uni.$u.toast(res.msg);
  259. }
  260. },
  261. }
  262. }
  263. </script>
  264. <style lang="scss">
  265. @import './index.scss';
  266. </style>