<template>
|
<view class="main">
|
<u-form :model="modelForm"
|
label-position="top"
|
:rules="rules"
|
ref="uForm"
|
label-width="80px">
|
<u-form-item prop="password"
|
label="密码"
|
required
|
borderBottom>
|
<u-input v-if='inputType==="password"'
|
v-model="modelForm.password"
|
border="surround"
|
placeholder="请输入密码(仅支持数字字母下划线)"
|
:type='inputType' />
|
<u-input v-else
|
v-model="modelForm.password"
|
border="surround"
|
placeholder="请输入密码(仅支持数字字母下划线)"
|
:type='inputType' />
|
</u-form-item>
|
<u-form-item prop="secondPassword"
|
label="二次确认"
|
required
|
borderBottom>
|
<u-input v-if='inputType==="password"'
|
v-model="modelForm.secondPassword"
|
border="surround"
|
placeholder="请再次输入密码(仅支持数字字母下划线)"
|
type='password' />
|
<u-input v-else
|
v-model="modelForm.secondPassword"
|
border="surround"
|
placeholder="请再次输入密码(仅支持数字字母下划线)"
|
type='text' />
|
</u-form-item>
|
<u-form-item>
|
<view class="process-button">
|
<u-button type="primary"
|
text="确定"
|
:loading="processLoading"
|
@click.stop="process"></u-button>
|
</view>
|
</u-form-item>
|
<u-form-item prop="checkboxValue">
|
<u-checkbox-group v-model="checkboxValue"
|
@change="checkChange">
|
<u-checkbox label="显示密码"
|
name="显示"
|
iconSize="32"
|
label-size="32"
|
size="40"
|
shape="circle">
|
</u-checkbox>
|
</u-checkbox-group>
|
</u-form-item>
|
</u-form>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
userInfo: {},
|
checkboxValue: [],
|
inputType: 'password',
|
isFocus: false,
|
modelForm: {
|
password: '',
|
secondPassword: ''
|
},
|
processLoading: false,
|
rules: {
|
password: [{
|
type: 'string',
|
required: true,
|
message: '请填写密码',
|
trigger: ['blur', 'change']
|
},
|
{
|
min: 2,
|
max: 10,
|
message: '密码长度应不小于2位,不大于10位 ',
|
trigger: ['blur', 'change']
|
},
|
{
|
pattern: /^[a-zA-Z0-9_]+$/,
|
message: '请输入正确格式的密码',
|
trigger: ['blur', 'change']
|
}
|
],
|
secondPassword: [{
|
type: 'string',
|
required: true,
|
message: '请填写二次密码',
|
trigger: ['blur', 'change']
|
},
|
{
|
min: 2,
|
max: 10,
|
message: '密码长度应不小于2,不大于10',
|
trigger: ['blur', 'change']
|
}
|
]
|
}
|
}
|
},
|
computed: {
|
roleType() {
|
return uni.getStorageSync('roleType')
|
}
|
},
|
onLoad(params) {
|
if (this.roleType === 3) {
|
this.userInfo = JSON.parse(params.userInfo)
|
} else {
|
this.getUserInfo(params.phone, params.idCard)
|
}
|
|
},
|
onReady() {
|
this.$refs.uForm.setRules(this.rules)
|
},
|
methods: {
|
getUserInfo(phone, idCard) {
|
this.$reqGet('phoneAndCard', { phone, idCard }).then(res => {
|
if (res.code === 0) {
|
this.userInfo = res.data
|
} else {
|
uni.$u.toast('加载失败')
|
}
|
})
|
|
},
|
checkChange(name) {
|
this.inputType = name.length === 0 ? 'password' : ''
|
this.isFocus = true
|
},
|
process() {
|
if (this.modelForm.password !== this.modelForm.secondPassword) return uni.$u.toast('密码不一致,请检查')
|
this.userInfo.password = this.modelForm.secondPassword;
|
this.processLoading = true;
|
this.$refs.uForm.validate().then(res => {
|
this.$reqAllJson('appUpdateById', this
|
.userInfo, { method: 'PUT', 'Content-type': 'application/json' }).then(res => {
|
this.processLoading = false;
|
if (res.code === 0) {
|
this.$u.toast('修改成功,即将回到首页')
|
setTimeout(() => {
|
uni.reLaunch({
|
url: '/pages/login/login'
|
})
|
}, 800)
|
} else {
|
this.$u.toast(res.msg ? res.msg : '修改失败')
|
}
|
})
|
}).catch(errors => {
|
uni.$u.toast('校验失败')
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss"
|
scoped>
|
.main {
|
width: 94%;
|
margin: vww(10) auto;
|
|
.process-button {
|
margin-top: vww(20);
|
}
|
}
|
</style>
|