<template>
	<view class="deposit" v-if="canTi == 1">
		<view class="deposit_head">
			<view class="deposit_head_name">提现金额</view>
			<view class="deposit_head_main">
				<view class="deposit_head_txt">提现比例1：1</view>
				<view class="deposit_head_ipt flexs">
					<text>￥</text>
					<input type="digit" placeholder="请输入" v-model="amount" maxlength="9" placeholder-style="color:#999999" />
				</view>
			</view>
		</view>
		<view class="deposit_main">
			<view class="deposit_main_name">选择提现方式</view>
			<view class="deposit_main_ul">
				<view class="deposit_main_li flex" v-for="(item, index) in payList" :key="index" @click="changePay(item.type)">
					<view class="deposit_main_img flexs" @click.stop="bindAccount(item.type)">
						<image :src="item.image" mode=""></image>
						<text>{{ item.name }}{{ item.account ? '(' + item.account + ')' : ' (请绑定)' }}</text>
					</view>
					<view class="deposit_main_li_select">
						<image :src="item.type == payType ? '/static/image/publice/xuanzhong1@2x.png' : '/static/image/publice/weixuanzhong@2x.png'" mode=""></image>
					</view>
				</view>
			</view>
			<view class="deposit_main_txt"><u-parse :content="message"></u-parse></view>
		</view>
		<button class="deposit_btn" hover-class="hover-view" @click="submit">提交</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			canTi: '',
			message: '',
			amount: '', //提现金额
			payType: 1, //支付方式
			payList: [
				// {
				// 	name:'微信提现',
				// 	type:'0',
				// 	account:'',
				// 	image:'/static/image/me/weixin@2x.png'
				// },
				{
					name: '支付宝提现',
					type: '1',
					account: '',
					image: '/static/image/me/zhifubao@2x.png'
				}
			] //支付列表
		};
	},
	methods: {
		submit() {
			// return uni.showToast({title:'不支持体现',icon:'none'})
			if (!this.amount) return uni.showToast({ title: '请输入金额', icon: 'none' });
			if (!this.payList.find(item => item.type == this.payType).account)
				return uni.showToast({ title: '请绑定' + (this.payType == 0 ? '微信' : '支付宝') + '账号', icon: 'none' });
			if (this.amount == 0) return;
			this.$api.withdrawal({ amount: this.amount, type: this.payType == 0 ? 'wechat' : 'alipay' }).then(res => {
				if (res.code === 1) {
					uni.showToast({ title: res.msg });
					this.amount = '';
				}
			});
		},
		//绑定账号
		bindAccount(type) {
			uni.navigateTo({ url: '/pages/me/WeChat?type=' + type });
		},
		changePay(type) {
			this.payType = type;
		},
		//huoqu
		getAccount() {
			this.$api.getWithdrawalSetting().then(res => {
				if (res.code === 1) {
					let alipay = this.payList.find(item => item.type == 1);
					alipay.account = res.data.alipay.account;
					let wechat = this.payList.find(item => item.type == 0);
					wechat && (wechat.account = res.data.wechat.account);
				}
			});
		},
		getMessage() {
			this.$api.agreement({ name: 'withdrawal_instruction' }).then(res => {
				if (res.code === 1) {
					this.message = res.data.content;
				}
			});
		}
	},
	onShow() {
		this.getAccount();
	},
	onLoad() {
		this.getMessage();
		this.$api.checkSwitch().then(({ data }) => {
			this.canTi = data;
		});
	}
};
</script>

<style lang="scss">
.deposit {
	padding: 0 35rpx 0 25rpx;
	.deposit_head {
		.deposit_head_name {
			font-size: 32rpx;
			padding: 30rpx 0 20rpx 20rpx;
		}
		.deposit_head_main {
			background: #ffffff;
			padding: 30rpx 30rpx 58rpx 20rpx;
			.deposit_head_txt {
				font-size: 28rpx;
				margin-bottom: 30rpx;
			}
			.deposit_head_ipt {
				padding: 20rpx 0;
				border-bottom: 2rpx solid #ebebeb;
				text {
					font-size: 36rpx;
					margin-right: 20rpx;
				}
				input {
					color: #f6af32;
					font-size: 36rpx;
				}
			}
		}
	}
}
.deposit_main {
	.deposit_main_name {
		font-size: 32rpx;
		padding: 50rpx 0 30rpx 20rpx;
	}
	.deposit_main_ul {
		background: #ffffff;
		.deposit_main_li {
			padding: 30rpx 20rpx;
			.deposit_main_img {
				image {
					width: 50rpx;
					height: 50rpx;
					margin-right: 20rpx;
				}
				text {
					font-size: 28rpx;
				}
			}
			.deposit_main_li_select {
				width: 32rpx;
				height: 32rpx;
			}
		}
	}
	.deposit_main_txt {
		padding: 20rpx 0;
	}
}
.deposit_btn {
	height: 98rpx;
	color: #333333;
	font-size: 30rpx;
	margin-top: 150rpx;
	background: #ffffff;
	box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(220, 220, 220, 0.2);
	border-radius: 20rpx;
}
</style>
