<template>
	<view class="se-m-40">
		<u--input v-model="realName" type="text" class="se-bgc-f5 se-fs-32" placeholder="请输入真实姓名">
		</u--input>
		<u--input v-model="bankCard" type="text" class="se-bgc-f5 se-mt-20 se-fs-32" placeholder="请输入银行卡号">
		</u--input>
		<u--input v-model="bankName" type="text" class="se-bgc-f5 se-mt-20 se-fs-32" placeholder="请输入开户行">
		</u--input>
		<u--input v-model="money" type="number" class="se-bgc-f5 se-mt-20 se-fs-32" placeholder="请输入提现金额">
		</u--input>
		<view class="se-flex se-flex-v se-pb-20 se-mt-80">
			<view class="se-ml-10 se-fs-26 se-c-black se-fw-5">
				提现说明
			</view>
			<view class="se-flex se-flex-v se-fs-24 se-c-66  se-mt-30">
				<u-parse :content="getValueByName('txsm')"></u-parse>
				<!-- <text class="se-hl-50">
					1、本次提现必须通过银行卡提现，暂不支持其他途径。</br>
					2、如若遇到24小时提现未到账，请联系客服。</br>
					3、提现金额至少不能低于300元。
				</text> -->
			</view>
		</view>
		<view class="se-pt-80 se-fs-20 se-flex">
			<view @click="onWithdrawal"
				class="se-mx-10 se-flex-1 se-br-40 se-flex-h-c se-h-80 se-lh-80 se-ta-c se-fs-28 se-c-white se-bgc-orange">
				<text>立即提现</text>
			</view>
		</view>
	</view>
</template>

<script>
	
	import {
		withdrawal
	} from "@/common/api.js"
	export default{
		props:["userId","myMoney"],
		data(){
			return{
				realName:"",
				bankCard:"",
				bankName:"",
				money:"",
				sysList:[]
			}
		},
		mounted() {
			this.sysList = uni.getStorageSync('sysList')
			this.loadBankInfo()
		},
		methods:{
			// 加载银行卡信息
			loadBankInfo() {
				const bankInfo = uni.getStorageSync('bankInfo')
				if (bankInfo) {
					this.realName = bankInfo.realName || ''
					this.bankCard = bankInfo.bankCard || ''
					this.bankName = bankInfo.bankName || ''
				}
			},
			// 保存银行卡信息
			saveBankInfo() {
				const bankInfo = {
					realName: this.realName,
					bankCard: this.bankCard,
					bankName: this.bankName
				}
				uni.setStorageSync('bankInfo', bankInfo)
			},
			getValueByName(name) {
				const item = this.sysList.find((item) => item.name == name);
				return item ? item.value : "";
			},
			onWithdrawal(){
				let that = this
				
				// 验证必填字段
				if(!that.realName){
					return that.$u.toast("请填写真实姓名！")
				}
				if(!that.bankCard){
					return that.$u.toast("请填写银行卡号！")
				}
				if(!that.bankName){
					return that.$u.toast("请填写开户行！")
				}
				if(!that.money){
					return that.$u.toast("请填写金额！")
				}
				
				// 保存银行卡信息到本地
				that.saveBankInfo()
				
				let params = {
					realName: that.realName,
					bankCard: that.bankCard,
					bankName: that.bankName,
					money: that.money
				}
				
				withdrawal(params).then(response=>{
					console.info("response",response)
					that.money=""
					that.$u.toast("申请成功！")
					that.$emit("onParent")
					//返回页面
					uni.navigateBack({
						delta: 1
					})
				}).catch(error=>{
					
				})
			}
		}
	}
</script>

<style>
</style>