<template>
	<view class="exchangeIntegral">
		<view class="integral">
			<view class="">
				可提现金额
			</view>
			<view class="num">
				{{integral}}
			</view>
		</view>
		<view class="applyIntegral flex">
			<view class="">
				申请提现金额
			</view>

			<input type="number" class="num" v-model="num" />
		</view>
		<view class="all" @click="all"> <text>满{{minPrice}}可提现</text><text>全部转换</text></view>
		<view class="between">

		</view>
		<view class="list" v-if="!weichatBsrowser">
			<radio-group @change="tabRadio">
				<!-- <label>
					<view class="box">
						<view class="icon iconfont iconweixin1"></view>
						<view class="title-box">
							<view class="title"><text>提现至微信</text></view>
						</view>
						<view class="right"><radio value="weixin" color="#5dbc7c" :checked="type == 'weixin'" /></view>
					</view>
				</label> -->
				<label>
					<view class="box">
						<view class="icon iconfont iconzhifubao"></view>
						<view class="title-box">
							<view class="title">
								<text v-if="aliData.fullname != null">提现至支付宝</text>
								<text v-else>请创建支付宝账号</text>
							</view>
							<view class="node">
								<text v-if="aliData.fullname != null">真实姓名({{ aliData.fullname }})</text>
							</view>
						</view>
						<view class="right">
							<radio value="alipay" style="transform:scale(0.7)" color="#5395F5"
								:checked="type == 'alipay'" />
						</view>
					</view>
				</label>
				<label>
					<view class="box">
						<view class="icon iconfont">
							<image class="icon-img" src="/static/icon/i8.png" mode="aspectFit"></image>
						</view>
						<view class="title-box">
							<view class="title">
								<text v-if="bankData.bankno != null">{{ bankData.bank + ' ' + bankData.bankno }}</text>
								<text v-else>请创建银行账号</text>
							</view>
							<view class="node">
								<text v-if="bankData.fullname != null">真实姓名({{ bankData.fullname}})</text>
							</view>
						</view>
						<view class="right">
							<radio value="bank" color="#5395F5" style="transform:scale(0.7)"
								:checked="type == 'bank'" />
						</view>
					</view>
				</label>
			</radio-group>
		</view>
		<!-- <view class="bottom">
			<view class="box">
				<view class="title">
					提现到
				</view>
				<radio-group name="">
					
				
				<view class="box-content">
					<view class="box-left">
						<view class="img">
							<image src="../../static/user/wx.png" mode=""></image>
						</view>
						<text>微信支付</text>
					</view>
					<label class="radio">
						<radio value="" style="transform:scale(0.7)" />
					</label>
				</view>
				<view class="box-content">
					<view class="box-left">
						<view class="img1 img">
							<image src="../../static/user/bank.png" mode=""></image>
						</view>
						<text>银行账户</text>
					</view>
					<label class="radio">
						<radio value="" style="transform:scale(0.7)" />
					</label>
				</view>
				</radio-group>
			</view>
			<view class="button" @click="submit">提交申请</view>
		</view> -->
		<button class="add-btn up" @click="confirm">提交申请</button>
		<button class="add-btn modified" v-if="!weichatBsrowser"
			@click="navTo('/pages/collection/collection')">账号管理</button>
	</view>
</template>

<script>
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	import {
		extractCash,
		extractBank,
		aliInfo,
		bankInfo
	} from '@/api/wallet.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
		},
		data() {
			return {
				type: 'alipay', //提现方式
				integral: '', //可提现金额
				num: '', //提现金额
				withdrawal: '', //提现金额
				minPrice: 1000, //最少提现金额
				aliData: {
					fullname: '',
					alino: ''
				},
				bankData: {
					fullname: '',
					bank: '',
					bankno: ''
				},
				// #ifdef H5
				weichatBsrowser: false
				// #endif
			}
		},
		onShow() {
			this.weichatBsrowser = uni.getStorageSync('weichatBsrowser')
			//加载提现金额信息
			this.loadData();
			//拿到用户的提现方式信息
			this.aliData.fullname = this.userInfo.alipay_name;
			console.log(this.userInfo);
			this.aliData.alino = this.userInfo.alipay_code;
			this.bankData.fullname = this.userInfo.bank_user_name;
			this.bankData.bank = this.userInfo.bank_name;
			this.bankData.bankno = this.userInfo.bank_code;
		
	},
	methods: {
		//提交带提现接口
		confirm(){
			//需要给到提现接口的信息
			let data = {
				extract_type: this.type, //bank -银行卡 alipay-支付宝 weixin-微信
				money: this.withdrawal, //金额
				money_type: "brokerage" //0佣金1余额
			}
			console.log(data);
			if(this.type == 'alipay'){
				data.name = this.aliData.fullName;
				data.alipay_code = this.aliData.alino;
			}
			if (this.type == 'bank') {
				data.name = this.bankData.fullname;
				data.bankname = this.bankData.bank;
				data.cardnum = this.bankData.bankno;
			}
			extractCash(data).then(
			e=>{
				console.log(data,'111111111')
				uni.navigateTo({
					url:'/pages/money/success?type=1'
				})
			}).catch(e=>{
				console.log()
			})
		},
			//加载余额信息
			async loadData() {
				extractBank({}).then(({
					data
				}) => {
					console.log(data, '余额');
					this.integral = data.brokerage_price //可提现金额
					this.minPrice = data.minPrice //最小提现金额
					this.num = data.commissionCount //提现金额
				})

			},
			navTo(url) {
				uni.navigateTo({
					url
				})
			},
			all() {
				this.num = this.integral
			},
			//切换选中对象
			tabRadio(e) {
				console.log(e, '选中方式')
				//type 提现方式  
				this.type = e.detail.value
			}
			// submit() {
			// 	if(this.integral < this.num) {
			// 		this.all()
			// 	}
			// }
		},
		// watch: {
		// 	num() {
		// 		if(this.integral < this.num) {
		// 			this.all()
		// 		}
		// 	}
		// }
	}
