<template>
	<view>
		<view class="logo">
			<view class="img">
				<image mode="widthFix" src="../../../static/img/logo2.jpg">
				</image>
			</view>
		</view>
		<!-- 账号密码输入框 -->
		<view class="form">
			<view class="password">
				<image src="../../../static/img/pas.png" style="width: 40rpx;height: 40rpx;margin-right: 10px;"></image>
				<input placeholder="请输入密码" type="number" maxlength="6" v-model="passwd" password=true
					placeholder-style="color: #333333;" />
			</view>
			<view class="password">
				<image src="../../../static/img/pas.png" style="width: 40rpx;height: 40rpx;margin-right: 10px;"></image>
				<input placeholder="请确认密码" type="number" maxlength="6" v-model="qrpasswd" password=true
					placeholder-style="color: #333333;" />
			</view>
			<view class="btn mart50" @tap="setUserPayPwd">确 认</view>
		</view>
	</view>
</template>

<script>
	import {
		setUserPayPwd
	} from "../../../Utils/Api.js";
	let app = getApp();
	export default {
		data() {
			return {
				passwd: '',
				qrpasswd: ''
			}
		},
		methods: {
			setUserPayPwd() {
				uni.hideKeyboard();
				if (this.passwd == '') {
					uni.showToast({
						title: '请填写密码',
						icon: "none"
					});
					return;
				}
				if (this.qrpasswd == '') {
					uni.showToast({
						title: '请确认密码',
						icon: "none"
					});
					return;
				}
				if (this.qrpasswd != this.passwd) {
					uni.showToast({
						title: '您输入的两次密码不相同',
						icon: "none"
					});
					return;
				}
				uni.showModal({
					title: '设置密码',
					content: '是否确认设置密码',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '设置中...'
							})
							let datas = {
								"password": this.passwd
							}
							setUserPayPwd(datas).then(res => {
								if (res.return_code == '000000') {
									uni.hideLoading();
									uni.showToast({
										title: '设置成功',
										icon: "none",
										duration: 2000,
										success() {
											setTimeout(() => {
												uni.navigateBack({
												})
											}, 800);
										}
									});
									app.globalData.userInfo = res.return_data
										.object
										.highUser;
									uni.setStorage({
										key: "user",
										data: res.return_data
											.object
											.highUser
									})
								} else {
									uni.hideLoading();
									uni.showToast({
										title: res.return_msg,
										icon: "none",
										success() {
											setTimeout(() => {
												uni.navigateBack({
												})
											}, 800);
										}
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	@import "../../../static/css/login.scss";

	.form {
		.res {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 100upx;
			color: rgba($color: #ffffff, $alpha: 0.8);
		}
	}
</style>
