<template>
	<view>
		<view class="w100 rows rowsm rowsa bgff h-100">
			<view class="rows rowsm rowsl" v-for="(item,index) in type" :key="index" @click="onSel(index)">
				<text :class="select==index?'fw-b fs-30':'fs-28 col666'">{{item.name}}</text>
				<view class="w-40 h-8 bg br-10 mt-10" v-if="select==index"></view>
			</view>
		</view>
		<view class="w100 rows rowsc mt-20">
			<view class="w-710 h-304 br-20 p-all-20 bgff br-20">
				<text class="fw-b fs-28">提现金额</text>
				<view class="rows rowsm mt-20">
					<text class="fw-b fs-76 col333 mr-20">￥</text>
					<view class="w-550 h-110 rows rowsm" style="border-bottom: 1rpx solid #eee;">
						<input type="text" placeholder="0.00" class="fs-76 h-92" v-model="price"/>
					</view>
				</view>
				<view class="w100 rows rowsm rowsb h-90 mt-10">
					<text class="fs-28">可提现金额：{{infor.money||0}}元</text>
					<text class="fs-22 col">手续费{{withdrawal||''}}%</text>
				</view>
			</view>
		</view>
		<view class="w100 rows rowsl rowsm" v-if="select==0">
			<!-- <view class="fs-30 w-710 fw-b">收款信息</view> -->
			<view class="w-710 rows rowsl rowsm bgff br-20 mt-20">
				<view class="w-670 h-120 p-all-20 bgff br-20 rows rowsb rowsm" style="border-bottom: 1rpx solid #f5f5f5;">
					<text class="fs-28">开户行</text>
					<input type="text" placeholder="请输入开户行" class="fs-28 trt" v-model="bank"/>
				</view>
				<view class="w-670 h-120 p-all-20 bgff br-20 rows rowsb rowsm" style="border-bottom: 1rpx solid #f5f5f5;">
					<text class="fs-28">卡号</text>
					<input type="text" placeholder="请输入卡号" class="fs-28 trt" v-model="bank_card"/>
				</view>
				<view class="w-670 h-120 p-all-20 bgff br-20 rows rowsb rowsm" style="border-bottom: 1rpx solid #f5f5f5;">
					<text class="fs-28">联系人</text>
					<input type="text" placeholder="请输入联系人" class="fs-28 trt" v-model="name"/>
				</view>
				<view class="w-670 h-120 p-all-20 bgff br-20 rows rowsb rowsm">
					<text class="fs-28">联系电话</text>
					<input type="number" placeholder="请输入联系电话" maxlength="11" class="fs-28 trt" v-model="mobile"/>
				</view>
			</view>
		</view>
		<view class="w100 rows rowsc mt-20 col666">
			<view class="w-710 bgff br-20 p-all-20 fs-26">
				{{tixian}}
			</view>
		</view>
		<view class="w100 rows rowsc bgff fixed h-170 pt-30" style="bottom: 0rpx;">
			<view class="w-690 h-88 rows rowsm rowsc bg colfff fw-b fs-30 br-100" @click="addWithdrawal">
				立即提现
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				price:'',
				infor:{},
				withdrawal:'',
				name:'',
				bank:'',
				bank_card:'',
				mobile:'',
				tixian:'',
				type:[{id:2,name:'银行卡'},{id:1,name:'微信'}],
				select:0
			}
		},
		onLoad() {this.richText()},
		onShow() {
			this.index()
		},
		methods: {
			onSel(index){
				this.select = index
			},
			index(){
				this.$tools.axiosFrom("POST","user/index").then(res => {
					this.infor = res.data
				})
			},
			addWithdrawal(){
				if(this.price=='') return this.$tools.showtt('提现金额不能为空')
				if(this.select==0){
					if(this.bank=='') return this.$tools.showtt('开户行不能为空')
					if(this.bank_card=='') return this.$tools.showtt('卡号不能为空')
					if(this.name=='') return this.$tools.showtt('联系人不能为空')
					if(this.mobile=='') return this.$tools.showtt('手机号不能为空')
					if(!this.$tools.isPhone(this.mobile)) return this.$tools.showtt('无效手机号')
				}
				this.$tools.axiosFromToken("POST","user/addWithdrawal",{
					price:this.price,
					name:this.name,
					bank:this.bank,
					bank_card:this.bank_card,
					mobile:this.mobile,
					type:this.type[this.select].id
				}).then(res => {
					this.$tools.showtt(res.msg)
					if(res.code!=1) return
					if(this.select==0){
						setTimeout(() => {
							this.$tools.goBack()
						},1000)
					}else{
						this.aaa(res.data)
					}
				})
			},
			aaa(e){
				let that = this
				if (wx.canIUse('requestMerchantTransfer')) {
					wx.requestMerchantTransfer({
						mchId: '1738050326',
						appId: 'wxbe6c2f19a19b3ce9',
						package: e.package_info,
						outBillNo:e.out_bill_no,
						success: (ress) => {
							console.log('success:', ress);
							setTimeout(() => {
								uni.navigateBack({
									delta: 1 
								})
							}, 1000)
						},
						fail: (res2) => {
							console.log('fail:', res2);
							this.$tools.showtt('收款确认失败，请稍后重试');
						}
					})
				} else {
					wx.showModal({
						content: '你的微信版本过低，请更新至最新版本。',
						showCancel: false,
					});
				}
			},
			richText(){
				this.$tools.axios("POST","index/richText").then(res => {
					this.withdrawal = res.data.withdrawal
					this.tixian = res.data.tixian
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #F7F6FA;
	}
</style>
