<template>
	<view class="content">

		<headers :titles="titles"><u-icon name="arrow-left" color="#fff" size="22"></u-icon></headers>
		<!-- <view class="top-box">
			<view class="inputbox">
				<u-icon name="search" size="20"></u-icon>
				<input type="text" />
			</view>
			<u-icon name="scan" color="#fff" size="38"></u-icon>
		</view> -->
		<view class="box_">
			<view class="leftbox" @click="goChooseUser()">
				<view class="title_">会员信息</view>
				<view v-if="!isChooseUser">
					请选择会员
				</view>
				<view v-if="isChooseUser">
					<view class="d-s">
						<view class="hui">会员名称:</view>
						<view class="hei">{{userInfo.name}}</view>
					</view>
					<view class="d-s">
						<view class="hui">手机号:</view>
						<view class="hei">{{userInfo.mobile}}</view>
					</view>
					<view class="d-s">
						<view class="hui">账户余额:</view>
						<view class="hei">{{userInfo.cardBalance}}元</view>
					</view>
				</view>
			</view>


			<view class="rightbox">
				<image src="../../static/imgs/av.png" mode=""></image>
			</view>
		</view>
		<view class="d-bs">
			<view class="title_h">充值面额</view>
			<!-- <view class="title_lan">充值记录</view> -->
		</view>
		<view class="wrap-box">
			<view class="w-box" v-for="(item,index) in numList " :key="index" @click="getindex(index,item)">
				<view class="hezi" :class="{ 'acv' : listindex == index }">
					{{item.rechargeBalance}}元
				</view>
			</view>
			<view class="w-box" @click="getindex(numList.length,null)">
				<view class="hezi" :class="{ 'acv' : listindex == numList.length }">
					<!-- 自定义金额 -->
					<input placeholder="自定义金额" v-model="value" @input="custom()"></input>
				</view>
			</view>
		</view>
		<view class="bai-box">
			<view class="h-box">
				<view class="h-ds">
					<view class="icon-img">
						<image src="../../static/imgs/wx.png" mode=""></image>
					</view>
					<view class="">微信扫码支付</view>
				</view>

				<view class="qiu" v-if="memberId != 0" @click="getmemberId(0,'WECHAT')"></view>
				<view class="qiux" v-if="memberId == 0">
					<u-icon name="checkmark" color="#fff" size="16"></u-icon>
				</view>
			</view>
			<view class="h-box">
				<view class="h-ds">
					<view class="icon-img">
						<image src="../../static/imgs/zfb.png" mode=""></image>
					</view>
					<view class="">支付宝扫码支付</view>
				</view>

				<view class="qiu" v-if="memberId != 1" @click="getmemberId(1,'ALIPAY')"></view>
				<view class="qiux" v-if="memberId == 1">
					<u-icon name="checkmark" color="#fff" size="16"></u-icon>
				</view>
			</view>
			<view class="h-box">
				<view class="h-ds">
					<view class="icon-img">
						<image src="../../static/imgs/yl.png" mode=""></image>
					</view>
					<view class="">银联扫码支付</view>
				</view>

				<view class="qiu" v-if="memberId != 2" @click="getmemberId(2,'UNIONPAY')"></view>
				<view class="qiux" v-if="memberId == 2">
					<u-icon name="checkmark" color="#fff" size="16"></u-icon>
				</view>
			</view>
			<view class="h-box">
				<view class="h-ds">
					<view class="icon-img">
						<image src="../../static/imgs/xjzf.png" mode=""></image>
					</view>
					<view class="">现金支付</view>
				</view>

				<view class="qiu" v-if="memberId != 3" @click="getmemberId(3,'CASH')"></view>
				<view class="qiux" v-if="memberId == 3">
					<u-icon name="checkmark" color="#fff" size="16"></u-icon>
				</view>
			</view>
		</view>
		<view class="bottom-b"></view>
		<view class="p-bottom" @click="scanQrcode()">
			<view class="anniu">
				确认支付
			</view>
		</view>
	</view>
</template>

