<template>
	<view class="page">
		<view class="input">
			<uni-easyinput type="password" v-model.trim="form.password" placeholder="请输入旧密码"></uni-easyinput>
		</view>
		<view class="input">
			<uni-easyinput type="password" v-model.trim="form.newPassword" placeholder="请输入新密码"></uni-easyinput>
		</view>
		<view class="input">
			<uni-easyinput type="password" v-model.trim="form.reNewPassword" placeholder="请再次输入新密码"></uni-easyinput>
		</view>
		<button type="primary" @click="submit">确认</button>
	</view>
</template>

<script>
	import { examinePassword } from '@/apis/modules/user.js'
	export default {
		data() {
			return {
				form: {
					password: '',
					newPassword: '',
					reNewPassword: ''
				},
			}
		},
		methods: {
			submit() {
				const { form } = this
				const { password, newPassword, reNewPassword } = form
				if(!password) return this.$util.errMsg('请输入旧密码')
				if(!newPassword) return this.$util.errMsg('请输入新密码')
				if(!reNewPassword) return this.$util.errMsg('请确认新密码')
				if(newPassword.length < 6 || reNewPassword.length < 6) return this.$util.errMsg('请输入6位数以上的密码')
				if(newPassword !== reNewPassword) return this.$util.errMsg('输入的新密码不一致，请重新确认')
				if(password === newPassword) return this.$util.errMsg('旧密码跟新密码不能一致')
	
				form.accountId = uni.getStorageSync('team').accountId
				examinePassword(form).then(res => {
					this.$util.sucMsg('修改成功！')
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}).catch(e => {})
			}
		}
	}
</script>

<style scoped lang="scss">
.page {
	padding: 20px;
	background-color: #fff;
}
/deep/.input {
	margin-bottom: 15px;
	.is-input-border {
		border-color: #dedede !important;
	}
}
</style>
