changephone.vue 6.53 KB
Newer Older
王建威's avatar
王建威 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
<template>
	<view class="main">
		<TopBar title="更换绑定手机"/>
		<view v-if="!next">
			<view class="set_title">请完成以下认证</view>
			<view class="set_subtitle">请输入{{phone.replace(/(\d{3})\d*(\d{4})/,"$1****$2")}}收到的短信验证码</view>
			<view class="flex confirm_box">
				<input type="text" class="code_input" v-model="code" placeholder="请输入手机验证码">
				<text class="get_code" v-if="codeFlag" @click="getCode()">获取验证码</text>
				<text v-else class="get_code grey_bg">{{countdown}}</text>
			</view>
			<view class="nextstep" @click="nextStep()">下一步</view>
		</view>
		<view v-else>
			<view class="set_title">请输入新手机号码</view>
			<view class="set_tip">验证号码后即可更换绑定手机</view>
			<input type="text" class="set_input" v-model="newPhone" placeholder="请输入新更换的手机号">
			<view class="flex confirm_box">
				<input type="text" class="code_input" v-model="newCode" placeholder="请输入手机验证码">
				<text class="get_code" v-if="newPhoneCodeFlag" @click="getNewCode()">获取验证码</text>
				<text v-else class="get_code grey_bg">{{newCountDown}}</text>
			</view>
			<view class="nextstep" style="margin-top: 108rpx;" @click="confirm()">确认</view>
		</view>
		<view class="success_page" v-if="changeSuccess">
			<image src="../../../static/common/icon_chenggong@2x.png"></image>
			<text>修改成功!</text>
			<view class="nextstep" @click="returnHome()">确认</view>
		</view>
	</view>
</template>

<script>
	import TopBar from '@/components/TopBar/TopBar';
	export default {
		data() {
			return {
				codeFlag: true,
				newPhoneCodeFlag: true,
				countdown: '(60)重新获取',
				newCountDown: '(60)重新获取',
				next: false,
				code: '',
				newPhone: '',
				newCode: '',
				changeSuccess: false
			}
		},
		props: {
			phone: {
				type: String
			}
		},
		methods: {
			getCode() {
				if(this.codeFlag) {
					uni.request({
						url: `/uni/api/mobile_msg/change/${this.phone}`,
						method: 'GET',
						dataType: 'json',
						success: (res) => {
							if(res.data.code === 0) {
								uni.showToast({
									title: '短信已发送',
									icon: 'none'
								})
							}
						}
					});
					let seconds = 60;
					this.codeFlag = false;
					let timer = setInterval(() => {
						seconds-=1;
						this.countdown = `(${seconds})重新获取`;
						if(seconds === 0) {
							clearInterval(timer);
							this.codeFlag = true;
							this.countdown = '(60)重新获取';
						}
					}, 1000);
				}
			},
			getNewCode() {
				if(!/^1[3456789]\d{9}$/.test(this.newPhone)) {
					uni.showToast({
						title: '手机号不正确',
						icon: 'none'
					})
					return
				}
				if(this.newPhoneCodeFlag) {
					uni.request({
						url: `/uni/api/mobile_msg/change/${this.newPhone}`,
						method: 'GET',
						dataType: 'json',
						success: (res) => {
							if(res.data.code === 0) {
								uni.showToast({
									title: '短信已发送',
									icon: 'none'
								})
							}
						}
					});
					let seconds = 60;
					this.newPhoneCodeFlag = false;
					let timer = setInterval(() => {
						seconds-=1;
						this.newCountDown = `(${seconds})重新获取`;
						if(seconds === 0) {
							clearInterval(timer);
王建威's avatar
王建威 committed
112
							this.newPhoneCodeFlag = true;
王建威's avatar
王建威 committed
113 114 115 116 117 118
							this.newCountDown = '(60)重新获取';
						}
					}, 1000);
				}
			},
			nextStep() {
王建威's avatar
王建威 committed
119 120 121 122 123 124 125
				if(!/^\d{6}$/.test(this.code)) {
					uni.showToast({
						title: '请输入6位数字验证码',
						icon: 'none'
					})
					return
				}
王建威's avatar
王建威 committed
126 127 128 129 130 131 132 133
				uni.request({
					url: `/uni/api/member/check_code/${this.code}`,
					method: 'GET',
					dataType: 'json',
					success: (res) => {
						if(res.data.code === 0) {
							this.next = true;
							this.countdown = '(60)重新获取';
王建威's avatar
王建威 committed
134 135 136 137 138
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none'
							});
王建威's avatar
王建威 committed
139 140 141 142 143
						}
					}
				})
			},
			confirm() {
王建威's avatar
王建威 committed
144 145 146 147 148 149 150
				if(!/^\d{6}$/.test(this.newCode)) {
					uni.showToast({
						title: '请输入6位数字验证码',
						icon: 'none'
					})
					return
				}
王建威's avatar
王建威 committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
				uni.request({
					url: `/uni/api/member/change_mobile`,
					method: 'POST',
					data: {
						code: this.newCode,
						phone_mob: this.newPhone
					},
					dataType: 'json',
					success: (res) => {
						if(res.data.code === 0) {
							this.changeSuccess = true;
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none'
							});
						}
					}
				})
			},
			returnHome() {
				this.$jump('/pages/setaccount/setaccount', 2);
			}
		},
		components: {
			TopBar
		}
	}
