<template>
	<view>
		<u-popup v-model="show" mode="bottom" :border-radius="'50'">
			<view class="popup-box">
				<view class="title">
					<text class="title-btn"></text>
					<text class="title-text">请输入密码</text>
					<text class="title-btn cancel-btn iconfont3" @click.stop="show = false">&#xe6e6;</text>
				</view>
				<view class="content-box">
					<view class="content-notarize">
						确认将：
					</view>
					<view class="content-nums">
						<template v-if="type === 1 || type === 0">
							<text class="iconfont3 content-nums-icon">&#xe619;</text>
							<text class="content-nums-text">{{ useNums }}积分</text>
						</template>
						<template v-else-if="type === 2">
							<text class="iconfont content-nums-icon">￥</text>
							<text class="content-nums-text">{{ useNums }}元</text>
						</template>
					</view>
					<view class="content-result">
						{{ result[type]}}
					</view>
					<view class="content-result-num" style="margin-top: 10px;">
						<text>{{ resultNum }}</text>
					</view>
					<view class="content-password">
						<u-message-input :focus="true" :breathe="false" dot-fill :maxlength="maxlength"
							:value="pay_password" @change="changePassword"></u-message-input>
					</view>
					<view class="content-btns">
						<view class="content-btn notarize-btn" @click.stop="givePresent()">
							{{ notarizeBtn[type]}}
						</view>
						<view class="content-btn" @click="show = false">
							取消
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name: "exchange-hint",
		props: {
			params: {
				type: Object,
				default: () => {
					return {
						url: '',
						mode: '',
						data: {}
					}
				}
			},
			type: {
				// 转赠/兑换类型 0：积分兑换余额；1：积分转赠；2：余额转赠
				type: Number,
				default: 0
			},
			useNums: {
				// 转赠 / 兑换 数量
				type: String | Number,
				default: 0
			},
			resultNum: {
				type: String,
				default: ''
			}

		},
		data() {
			return {
				show: false,
				maxlength: 6, // 密码长度
				pay_password: '',
				result: [
					"兑换为余额",
					"转赠给：",
					"转赠给："
				],
				notarizeBtn: [
					'确认兑换',
					'确认转赠',
					'确认转赠'
				],
				givePresentLoading: false
			};
		},
		watch: {

		},
		methods: {
			changePassword(e) {
				this.pay_password = e
			},
			open() {
				this.show = true
			},
			givePresent() {
				if (this.givePresentLoading) {
					return false;
				};
				if (!this.pay_password) {
					this.$mUtil.toast("请输入支付密码")
					return false
				};
				if (this.pay_password.length !== this.maxlength) {
					this.$mUtil.toast("请确认密码是否输入完整")
					return false
				};
				this.givePresentLoading = true;
				const data = {
					...this.params.data,
					pay_password: this.pay_password
				}
				try {
					this.$http[this.params.mode](this.params.url, data).then((res) => {
						if (res && res.code == 200) {
							console.log('resresres = ', res)
							if (this.type === 0) {
								this.$mUtil.toast("兑换成功")
							} else if (this.type === 1 || this.type === 2) {
								this.$mUtil.toast("转赠成功")
							}
							this.show = false;
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000)
						};
						this.givePresentLoading = false;
					}).catch(err => {
						this.givePresentLoading = false;
					})
				} catch (e) {
					this.givePresentLoading = false;
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.popup-box {

		padding: 60rpx 60rpx 0;
	}

	.title {
		width: 100%;
		height: 68rpx;
		border-radius: 50rpx 50rpx 0 0;
		display: flex;
		justify-content: space-between;
		align-items: center;

		text {
			height: 100%;
		}

		.title-btn {
			width: 80rpx;
			text-align: right;
		}

		.cancel-btn {
			font-size: 50rpx;
			display: flex;
			justify-content: flex-end;
		}

		.title-text {
			position: relative;
			font-size: 36rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			color: #1a1a1a;

			&:before {
				content: '';
				position: absolute;
				left: 50%;
				bottom: 0;
				width: 64rpx;
				height: 8rpx;
				background: #cccccc;
				transform: translateX(-50%);
				border-radius: 4rpx;
			}
		}
	}

	.content-box {
		width: 100%;

		.content-notarize {
			padding: 50rpx 0 3px;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			color: #333333;
		}

		.content-nums {

			.content-nums-icon {
				font-size: 45rpx;
				color: #000000;
				margin-right: 10px;
			}

			.content-nums-text {

				font-size: 60rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				color: #1a1a1a;
			}
		}

		.content-result {
			margin-top: 61rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			color: #333333;
		}

		.content-result-num {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
		}

		.content-password {
			padding: 60rpx 0 76rpx;
		}

		.content-btns {
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-bottom: 106rpx;

			.content-btn {
				width: 298rpx;
				height: 85rpx;
				border-radius: 43rpx;
				color: #FA6138;
				background: #e7eefc;
				border: 1rpx solid #3775f6;
				text-align: center;
				line-height: 83rpx;
			}

			.notarize-btn {
				background-color: #FA6138;
				color: #FFFFFF;
			}
		}

		// <view class="content-btns">
		// 	<view class="content-btn">
		// 		确认兑换
		// 	</view>
		// 	<view class="content-btn">
		// 		取消
		// 	</view>
		// </view>
	}

	/deep/.u-char-item {
		background-color: #e6e6e6;
		border: none;
	}
</style>
