changeMobile.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <!-- 账号安全页面 -->
  2. <template>
  3. <view class="container flex_column_start_start">
  4. <template v-if="step==1">
  5. <view class="bind_mobile flex_row_start_center">
  6. {{$L('使用已绑定手机号')}}{{userCenterData.memberMobile?this.$replaceConByPosition(this.userCenterData.memberMobile,4,6,'****'):''}}{{$L('进行身份验证')}}
  7. </view>
  8. <view class="main_content">
  9. <view class="input-item pwd_wrap flex_row_between_center">
  10. <input type="number" class="sms_code" :value="smsCodeOri" maxlength="6" :placeholder="$L('请输入短信验证码')" placeholder-class='smsCodePlaceholder'
  11. data-key="smsCodeOri" @input="inputChange" @confirm="toLogin" />
  12. <view class="pwd-right flex_row_end_center">
  13. <text class="clear-pwd iconfont iconziyuan51" v-show="smsCodeOri" @click="clearContent('smsCodeOri')"></text>
  14. <view :style="{opacity: countDownM?0.3:1}" class="sms-code-view" @click="getSmsCode">
  15. <text class="sms-code">{{countDownM?`${countDownM}s后重新获取`:'获取验证码'}}</text>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <template v-if="step==2">
  22. <view class="second_main_content">
  23. <view class="flex_row_between_center input-item pwd_wrap ">
  24. <input type="number" class="sms_code" :value="mobile" maxlength="11" :placeholder="$L('请输入新手机号')" placeholder-class='smsCodePlaceholder'
  25. data-key="mobile" @input="inputChange" />
  26. <view class="pwd-right flex_row_end_center">
  27. <text class="clear-pwd iconfont iconziyuan51" v-show="mobile" @click="clearContent('mobile')"></text>
  28. </view>
  29. </view>
  30. <view class="flex_row_between_center input-item pwd_wrap " style="margin-top: 20rpx">
  31. <input type="number" class="sms_code" :value="smsCode" maxlength="6" :placeholder="$L('请输入短信验证码')" placeholder-class='smsCodePlaceholder'
  32. data-key="smsCode" @input="inputChange" @confirm="toLogin" />
  33. <view class="pwd-right flex_row_end_center">
  34. <text class="clear-pwd iconfont iconziyuan51" v-show="smsCode" @click="clearContent('smsCode')"></text>
  35. <view :style="{opacity: countDownM?0.3:1}" class="sms-code-view" @click="getSmsCode">
  36. <text class="sms-code">{{countDownM?`${countDownM}s后重新获取`:'获取验证码'}}</text>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <view class="confirm_btn flex_row_center_center" @click="confirm">
  43. 确定
  44. </view>
  45. <uni-popup ref="popup" type="dialog">
  46. <uni-popup-dialog type="input" :title="$L('温馨提示')" :content="bindTip" :duration="2000" before-close="true" @close="closeDialog" @confirm="confirmBind"></uni-popup-dialog>
  47. </uni-popup>
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. mapState,mapMutations
  53. } from 'vuex';
  54. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  55. import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
  56. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
  57. export default {
  58. components: {
  59. uniPopup,
  60. uniPopupMessage,
  61. uniPopupDialog
  62. },
  63. data() {
  64. return {
  65. mobile:'',//新手机号
  66. smsCodeOri: '', //手机短信验证码(原先的)
  67. smsCode: '', //新手机短信验证码
  68. step: 1, //步骤
  69. countDownM: 0,//短信验证码倒计时
  70. timeOutId:'',//定时器的返回值
  71. bind:'',//是否进行绑定,1-解绑,0-不解绑
  72. bindTip:'',//弹框内容提示
  73. };
  74. },
  75. computed: {
  76. ...mapState(['userInfo', 'userCenterData'])
  77. },
  78. onLoad() {
  79. },
  80. methods: {
  81. ...mapMutations(['setUserCenterData']),
  82. //获取个人中心数据
  83. initData() {
  84. if(this.userInfo.access_token){
  85. this.$request({
  86. url: 'v3/member/front/member/getInfo',
  87. }).then(res => {
  88. if (res.state == 200) {
  89. this.setUserCenterData(res.data);
  90. } else {
  91. this.$api.msg(res.msg);
  92. }
  93. }).catch((e) => {})
  94. }
  95. },
  96. inputChange(e) {
  97. const key = e.currentTarget.dataset.key;
  98. this[key] = e.detail.value;
  99. },
  100. //清空输入的内容
  101. clearContent(type) {
  102. this[type] = '';
  103. },
  104. //获取短信验证码
  105. getSmsCode() {
  106. if(this.countDownM){
  107. return;
  108. }
  109. //验证新手机号
  110. if (this.step==2&&!this.$checkMobile(this.mobile)) {
  111. return;
  112. }
  113. let param = {};
  114. param.url = 'v3/msg/front/commons/sendVerifyCode';
  115. param.data = {};
  116. param.data.verifyType = 2;
  117. param.data.changeType = this.step==1?'old':'new';
  118. param.data.verifyAddr = this.step==1?this.userCenterData.memberMobile:this.mobile;
  119. param.data.type = '';
  120. this.$request(param).then(res => {
  121. this.$api.msg(res.msg);
  122. if(res.state == 200){
  123. this.countDownM = 60;
  124. this.countDown();
  125. }else if(res.state == 267){
  126. if(this.step == 2){
  127. this.step = 1;
  128. //设置页面标题
  129. uni.setNavigationBarTitle({
  130. title: '身份验证'
  131. });
  132. }
  133. }
  134. })
  135. },
  136. //倒计时
  137. countDown() {
  138. this.countDownM--;
  139. if (this.countDownM == 0) {
  140. clearTimeout(this.timeOutId);
  141. } else {
  142. this.timeOutId = setTimeout(this.countDown,1000);
  143. }
  144. },
  145. //确认事件
  146. confirm(){
  147. let param = {};
  148. param.data = {};
  149. param.data.key = this.userInfo.access_token;
  150. if(this.step == 1){
  151. param.method = 'GET';
  152. param.url = 'v3/member/front/member/verifyOldMobile';
  153. param.data.smsCode = this.smsCodeOri;
  154. param.data.memberMobile = this.userCenterData.memberMobile;
  155. }else{
  156. param.method = 'POST';
  157. param.url = 'v3/member/front/memberPassword/editMobile';
  158. param.data.memberMobile = this.mobile;
  159. param.data.smsCode = this.smsCode;
  160. if(this.bind != ''){
  161. param.data.isUnbound = this.bind;
  162. }
  163. }
  164. this.$request(param).then(res => {
  165. if(res.state == 200){
  166. this.$api.msg(res.msg);
  167. this.countDownM = 0
  168. clearTimeout(this.timeOutId);
  169. if(this.step == 1){
  170. this.step = 2;
  171. //设置页面标题
  172. uni.setNavigationBarTitle({
  173. title: '修改手机号'
  174. });
  175. }else{
  176. //更新个人信息数据
  177. this.userCenterData.memberMobile = this.mobile;
  178. this.setUserCenterData(this.userCenterData);
  179. //返回上级页面
  180. setTimeout(() => {
  181. uni.navigateBack();
  182. }, 2000)
  183. }
  184. }else if(res.state == 267){
  185. //提示是否进行绑定
  186. this.bindTip = res.msg;
  187. this.$refs.popup.open();
  188. }else{
  189. this.$api.msg(res.msg);
  190. }
  191. })
  192. },
  193. //关闭弹框
  194. closeDialog(){
  195. this.bind = 0;
  196. this.$refs.popup.close();
  197. //返回上级页面
  198. setTimeout(() => {
  199. uni.navigateBack();
  200. }, 200)
  201. },
  202. //确认绑定
  203. confirmBind(){
  204. this.bind = 1;
  205. this.$refs.popup.close();
  206. this.confirm();
  207. },
  208. }
  209. }
  210. </script>
  211. <style lang='scss'>
  212. page {
  213. background: $bg-color-split;
  214. display: flex;
  215. flex: 1;
  216. height: 100%;
  217. width: 750rpx;
  218. margin: 0 auto;
  219. }
  220. .container {
  221. display: flex;
  222. flex: 1;
  223. .bind_mobile {
  224. height: 80rpx;
  225. width: 100%;
  226. width: 100%;
  227. background: #F8F8F8;
  228. padding-left: 40rpx;
  229. color: $main-font-color;
  230. font-size: 26rpx;
  231. }
  232. .second_main_content{
  233. display: flex;
  234. flex-direction: column;
  235. flex: 1;
  236. width: 100%;
  237. background-color: #fff;
  238. margin-top: 20rpx;
  239. padding: 20rpx 40rpx 0;
  240. }
  241. .main_content {
  242. display: flex;
  243. flex: 1;
  244. width: 100%;
  245. background-color: #fff;
  246. padding: 20rpx 40rpx 0;
  247. }
  248. .input-item {
  249. height: 100rpx;
  250. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  251. position: relative;
  252. width: 100%;
  253. .sms_code_laceholder {
  254. color: #949494;
  255. font-size: 26rpx;
  256. }
  257. .sms_code {
  258. font-size: 28rpx;
  259. color: $main-font-color;
  260. }
  261. .clear-account {
  262. position: absolute;
  263. right: 6rpx;
  264. top: 28rpx;
  265. font-size: 24rpx;
  266. color: #999;
  267. }
  268. .pwd-right {
  269. flex-shrink: 0;
  270. .clear-pwd {
  271. font-size: 24rpx;
  272. color: #999;
  273. }
  274. .sms-code-view {
  275. border: 1px solid $main-color;
  276. padding: 14rpx;
  277. border-radius: 6rpx;
  278. line-height: 0;
  279. margin-left: 20rpx;
  280. .sms-code {
  281. color: $main-color;
  282. font-size: 24rpx;
  283. line-height: 24rpx;
  284. }
  285. }
  286. }
  287. .tit {
  288. height: 50upx;
  289. line-height: 56upx;
  290. font-size: $font-sm+2upx;
  291. color: $font-color-base;
  292. }
  293. input {
  294. height: 60upx;
  295. font-size: $font-base + 2upx;
  296. color: $font-color-dark;
  297. width: 100%;
  298. }
  299. }
  300. .confirm_btn {
  301. position: fixed;
  302. width: 668rpx;
  303. margin: 0 41rpx;
  304. height: 88rpx;
  305. background: linear-gradient(-90deg, rgba(252, 29, 28, 1) 0%, rgba(255, 122, 24, 1) 100%);
  306. border-radius: 44rpx;
  307. left: 50%;
  308. bottom: 40rpx;
  309. transform: translateX(-375rpx);
  310. color: #fff;
  311. font-size: 36rpx;
  312. }
  313. }
  314. </style>