<script>
	import request from "../../utils/request";
	import headers from '../../components/header/headers.vue'

	export default {
		data() {
			return {
				titles: "会员充值",
				listindex: 0,
				memberId: 0,
				numList: [
					// "50元",
					// "100元",
					// "300元",
					// "500元",
					// "1000元",
					"自定义金额",
				],
				isChooseUser: false,
				userId: "",
				userInfo: "",
				order: {
					paymentType: "WECHAT"
				},
				value: "",
				realyPayBills: 0,
				authCode: "",
			}
		},
		onLoad(e) {
			this.userId = e.userId
			if (e.userId) {
				this.isChooseUser = true
				this.getUser()
			}
		},
		onShow() {
			// this.actList = ["1", "1", "1", "1", "1", ]
			// this.status = "nomore" 底部刷新结束
			this.getRechargeAmount()
		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		components: {
			headers
		},
		methods: {
			// 自定义金额
			custom() {


				if (this.numList.length > 0) {
					// const changeList = this.cardValueList
					this.numList.forEach(change => {
						if (data >= change.rechargeBalance) {
							this.order.points = change.points
							this.order.bidBalance = change.bidBalance
							this.order.giftBalance = change.giftBalance
							this.order.growthValue = change.growthValue
							this.order.rechargeBalance = change.rechargeBalance

							this.order.royaltyType = change.royaltyType
							this.order.percentageCommissions = change.percentageCommissions
							this.order.amountCommission = change.amountCommission
							this.order.cardValueId = change.id
						}
					})
				}


				this.order.rechargType = 1

				console.log(this.value);
				this.order.amount = this.value
				this.realyPayBills = this.order.amount
				this.order.rechargeBalance = this.order.amount
			},
			// 获取充值金额列表
			getRechargeAmount() {
				request({
					url: 'business/marketingActivity/cardFuelDiesel',
					method: 'get',
					params: {
						pageNo: 1,
						pageSize: 10000
					}
				}).then((res) => {
					this.numList = res.data.records
					this.numList.sort((a, b) => a.rechargeBalance - b.rechargeBalance);

					this.order.amount = this.numList[0].rechargeBalance
					this.order.rechargeBalance = this.numList[0].rechargeBalance
					this.order.points = this.numList[0].points
					this.realyPayBills = this.numList[0].rechargeBalance


					this.order.bidBalance = this.numList[0].bidBalance
					this.order.points = this.numList[0].points
					this.order.giftBalance = this.numList[0].giftBalance
					this.order.growthValue = this.numList[0].growthValue
					this.order.cardValueId = this.numList[0].id
					// this.order.amount = null
					this.order.royaltyType = this.numList[0].royaltyType
					this.order.rechargType = 0
					this.order.percentageCommissions = this.numList[0].percentageCommissions
					this.order.amountCommission = this.numList[0].amountCommission

				})
			},
			getmemberId(num, payType) {
				this.memberId = num
				this.order.paymentType = payType
			},
			// 获取用户信息
			getUser() {
				request({
					url: '/business/userManager/user/' + this.userId,
					method: 'get',
				}).then((res) => {
					this.userInfo = res.data
				})
			},
			goChooseUser() {
				uni.navigateTo({
					url: "/pagesHome/searchVip/searchVip?type=1"
				})
			},
			getindex(index, data) {
				this.listindex = index
				this.order.rechargType = 0
				if (data) {
					this.order.amount = data.rechargeBalance
					this.order.rechargeBalance = data.rechargeBalance
					this.order.points = data.points
					this.realyPayBills = data.rechargeBalance

					this.order.bidBalance = file.bidBalance
					this.order.points = file.points
					this.order.giftBalance = file.giftBalance
					this.order.growthValue = file.growthValue
					this.order.cardValueId = file.id
					// this.order.amount = null
					this.order.royaltyType = file.royaltyType
					this.order.percentageCommissions = file.percentageCommissions
					this.order.amountCommission = file.amountCommission


				} else {
					this.order.amount = this.value
					this.realyPayBills = this.value
					this.order.rechargeBalance = this.value
				}
			},
			// 二维码
			scanQrcode() {
				if (!this.userInfo) {
					uni.showToast({
						title: "请先选择会员",
						icon: "none"
					})
					return;
				}
				if (!this.order.amount) {
					uni.showToast({
						title: "请先选择充值金额",
						icon: "none"
					})
					return;
				}
				if (this.order.paymentType == "CASH") {
					this.authCode = this.order.amount
					this.govipjs()
				} else {
					let _this = this
					uni.scanCode({
						onlyFromCamera: true,
						success: (res) => {
							console.log('扫描二维码成功,结果:' + JSON.stringify(res) + res.result);
							_this.authCode = res.result
							_this.govipjs()
						},
						error: (res) => {
							console.log('扫描二维码出现错误')
						}
					})
				}
			},
			govipjs() {
				let actualPayment = 0
				if (this.order.paymentType == "CASH") actualPayment = this.authCode
				// 会员id  会员名字会员手机号码
				this.order.mtUserId = this.userInfo.id
				this.order.name = this.userInfo.name
				this.order.mobile = this.userInfo.mobile
				// 支付码
				this.order.authCode = this.authCode
				this.order.realyPayBills = this.realyPayBills
				this.order.actualPayment = actualPayment
				this.order.payChannel = "POS"
				this.order.terminal = "POS"
				// cardValueId

				// growthValue
				// rechargeType	
				// royaltyType
				this.order.makeChange = 0
				// url: 'business/marketingActivi	ty/cardFuelRecord/prepaidFuelTopUp',
				request({
					url: 'business/marketingActivity/cardValueRecord/prepaidCardTopUp',
					method: 'post',
					data: this.order
				}).then((res) => {
					uni.navigateTo({
						url: '/pagesHome/PaymentResults/PaymentResults?type=1&orderNo=' + res.data
							.paymentNo
					})
				})

			},
			goback() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #0864e9;
		// background: linear-gradient(180deg, #B2D2FC 0%, #B2D2FC 14%, rgba(255, 255, 255, 0.84) 24%, rgba(255, 255, 255, 0.84) 100%);
		height: 30vh;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.container {
		width: 100%;
		background: #f4f5f6;

	}

	.top-box {
		width: 95%;
		margin: 15px auto;

		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.inputbox {
		width: 90%;
		background: #fff;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 5px 15px;
		border-radius: 50px;
	}

	.box_ {
		width: 95%;
		border-radius: 8px;
		height: 154px;
		background: #fff;
		margin: 15px auto;
		border: 1px solid #0864e9;
		box-sizing: border-box;
		padding: 15px;
		display: flex;

		justify-content: space-between;
		position: relative;
		overflow: hidden;

	}

	.d-s {
		display: flex;
		align-items: center;
		margin-bottom: 10px;
	}

	.title_ {
		font-weight: bold;
		font-size: 16px;
		color: #0864E9;
		margin-bottom: 10px;
	}

	.leftbox {
		width: 50%;
	}

	.rightbox {
		position: absolute;
		right: 0px;
		bottom: 0px;

		image {
			width: 145px;
			height: 130px;
		}
	}

	.hui {
		font-weight: 500;
		font-size: 14px;
		color: #333333;
		margin-right: 5px;
	}

	.hei {
		font-weight: bold;
		font-size: 14px;
		color: #333333;
	}

	.bottom-b {
		width: 100%;
		height: 68px;
	}

	.p-bottom {
		width: 100%;
		height: 68px;
		background: #fff;
		position: fixed;
		bottom: 0px;
		left: 0px;
	}

	.anniu {
		height: 40px;
		background: #0864E9;
		width: 80%;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		border-radius: 50px;
		margin: 5px auto;
	}

	.d-bs {
		width: 90%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 5px auto;
	}

	.wrap-box {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
	}

	.title_h {
		color: #333333;
		font-weight: bold;
	}

	.title_lan {
		font-weight: 500;
		font-size: 16px;
		color: #0864E9;
	}

	.w-box {
		width: 33.3%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.hezi {
		width: 100px;
		height: 70px;
		background: #f8f8f8;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 6px;
		overflow: hidden;
		margin: 10px auto;
	}

	.acv {
		background: #0864E9 !important;
		color: #fff !important;
	}

	.bai-box {
		width: 90%;
		margin: 15px auto;

	}

	.h-box {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 15px auto;
	}

	.h-ds {
		display: flex;
		align-items: center;
	}

	.icon-img {
		width: 30px;
		height: 30px;
		margin-right: 10px;

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

	.qiu {
		width: 16px;
		height: 16px;
		border-radius: 50%;
		border: 1px solid #333333;
	}

	.qiux {
		width: 16px;
		height: 16px;
		border-radius: 50%;
		border: 1px solid #0864e9;
		background: #0864e9;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
	}
</style>