<template>
	<view class="main">
		<u--form labelPosition="left" labelWidth='180' :model="model1" :rules="rules" ref="form1">
			<u-form-item label="旧登录密码" prop="userInfo.password" borderBottom ref="item1" required>
				<u--input v-model="model1.userInfo.password" border="none" clearable placeholder="请输入"></u--input>
			</u-form-item>
			<u-form-item label="新登录密码" prop="userInfo.newPassword" borderBottom ref="item1" required>
				<u--input v-model="model1.userInfo.newPassword" border="none" clearable placeholder="请输入"></u--input>
			</u-form-item>
			</u-form-item>
			<u-form-item label="请再次输入" prop="userInfo.confirmPassword" borderBottom ref="item1" required>
				<u--input v-model="model1.userInfo.confirmPassword" border="none" clearable
					placeholder="请输入"></u--input>
			</u-form-item>

		</u--form>
		<view class="tijiao">
			<u-button type="primary" @click="submit">确定修改</u-button>
		</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>
