<template>
	<view class="main">
		<view class="form_group">
			<view class="lable re">充值金额</view>
			<input type="digit" v-model="item.money" placeholder="请输入充值金额" />
		</view>
		<button class="btn" @click="pay()">确认</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {}
		};
	},
	methods: {
		pay() {
			this.http.request({
				url: '/app/wxPay/pay',
				method: 'POST',
				data: this.item,
				success: (res) => {
					wx.requestPayment({
						appId: res.data.data.appId,
						nonceStr: res.data.data.nonceStr,
						package: res.data.data.package,
						paySign: res.data.data.paySign,
						timeStamp: res.data.data.timeStamp,
						signType: res.data.data.signType,
						success: (r) => {
							uni.showModal({
								title: '提示',
								content: '充值成功：' + this.item.money + ' 元',
								showCancel: false,
								success: (res) => {
									uni.$emit('payMoney');
									uni.navigateBack();
								}
							});
						},
						fail: (r) => {
							uni.showModal({
								title: '提示',
								content: r.errMsg.includes('cancel') ? '支付取消' : '支付异常',
								showCancel: false,
								success: (res) => {
									uni.$emit('payMoney');
									uni.navigateBack();
								}
							});
						}
					});
				}
			});
		}
	}
};
</script>

<style lang="scss"></style>
