<template>
	<view class="content">
		<view class="total">
			<view class="">
				账户总余额(元)
			</view>
			<view style="font-size: 36rpx;">
				￥{{balance||0.00}}
			</view>
		</view>
		<view class="action">
			<view class="">
				提现至
			</view>
			<view style="font-weight: bold;" @click="showPop1=true">
				{{target_bank.is_own?'对公账户':"个人账户"}}
			</view>
			<view style="display: flex;align-items: center;color: #20B128;" @click="navgo('/pages/quote/bindAccout')">
				<text>更换账户</text> <u-icon color="#20B128" name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="form" v-if='target_bank.bank_name'>
			<u-form labelPosition="left" borderBottom :label-style="{fontSize:'30rpx'}" ref="form1" labelWidth='70'>
				<u-form-item label="银行卡" borderBottom ref="item1">
					<u-input style="border: none;" v-model="target_bank.bank_name" />
				</u-form-item>
				<u-form-item label="持卡人" borderBottom ref="item1">
					<u-input style="border: none;" v-model="target_bank.name" />
				</u-form-item>
				<u-form-item label="银行账户" borderBottom ref="item1">
					<u-input style="border: none;" v-model="target_bank.bank_code" />
				</u-form-item>
				<u-form-item label="开户网点" borderBottom ref="item1">
					<u-input style="border: none;" v-model="target_bank.bank_branch" />
				</u-form-item>
				<u-form-item label="提现金额" borderBottom ref="item1">
					<u-input style="border: none;" v-model="form.money" placeholder="请输入提现金额" />
				</u-form-item>
				<text style="color: #999999;font-size: 24rpx;">
					说明:用户下单后该订单金额存放在暂存金额中，用户确认收货后次日18:00才可提现该笔订单金额
					提货付款订单在完成后次日18:00才可提现
				</text>
			</u-form>
		</view>
		<u-empty mode="data" v-else :text='emptyText'
			icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/attach/89e93202405131146497294.png" />
		<view class="detail" @click="navgo('/pages/quote/financialyDeatil')">
			明细
		</view>
		<view class="submit-btn">
			<u-button text="提现" @click="submit" shape="circle" color="#50C758"></u-button>
		</view>
		<u-popup :show="showPop1" :round="10" mode="bottom" @close="showPop1=false" @open="showPop1=true">
			<view class="popContent">
				<view style="text-align: center;font-weight: bold;">请选择提现账户</view>
				<u-icon name="close" color="#303133" size="24" @click="showPop1=false"
					style="position: absolute;top: 20rpx;right: 20rpx;"></u-icon>
				<view class="bank-list">
					<view class="bank-li" @click="choseAccount(0)">
						<text>个人账户</text>
					</view>

					<view class="bank-li" @click="choseAccount(1)">
						<text>对公账户</text>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		hasBindAccount,
		amountAccountApi
	} from "@/api/supplier.js"
	export default {
		data() {
			return {
				balance: '',
				target_bank: {},
				emptyText: "撒大声地",
				form: {
					money: ''
				},
				hasBindAccount: [],
				showPop1: false,
			}
		},
		methods: {
			navgo(url) {
				uni.navigateTo({
					url
				})
			},
			choseAccount(type) {
				this.target_bank = this.hasBindAccount[type] || {}
				this.target_bank.is_own = type
				this.showPop1 = false
			},
			async getHasBindBankList() {
				// this.target_bank = this.hasBindAccount[0]
				// return
				let res = await amountAccountApi({})
				this.balance = res.data.balance
				// this.hasBindAccount = res.data.hasBindAccount
				// this.target_bank = res.data.hasBindAccount[0] || {}
			},
			async submit() {
				console.log({
					"merchant_bank_id": this.target_bank.id,
					"amount": this.form.money
				})
				return
				await UserWithdrawApi({
					"merchant_bank_id": this.target_bank.id,
					"amount": this.form.money
				})
				uni.showToast({
					title: '提交成功',
					duration: 1500,
				})
				uni.$u.sleep(1500).then(res => {
					uni.navigateTo({
						url: '/pages/quote/financialyDeatil'
					})
				})
			}
		},
		onLoad() {
			uni.showTabBar()
			this.getHasBindBankList()

		}
	}
</script>




<style lang="scss">
	.content {
		padding: 20rpx;
		min-height: 100vh;

		.total {
			background-color: #50C758;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			color: white;
			display: flex;
			justify-content: space-between;
			padding: 42rpx 30rpx;
			font-size: 30rpx;
			margin-bottom: 30rpx;
		}

		.action {
			background-color: white;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			margin-bottom: 30rpx;
		}

		.form {
			padding: 28rpx 30rpx;
			background-color: white;
			border-radius: 20rpx;
		}

	}

	.popContent {
		padding: 20rpx;

		.bank-list {
			overflow-y: auto;
			position: relative;
			max-height: 40vh;

			.bank-li {
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 20rpx;
				border-bottom: 1px solid #F8F9FA;
			}
		}
	}


	.detail {
		width: 88rpx;
		height: 88rpx;
		border-radius: 88rpx;
		text-align: center;
		line-height: 88rpx;
		background-color: #50C758;
		color: white;
		position: absolute;
		bottom: 300rpx;
		right: 20rpx;
	}

	.submit-btn {
		position: fixed;
		bottom: 146rpx;
		width: 710rpx;

	}
</style>