TraceabilityAPP/pages/updatePassword/updatePassword.vue

154 lines
3.3 KiB
Vue

<template>
<view class="content">
<view class="reset-password">
<u--form ref="formRef" :rules="rules" :model="formData">
<u-form-item label="原密码" labelWidth="140rpx" borderBottom prop="old_password">
<u-input placeholder="请输入原密码" border="surround" v-model="formData.old_password"
:password="!pwdShow.old_password">
<template #suffix>
<u-icon :name="pwdShow.old_password?'eye-off':'eye-fill'" size="25"
@click="pwdShow.old_password=!pwdShow.old_password"></u-icon>
</template>
</u-input>
</u-form-item>
<u-form-item label="新密码" labelWidth="140rpx" borderBottom prop="password">
<u-input border="surround" v-model="formData.password" :password="!pwdShow.password"
placeholder="请输入新密码">
<template #suffix>
<u-icon :name="pwdShow.password?'eye-off':'eye-fill'" size="25"
@click="pwdShow.password=!pwdShow.password"></u-icon>
</template>
</u-input>
</u-form-item>
<u-form-item label="确认密码" labelWidth="140rpx" borderBottom prop="password_confirm">
<u-input border="surround" v-model="formData.password_confirm" :password="!pwdShow.password_confirm"
placeholder="请确认新密码">
<template #suffix>
<u-icon :name="pwdShow.password_confirm?'eye-off':'eye-fill'" size="25"
@click="pwdShow.password_confirm=!pwdShow.password_confirm"></u-icon>
</template>
</u-input>
</u-form-item>
<u-button style="margin-top: 28rpx;background-color:#34D190;color: #fff;" @click="submit">提交</u-button>
</u--form>
</view>
</view>
</template>
<script>
import {
changePassword
} from '@/api/api.js'
export default {
data() {
return {
pwdShow: {
old_password: false,
password: false,
password_confirm: false,
},
formData: {
old_password: '', // 原密码
password: '', // 新密码
password_confirm: '', // 确认密码
},
rules: {
old_password: {
type: 'string',
required: true,
min: 6,
max: 18,
message: '请输入6-18位密码',
trigger: ['change', 'blur']
},
password: {
type: 'string',
required: true,
min: 6,
max: 18,
message: '请输入6-18位密码',
trigger: ['change', 'blur']
},
password_confirm: {
type: 'string',
required: true,
min: 6,
max: 18,
message: '请输入6-18位密码',
trigger: ['change', 'blur']
},
}
}
},
methods: {
submit() {
this.$refs.formRef.validate().then(async (e) => {
if (e) {
if (this.formData.password == this.formData.old_password) return uni.$u.toast(
'新密码不能与原密码一致');
if (this.formData.password !== this.formData.password_confirm) return uni.$u.toast(
'两次新密码不一致');
changePassword(
this.formData
).then((res) => {
if (res.code == 1) {
uni.$u.toast('修改成功');
uni.switchTab({
url: '/pages/index/personal',
})
}
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.content {
padding-top: 10rpx;
background-color: $theme-bg-color;
height: 100vh;
}
.reset-password {
margin: 28rpx;
padding: 28rpx;
background-color: #fff;
border-radius: 14rpx;
}
</style>