<template>
	<view class="main">
		<view class="mcard">
			<view class="money">{{ money }}</view>
			<view class="desc">可提现余额（元）</view>
		</view>
		<view class="mcard mt10">
			<view class="form_group">
				<view class="lable re">提现金额</view>
				<view class="bgm">
					<input type="digit" v-model="item.money" placeholder="请输入提现金额" class="input" />
					<view class="msg" @click="all()">提现全部</view>
				</view>
			</view>
			<view class="form_group">
				<view class="lable re">提现方式</view>
				<view class="item">
					<view class="lit">
						<text class="icon tb" style="color: #4caf50">&#xe620;</text>
						<view class="title">提现到微信</view>
					</view>
					<view class="lit">
						<text class="icon tb" style="color: #ff9800">&#xe635;</text>
						<view class="title">
							<text>提现到银行卡</text>
							<text class="desc" v-if="!bankName">(未填)</text>
						</view>
						<text class="icon check">&#xe612;</text>
					</view>
				</view>
			</view>
		</view>
		<button class="btn" @click="save()">确认</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			money: 0,
			bankName: '',
			item: {}
		};
	},
	onShow() {
		this.money = uni.getStorageSync('money');
		this.bankName = uni.getStorageSync('bankName');
	},
	methods: {
		all() {
			this.item.money = this.money;
			this.$forceUpdate();
		},
		save() {
			let rule = [{ name: 'money', checkType: 'notnull', errorMsg: '请输入提现金额' }];
			if (!this.verify.check(this.item, rule)) {
				uni.showModal({ content: this.verify.error, showCancel: false });
				return false;
			}
			if (!this.bankName) {
				uni.showModal({
					title: '提示',
					content: '请先填写银行卡信息',
					showCancel: false,
					success: (res) => {
						uni.navigateTo({ url: '/pages/statement/user/info' });
					}
				});
				return;
			}
			uni.showModal({
				title: '提示',
				content: '确定提现' + this.item.money + '元',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/pay/cashOut',
							data: this.item,
							method: 'POST',
							success: (res) => {
								//通知模板订阅消息
								uni.requestSubscribeMessage({
									tmplIds: ['PtdKbqfzmpvGsJPx_YekDX4-cljbhOXcvoUB3XJaVLg', 'NIqSQq0j765o9Iz9gMiSelnuxMgPIPeCnk3lvEnWJlo'],
									complete: (c) => {
										uni.showModal({
											title: '提示',
											content: '提现申请成功,等待平台审核打款',
											showCancel: false,
											success: (res) => {
												uni.$emit('payMoney');
												uni.navigateBack();
											}
										});
									}
								});
							}
						});
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
.bgm {
	.input {
		width: 50%;
	}
}
.lit {
	padding: 15px 0px 10px 0px;
	border-bottom: 1px solid $line;
	.tb {
		padding-right: 5px;
		font-size: 25px;
		float: left;
	}
	.desc {
		font-size: 13px;
		padding-left: 5px;
		color: #a8a8a8;
	}
	.check {
		float: right;
		color: $main-color;
		margin-top: -18px;
	}
	&:last-child {
		border: 0px;
		padding-bottom: 0px;
	}
}
</style>
