<template>
	<view
		style="--view-theme: rgb(32, 177, 40);--view-priceColor:#FF7600;--view-minorColor:rgba(108, 198, 94, 0.5);--view-minorColorT:rgba(66, 202, 77, 0.1);--view-bntColor:#FE960F;--view-gradient:#4DEA4D">
		<view class='cash-withdrawal'>
			<!-- #ifdef MP -->
			<view class="accountTitle">
				<view :style="{height:getHeight.barTop+'px'}"></view>
				<view class="sysTitle acea-row row-center-wrapper" :style="{height:getHeight.barHeight+'px'}">
					<text class="iconfont icon-ic_leftarrow" @click="goarrow"></text>
				</view>
			</view>
			<view :style="{height:(getHeight.barTop+getHeight.barHeight)+'px'}"></view>
			<!-- #endif -->
			<view class="header">
				<view class="headerCon">
					<navigator url="/pageQuota/balanceDetail/index?type=2" hover-class="navigator-hover">
						<view class="money">{{userInfo.now_money}}</view>
						<view>可提现金额</view>
					</navigator>
				</view>
			</view>
			<view class='wrapper'>
				<view>
					<form @submit="subCash">
						<view class="list">
							<view class="itemCon">
								<view class='item acea-row row-between-wrapper'>
									<view class='name'>提现</view>
									<view class='input acea-row row-between-wrapper'>
										<input :value='cashVal' :maxlength="moneyMaxLeng"
											:placeholder='"最低提现金额：¥"+minPrice' placeholder-class='placeholder'
											name="money" type='digit'></input>
										<view class="all" @click="allCash">全部提现</view>
									</view>
								</view>
							</view>
							<view class='tip'>
								<navigator url="/pages/user_cash/list" hover-class="navigator-hover">

									当前可提现金额: <text class="price">￥{{userInfo.now_money}}</text>

									<text>查看提现记录</text>
								</navigator>

							</view>
							<view class='tip'>
								本月已提现金额:<text class="num">￥{{userInfo.extract_price}}</text>
							</view>
							<view class='tip'>
								说明: <text class="num">{{userInfo.notes}}</text>
							</view>
						</view>
						<button formType="submit"
							style="margin-top: 15rpx;color: white; background-color: rgb(32, 177, 40); border-color: rgb(32, 177, 40); border-width: 1px; border-style: solid;">立即提现</button>
					</form>
				</view>
			</view>
		</view>
		<!-- #ifdef MP -->
		<authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
		<!-- #endif -->

			<up-modal :show="IDCardShow" title="提现信息补充" showCancelButton @cancel="IDCardShow=false" @confirm="UpdateCard()">
				<up-form labelPosition="left">
					<up-form-item label="姓名:" label-width="80px">
						<up-input v-model="real_name" border="none" placeholder="请输入对应的真实姓名"></up-input>
					</up-form-item>
					<up-form-item label="电话:" label-width="80px">
						<up-input v-model="mobile" border="none" disabled></up-input>
					</up-form-item>
					<up-form-item label="身份证号:" label-width="80px">
						<up-input v-model="id_card" border="none" placeholder="请输入身份证号"></up-input>
					</up-form-item>
				</up-form>
			</up-modal>
	</view>
</template>

