purchase-let/pagesOrder/setPayPassword/index.vue

146 lines
3.9 KiB
Vue
Raw Normal View History

2024-06-20 14:58:05 +08:00
<template>
2024-06-20 16:28:19 +08:00
<view class='card'>
2024-06-21 14:27:24 +08:00
<up-input v-model="form.phone" placeholder="手机号" border="none" readonly></up-input>
<view style="margin: 30rpx 0;">
<up-line color="#D3E3FD"></up-line>
</view>
2024-06-20 16:28:19 +08:00
<view style="display: flex;justify-content: space-between;align-items: center;">
2024-06-21 10:59:01 +08:00
<up-input v-model="form.code" placeholder="验证码" border="none" type='number'></up-input>
2024-06-20 16:28:19 +08:00
<view class="code-btn">
2024-06-21 14:27:24 +08:00
<view style="margin: 0 20rpx;">
<up-line color="grey" direction="col" length="30rpx"></up-line>
</view>
2024-06-21 10:59:01 +08:00
<text class='btn-text' style="color: grey;" v-if='cutDown'>重新获取({{cutDown}})</text>
<text @click="getCode" class='btn-text' v-else> {{flag?'获取验证码':'重新获取' }} </text>
2024-06-20 16:28:19 +08:00
</view>
</view>
2024-06-20 14:58:05 +08:00
</view>
2024-06-20 16:28:19 +08:00
<view class='card'>
2024-06-21 10:59:01 +08:00
<view @click="showKeyBorad=true,type=1">
2024-06-21 15:27:09 +08:00
<up-input style="pointer-events: none;" type='password' v-model="form.password" placeholder="请输入你的密码"
border="none" readonly></up-input>
2024-06-21 10:59:01 +08:00
</view>
2024-06-21 14:27:24 +08:00
<view style="margin: 30rpx 0;">
<up-line color="#D3E3FD"></up-line>
</view>
2024-06-21 10:59:01 +08:00
<view @click="showKeyBorad=true,type=2">
2024-06-21 15:27:09 +08:00
<up-input style="pointer-events: none;" type='password' v-model="form.rePassword" placeholder="请再次输入你的密码"
border="none" readonly></up-input>
2024-06-21 10:59:01 +08:00
</view>
2024-06-20 16:28:19 +08:00
</view>
<view class='submit-btn'>
<up-button color="#20B128" shape="circle" @click="submit">确认</up-button>
</view>
2024-06-21 10:59:01 +08:00
<up-keyboard dotDisabled safeAreaInsetBottom ref="uKeyboard" @close="showKeyBorad=false" mode="number"
:tooltip="false" :show="showKeyBorad" @change='onKetDown' @backspace='backspaceFn' />
2024-06-20 14:58:05 +08:00
</template>
<script setup>
2024-06-21 10:59:01 +08:00
import useUserStore from "@/store/user";
import {
getMassageCode,
setPayPassword
} from "@/api/address.js"
2024-06-20 16:28:19 +08:00
import {
2024-06-21 10:59:01 +08:00
ref,
reactive
2024-06-20 16:28:19 +08:00
} from "vue"
2024-06-21 10:59:01 +08:00
const userInfo = useUserStore().userInfo;
const form = reactive({
phone: userInfo.mobile, //手机号
code: "", //验证码
password: "", //6位数密码
rePassword: "" //确认密码
})
2024-06-20 16:28:19 +08:00
2024-06-21 10:59:01 +08:00
// 获取验证码
const cutDown = ref(0)
const flag = ref(true)
const code = ref('')
const checkPhone = (phone) => {
const regex = /^1[3-9]\d{9}$/;
return regex.test(phone) ? true : false
}
2024-06-20 16:28:19 +08:00
2024-06-21 10:59:01 +08:00
const getCode = async () => {
2024-06-21 14:27:24 +08:00
if (!checkPhone(form.phone)) return uni.$u.toast('请输入正确的手机号')
2024-06-21 10:59:01 +08:00
await getMassageCode()
flag.value = false
2024-06-21 15:27:09 +08:00
cutDown.value = 60
2024-06-21 10:59:01 +08:00
let timer = setInterval(() => {
cutDown.value--
if (cutDown.value <= 0) clearInterval(timer)
}, 1000)
}
// 获取验证码结束
// 键盘事件
const showKeyBorad = ref(false)
const type = ref(1) // 1 输入密码 2 再次输入密码
const onKetDown = (e) => {
2024-06-27 20:15:39 +08:00
uni.vibrateShort();
2024-06-21 10:59:01 +08:00
if (type.value == 1) {
form.password.length < 6 ?
form.password += e :
showKeyBorad.value = false
2024-06-25 15:34:24 +08:00
if (form.password.length == 6) showKeyBorad.value = false;
2024-06-21 10:59:01 +08:00
} else {
form.rePassword.length < 6 ?
form.rePassword += e :
showKeyBorad.value = false
2024-06-25 15:34:24 +08:00
if (form.rePassword.length == 6) showKeyBorad.value = false;
2024-06-21 10:59:01 +08:00
}
}
const backspaceFn = () => {
if (type.value == 1) {
form.password = form.password.slice(0, -1);
} else {
form.rePassword = form.rePassword.slice(0, -1);
}
}
2024-06-20 16:28:19 +08:00
2024-06-21 10:59:01 +08:00
// 键盘事件结束
2024-06-21 15:27:09 +08:00
2024-06-21 10:59:01 +08:00
const submit = async () => {
if (!form.code) return uni.$u.toast('请输入验证码');
2024-06-25 15:34:24 +08:00
if (form.password.length < 6) return uni.$u.toast('请输入6位数密码');
2024-06-21 10:59:01 +08:00
if (form.password !== form.rePassword) return uni.$u.toast('两次密码不一致');
2024-06-21 14:27:24 +08:00
await setPayPassword({
...form
})
2024-06-21 10:59:01 +08:00
uni.$u.toast('设置成功')
setTimeout(() => {
uni.navigateBack()
}, 1000)
2024-06-20 16:28:19 +08:00
}
2024-06-20 14:58:05 +08:00
</script>
2024-06-20 16:28:19 +08:00
<style lang='scss'>
.card {
padding: 50rpx;
background-color: white;
margin-bottom: 30rpx;
padding-bottom: 30rpx;
}
.submit-btn {
position: absolute;
bottom: 100rpx;
width: 710rpx;
left: 50%;
transform: translateX(-50%);
}
.code-btn {
display: flex;
align-items: center;
}
.btn-text {
color: #20B128;
}
2024-06-20 14:58:05 +08:00
</style>