<template>
	<view>
		<block v-if="!ifWithdraw">
			<view class="p-2 m-b-48 ">
				<view class="b-r-8 white">
					<view class="p-32 flex-row flex-ali-center flex-jus-sp">
						<d-text text="提现至" className="fs-3 content-c"></d-text>
						<view class="flex-row flex-ali-center">
							<u-icon name="weixin-fill" size="44" color="#09BB07"></u-icon>
							<d-text text="零钱" className="m-l-16 fs-3 tips-c"></d-text>
						</view>
					</view>
					<view class="p-32 flex-row">
						<d-text text="提现金额" className="fs-3 content-c"></d-text>
					</view>
					<view class="p-32 flex-row flex-ali-center">
						<d-text text="￥" className="fs-36 main-c m-r-16"></d-text>
						<u-input v-model="money" type="digit" m placeholder="请输入大于0的数"
							@input="inputChange($event,'money')" :custom-style="{fontSize:'36rpx'}" />
					</view>
					<view class="p-32 flex-row flex-ali-center" v-if="money<=balance">
						<d-text text="可提现" className="m-r-16 tips-c"></d-text>
						<d-text :text="'￥'+balance" className="m-r-16 tips-c"></d-text>
						<d-text text="全部提现" :bold="true" className="primary-c tips-c" @click="money=balance"></d-text>
					</view>
					<view class="p-32 flex-row flex-ali-center" v-if="money>balance">
						<d-text text="输入金额超过提现金额" color="red"></d-text>
						</d-text>
					</view>
				</view>
			</view>
			<view class="p-32">
				<u-button @click="ifWithdraw=true" :throttle-time="0" type="primary" shape="circle" :ripple="true"
					:disabled="!money||money<=0||money>balance">提现</u-button>
			</view>
			<view class="m-t-4 flex-row flex-jus-center">
				<d-text text="提现明细" className="primary-c tips-c" @click="$go('record')"></d-text>
			</view>
		</block>
		<view class="m-t-48 p-row-2" v-else>
			<view class="b-r-8 flex-col m-t-48 flex-ali-center">
				<image src="../../../static/image/sf.png" style="width: 248rpx;height: 180rpx;"></image>
				<d-text text="提现申请已提交，等待人工审核" className="fs-32 content-c m-t-48"></d-text>
			</view>
			<view class="white b-r-8 flex-col m-t-48 ">
				<view class="flex-row flex-jus-sp p-32 flex-ali-center flex-1">
					<d-text text="提现至" color="#6C7380" className="fs-32 tips-c"></d-text>
					<d-text text="微信零钱" className="content-c fs-3"></d-text>
				</view>
				<view class="flex-row flex-jus-sp p-32 flex-ali-center flex-1">
					<d-text text="提现金额" color="#6C7380" className="fs-32 tips-c"></d-text>
					<d-text :text="'￥'+money" className="content-c fs-3"></d-text>
				</view>
			</view>
		</view>
		<d-loading-page :loading="loading"></d-loading-page>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				balance: 288.88,
				money: '',
				loading: true,
				ifWithdraw: false
			};
		},
		computed: {},
		created() {
			this.loading = false
		},
		onShow() {},
		onHide() {},
		methods: {
			inputChange(val, key) {
				var that = this;
				var idx = -1;
				var value = val.replace(/[^0-9.]/g, '').trim();
				if (value == "") {
					return;
				}

				idx = value.indexOf('.');
				var raw = value;
				if (idx > 0) {
					var ext = value.slice(idx + 1, idx + 3)
					if (ext.indexOf('.') > -1) {
						ext = ext.slice(0, ext.indexOf('.'));
					}
					if (ext.length > 2) {
						ext = ext.slice(0, 2);
					}

					value = value.slice(0, idx) + '.' + ext;

				} else if (idx == 0) {
					value = '0.'
				}

				setTimeout(function() {
					that[key] = value
				}, 0);
			},
			async getList() {
				if (this.userInfo.status != 2) {
					this.loading = false
					return
				}
				let res = {}
				this.index == 0 && (res = await tobeReviewed())
				this.index == 1 && (res = await passed())
				this.index == 2 && (res = await unPassed())
				this.list = []
				if (res.errcode == 0) {
					this.list = res.data
					this.$nextTick(() => {
						this.loading = false
					})
				} else {
					this.$toast(res.msg);
					this.loading = false
				}
			}
		}
	};
</script>
<style>
	page {
		background-color: #F9FAFB;
	}
</style>
