<template>
	<view class="OutermostLayer">
		<h4>登录密码修改</h4>
		<view class="xgmy">
			<u--form labelPosition="left" labelWidth='180' :model="model1" :rules="rules" ref="form1">
				<u-form-item label="旧登录密码" prop="userInfo.password" borderBottom ref="item1">
					<u--input v-model="model1.userInfo.password" border="surround" clearable></u--input>
				</u-form-item>
				<u-form-item label="新登录密码" prop="userInfo.newPassword" borderBottom ref="item1">
					<u--input v-model="model1.userInfo.newPassword" border="surround" clearable></u--input>
				</u-form-item>
				</u-form-item>
				<u-form-item label="请再次输入" prop="userInfo.confirmPassword" borderBottom ref="item1">
					<u--input v-model="model1.userInfo.confirmPassword" border="surround" clearable></u--input>
				</u-form-item>
			
			</u--form>
			<view class="tijiao">
				<u-button type="primary" @click="submit">确定修改</u-button>
			</view>
		</view>
		
		<u-notify ref="uNotify" message="" ></u-notify>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				 dataForm: {
				        password: "",
				        newPassword: "",
				        confirmPassword: "",
				      },
				
				model1: {
					userInfo: {
						password: '',
						newPassword: '',
						confirmPassword: '',
					},
				},
				rules: {
					'userInfo.password': {
						type: 'string',
						required: true,
						message: '请填写旧登录密码',
						trigger: ['blur', 'change']
					},
					'userInfo.newPassword': {
						type: 'string',
						required: true,
						message: '请填写新登录密码',
						trigger: ['blur', 'change']
					},
					'userInfo.confirmPassword': {
						type: 'string',
						required: true,
						message: '请填写新登录密码',
						trigger: ['blur', 'change']
					},

				},


			};
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.form1.setRules(this.rules)
		},
		methods: {
			submit() {
				this.$refs.form1.validate().then(res => {
					if(this.model1.userInfo.newPassword!=this.model1.userInfo.confirmPassword){
						uni.$u.toast('您的新密码不一致，请重新输入')
					}else{
						//uni.$u.toast('校验通过')
						//  console.log('111111111111111111',this.model1.userInfo)
						  let postdata={
							  "newPassword":this.model1.userInfo.newPassword,
							    "password": this.model1.userInfo.password
						  }
						  
						this.$api.put('/user/password',postdata)
						.then(res=>{
						if(res.data.code==0){
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}else{
							this.$refs.uNotify.error(res.data.msg)	
						}						
						
						})
					}
					
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
			}

		}

	}
</script>

<style lang="scss">
	.tijiao {
		margin-top: 50rpx;
		padding-bottom: 30rpx;
	}
.xgmy{
	padding: 20rpx;
}
	.OutermostLayer h4 {
		font-size: 35rpx;
		margin-bottom: 10rpx;
		padding-top: 20rpx;
		text-align: center;
	}
</style>
