<template>
	<view style="padding-bottom: 160rpx;">
		<view class="padding">
			<view class="money">
				<view class="money-top">
					<image src="../../static/images/me/moneyBanner.png" mode=""></image>
					<view class="money-top-title">
						当前剩余金豆
					</view>
					<view class="money-top-money">
						{{formatNumber(moneyNum)}}
					</view>
				</view>
				<view @click="goNav('/me/wallet/mingxi')" class="money-bto flex align-center justify-between">
					金豆明细
					<u-icon name="arrow-right" color="#6696ff" size="40"></u-icon>
				</view>
			</view>
			<u-radio-group v-model="current" @change="radioGroupChange">
				<view v-if="wallet.length>0" style="margin-top: 20rpx;border-radius: 24rpx;"
					class=" bg flex justify-between flex-wrap padding-lr padding-bottom">
					<view @click="selectTypeClassify(index)" v-for="(item,index) in wallet" :key='index'
						class="flex radius margin-top justify-center"
						style="background: #f5f5f5;color: #000; width: 48%;padding: 30rpx 30rpx;border: 1px solid #f5f5f5;">
						<view style="font-size: 24upx;width: 100%;">
							<view class="flex align-center justify-between" style="width: 100%;font-size: 30rpx;">
								<view class="moneycz">
									<view class="moneycz-top flex align-center">
										<view class="moneycz-top-l">
											¥{{item.price}}
										</view>
										<view class="moneycz-top-r" v-if="item.giveMoney>0">
											多送{{item.giveMoney}}
										</view>
									</view>
									<view class="moneycz-bom">
										{{item.money}}金豆<text v-if="item.giveMoney>0">+{{item.giveMoney}}赠豆</text>
									</view>
								</view>
								<u-radio :name="index"></u-radio>
							</view>
						</view>
					</view>
				</view>
			</u-radio-group>
			<!-- <view class="inputMoney">
				<view class="inputMoney-box flex align-center justify-center">
					<u-input input-align="center" placeholder="请输入自定义金额" v-model="money" type="number"
						:border="false" />
				</view>
			</view> -->
			<view v-if="openLists.length>0" class="bg margin-top padding-lr radius">
				<view>
					<view class="flex align-center justify-between" style="height: 100upx;padding: 20upx 0;"
						v-for="(item,index) in openLists" :key='index' @tap='selectWay(item)'>
						<view class="flex align-center">
							<image :src="item.image" style="width: 55upx;height: 55upx;"></image>
							<view style="font-size: 30upx;margin-left: 20upx;">{{item.text}}
							</view>
						</view>

						<radio-group name="openWay" style="margin-left: 20upx;">
							<label class="tui-radio">
								<radio color="#6696FF" :checked="openWay === item.id ? true : false" />
							</label>
						</radio-group>
					</view>
				</view>
			</view>
			<!-- <view class="btn" @click="pay">确认支付</view> -->
		</view>
		<view v-if="moneyTips" class="tips flex align-center justify-center">
			<view class="tips-box">
				<view class="tips-box-title">
					温馨提示
				</view>
				<view class="tips-box-contont">
					{{moneyTips}}
				</view>
			</view>
		</view>
		<view class="illustrate flex align-center justify-center">
			<view class="illustrate-box flex align-center">
				<u-checkbox v-model="checked" shape="circle"></u-checkbox>
				<text @click="checked = !checked">
					我已经阅读并同意
				</text>
				<view @click="goXieyi()" class="illustrate-box-txt">
					《付费须知说明》
				</view>
			</view>
		</view>
		<view class="sumbit flex align-center justify-center">
			<view class="sumbit-box flex align-center justify-center">
				<!-- #ifdef MP-WEIXIN -->
				<button v-if="osName!='ios'"
					style="background: #6696FF;color: #FFFFFF;width: 100%;height: 100%;border-radius: 44rpx;"
					bindtap="getUserProfile" @tap="wxGetUserInfo">
					确认支付
				</button>
				<button v-else style="background: #6696FF;color: #FFFFFF;width: 100%;height: 100%;border-radius: 44rpx;"
					@tap="goMsg()">
					联系客服
				</button>
				<!-- #endif -->
				<!-- #ifndef MP-WEIXIN -->
				<view @tap="pay()" class="flex align-center justify-center"
					style="background: #6696FF;color: #FFFFFF;width: 100%;height: 100%;border-radius: 44rpx;">
					确认支付
				</view>
				<!-- <button style="background: #6696FF;color: #FFFFFF;width: 100%;height: 100%;border-radius: 44rpx;"
					bindtap="getUserProfile" @tap="pay()">
					确认支付
				</button> -->
				<!-- #endif -->
			</view>
		</view>
		<!-- 抖音im客服 -->
		<ttMsg />
		<!-- 关注公众号弹窗 -->
		<u-popup v-model="showAccount" width="500" mode="center" border-radius="14" closeable>
			<view class="showAccount-title">请关注公众号充值</view>
			<view class="showAccount-img">
				<image :show-menu-by-longpress="true" @click="prewImg(accountImg)" :src="accountImg" mode=""></image>
			</view>
			<view class="showAccount-txt">
				长按/点击二维码后长按识别
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: -1,
				openLists: [],
				openWay: 1,
				wallet: [],
				money: '',
				placeholder: '',
				moneyNum: 0,
				OfferID: '',
				sessionkey: '',
				payEnv: 0, //虚拟支付环境
				moneyTips: '', //充值提示
				osName: '',
				checked: false,
				ordersId: '',
				iosPayId: '',
				iapChannel: null,
				productId: '', //默认苹果内购商品ID
				productIds: ['sixzuan', 'shierzuan'], //苹果内购商品
				account: '', //公众号图片
				showAccount: false, //打开关注公众号弹窗
				accountImg: '', //公众号二维码
			}
		},
		onLoad() {
			// #ifdef MP-WEIXIN
			this.osName = uni.getSystemInfoSync().osName;
			// #endif

			this.OfferID = uni.getStorageSync('OfferID')
			this.payEnv = Number(uni.getStorageSync('payEnv'))
			this.moneyTips = uni.getStorageSync('moneyTips')
			// this.getwalletList() //获取充值列表 
			// #ifdef APP-PLUS
			if (plus.os.name.toLowerCase() === 'android') {
				this.openLists = [{
					image: '/static/images/pay/weixin.png',
					text: '微信',
					id: 2
				}, {
					image: '/static/images/pay/zhifubao.png',
					text: '支付宝',
					id: 1
				}];
				this.openWay = 2;
				let syPaySel = this.$queue.getData('syPaySel')
				if (syPaySel === '是') {
					let openListsItem = {
						image: '/static/images/pay/shouyi.png',
						text: '收益余额',
						id: 4
					};
					this.openLists.push(openListsItem)
				}
			} else {
				let checkIosPay = this.$queue.getData('checkIosPay');
				if (checkIosPay === '是') {
					this.openLists = [{
						image: '/static/images/pay/weixin.png',
						text: '苹果',
						id: 3
					}];
					this.openWay = 3;
				} else {
					this.openLists = [{
						image: '/static/images/pay/weixin.png',
						text: '微信',
						id: 2
					}, {
						image: '/static/images/pay/zhifubao.png',
						text: '支付宝',
						id: 1
					}];
					this.openWay = 2;
					let syPaySel = this.$queue.getData('syPaySel')
					if (syPaySel === '是') {
						let openListsItem = {
							image: '/static/images/pay/shouyi.png',
							text: '收益余额',
							id: 4
						};
						this.openLists.push(openListsItem)
					}
				}
			}

			// #endif

			// #ifdef MP-WEIXIN
			this.openLists = [{
				image: '/static/images/pay/weixin.png',
				text: '微信',
				id: 2
			}];
			this.openWay = 2;
			// #endif

			// #ifdef H5
			let ua = navigator.userAgent.toLowerCase();
			if (ua.indexOf('micromessenger') !== -1) {
				this.openLists = [{
					image: '/static/images/pay/weixin.png',
					text: '微信',
					id: 2
				}];
				this.openWay = 2;
			} else {
				this.openLists = [{
					image: '/static/images/pay/zhifubao.png',
					text: '支付宝',
					id: 1
				}];
				this.openWay = 1;
			}

			let syPaySel = this.$queue.getData('syPaySel')
			if (syPaySel === '是') {
				let openListsItem = {
					image: '/static/images/pay/shouyi.png',
					text: '收益余额',
					id: 4
				};
				this.openLists.push(openListsItem)
			}
			// #endif
		},
		onShow() {
			this.getAccountImg()
			this.getMoneyList()
			if (!uni.getStorageSync('token')) { //未登录下进行公众号自动登录
				this.accountLogin()
			}
			if (uni.getStorageSync('token')) {
				this.getMyMoney()
			}
		},
		methods: {
			//公众号自动登录
			accountLogin() {
				let ua = navigator.userAgent.toLowerCase();
				if (ua.indexOf('micromessenger') !== -1) {
					let openid = uni.getStorageSync('openId');
					let userId = uni.getStorageSync('userId');
					let that = this;
					if (!openid) {
						if (window.location.href.indexOf('?code=') !== -1 || window.location.href.indexOf(
								'&code=') !==
							-1) {
							let code;
							if (window.location.href.indexOf('?code=') !== -1) {
								code = window.location.href.split('?code=')[1].split('&')[0];
							} else {
								code = window.location.href.split('&code=')[1].split('&')[0];
							}
							this.$Request.get('/app/Login/getOpenId?code=' + code).then(ret => {
								uni.setStorageSync('openId', ret.data)
								this.$Request.get('/app/Login/openid/login?openId=' + ret.data).then(
									res => {
										if (res.code == 0) {
											this.$queue.setData("userId", res.user.userId);
											this.$queue.setData("token", res.token);
											uni.setStorageSync('openId', res.user.openId)
											this.getMyMoney()
										} else {
											uni.navigateTo({
												url: '/pages/login/bind'
											});
										}
									});
							});
						} else {
							window.location.href =
								'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
								that.$queue.getWxAppid() +
								'&redirect_uri=' +
								window.location.href.split('#')[0] +
								'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
						}
					} else {
						this.$Request.get('/app/Login/openid/login?openId=' + openid).then(res => {
							if (res.code == 0) {
								this.$queue.setData("userId", res.user.userId);
								this.$queue.setData("token", res.token);
								this.getMyMoney()
							} else {
								uni.navigateTo({
									url: '/pages/login/bind'
								});
							}
						});
					}
				}
			},
			//预览二维码
			prewImg(img) {
				uni.previewImage({
					urls: [img]
				})
			},
			//获取公众号二维码
			getAccountImg() {
				this.$Request.get('/app/common/type/2').then(res => {
					if (res.code == 0 && res.data) {
						this.accountImg = res.data.value
					}
				});
			},
			iphonepay() {
				let that = this
				plus.payment.getChannels((res) => {
					let channel = res.find(i => i.id === 'appleiap')
					that.iapChannel = channel ? channel : null
					that.requestOrder()
				})
			},
			requestOrder() {
				let that = this
				console.log(that.productIds)
				// ['xxxxx'] 是平台申请拿到的内购商品的id 
				that.iapChannel.requestOrder(that.productIds, function(event) {
					uni.hideLoading()
					console.log(event)
				}, function(erroemsg) {
					uni.hideLoading()
					uni.showToast({
						title: "获取支付通道失败：" + errormsg.message,
						icon: 'none'
					})
				})
			},
			async topay() {
				let that = this
				uni.showLoading({
					title: '充值中，请勿离开！',
					mask: true
				})
				let productId = that.wallet[that.current].productId ? that.wallet[that.current].productId : '';
				plus.payment.request(that.iapChannel, {
					productid: productId,
					optimize: true // 支付时设置 optimize: true  
				}, result => {
					that.getIosSaveMessage(JSON.stringify(result));
					// 支付成功回调
					// console.log("plus.payment.request-success--------------------",JSON.stringify(results));
					uni.showLoading({
						title: '查询结果中，请勿离开！',
						mask: true
					})

				}, e => {
					uni.hideLoading();
					that.$queue.showToast('支付失败');
				});
			},

			async getIosSaveMessage(receipt) {
				let that = this;
				that.$Request.postT('/app/ios/isoPayApp?receipt=' + receipt + '&ordersId=' + that.iosPayId).then(
					res => {
						uni.hideLoading();
						if (res.status == 0) {
							uni.showToast({
								title: '支付成功',
								icon: 'none',
								duration: 2000,
							})
							that.getMyMoney()
						}
					});
			},
			//去付费须知说明
			goXieyi() {
				uni.navigateTo({
					url: '/me/setting/payXieYi'
				})
			},
			selectTypeClassify(index) {
				this.current = index
			},
			goMsg() {
				let kefu = uni.getStorageSync('kefu'); // 用户端联系方式 1 手机号 2企业微信
				let kefuPhone = uni.getStorageSync('kefuPhone');
				if (kefu == 1) {
					uni.navigateTo({
						url: '/me/setting/kefu'
					})
				} else if (kefu == 3) {
					uni.makePhoneCall({
						phoneNumber: kefuPhone //仅为示例
					});
				} else if (kefu == 2) {
					// #ifdef MP-WEIXIN
					let that = this
					try {
						wx.openCustomerServiceChat({
							extInfo: {
								url: uni.getStorageSync('kefuUrl')
							},
							corpId: uni.getStorageSync('kefuAppId'),
							success(res) {},
							fail(res) {
								console.error(res)
							}
						})
					} catch (error) {
						console.error("catchcatch" + error)
						uni.showToast({
							title: '请更新至微信最新版本'
						});
					}
					// #endif
					// #ifndef MP-WEIXIN
					let url = uni.getStorageSync('kefuUrl');
					if (url.indexOf('/pages/') !== -1 || url.indexOf('/my/') !== -1) {
						uni.navigateTo({
							url
						});
					} else {
						//#ifndef H5
						uni.navigateTo({
							url: '/pages/index/webView?url=' + url
						});
						//#endif
						//#ifdef H5
						window.location.href = url;
						//#endif
					}
					// #endif
				} else if (kefu == 4) {
					this.showAccount = true //打开公众号二维码弹窗
				}
			},
			radioGroupChange() {
				this.money = this.wallet[this.current].price
			},
			/**
			 * 获取充值列表
			 */
			getMoneyList() {
				this.$Request.getT('/app/payClassify/selectPayClassifyList').then(res => {
					if (res.code == 0) {
						this.wallet = res.data
						this.productIds = [];
						res.data.forEach(d => {
							this.productIds.push(d.productId);
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			/**
			 * 获取充值列表
			 */
			// getMoneyList() {
			// 	this.$Request.get('/app/common/type/245').then(res => {
			// 		if (res.code == 0) {
			// 			let arr = []
			// 			res.data.value.split(',').map((item, index) => {
			// 				let obj = {
			// 					money: Number(item),
			// 					id: index + 1
			// 				}
			// 				arr.push(obj)
			// 			})
			// 			this.wallet = arr
			// 		}
			// 	});
			// },
			/**
			 * @param {Number} num
			 * @param 保留两位小数
			 */
			formatNumber(num) {
				// 判断是否为整数
				if (Number.isInteger(num)) {
					return num.toFixed(2);
				} else {
					return num.toFixed(2).replace(/\.?0+$/, '');
				}
			},
			/**
			 * 获取余额
			 */
			getMyMoney() {
				this.$Request.getT('/app/moneyDetails/selectUserMoney').then(res => {
					if (res.code == 0) {
						this.moneyNum = res.data.money
						// this.$Request.getT('/app/invite/selectInviteMoney').then(ret => {
						// 	if (ret.code == 0) {
						// 		if (ret.data.inviteMoney && ret.data.inviteMoney.money) {
						// 			this.moneyNum = Number(res.data.money) + Number(ret.data.inviteMoney
						// 				.money)
						// 		} else {
						// 			this.moneyNum = Number(res.data.money)
						// 		}
						// 	}
						// })
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			goChat() {
				let that = this
				// #ifdef MP-WEIXIN
				wx.openCustomerServiceChat({
					extInfo: {
						url: that.$queue.getData('kefuq')
					},
					corpId: that.$queue.getData('kefuAppidq'),
					success(res) {
						console.log(res)
					},
				})
				// #endif
				// #ifdef H5
				window.location.href = that.$queue.getData('kefuq');
				// #endif
				// #ifdef APP
				let kefu = that.$queue.getData('kefuq')
				console.log(kefu)
				plus.runtime.openURL(kefu, function(res) {});
				// #endif
			},
			input(e) {
				console.log(e)
				this.tabIndex = -1
				this.money = e
			},
			//获取充值列表 
			getwalletList() {
				this.$Request.get("/app/payClassify/selectPayClassifyList").then(res => {
					if (res.code == 0) {
						this.wallet = res.data
					}
				});
			},
			goNav(url) {
				uni.navigateTo({
					url
				})
			},
			selectWay: function(item) {
				this.openWay = item.id;
			},
			wxGetUserInfo() {
				if (this.checked == false) {
					uni.showToast({
						title: '请阅读并同意《付费须知说明》',
						icon: 'none'
					})
					return
				}
				if (this.current == -1) {
					uni.showToast({
						title: '请选择充值',
						icon: 'none'
					})
					return
				}
				let that = this
				uni.showLoading({
					title: '支付中'
				})
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes, '111111111111')
						let data = {
							code: loginRes.code
						}
						that.$Request.getT('/app/Login/wxLogin', data).then(res => {
							if (res.code == 0 && res.data) {
								that.sessionkey = res.data.session_key;
								that.pay()
							} else {
								uni.hideLoading()
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							}
						})
					}
				})
			},
			pay() {
				if (this.checked == false) {
					uni.showToast({
						title: '请阅读并同意《付费须知说明》',
						icon: 'none'
					})
					return
				}
				if (this.current == -1) {
					uni.showToast({
						title: '请选择充值',
						icon: 'none'
					})
					return
				}
				let that = this
				// #ifdef MP-TOUTIAO
				let userId = this.$queue.getData('userId');
				let data = {
					payClassifyId: this.wallet[this.current].payClassifyId,
					userId: userId
				}
				uni.showLoading({
					title: '支付中...'
				})
				this.$Request.postT('/app/dyPay/payVirtualMoney', data).then(res => {
					if (res.code == 0) {
						tt.requestOrder({
							data: JSON.stringify(res.data.data), // 请勿在前端对data做任何处理
							byteAuthorization: res.data
								.byteAuthorization, // 请勿在前端对byteAuthorization做任何处理
							success(redd) {
								console.log(JSON.stringify(redd))
								tt.getOrderPayment({
									orderId: redd.orderId,
									success(reee) {
										uni.hideLoading()
										uni.showToast({
											title: '支付成功',
											icon: 'none',
											duration: 2000,
										})
										that.getMyMoney()
									},
									fail(ee) {
										uni.hideLoading()
										console.log(ee)
										uni.showToast({
											title: '支付失败,请重试',
											icon: 'none',
											duration: 2000,
										})
									}
								});
							},
							fail(e) {
								uni.hideLoading()
								uni.showToast({
									title: '支付失败,请重试',
									icon: 'none',
									duration: 2000,
								})
								console.log(e)
							}
						});
					} else {
						uni.hideLoading()
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
				// #endif
				// #ifndef MP-TOUTIAO
				if (this.openWay == 2) {
					// #ifdef APP-PLUS
					// 微信APP支付 根据订单id获取支付信息
					this.$Request.postT("/app/wxPay/payMoney", {
						classify: 1,
						payClassifyId: this.wallet[this.current].payClassifyId,
					}).then(ret => {
						this.isCheckPay(ret.code, 'wxpay', JSON.stringify(ret.data));
					});
					// #endif

					// #ifdef MP-WEIXIN
					// 微信小程序支付
					this.$Request.postT('/app/wxPay/payMoneyOrders', {
						payClassifyId: this.wallet[this.current].payClassifyId,
						classify: 3,
					}).then(res => {
						if (res.code == 0) {
							let data = {
								sessionKey: this.sessionkey,
								signData: {
									offerId: this.OfferID, //offerId
									buyQuantity: 1, //购买数量
									env: this.payEnv, //环境配置, 0 米大师正式环境, 1 米大师沙箱环境, 默认为 0
									currencyType: 'CNY', //币种  CNY-人民币
									productId: this.wallet[this.current].wxGoodsId, //道具id
									goodsPrice: Number(this.wallet[this.current].price * 100), //价格 单位：分
									outTradeNo: res.data.orderId, //业务订单号
									attach: '' //透传数据, 发货通知时会透传给开发者
								}
							}
							this.$Request.postJson('/app/wxPay/selectSign', data).then(ret => {
								if (ret.code == 0) {
									wx.requestVirtualPayment({
										signData: JSON.stringify(data.signData),
										mode: 'short_series_goods',
										paySig: ret.data.paySig,
										signature: ret.data.signature,
										success(ree) {
											uni.hideLoading()
											uni.showToast({
												title: '支付成功'
											})
											that.getMyMoney()
										},
										fail(err) {
											console.log(err, '拉起支付失败')
											uni.hideLoading()
											uni.showToast({
												title: '支付失败，请重试',
												icon: 'none'
											})
										}
									})
								} else {
									uni.hideLoading()
									uni.showToast({
										title: ret.msg,
										icon: 'none'
									})
								}
							})
						} else {
							uni.hideLoading()
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})
					// this.$Request.postT('/app/wxPay/payMoney', {
					// 	classify: 3,
					// 	money: this.money,
					// }).then(ret => {
					// 	uni.hideLoading()
					// 	console.log(ret.data)
					// 	uni.requestPayment({
					// 		provider: 'wxpay',
					// 		timeStamp: ret.data.timestamp,
					// 		nonceStr: ret.data.noncestr,
					// 		package: ret.data.package,
					// 		signType: ret.data.signType,
					// 		paySign: ret.data.sign,
					// 		success: function(suc) {
					// 			console.log('success:' + JSON.stringify(suc));
					// 			uni.showToast({
					// 				title: '支付成功',
					// 				icon: 'success'
					// 			})
					// 			setTimeout(d => {
					// 				uni.navigateBack(1)
					// 			}, 1000);
					// 		},
					// 		fail: function(err) {
					// 			console.log('fail:' + JSON.stringify(err));
					// 			uni.showToast({
					// 				title: '支付失败',
					// 				icon: 'none'
					// 			})
					// 		}
					// 	});
					// });
					// #endif

					// #ifdef H5
					let ua = navigator.userAgent.toLowerCase();
					if (ua.indexOf('micromessenger') !== -1) {
						let data = {
							classify: 2,
							payClassifyId: this.wallet[this.current].payClassifyId,
						}
						this.$Request.postT('/app/wxPay/payMoney', data).then(res => {
							if (res.code == 0) {
								this.callPay(res.data);
							} else {
								uni.showToast({
									icon: 'none',
									title: '支付失败!'
								});
							}
						});
					}
					// #endif

				} else if (this.openWay == 1) {
					// APP支付宝支付
					// #ifdef APP
					this.$Request.postT("/app/aliPay/payMoney", {
						classify: 1,
						payClassifyId: this.wallet[this.current].payClassifyId,
					}).then(ret => {
						console.log(ret)
						this.isCheckPay(ret.code, 'alipay', ret.data);
					});
					// #endif
					// #ifdef H5
					let data = {
						classify: 2,
						payClassifyId: this.wallet[this.current].payClassifyId,
					}
					this.$Request.postT('/app/aliPay/payMoney', data).then(
						res => {
							if (res.code === 0) {
								const div = document.createElement('div')
								div.innerHTML = res.data //此处form就是后台返回接收到的数据
								document.body.appendChild(div)
								document.forms[0].submit()
							} else {
								uni.showToast({
									icon: 'none',
									title: '支付失败!'
								});
							}
						});
					// #endif
				} else if (this.openWay == 3) {
					let userId = this.$queue.getData('userId');
					let data = {
						payClassifyId: this.wallet[this.current].payClassifyId,
						userId: userId
					}
					this.$Request.postT("/app/ios/insertPayMoneyOrders", data).then(res => {
						if (res.code === 0) {
							this.iosPayId = res.data.orderId;
							this.iphonepay();
						} else {
							uni.showToast({
								icon: 'none',
								title: '支付失败!'
							});
						}
					});
				} else if (this.openWay == 4) {
					let userId = this.$queue.getData('userId');
					let data = {
						money: this.wallet[this.current].price
					}
					this.$Request.postT("/app/invite/inviteMoneyConvertUserMoney", data).then(res => {
						if (res.code === 0) {
							uni.showToast({
								icon: 'none',
								title: '支付成功'
							})
							setTimeout(function() {
								that.getMyMoney()
								uni.hideLoading();
							}, 1000);
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							});
						}
					});
				}
				// #endif

			},
			callPay: function(response) {
				if (typeof WeixinJSBridge === "undefined") {
					if (document.addEventListener) {
						document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
					} else if (document.attachEvent) {
						document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
						document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
					}
				} else {
					this.onBridgeReady(response);
				}
			},
			onBridgeReady: function(response) {
				let that = this;
				if (!response.package) {
					return;
				}
				console.log(response, '++++++++')
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest', {
						"appId": response.appid, //公众号名称，由商户传入
						"timeStamp": response.timestamp, //时间戳，自1970年以来的秒数
						"nonceStr": response.noncestr, //随机串
						"package": response.package,
						"signType": response.signType, //微信签名方式：
						"paySign": response.sign //微信签名
					},
					function(res) {
						console.log(res, '/*-/*-/*-')
						if (res.err_msg === "get_brand_wcpay_request:ok") {
							// 使用以上方式判断前端返回,微信团队郑重提示：
							//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
							uni.showLoading({
								title: '支付成功'
							});
							setTimeout(function() {
								uni.hideLoading();
							}, 1000);
						} else {
							uni.hideLoading();
						}
						WeixinJSBridge.log(response.err_msg);
					}
				);
			},
			isCheckPay(status, name, order) {
				if (status == 0) {
					this.setPayment(name, order);
				} else {
					uni.hideLoading();
					uni.showToast({
						title: '支付信息有误',
						icon: 'none'
					});
				}
			},
			setPayment(name, order) {
				console.log('*-*-*')
				uni.requestPayment({
					provider: name,
					orderInfo: order, //微信、支付宝订单数据
					success: function(res) {
						console.log(res)
						uni.hideLoading();
						uni.showLoading({
							title: '支付成功'
						});
					},
					fail: function(err) {
						console.log(err)
						uni.hideLoading();
					},
					complete() {
						uni.hideLoading();
					}
				});
			},
			// 提现
			cashMoney() {
				if (!this.moneyNum) {
					uni.showToast({
						icon: 'none',
						title: '请输入提现金额'
					})
					return
				}
				if (this.moneyNum > this.money * 1) {
					uni.showToast({
						icon: 'none',
						title: '您的余额不足'
					})
					return
				}
				// if (this.moneyNum*1+this.charge*this.moneyNum > this.money*1) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '您的手续费不足'
				// 	})
				// 	return
				// }

				let zhiFuBao = uni.getStorageSync('zhiFuBao')
				let zhiFuBaoName = uni.getStorageSync('zhiFuBaoName')

				if (!zhiFuBao && !zhiFuBaoName) {
					uni.navigateTo({
						url: '/my/wallet/zhifubao'
					})
					return
				}

				let that = this
				that.sp = (that.moneyNum * this.charge).toFixed(2)
				uni.showModal({
					title: '提示',
					content: '本次提现' + that.moneyNum + '元，服务费' + this.sp + '元，是否确认提现？',
					success: function(res) {
						if (res.confirm) {
							that.$Request.get("/app/cash/cashMoney", {
								money: that.moneyNum
							}).then(res => {
								if (res.code == 0) {
									uni.showToast({
										icon: 'none',
										title: res.msg
									})
									that.moneyNum = null
								} else {
									uni.showToast({
										icon: 'none',
										title: res.msg
									})
								}
								that.getMoney()
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	.showAccount-title {
		width: 100%;
		margin-top: 30rpx;
		text-align: center;
		font-weight: bold;
	}

	.showAccount-img {
		width: 400rpx;
		height: 400rpx;
		margin: 0 auto;
		margin-top: 20rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.showAccount-txt {
		width: 100%;
		text-align: center;
		margin-top: 20rpx;
		padding-bottom: 30rpx;
	}


	button::after {
		border: none;
		background-color: none;
	}

	button {
		display: flex;
		align-items: center;
		position: relative;
		display: block;
		margin-left: auto;
		margin-right: auto;
		padding-left: 0px;
		padding-right: 0px;
		box-sizing: border-box;
		text-decoration: none;
		line-height: 88rpx;
		overflow: hidden;
		color: #000000;
		/* background-color: #fff; */
		background: rgba(255, 255, 255, 0);
		font-size: 28rpx;
		width: 100%;
		height: 100%;
	}

	.illustrate {
		width: 100%;
		margin: 30rpx 0;

		.illustrate-box {
			width: 686rpx;
		}

		.illustrate-box-txt {
			color: #5173F8;
		}

	}

	/deep/.u-radio__label {
		display: none !important;
	}

	.moneycz {
		font-size: 24rpx;
	}

	.moneycz-top-l {
		font-size: 30rpx;
		font-weight: bold;
	}

	.moneycz-top-r {
		margin-left: 10rpx;
		background-color: #f3aa49;
		padding: 4rpx 10rpx;
		border-radius: 20rpx;
		color: #FFFFFF;
	}

	.moneycz-bom {
		margin-top: 20rpx;
	}

	.tips {
		width: 100%;
		height: auto;

		.tips-box {
			width: 686rpx;
			height: 100%;
		}

		.tips-box-title {
			width: 100%;
			font-size: 30rpx;
			color: #333333;
			font-weight: bold;
		}

		.tips-box-contont {
			margin-top: 10rpx;
			color: gray;
			text-indent: 1rem;
		}

	}

	.inputMoney {
		width: 100%;
		background-color: #FFFFFF;
		margin-top: 20rpx;
		border-radius: 24rpx;

		.inputMoney-box {
			padding: 30rpx 20rpx;
		}
	}

	.sumbit {
		width: 100%;
		height: 140rpx;
		background-color: #FFFFFF;
		position: fixed;
		bottom: 0;
		left: 0;

		.sumbit-box {
			width: 686rpx;
			height: 88rpx;
			background: #6696FF;
			border-radius: 44rpx;
			color: #FFFFFF;
			font-weight: bold;
		}
	}

	.money {
		width: 100%;
		height: 100%;
		border-radius: 32rpx;
		background-color: #FFFFFF;

		.money-top {
			width: 100%;
			height: 240rpx;
			position: relative;

			image {
				width: 100%;
				height: 100%;
				border-radius: 32rpx 32rpx 0 0;
			}

			.money-top-title {
				position: absolute;
				font-size: 32rpx;
				color: hsla(0, 0%, 100%, .9);
				top: 40rpx;
				left: 40rpx;

			}

			.money-top-money {
				position: absolute;
				font-size: 64rpx;
				font-weight: 500;
				color: #FFFFFF;
				top: 120rpx;
				left: 40rpx;
			}
		}

		.money-bto {
			width: 100%;
			height: 108rpx;
			border-radius: 0 0 32rpx 32rpx;
			padding: 0 30rpx;
			color: #2e2f33;
			font-weight: bold;
		}
	}

	.bg {
		background-color: #FFFFFF;
	}

	.title_btn {
		height: 78upx;
		line-height: 78upx;
		/* background: #f7f7f7; */
	}

	.btn {
		width: 100%;
		height: 88upx;
		background: #6696FF;
		border-radius: 44upx;
		text-align: center;
		line-height: 88upx;
		margin-top: 40upx;
		font-size: 28upx;
		color: #FFFFFF;
	}
</style>