<template>
	<view class="main">
		<view class="mcard pd5 pt5">
			<view class="form_group">
				<view class="lable">充值金额</view>
				<input type="digit" v-model="item.money" placeholder="请输入充值金额" />
			</view>
		</view>
		<view class="mcard mt10 pd0 pt5">
			<view class="form_group">
				<view class="lable">充值方式</view>
				<view class="item">
					<view class="lit" @click="item.way = 0">
						<text class="icon tb" style="color: #4caf50">&#xe620;</text>
						<view class="title">微信充值</view>
						<text class="icon check" v-if="item.way == 0">&#xe612;</text>
					</view>
					<view class="lit" @click="item.way = 1">
						<text class="icon tb" style="color: #ff9800">&#xe635;</text>
						<view class="title">转账充值</view>
						<text class="icon check" v-if="item.way == 1">&#xe612;</text>
					</view>
				</view>
			</view>
		</view>
		<view v-if="item.way == 1">
			<view class="mcard mt10 pt5">
				<view class="form_group"><view class="lable">转账信息</view></view>
				<view class="lit">
					<view class="title">{{ platform.serviceCompany }}</view>
				</view>
				<view class="lit">
					<view class="title">{{ platform.bankName }}</view>
				</view>
				<view class="lit">
					<view class="title">{{ platform.bankAccount }}</view>
				</view>
			</view>
			<view class="mcard mt10 pt5">
				<view class="form_group">
					<view class="lable">充值凭证</view>
					<images v-model="item.pic" :limit="1"></images>
				</view>
				<view class="bz">
					<text class="icon">&#xe694;</text>
					<text>例如：付款或者转账截图</text>
				</view>
			</view>
		</view>
		<button class="btn" @click="pay()">确认</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: { way: 0, pic: [] },
			platform: {}
		};
	},
	onLoad() {
		this.getPlatform();
	},
	methods: {
		//平台服务费信息
		getPlatform() {
			this.http.request({
				url: '/app/pay/getPlatform',
				success: (res) => {
					this.platform = res.data.data;
				}
			});
		},
		pay() {
			if (this.item.way == 0) {
				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();
									}
								});
							}
						});
					}
				});
			} else {
				this.item.certificate = this.item.pic[0];
				this.http.request({
					url: '/app/pay/add',
					method: 'POST',
					data: this.item,
					success: (res) => {
						uni.showModal({
							title: '提示',
							content: '提交成功，待后台审核确认',
							showCancel: false,
							success: (res) => {
								uni.$emit('payMoney');
								uni.navigateBack();
							}
						});
					}
				});
			}
		}
	}
};
</script>

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