<template>
	<view class="content">
		<!-- <uni-notice-bar v-if="case_fee !=0" single="true" :text="'提现收取'+case_fee+'%手续费'"></uni-notice-bar> -->
		<view class="content-money">
			<view class="flex ">
				<view class="buttom">
					<view class="icon">{{ money | getMoneyStyle }}</view>
					<text class="text">可提现金额</text>
				</view>
				<!-- <view class="interval"></view>
				<view class="buttom">
					<view class=" icon">{{ freeze | getMoneyStyle }}</view>
					<text class="text">待审核提现金额</text>
				</view> -->
			</view>
		</view>
		
	<!-- 	<view class="row-box" v-if="case_fee !=0">
			<view class="title">实际到账金额</view>
			<view class="row">
				<text class="tit">￥</text>
				<input class="input" type="number" v-model="realmoney"  disabled="true"  placeholder="实际到账" placeholder-class="placeholder" />
			</view>
		</view> -->
		<!-- <view class="list_row b-b">
			<text class="tit">手机号</text>
			<input class="input"  v-model="account" type="text" placeholder="请输入手机号" placeholder-class="placeholder" />
		</view>
		<view class="list_row b-b">
			<text class="tit">验证码</text>
			<input class="input" v-model="captcha" type="text" placeholder="请填写验证码" placeholder-class="placeholder" />
			<view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
		</view> -->
		<view class="list">
			<radio-group @change="tabRadio">
				<label>
					<view class="box">
						<view class="icon"><image class="icon-img" src="../../static/spend/img-weixin.png" mode="aspectFit"></image></view>
						<view class="title-box flex-start">
							<view class="title">
								<text v-if="aliData.fullname">微信</text>
								<text v-else>请创建微信账号</text>
							</view>
							<view class="node">
								<text v-if="weixinData.fullname">（微信号：{{weixinData.fullname}})</text>
							</view>
						</view>
						<view class="right"><radio class="radio" value="weixin"  color="#FA2740" :checked="type == 'weixin'" /></view>
					</view>
				</label>
				<label>
					<view class="box">
						<view class="icon iconfont iconzhifubao"></view>
						<view class="title-box flex-start">
							<view class="title">
								<text v-if="aliData.fullname">支付宝</text>
								<text v-else>请创建支付宝账号</text>
							</view>
							<view class="node">
								<text v-if="aliData.fullname">（账号：{{aliData.fullname}})</text>
							</view>
						</view>
						<view class="right"><radio class="radio" value="alipay" color="#FA2740" :checked="type == 'alipay'" /></view>
					</view>
				</label>
				<label>
					<view class="box">
						<view class="icon"><image class="icon-img" src="/static/img/img31.jpg" mode="aspectFit"></image></view>
						<view class="title-box">
							<view class="title">
								<text v-if="bankData.bankno">{{ bankData.bank + ' ' + bankData.bankno }}</text>
								<text v-else>请创建银行账号</text>
							</view>
							<view class="node">
								<text v-if="bankData.fullname">（卡号：{{bankData.fullname}}）</text>
							</view>
						</view>
						<view class="right"><radio class="radio" value="bank" color="#FA2740" :checked="type == 'bank'" /></view>
					</view>
				</label>
			</radio-group>
		</view>
		<view class="row-box">
			<view class="title">提现金额</view>
			<view class="row">
				<text class="tit">￥</text>
				<input class="input" type="number" v-model="withdrawal"  @blur="bindTextAreaBlur" :placeholder="'最低提现金额' + minPrice + '元'" placeholder-class="placeholder" />
				<view class="buttom" @click="withdrawal = money">全部提现</view>
			</view>
		</view>
		<button class="add-btn up" @click="confirm">提交申请</button>
		<!-- <button class="add-btn modified" @click="navTo('/pages/wallet/account')">账号管理</button> -->
	</view>
</template>

