<template>
	<view class="fs-p30">
		<view class="fs-radius__sm">
			<tui-form ref="form" :showMessage="false" :model="formData">
				<tui-form-item label="旧密码">
					<tui-input type="password" padding="0" :borderBottom="false" placeholder="请输入旧密码" v-model="formData.oldPassWord"></tui-input>
				</tui-form-item>
				<tui-form-item label="新密码">
					<tui-input type="password" padding="0" :borderBottom="false" placeholder="请输入新密码" v-model="formData.newPassWord"></tui-input>
				</tui-form-item>
				<tui-form-item label="确认密码" :bottomBorder="false">
					<tui-input type="password" padding="0" :borderBottom="false" placeholder="请输入确认密码" v-model="formData.confirmPwd"></tui-input>
				</tui-form-item>
			</tui-form>
		</view>
		<view class="fs-mt60 fs-flex__center">
			<tui-button width="520rpx" height="80rpx" shadow shape="circle" @click="onSubmit">提 交</tui-button>
		</view>
	</view>
</template>

<script>
const rules = [
	{
		name: "oldPassWord",
		rule: ["required"],
		msg: ["请输入旧密码"]
	}, 
	{
		name: "newPassWord",
		rule: ["required"],
		msg: ["请输入新密码"]
	},
	{
	 	name: "confirmPwd",
	 	rule: ["required", "isSame:newPassWord"],
	 	msg: ["请输入确认密码", "两次输入的密码不一致"]
	}
]
import { apiModifyPwd } from '@/api/user'
export default {
	data() {
		return {
			formData: {
				oldPassWord: '',
				newPassWord: '',
				confirmPwd: ''
			}
		}
	},
	onLoad() {

	},
	methods: {
		// 提交
		onSubmit() {
			this.$refs.form.validate(this.formData, rules).then(res => {
				if (!res.isPass) {
					uni.$tui.toast(res.errorMsg)
					return
				}
				apiModifyPwd({data:{...this.formData}}).then(res => {
					this.loginOut()
					uni.$tui.href('/pages/login', 2)
				})
			})
		}
	}
}
</script>

<style lang="scss" scoped>

</style>
