<template>
	<view class="page">
		<navbar title="提现" 
		bgColor="#A3D250"
		color="#fff"
		leftClick 
		@leftClick="$utils.navigateBack" />
		
		<view class="bg"/>
		
		<view class="price">
			<!-- <view class="title">
				请输入提现金额（元）
			</view> -->
			<view class="input-box">
				<view class="input">
					<input type="number" v-model="form.money"
					placeholder="请输入提现金额"/>
				</view>
				<view class=""
				@click="selectAll">
					全部提现
				</view>
			</view>
			<view class="input-box">
				<view class="input">
					<input type="text" v-model="form.name"
					placeholder="请输入姓名"/>
				</view>
			</view>
			<view class="input-box">
				<view class="input">
					<input type="text" v-model="form.bankName"
					placeholder="请输入开户行"/>
				</view>
			</view>
			<view class="input-box">
				<view class="input">
					<input type="text" v-model="form.bankNo"
					placeholder="请输入银行卡号"/>
				</view>
			</view>
			<view class="num">
				可提现金额：{{ riceInfo.canWithdraw || 0 }}
			</view>
		</view>
		
		<view class="cell">
			<view class="cell-top">提现说明</view>
			<view style="padding: 0 20rpx;">
				<uv-parse :content="configList.withdrawal_instructions"></uv-parse>
			</view>
		</view>
		
		<view class="uni-color-btn"
		@click="submit">
			提现
		</view>
		
		<view class="cell">
			<view class="cell-top">提现记录</view>
			<view class="cell-box" 
			:key="index"
			v-for="(item,index) in list">
				<uv-cell-group>
					<uv-cell 
					:title="item.title" 
					:label="item.createTime" 
					:center="true">
						<template #value>
							<view class="cell-text">
								
								<view class="price-text"
								v-if="item.type">{{ type[item.type] }}{{ item.money }}</view>
								
								<view class="price-text add"
								v-else>{{ type[item.type] }}{{ item.money }}</view>
								
								<view class="tips">{{ state[item.state] }}</view>
							</view>
						</template>
					</uv-cell>
				</uv-cell-group>
			</view>
		</view>
		
	</view>
</template>

<script>
	import mixinsList from '@/mixins/list.js'
	import { mapState } from 'vuex'
	export default {
		mixins : [mixinsList],
		data() {
			return {
				mixinsListApi : 'getWaterPageList',
				list : [],
				type : ['+', '-'],
				state : ['未到账', '已到账'],
				form : {
					money : '',
					bankNo : '',
					bankName : '',
				},
			}
		},
		computed: {
			...mapState(['userInfo', 'riceInfo']),
		},
		onShow() {
			this.$store.commit('getUserInfo')
			this.$store.commit('getRiceInfo')
		},
		methods: {
			selectAll(){
				this.form.money = this.riceInfo.canWithdraw
			},
			submit(){
					
				if(this.$utils.verificationAll(this.form, {
					money : '请输入金额',
					bankName : '请输入开户行',
					bankNo : 'bankNo',
				})){
					return
				}
				
				if(this.form.money <= 0){
					uni.showToast({
						title: '输入金额必须大于0',
						icon: 'none'
					})
					return
				}
				
				this.$api('withdraw', this.form, res => {
					if(res.code == 200){
						uni.showToast({
							title: '提现成功',
							icon : 'none'
						})
						this.form.money = ''
						this.$store.commit('getUserInfo')
						this.$store.commit('getRiceInfo')
						this.getData()
					}
				})
			},
		},
	}
</script>

<style scoped lang="scss">
.page{
	.bg{
		background-color: $uni-color;
		height: 640rpx;
		position: absolute;
		left: 0;
		width: 100%;
		z-index: -1;
		border-bottom-left-radius: 30rpx;
		border-bottom-right-radius: 30rpx;
	}
	
	.price{
		color: #FFFFFF;
		padding: 40rpx;
		.title{
			color: #eee;
			font-size: 28rpx;
		}
		.input-box{
			background-color: #FFFFFF;
			color: $uni-color;
			display: flex;
			justify-content: center;
			border-radius: 30rpx;
			align-items: center;
			padding: 10rpx;
			margin: 20rpx 0;
			.input{
				color: #000;
				// font-size: 40rpx;
				// font-weight: 900;
				display: flex;
				flex: 1;
				input{
					flex: 1;
					padding: 14rpx 20rpx;
				}
			}
		}
		.num{
			font-size: 30rpx;
			font-weight: 900;
			margin-top: 10rpx;
		}
	}
	
	.cell {
		margin: 20rpx;
		background-color: #FFFFFF;
		border-radius: 16rpx;
	
	
		.cell-top {
			padding: 40rpx 34rpx;
			color: #474747;
			font-size: 34rpx;
			font-weight: 600;
			position: relative;
			&::after{
				content: '';
				display: block;
				position: absolute;
				left: 55rpx;
				bottom: 38rpx;
				height: 10rpx;
				width: 120rpx;
				background: linear-gradient(to right, #fff, $uni-color);
			}
		}
		.cell-text{
			text-align: right;
			.price-text{
				font-size: 32rpx;
				font-weight: 900;
			}
			.add{
				color: #f40;
			}
			.tips{
				font-size: 22rpx;
				color: #aaa;
				margin-top: 10rpx;
			}
		}
	}
}
</style>