</script>

<style lang="scss" scoped>
	page,
	.exchangeIntegral {
		background-color: #FFFFFF;
		height: 100%;

		.integral,
		.applyIntegral {
			display: flex;
			justify-content: space-between;
			padding: 30rpx;
			background-color: #FFFFFF;
			margin-bottom: 5rpx;
			font-size: 30rpx;

			.num {
				font-size: 40rpx;
				text-align: right;
				max-width: 400rpx;
			}
		}

		.between {
			width: 100%;
			height: 20rpx;
			background-color: #F7F7F7
		}

		.all {
			display: flex;
			justify-content: space-between;
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			margin-top: 2rpx;
			background-color: #fff;
			padding: 0 30rpx;
			margin-bottom: 20rpx;

			text:nth-child(1) {

				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;

			}

			text:nth-child(2) {
				font-size: 26rpx;
				font-family: SourceHanSansCN;
				font-weight: 400;
				color: #438BED;

			}
		}

		.bottom {
			width: 750rpx;


			background: #FFFFFF;
			padding: 20rpx;

			.box {
				margin-bottom: 120rpx;
				display: flex;
				flex-direction: column;

				.title {
					display: flex;
					margin-bottom: 10rpx;
					font-size: 30rpx;
					font-family: SourceHanSansCN;
					font-weight: 400;
					color: #333333;
				}

				.box-content {
					padding: 20rpx;
					border-bottom: 1rpx solid #E6E6E6;

					display: flex;
					justify-content: space-between;

					.box-left {
						display: flex;

						.img {

							width: 40rpx;
							height: 40rpx;

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

						text {
							margin-left: 30rpx;
							font-size: 26rpx;
							font-family: SourceHanSansCN;
							font-weight: 400;
							color: #515151;
						}
					}

					.radio {
						width: 20rpx;
						height: 20rpx;

						radio {

							width: 20rpx;
							height: 20rpx;
						}

					}
				}
			}
		}

		// .img1{
		// 	width: 40rpx;
		// 	height: 30rpx;
		// 	image{
		// 		width: 100%;
		// 		height: 100%;
		// 	}
		// }
		.button {

			background: linear-gradient(90deg, #3C82E6, #5395F5);
			color: #fff;
			width: 670rpx;
			padding: 20rpx;
			font-size: 30rpx;
			border-radius: 10rpx;
			text-align: center;
			margin: 0 auto;
		}
	}

	.list {
		padding-left: 30rpx;
		margin-top: 30rpx;
		background-color: #ffffff;

		.box {
			display: flex;
			align-items: center;
			width: 100%;
			height: 120rpx;
			border-bottom: 1px solid $border-color-light;

			.icon {
				font-size: 48rpx;
				padding-right: 20rpx;

				.icon-img {
					height: 50rpx;
					width: 50rpx;
				}
			}

			.iconweixin1 {
				color: #18bf16;
			}

			.iconzhifubao {
				color: #08aaec;
			}

			.title-box {
				flex-grow: 1;
				text-align: left;

				.title {
					font-size: $font-base + 2rpx;
					color: $font-color-base;
				}

				.node {
					font-size: $font-sm;
					color: $font-color-light;
				}
			}
		}
	}

	.add-btn {
		&.modified {
			color:  #5395F5;
		}

		&.up {
			background: linear-gradient(90deg, #3C82E6, #5395F5);
			color: #fff;
		}

		display: flex;
		align-items: center;
		justify-content: center;
		width: 690rpx;
		height: 80rpx;
		margin: 0 auto;
		margin-top: 30rpx;
		font-size: $font-lg;
		border-radius: 10rpx;
		// box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
</style>
