<template>
	<view class="cash-out-box">
		<view style="color:#666;font-size: 32rpx;">
			提现申请需要审核，请耐心等待，注意查收微信红包。
		</view>
		
		<view class="cash-input-box">
			<text>￥</text>
			<input type="number" v-model="money">
		</view>
		
		<view class="all-cash-out-box">
			<text>当前积分为{{userInfoObj.scorenumber || '0'}}，可抵现金{{userInfoObj.nowmoney || '0'}}，</text>
			<text style="color: #1a9ed3;" @click.stop="getAll">全部提现</text>
		</view>
		
		<button type="primary" @click="getCash">提现</button>
		
	</view>
</template>

<script>
var md5 = require('../../../../common/md5.js')
export default {
	data() {
		return {
			money:'',
			userInfoObj:{},
		};
	},
	onLoad() {
	},
	onShow() {
		this.getUserInfo();
	},
	methods: {
		getUserInfo(){
				 uni.showLoading({
					title: '加载中',
				});
				  let that = this;
					 uni.request({
						url: getApp().globalData.shareUrl, //需要设置为全局
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							method: 'getUserInfo',
							timestamp: getApp().globalData.globalTimestamp, //Date.now()
							uid:getApp().globalData.user_id,
							sign: md5('getUserInfo' + getApp().globalData.globalTimestamp)
						},
						success: res => {
							if (res.data.code === 200) {
								uni.hideLoading();
								that.userInfoObj = res.data.msg
							}
						}
					 });
		},
		getCash(){
			  let that = this;
			  if(that.money > 0 && that.money <= that.userInfoObj.nowmoney){
			  	 uni.request({
					url: getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'tixian',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						uid:getApp().globalData.user_id,
						num:that.money,
						sign: md5('tixian' + getApp().globalData.globalTimestamp)
					},
					success: res => {
						if (res.data.code === 200) {
							uni.showToast({
								title: '递交已申请',
								icon: 'none',
								duration:2000
							});
							that.money = 0;
							that.getUserInfo();
						}else{
						   uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration:2000
						   });
					  }
					}
			  	});
			  }else {
				  that.money = '';
				  uni.showToast({
				  	title: '可提现金额不足，请重新填写',
				  	icon: 'none',
					duration:3000
				  });
			  }
				
		   },
		   getAll(){
			   this.money = this.userInfoObj.nowmoney
		   }
	}
};
</script>

<style>
	.cash-out-box {
		width: 85%;
		height: 600rpx;
		background: #fff;
		border-radius: 15rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: 5% auto;
		padding: 15px;
	}
	.cash-input-box {
		width: 100%;
		margin-top: 5%;
		border-bottom: 1px solid #dbdbdb;
		display: flex;
		align-items: center;
		height: 80rpx;
	}
	.cash-input-box text {
		margin-right: 2%;
	}
	.all-cash-out-box {
		margin-top: 3%;
		font-size: 28rpx;
		width: 99%;
		color: #999;
	}
	.cash-out-box button {
		background: #1a9ed3;
		color: #fff;
		width: 99%;
		margin-top: 5%;
	}
</style>