<script>
import { getMoneyStyle } from '@/utils/rocessor.js';
import { mapState } from 'vuex';
import { verify } from '@/api/login.js';
import { extractCash, extractBank, aliInfo, bankInfo } from '@/api/wallet.js';
import uniNoticeBar from '@/components/uni-notice-bar/uni-notice-bar.vue';
export default {
	filters: {
		getMoneyStyle
	},
	components: {
		uniNoticeBar
	},
	data() {
		return {
			time: '', //保存倒计时对象
			type: 'alipay', //提现方式
			money: '0.00', //可提现金额
			freeze: '0.0', //冻结金额
			withdrawal: '', //提现金额
			minPrice: '', //最少提现金额
			case_fee:'',//提现手续费
			aliData: {
				/* fullname:'45214mjj@qq.com', */
			},
			bankData:{
				/* fullname:'6228 8458 458', */
			},
			weixinData:{
				/* fullname:'6228lsd', */
			},
			countDown: 0, //倒计时
			account:'',//手机号
			captcha:'',//验证码
			realmoney:'0.00',//实际到账金额
			// #ifdef H5
			weichatBsrowser: false
			// #endif
		};
	},
	onLoad(options) {
		// #ifdef H5
		this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
		// #endif
		//加载提现信息
		this.loadData();
		// 加载提款账号信息
		this.loadAli();
		this.loadBank();
	},
	watch: {
		// 监听倒计时
		countDown(i) {
			if (i == 0) {
				clearInterval(this.time);
			}
		}
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		//发送验证码
		verification() {
			let obj = this;
			if (this.account == '') {
				this.$api.msg('请输入电话号码');
				return;
			}
			if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.account)) {
				this.$api.msg('请输入正确的手机号');
				return;
			}
			// 判断是否在倒计时
			if (obj.countDown > 0) {
				return false;
			} else {
				obj.countDown = 60;
				obj.time = setInterval(() => {
					obj.countDown--;
				}, 1000);
				//调用验证码接口
				verify({
					phone: obj.account,
					type: 'BDING_CODE'
				})
					.then(({ data }) => {})
					.catch(err => {
						console.log(err);
					});
			}
		},
		//失去焦点，实际到账金额
		bindTextAreaBlur(event){
			let obj = this;
			if(obj.case_fee == 0){
				return;
			}
			if(eval(event.detail.value) > obj.money){
				obj.$api.msg('提现金额不足');
				obj.realmoney = '0.00';
				return;
			}
			if(eval(event.detail.value) < obj.minPrice){
				obj.$api.msg('最小提现金额为'+obj.minPrice);
				obj.realmoney = '0.00';
				return;
			}
			let case_fee = (100 - obj.case_fee)/100;
			obj.realmoney = (event.detail.value * case_fee).toFixed(2);
		},
		// 更新数据
		dataUp(){
			this.loadAli();
			this.loadBank();
			this.loadData();
		},
		//加载数据
		async loadAli(source) {
			aliInfo({}).then(e => {
				this.aliData = e.data;
			});
		},
		// 加载银行卡信息
		async loadBank() {
			bankInfo({}).then(e => {
				this.bankData = e.data;
			});
		},
		// 加载余额信息
		async loadData() {
			extractBank({}).then(({ data }) => {
				console.log(data,'100');
				this.money = data.commissionCount;//可提现余额
				this.minPrice = data.minPrice;//最小提现
				this.freeze =data.Cashin;//提现中的余额
				this.case_fee = data.case_fee;//提现手续费
				if(this.userInfo.phone == ''){
					this.account = ''
				}else{
					this.account = this.userInfo.phone;
				}
				
			});
		},
		// 跳转
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		// 切换选中对象
		tabRadio(e) {
			this.type = e.detail.value;
		},
		// 提交
		confirm() {
			let data = {
				extract_type: this.type, //bank -银行卡 alipay-支付宝 weixin-微信
				money: this.withdrawal, //金额
				money_type: 0,//0佣金1余额
				captcha:this.captcha,
				phone:this.account,
			}
			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 => {
					uni.showToast({
						title: '提交成功',
						duration: 2000,
						position: 'top',
						icon:"none"
					});
					this.dataUp();
				})
				.catch(e => {
					this.dataUp();
					console.log();
				});
		}
	}
};
</script>

<style lang="scss">
page {
	height: 100%;
}
.content{
	padding-bottom: 25rpx;
}
.content-money {
	margin: 20rpx 0;
	padding: 20rpx 0;
	background: #ffffff;
}
.flex {
	background-color: #ffffff;
	text-align: center;
	margin: 0 30rpx;
	border-radius: $border-radius-sm;
	.buttom {
		flex:1;
		font-size: $font-lg;
		width: 50%;
	}
	.interval {
		width: 2px;
		height: 60rpx;
		background-color: #eeeeee;
	}
	.icon {
		background-size: 100%;
		font-size: 42rpx;
		color: $font-color-dark;
		font-weight: bold;
		background-repeat: no-repeat;
		background-position: center;
	}
	.text {
		font-size: 28rpx;
		color: #666666;
	}
}

.list_row{
	display: flex;
	align-items: center;
	position: relative;
	padding: 0 30rpx;
	height: 110rpx;
	background: #fff;
	.tit {
		flex-shrink: 0;
		width: 120rpx;
		font-size: 30rpx;
		color: $font-color-dark;
	}
	.input {
		flex: 1;
		font-size: 30rpx;
		color: $font-color-dark;
	}
	.code {
		color: #5dbc7c;
		font-size: 23rpx;
		border-left: 1px solid #eeeeee;
		width: 150rpx;
		flex-shrink: 0;
		text-align: center;
	}
	.iconlocation {
		font-size: 36rpx;
		color: $font-color-light;
	}
}
.row-box {
	margin: 20rpx 0rpx;
	padding: 20rpx 30rpx;
	background: #fff;
	.title {
		font-size: $font-base + 2rpx;
		color: $font-color-dark;
	}
	.row {
		display: flex;
		align-items: center;
		position: relative;
		height: 80rpx;
		.tit {
			flex-shrink: 0;
			width: 40rpx;
			font-size: 30rpx;
			color: $font-color-dark;
		}
		.input {
			flex: 1;
			font-size: 30rpx;
			color: $font-color-dark;
		}
		.iconlocation {
			font-size: 36rpx;
			color: $font-color-light;
		}

		.buttom {
			color: $font-color-spec;
			font-size: $font-base;
		}
	}
}
.add-btn {
	&.modified {
		color: $base-color;
	}
	&.up {
		
		background:linear-gradient(0deg,#fa2740,#fe5544);
		color: #fff;
	}
	display: flex;
	align-items: center;
	justify-content: center;
	width: 560rpx;
	height: 80rpx;
	margin: 0 auto;
	margin-top: 60rpx;
	font-size: $font-lg;
	border-radius: 40rpx;
	// box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
}

.list {
	padding-left: 30rpx;
	margin-top: 20rpx;
	background-color: #ffffff;
	.box {
		display: flex;
		align-items: center;
		width: 100%;
		height: 120rpx;
		border-bottom: 1px solid $border-color-light;
		.box-weixin{
			
		}
		.icon {
			height: 45rpx;
			width: 45rpx;
			
			font-size: 42rpx;
			margin-right: 20rpx;
			.icon-img {
				height: 45rpx;
				width: 45rpx;
			}
		}
		.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;
			}
		}
		.right{
			margin-right: 15rpx;
		}
		.radio{
			transform: scale(0.75);
		}
	}
}
</style>
