<template>
	<view class="page">
		<!-- 导航栏 -->
		<navbar title="提现" leftClick @leftClick="$utils.navigateBack" bgColor="#E3441A" color="#fff" />

		<!-- 佣金信息 -->
		<view class="b-relative center font-m">
			<image :src="configList.tx_image" mode="aspectFill" />

			<view class="user-money">
				<view class="title">总佣金</view>
				<view class="money">{{ riceInfo.canWithdraw}}元</view>
			</view>

			<view class="operation">
				<!-- <view @click="toRunningWater" class="operation-item">
					余额记录
				</view>
				|
				<view @click="toRunningWater" class="operation-item">
					提现记录
				</view>
				| -->
				<view @click="toRunningWater" class="operation-item">
					流水记录
				</view>
			</view>
		</view>

		<!-- 我要提现 -->
		<view class="from-body">
			<view class="title">我要提现</view>

			<view class="money-form">
				<view class="unit">
					￥
				</view>
				<uv-input type="number" placeholder="请输入提现金额" border="surround" v-model.number="form.money"></uv-input>
			</view>
		</view>

		<!-- 提现说明 -->
		<view class="withdrawal-statement">
			<view class="title">提现说明</view>
			<view v-html="configList.recharge_instructions" class="withdrawal-statement" style="color: #666666;"></view>
		</view>

		<view @click="withdraw" class="uni-color-btn">
			立即提现
		</view>
	</view>
</template>

<script>
	import mixinsList from '@/mixins/list.js'
	import {
		mapState
	} from 'vuex'
	export default {
		mixins: [mixinsList],
		computed: {
			...mapState(['userInfo', 'riceInfo']),
		},
		data() {
			return {
				form: {
					money: ''
				},
			}
		},
		onShow() {
			this.$store.commit('getUserInfo')
			this.$store.commit('getRiceInfo')
		},
		methods: {
			withdraw() { //立即提现
				if (this.form.money < 300) {
					return uni.showToast({
						title: '未满300元不可提现哦！',
						icon: 'none'
					})
				}
				let isOk = this.parameterVerification();
				if (isOk && !isOk.auth) {
					return uni.showToast({
						title: isOk.title,
						icon: 'none'
					})
				}
				this.$api('recharge', this.form, res => {
					if (res.code == 200) {
						uni.showToast({
							title: '提现成功',
							icon: 'none'
						})
						this.$store.commit('getUserInfo')
						this.$store.commit('getRiceInfo')
					}
				})
			},

			parameterVerification() { //验证用户参数合法性
				let {
					money
				} = this.form
				if (!money) {
					return {
						title: '请填写提现金额',
						auth: false
					}
				}
				return {
					title: '验证通过',
					auth: true
				}
			},

			toRunningWater() {
				uni.navigateTo({
					url: "/pages_order/mine/runningWater"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.page {

		// 佣金信息
		.center {
			position: relative;
			width: 710rpx;
			height: 316rpx;
			margin: 20rpx auto;
		}

		.center image {
			position: absolute;
			left: 0;
			top: 0;
			width: 710rpx;
			height: 316rpx;
			border-radius: 12rpx;
		}

		.center .user-money {
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			z-index: 9;
			color: white;
			padding-left: 50rpx;
			box-sizing: border-box;

			.title {
				font-size: 36rpx;
			}

			.money {
				font-size: 40rpx;
			}
		}

		.operation {
			position: absolute;
			bottom: 20rpx;
			left: 0rpx;
			width: 100%;
			display: flex;
			justify-content: flex-end;
			color: white;

			.operation-item {
				margin: 0rpx 20rpx;
			}
		}

		// 我要提现
		.from-body {
			padding: 40rpx 20rpx;
			font-size: 28rpx;
			text-align: left;
			color: #333333;
		}

		.from-body .title {
			font-size: 36rpx;
		}

		.money-form {
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			background: #ebebeb;
			border-radius: 10rpx;
			margin-top: 20rpx;
		}

		.money-form .unit {
			display: flex;
			justify-content: flex-end;
			color: $uni-color;
			width: 60rpx;
		}

		&::v-deep .uv-border {
			border: none;
		}

		.money {
			margin: 20rpx 0rpx;
		}

		// 提现说明
		.withdrawal-statement {
			padding: 0rpx 20rpx;
			box-sizing: border-box;

			.title {
				font-size: 36rpx;
				margin-bottom: 20rpx;
			}
		}

		.recharge {
			position: fixed;
			display: flex;
			justify-content: center;
			align-items: center;
			left: 0;
			bottom: 0;
			width: 750rpx;
			height: 100rpx;
			background: white;
		}

		.recharge .btn {
			width: 85%;
			height: 80rpx;
			border-radius: 40rpx;
			color: white;
			text-align: center;
			line-height: 80rpx;
			font-size: 28rpx;
			background: $uni-color;
		}

		@media all and (min-width: 961px) {
			.recharge {
				left: 50% !important;
				transform: translateX(-50%);
			}
		}
	}
</style>