<template>
	<view class="xkl-com-bg">
		<view style="height: 100rpx;"></view>
		<view>
			<view style="font-size: 30rpx; color: #949494;">当前余额 ￥{{info.info.money}}，最低充值￥{{info.recharge.min_money}}
			</view>
			<view style="height:20rpx"></view>
			<u--input :customStyle="{backgroundColor: '#ffffff'}" type="number" placeholder="请输入充值金额" border="surround"
				v-model="form.money"></u--input>
		</view>
		<view style="height: 30rpx;"></view>
		<view style="background-color: #fff; padding: 30rpx;border-radius: 10rpx;">
			<view style="font-size: 28rpx;#606266">支付方式</view>
			<view style="height: 20rpx;"></view>
			<u-radio-group v-model="form.pay_type" iconPlacement="right" :borderBottom="true" placement="column">
				<u-radio :name="1">
					<view class="u-flex u-flex-y-center">
						<u-icon name="/static/icon/weixin.png" size="50rpx" />
						<view style="width: 20rpx;"></view>
						<view>
							<view style="font-size: 30rpx;">微信支付</view>
							<view style="font-size: 28rpx;color: #909399;">微信快捷支付</view>
						</view>
					</view>
				</u-radio>
			</u-radio-group>
		</view>
		<view style="height: 100rpx;"></view>
		<u-button type="primary" @click="getRecharge">立即支付</u-button>
		<view style="height: 100rpx;"></view>
		<u-modal :show="paynoticeshow" content='未检测到支付结果, 您可以查看余额' @confirm="navback()" @close="paynoticeshow = false"
			@cancel="paynoticeshow = false" showCancelButton confirmText="查看余额" cancelText="取消"
			closeOnClickOverlay></u-modal>
	</view>
</template>

<script>
	let self;
	export default {
		data() {
			return {
				paynoticeshow: false,
				info: {
					recharge: {
						min_money: 0
					}
				},
				current: 0,
				items: [],
				form: {
					money: '',
					pay_type: 1,
				},
				ossdata: null,
				filelist: [],
				order_no: '',
			}
		},
		onLoad(option) {
			self = this;
			if (option && option.data) {
				self.info = JSON.parse(decodeURIComponent(option.data));
			}
		},
		onShow() {
			let options = uni.getEnterOptionsSync();
			const shop_recharge_show = uni.getStorageSync('shop_recharge_show');

			if (options.scene == '1038' &&
				options.referrerInfo.appId == 'wxef277996acc166c3' && shop_recharge_show == 1) {
				uni.setStorageSync('shop_recharge_show', 0);
				// 代表从收银台小程序返回
				let extraData = options.referrerInfo.extraData;
				if (!extraData) {
					// "当前通过物理按键返回，未接收到返参，建议自行查询交易结果";
					self.paynoticeshow = true;
				} else {
					if (extraData.code == 'success') {
						// "支付成功";
						uni.showToast({
							title: '支付成功',
							icon: 'none',
							duration: 3500
						});
						uni.navigateBack();
					} else if (extraData.code == 'cancel') {
						// "支付已取消";
						uni.showToast({
							title: '支付已取消',
							icon: 'none',
							duration: 3500
						})
					} else {
						// "支付失败：" + extraData.errmsg;
						uni.showToast({
							title: "支付失败：" + extraData.errmsg,
							icon: 'none',
							duration: 3500
						})
					}
				}
			}
		},
		methods: {
			navback(url) {
				uni.navigateBack();
			},
			getRecharge() {
				if (self.form.money < self.info.recharge.min_money) {
					uni.showToast({
						title: `最低充值${self.info.recharge.min_money}元`,
						icon: 'none'
					})
					return;
				}

				uni.showLoading({
					title: '',
					mask: true
				});
				self.$http.post('/shop/v10/wallet/recharge', self.form).then(({
					data,
					success
				}) => {
					uni.hideLoading();
					self.order_no = data.extraData.reqsn;
					uni.openEmbeddedMiniProgram({
						appId: data.appid,
						extraData: data.extraData,
						success(res) {
							// 打开成功
							uni.setStorageSync('shop_recharge_show', 1);
						}
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	.xkl-no {
		background-color: #f1f1f1;
	}

	.xkl-cur {
		background-color: #2CCE7F;
		color: #ffffff;
	}
</style>