<script>
	import {
		getCashInfoApi,
		CashApplicationApi,
		getCashRecordApi,
		UpdateIdCardApi
	} from "@/api/user.js"
	// import {
	// 	extractCash,
	// } from '@/api/user.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		components: {},
		data() {
			return {
				// #ifdef MP
				getHeight: this.getWXStatusHeight(),
				// #endif
				index: 0,
				minPrice: 1.00, //最低提现金额
				userInfo: [],
				prevent: true, //避免重复提交成功多次
				moneyMaxLeng: 8,
				withdraw_fee: '0',
				true_money: 0,
				cashVal: '',
				IDCardShow: false,
				id_card:'',
				real_name:'',
				mobile:''
			};
		},
		computed: {
			...mapGetters(['isLogin']),
			disabled() {
				return true
			}
		},
		onLoad() {},
		onShow() {
			getCashInfoApi().then(res => {
				this.userInfo = res.data;
				this.mobile=res.data.mobile;
				this.real_name=res.data.real_name;
			})
		},
		methods: {
			goarrow() {
				uni.navigateBack()
			},
			allCash() {
				this.cashVal = '';
				this.$nextTick(() => {
					this.cashVal = this.userInfo.now_money;
				})
			},
			// 计算头部自定义导航高度；
			getWXStatusHeight() {
				// 获取距上
				const barTop = uni.getSystemInfoSync().statusBarHeight;
				// #ifdef MP
				// 获取胶囊按钮位置信息
				const menuButtonInfo = wx.getMenuButtonBoundingClientRect() || 0
				// 获取导航栏高度
				const barHeight = menuButtonInfo.height + (menuButtonInfo.top - barTop) * 2
				let barWidth = menuButtonInfo.width
				// #endif
				// #ifndef MP
				// 获取导航栏高度
				const barHeight = parseInt(barTop) + 10;
				let barWidth = '100%'
				// #endif
				return {
					barHeight,
					barTop,
					barWidth
				}
			},
			subCash: function(e) {
				let that = this,
					value = e.detail.value;
				value.extract_type = 'balance';

				if (value.money.length == 0) return uni.$u.toast('请填写提现金额');

				if (Number(value.money) < Number(that.minPrice)) return uni.$u.toast('提现金额不能低于：¥' + that.minPrice);
				if (this.prevent) {
					this.prevent = false
				} else {
					return
				}
				if (this.userInfo.id_card==''||this.userInfo.id_card==null) {
					this.IDCardShow = true
					return
				}
				CashApplicationApi(value).then(res => {
					uni.$u.toast(res.msg);
					setTimeout(() => {
						uni.navigateTo({
							url: `/pages/my/my`
						})
					}, 1500)
				}).catch(err => {
					return uni.$u.toast(err.msg);
				});
			},
			UpdateCard:function(){
				UpdateIdCardApi({'id_card':this.id_card,'real_name':this.real_name}).then(res => {
					uni.$u.toast(res.msg);
					setTimeout(() => {
						uni.navigateTo({
							url: `/pages/user_cash/index`
						})
					}, 1500)
				}).catch(err => {
					return uni.$u.toast(err.msg);
				});
			}
		}
	}
</script>

