123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <!-- 更换绑定手机号 -->
- <template>
- <view class="wrap">
- <view class="head-msg">
- 更换绑定后可使用新手机号登录
- </view>
- <view class="padding-box">
- <view class="module">
- <view class="row-between">
- <input type="text" v-model="params.phone" class="input" placeholder="请输入新绑定的手机号" placeholder-class="placeholder" />
- </view>
- <view class="row-between">
- <input type="text" v-model="params.code" class="input" placeholder="请输入验证码" placeholder-class="placeholder" />
- <button v-if="countDown <= 0" @tap="sendSms()" type="default" class="send-code">发送验证码</button>
- <button v-else type="default" class="send-code">{{countDown}}秒后重发</button>
- <!-- 60s后重新发送 -->
- </view>
- </view>
- <view class="btn-box">
- <button type="default" @tap="modifyPhone()" class="active">确认</button>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { generalSendSms, userCenterModifyPhone } from '../../../common/service.js';
- import { validatorFun } from '../../../common/utils/util.js';
- export default {
- data() {
- return {
- info: {},
- params: {
- phone: '',
- code: '',
- },
- countDown: 0,
- }
- },
- onLoad() {
- this.info = uni.getStorageSync('USER_INFO') || {};
- this.info.showPhone = this.info.phone.split('').map((n, i) => i > 2 && i < 7 ? '*' : n).join('');
- },
- methods: {
- modifyPhone() {
- const params = this.params;
- const errList = validatorFun(params, [
- ['phone', ['notNull', '请输入手机号'], ['isMobile', '请输入正确手机号']],
- ['code', ['notNull', '请输入验证码']],
- ]);
- if (errList.length > 0) {
- return uni.showToast({
- icon: 'none',
- title: errList[0].errMsg,
- });
- }
- userCenterModifyPhone({
- data: params,
- success: ({code, msg, data}) => {
- if (code == 1) {
- this.info.phone = params.phone;
- uni.setStorageSync('USER_INFO', info);
- this.params = {
- phone: '',
- code: '',
- };
- uni.showModal({
- title: '提示',
- content: '修改成功,请重新登录',
- showCancel: false,
- success: (res) => {
- if (res.confirm) {
- uni.removeStorageSync('session_key');
- uni.removeStorageSync('USER_INFO');
- uni.reLaunch({
- url: '/pages/index/index',
- });
- }
- }
- });
- } else {
- uni.showToast({
- icon: 'none',
- title: msg,
- });
- }
- },
- });
- },
- sendSms() {
- const params = this.params;
- const errList = validatorFun(params, [
- ['phone', ['notNull', '请输入手机号'], ['isMobile', '请输入正确手机号']],
- ]);
- if (errList.length > 0) {
- return uni.showToast({
- icon: 'none',
- title: errList[0].errMsg,
- });
- }
- generalSendSms({
- data: {
- phone: params.phone,
- },
- success: ({code, msg, data}) => {
- if (code == 1) {
- this.countDownFn();
- }
- uni.showToast({
- icon: 'none',
- title: msg,
- });
- },
- });
- },
- countDownFn() {
- let num = 60;
- const fn = () => {
- if (num == 0) return;
- this.countDown = --num;
- setTimeout(() => fn(), 1000);
- };
- fn();
- },
- }
- }
- </script>
- <style scoped lang="scss">
- @import "./change-bind-mobile-phone-number.css";
- </style>
|