<template>
|
<view class="change-password">
|
<view class="form">
|
<view class="form-item">
|
<view class="form-item-left">
|
<image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
|
</view>
|
<input type="password" v-model="form.oldPassword" placeholder="请输入原密码" />
|
</view>
|
<view class="form-item">
|
<view class="form-item-left">
|
<image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
|
</view>
|
<input type="password" v-model="form.newPassword" placeholder="请输入新密码(至少8位)" />
|
</view>
|
<view class="form-item">
|
<view class="form-item-left">
|
<image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
|
</view>
|
<input type="password" v-model="form.confirmPassword" placeholder="请再次输入新密码" />
|
</view>
|
</view>
|
<view class="btn" @click="submit">确认修改</view>
|
</view>
|
</template>
|
|
<script>
|
import { mapState } from 'vuex'
|
export default {
|
computed: {
|
...mapState(['userInfo'])
|
},
|
data() {
|
return {
|
form: {
|
oldPassword: '',
|
newPassword: '',
|
confirmPassword: ''
|
}
|
};
|
},
|
methods: {
|
async submit() {
|
if (!this.form.oldPassword) {
|
uni.showToast({
|
title: '请输入原密码',
|
icon: 'none'
|
})
|
return
|
}
|
if (!this.form.newPassword) {
|
uni.showToast({
|
title: '请输入新密码',
|
icon: 'none'
|
})
|
return
|
}
|
if (this.form.newPassword.length < 8) {
|
uni.showToast({
|
title: '新密码至少8位',
|
icon: 'none'
|
})
|
return
|
}
|
if (!this.form.confirmPassword) {
|
uni.showToast({
|
title: '请再次输入新密码',
|
icon: 'none'
|
})
|
return
|
}
|
if (this.form.newPassword !== this.form.confirmPassword) {
|
uni.showToast({
|
title: '两次密码输入不一致',
|
icon: 'none'
|
})
|
return
|
}
|
let res = await this.$u.api.updatePwd({
|
oldPassword: this.form.oldPassword,
|
newPassword: this.form.newPassword
|
})
|
if (res.code === 200) {
|
uni.showToast({
|
title: '修改成功',
|
icon: 'success'
|
})
|
setTimeout(() => {
|
uni.navigateBack()
|
}, 1500)
|
} else {
|
uni.showToast({
|
title: res.msg || '修改失败',
|
icon: 'none'
|
})
|
}
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.change-password {
|
width: 100%;
|
min-height: 100vh;
|
background-color: #F9F9FB;
|
padding: 30rpx;
|
box-sizing: border-box;
|
}
|
.form {
|
width: 100%;
|
background-color: #fff;
|
border-radius: 16rpx;
|
padding: 0 30rpx;
|
.form-item {
|
width: 100%;
|
height: 100rpx;
|
display: flex;
|
align-items: center;
|
border-bottom: 1rpx solid #E5E5E5;
|
&:last-child {
|
border-bottom: none;
|
}
|
.form-item-left {
|
width: 40rpx;
|
height: 40rpx;
|
flex-shrink: 0;
|
margin-right: 20rpx;
|
image {
|
width: 100%;
|
height: 100%;
|
}
|
}
|
input {
|
flex: 1;
|
height: 100%;
|
font-size: 28rpx;
|
color: #333;
|
}
|
}
|
}
|
.btn {
|
width: 100%;
|
height: 88rpx;
|
background-color: #004096;
|
border-radius: 44rpx;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
font-size: 32rpx;
|
color: #fff;
|
margin-top: 60rpx;
|
}
|
</style>
|