<style lang="scss">
	.cash-withdrawal {
		.accountTitle {
			background: linear-gradient(90deg, var(--view-theme) 0%, var(--view-gradient) 100%);
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			z-index: 99;

			.sysTitle {
				width: 100%;
				position: relative;
				font-weight: 500;
				color: #fff;
				font-size: 30rpx;

				.iconfont {
					position: absolute;
					font-size: 36rpx;
					left: 11rpx;
					width: 60rpx;
				}
			}
		}

		.header {
			width: 100%;
			height: 380rpx;
			background: linear-gradient(90deg, var(--view-theme) 0%, var(--view-gradient) 100%);
			font-size: 30rpx;
			font-weight: 400;
			color: #F5F5F5;
			text-align: center;
			padding-top: 88rpx;
			position: relative;

			&::after {
				position: absolute;
				content: ' ';
				width: 50%;
				height: 160rpx;
				background: linear-gradient(180deg, var(--view-theme) 0%, #F5F5F5 100%);
				left: 0;
			}

			&:before {
				position: absolute;
				content: ' ';
				width: 50%;
				height: 160rpx;
				background: linear-gradient(180deg, var(--view-gradient) 0%, #F5F5F5 100%);
				right: 0;
				bottom: -146rpx;
			}

			.headerCon {
				background-image: url('../static/cashBg.png');
				background-repeat: no-repeat;
				background-size: 100% 100%;
				width: 100%;
				height: 278rpx;
			}

			.money {
				font-size: 76rpx;
				font-weight: 600;
				color: #FFFFFF;
				font-family: 'Regular';
				margin-bottom: 16rpx;
			}
		}
	}

	.cash-withdrawal .wrapper {
		width: 710rpx;
		margin: -100rpx auto 0 auto;
		position: relative;
		z-index: 9;

		.nav {
			width: 100%;
			height: 110rpx;
			background-color: rgba(255, 255, 255, 0.9);
			border-radius: 24rpx 24rpx 0 0;
			position: relative;
			z-index: 9;

			&.on {
				height: unset;
				padding: 18rpx 0 8rpx 0;
				background-color: #fff;

				.item {
					padding-top: 0;
					padding-left: 30rpx;
					font-weight: 500;
					color: #333;
				}
			}

			.item {
				width: 33.33%;
				height: 84rpx;
				line-height: 84rpx;
				color: #666666;
				font-size: 26rpx;
				position: relative;
				z-index: 9;

				&.items {
					font-size: 28rpx;
					color: var(--view-theme);
					font-weight: 500 !important;
				}

				&.on {
					width: 50%;
					padding-left: 0;
					text-align: center;
				}

				&.ons {
					color: var(--view-theme);
					font-weight: 500;
					font-size: 28rpx;
				}

				&.on1,
				&.on2,
				&.on3 {
					font-weight: 400;
					padding-left: 0;
					text-align: center;
				}

				&.on6,
				&.on7,
				&.on8,
				&.on9 {
					width: 25%;
					font-weight: 400;
					padding-left: 0;
					text-align: center;
				}
			}

			.navBg {
				position: absolute;
				background-repeat: no-repeat;
				background-size: 100% 100%;
				width: 710rpx;
				height: 122rpx;
				left: 0;
				bottom: 0;
				box-sizing: border-box;

				&.on1 {
					background-image: url('../static/tixian01.png');
				}

				&.on2 {
					background-image: url('../static/tixian02.png');
				}

				&.on3 {
					background-image: url('../static/tixian03.png');
				}

				&.on4 {
					background-image: url('../static/tixian04.png');
				}

				&.on5 {
					background-image: url('../static/tixian05.png');
				}

				&.on6 {
					background-image: url('../static/tixian06.png');
				}

				&.on7 {
					background-image: url('../static/tixian07.png');
				}

				&.on8 {
					background-image: url('../static/tixian08.png');
				}

				&.on9 {
					background-image: url('../static/tixian09.png');
				}
			}
		}

		.bnt {
			font-size: 28rpx;
			color: #fff;
			width: 710rpx;
			height: 88rpx;
			text-align: center;
			border-radius: 50rpx;
			line-height: 88rpx;
			margin: 48rpx auto;
		}
	}

	.cash-withdrawal .wrapper .list {
		padding: 0 30rpx 48rpx 30rpx;
		background-color: #fff;
		border-radius: 0 0 24rpx 24rpx;

		.itemCon {
			border-bottom: 1px solid #EEEEEE;
			padding-bottom: 15rpx;
			margin-bottom: 42rpx;
		}
	}

	.cash-withdrawal .wrapper .list .item {
		font-size: 28rpx;
		color: #333;
		padding: 28rpx 0;
	}

	.cash-withdrawal .wrapper .list .item .name {
		width: 130rpx;
	}

	.cash-withdrawal .wrapper .list .item .input {
		width: 505rpx;

		input {
			font-size: 28rpx;
		}

		.iconfont {
			color: #ccc;
		}

		.icon-ic_camera {
			font-size: 38rpx;
			margin-bottom: 6rpx;
		}

		.all {
			font-size: 26rpx;
			color: var(--view-theme);
		}
	}

	.cash-withdrawal .wrapper .list .item .input .placeholder {
		color: #ccc;
	}

	.cash-withdrawal .wrapper .list .item .picEwm,
	.cash-withdrawal .wrapper .list .item .pictrue {
		width: 128rpx;
		height: 128rpx;
		border-radius: 14rpx;
		position: relative;
		margin-right: 23rpx;
		background: #F5F5F5;
	}

	.cash-withdrawal .wrapper .list .item .picEwm image {
		width: 100%;
		height: 100%;
		border-radius: 3rpx;
	}

	.cash-withdrawal .wrapper .list .item .picEwm .icon-ic_close {
		position: absolute;
		right: 0;
		top: 0;
		font-size: 24rpx;
		width: 32rpx;
		height: 32rpx;
		background: #999999;
		border-radius: 0 16rpx 0 16rpx;
		color: #fff;
		text-align: center;
		line-height: 32rpx;
	}

	.cash-withdrawal .wrapper .list .item .pictrue {
		font-size: 22rpx;
		color: #BBBBBB;
	}

	.cash-withdrawal .wrapper .list .item .pictrue .icon-icon25201 {
		font-size: 47rpx;
		color: #DDDDDD;
		margin-bottom: 3px;
	}

	.cash-withdrawal .wrapper .list .tip {
		font-size: 24rpx;
		color: #999;
		margin-top: 16rpx;

		.price {
			color: var(--view-theme);
			margin: 0 16rpx;
		}

		.num {
			margin-left: 16rpx;
		}
	}

	.cash-withdrawal .wrapper .list .tip2 {
		font-size: 26rpx;
		color: #999;
		text-align: center;
		margin: 44rpx 0 20rpx 0;
	}

	.cash-withdrawal .wrapper .list .value {
		height: 135rpx;
		line-height: 135rpx;
		border-bottom: 1rpx solid #eee;
		width: 690rpx;
		margin: 0 auto;
	}

	.cash-withdrawal .wrapper .list .value input {
		font-size: 80rpx;
		color: #282828;
		height: 135rpx;
		text-align: center;
	}

	.cash-withdrawal .wrapper .list .value .placeholder2 {
		color: #bbb;
	}

	.bg-gray {
		background-color: var(--view-theme);
		opacity: 0.4;
	}
</style>