</script>

<style lang="less" scoped>
	.main {
		padding: 80rpx 40rpx 0;
		.flex {
			display: flex;
		}
		.set_title {
			font-size: 32rpx;
			color: #212121;
			line-height: 44rpx;
			font-family:PingFangSC-Medium,PingFang SC;
			font-weight:500;
			margin-top: 40rpx;
		}
		.set_tip {
			color: #7C7C7C;
			font-size: 26rpx;
			line-height: 36rpx;
			margin-top: 4rpx;
		}
		.set_subtitle {
			font-size: 28rpx;
			color: #212121;
			line-height: 40rpx;
			margin-top: 16rpx;
			font-size: 30rpx;
		}
		.set_input {
			width: 670rpx;
			height: 88rpx;
			line-height: 88rpx;
			background-color: #f5f5f5;
			padding-left: 20rpx;
			box-sizing: border-box;
			border-radius: 8rpx;
			margin-top: 32rpx;
		}
		.set_input::placeholder {
			color: #aeaeae;
		}
		.confirm_box {
			justify-content: space-between;
			margin-top: 24rpx;
			.code_input {
				width: 400rpx;
				height: 88rpx;
				line-height: 88rpx;
				background-color: #f5f5f5;
				color: #212121;
				font-size: 30rpx;
				padding-left: 20rpx;
				box-sizing: border-box;
				border-radius: 8rpx;
			}
			.code_input::placeholder {
				color: #aeaeae;
			}
			.get_code {
				width: 250rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				font-size: 30rpx;
				background-color: #FFCD00;
				border-radius: 16rpx;
			}
			.grey_bg {
				background-color: #ECECEC;
				color: #7c7c7c;
			}
		}
		.nextstep {
			background-color: #FFCD00;
			border-radius: 16rpx;
			text-align: center;
			width: 670rpx;
			height: 88rpx;
			line-height: 88rpx;
			margin: 208rpx auto 0;
			font-size: 30rpx;
		}
		.success_page {
			display: flex;
			flex-direction: column;
			align-items: center;
			position: absolute;
			left: 0;
			top: 0;
			z-index: 10;
			width: 100%;
			height: 100vh;
			background-color: #fff;
			image {
				width: 152rpx;
				height: 152rpx;
				margin-top: 282rpx;
			}
			text {
				font-size: 32rpx;
				font-family:PingFangSC-Medium,PingFang SC;
				font-weight:500;
				line-height: 44rpx;
				margin: 16rpx auto 78rpx;
			}
		}
	}
</style>