<template>
	<view class='container'>
		<view>
			<u-input v-model="psd1" type="password" placeholderStyle="color:#999;"
				   :customStyle="{'height': '85rpx'}" border="none" placeholder="请设置新密码（6位）" maxlength="6">
			</u-input>
		</view>
		
		<view class="mt-30">
			<u-input v-model="psd2" type="password" :customStyle="{'height': '85rpx'}" border="none" placeholderStyle="color:#999;"
				placeholder="请再次输入新密码（6位）" maxlength="6">
			</u-input>
		</view>
		
		<view @click="onSubmit" class="btn">
			<text>确认修改</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				psd1: '',
				psd2: ''
			};
		},
		methods: {
			onSubmit(){
				if(!this.psd1) {
					return this.$u.toast('请输入新的支付密码')
				}
				if(!this.psd2) {
					return this.$u.toast('请再次输入支付密码')
				}
				if(this.psd1 !== this.psd2) {
					return this.$u.toast('两次输入密码不一致')
				}
				const params = {
					url: '/api/user/editpassword',
					loadingTip: '',
					data: {
						psd1: this.psd1,
						psd2: this.psd2
					}
				}
				this.$request(params).then(res => {
					// console.log(res)
					if (res.code === 1) {
						this.$u.toast(res.msg || '修改成功')
						this.$store.dispatch('user/getUserInfo');
						setTimeout(() => {
							uni.navigateBack({
								delta: 2
							})
						}, 600)
					} else {
						this.$u.toast(res.msg || '修改失败')
					}
				}).catch(err => {
					// console.log(err)
					this.$u.toast(err.msg || '修改失败')
				})
			}
		},
	};
</script>

<style scoped>
	.container {
		padding: 20rpx 20rpx;
	}
	.btn{
		width: 100%;
		height: 88rpx;
		margin: 500rpx auto 0;
		text-align: center;
		line-height: 88rpx;
		color: #FFF;
		background-color: #EB6918;
		border-radius: 8rpx;
	}
</style>