<template>
	<view class="YmContent" :animation="animationData">
		<view class="application_for_withdrawal_71">
			<text decode="true" class="application_for_withdrawal_74">提现金额</text>
			<view class="application_for_withdrawal_75">
				<text decode="true" class="application_for_withdrawal_76">￥</text>
				<input v-model="moneys" class="application_for_withdrawal_77" maxlength="10" />
				<!-- @input="AmountBlur"  -->
			</view>
			<view class="application_for_withdrawal_81">
				<text decode="true" class="application_for_withdrawal_82">可提现金额为{{balance}}元</text>
				<text decode="true" class="application_for_withdrawal_83" @click="AllMoney">全部提现</text>
			</view>
			<!-- 	<radio-group class="payType">
					<image   src="../../static/application_for_withdrawal_85_10.jpg" mode="scaleToFill" border="0"    class="application_for_withdrawal_85"></image>
					<text decode="true" class="application_for_withdrawal_86">微信</text>
					<radio value="wx"  class="application_for_withdrawal_87">
					</radio>
					<image   src="/static/application_for_withdrawal/images/application_for_withdrawal_88_13.jpg" mode="scaleToFill" border="0"    class="application_for_withdrawal_88"></image>
					<text decode="true" class="application_for_withdrawal_89">支付宝</text>
					<radio value="zfb"  class="application_for_withdrawal_90">
					</radio>
				</radio-group> -->
			<button class="btSubmit" @click="deposit">确认提现
			</button>
		</view>
		<view class="loading">{{loadingText}}</view>
		<view class="ymBbottom"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				balance: 0,
				model: {
					"openid": "",
					// 分单位
					"amount": 0,
					"desc": "尚腾提现"
				},
				moneys: 0,
				boolmoney: true,
				// 提现记录
				modelmoney: {
					"id": 0,
					"openid": '',
					"remark": '',
					"username": "",
					"userid": 0,
					"oldmoney": 0,
					"nowmoney": 0,
					"money": 0,
					"add_time": "2022-01-18T01:51:01.541Z",
					"status": 0
				}
			}
		},
		onLoad(item) {
			console.log('原始', item)
			let data = JSON.parse(decodeURIComponent(item.balance))
			this.balance = data
			// 原金额
			// this.modelmoney.oldmoney=this.balance
			console.log('数据', data)
		},
		methods: {
			// 审核提现
			checkDeposit() {
				let regs = /^\d+(\.\d{0,2})?$/;
				let storage = uni.getStorageSync('userinfo')
				// this.model.openid = storage.openid
				this.modelmoney.openid = storage.data.openid
				if (this.moneys == 0) {
					uni.showToast({
						title: '请输入金额',
						icon: 'none'
					})
				} else if (!regs.test(this.moneys)) {
					uni.showToast({
						title: '不能出现金额外的字符',
						icon: 'none'
					})
				} else if (this.moneys < 1) {
					uni.showToast({
						title: '金额不能小于1',
						icon: 'none'
					})
				} else {
					this.modelmoney.oldmoney = this.balance * 100
					this.modelmoney.money = this.moneys * 100
					if (this.modelmoney.oldmoney < this.modelmoney.money) {
						uni.showToast({
							title: '余额不足，无法进行提现',
							icon: 'none'
						})
					} else {
						this.modelmoney.nowmoney = this.modelmoney.oldmoney - this.modelmoney.money
						let bool = this.AddMoney()
						if (bool) {
							uni.showToast({
								title: '已提交审核提现',
								icon: 'success'
							})
						} else {
							uni.showToast({
								title: '提现失败',
								icon: 'none'
							})
						}
					}
				}
			},
			// 确认提现
			deposit() {
				let regs = /^\d+(\.\d{0,2})?$/;
				let storage = uni.getStorageSync('userinfo')
				this.model.openid = storage.data.openid
				this.modelmoney.oldmoney = this.balance * 100
				if (this.moneys == 0) {
					uni.showToast({
						title: '请输入金额',
						icon: 'none'
					})
				} else if (!regs.test(this.moneys)) {
					uni.showToast({
						title: '不能出现金额外的字符',
						icon: 'none'
					})
				} else if (this.moneys < 1) {
					uni.showToast({
						title: '金额不能小于1',
						icon: 'none'
					})
				} else {
					this.model.amount = this.moneys * 100
					if (this.balance < this.moneys) {
						uni.showToast({
							title: '余额不足，无法进行提现',
							icon: 'none'
						})
					}else{
						this.API.GetPay(this.model).then(res => {
							console.log('res支付', res)
							if (res.data.code == 200) {
								this.API.UpdBlanceByUser({
									userid: storage.data.id,
									amount: this.model.amount
								}).then(res => {
									console.log('res更改金额')
									if (res.data.code == 200) {
										storage = res.data
										uni.setStorageSync('userinfo', storage)
										uni.showToast({
											title: '提现成功',
											icon: 'success',
											duration: 1000
										})
										this.modelmoney.status = 0
										setTimeout(() => {
											uni.switchTab({
												url: '../my/my'
											})
										}, 1000)
									} else {
										uni.showToast({
											title: '提现失败',
											icon: 'none'
										})
										this.modelmoney.status = -99
									}
									this.modelmoney.money = this.model.amount
									this.modelmoney.nowmoney = this.modelmoney.oldmoney - this.modelmoney.money
									this.AddMoney()
								})
						
							} else {
								uni.showToast({
									title: res.message,
									icon: 'none'
								})
							}
						})
					}
				}


			},
			// 添加提现记录
			AddMoney() {
				let jsonstorage = uni.getStorageSync('userinfo').data
				this.modelmoney.username = jsonstorage.username
				this.modelmoney.openid = jsonstorage.openid
				this.modelmoney.remark = "提现"
				this.modelmoney.userid = jsonstorage.id
				// this.modelmoney.oldmoney = jsonstorage.balance
				this.model.status = 0
				this.API.AddOrUpdMoney(this.modelmoney).then(res => {
					console.log('添加记录', res)
					if (res.code == 200) {
						console.log('添加提现记录成功')
					} else {
						console.log('添加提现记录失败')
					}
				})
				return true
			},
			// 全部提现
			AllMoney() {
				this.moneys = this.balance
			},
			// 输入框验证
			AmountBlur(e) {
				var money = e.target.value;
				let regs = /^\d+(\.\d{0,2})?$/;
				if (!regs.test(money)) {
					uni.showToast({
						title: '请输入整数或者小数(保留两位数)',
						icon: 'none'
					})
					this.boolmoney = false
				} else {
					this.boolmoney = true
				}
			}
		}
	}
</script>


<style>
	html,
	body,
	#app {
		height: 100%;
		width: 100%;
	}
	.YmContent {
		height: 100%;
		width: 100%;
	}
	uni-page-body,
	#app {
		height: 100%;
	}
	button::after {
		border: none;
		width: auto;
	}
	input {
		outline: none;
		border: none;
		list-style: none;
		width: auto;
	}
	.list_item {
		float: left;
	}
	.ym_hide {
		display: none;
	}
	.ym_show {
		display: block;
	}
	.slide-image {
		width: 100%;
		height: 100%;
	}
	.list_horizontal {
		width: auto;
		display: inline-block;
	}
	.application_for_withdrawal_71 {
		white-space: normal;
		width: 749upx;
		height: 100%;
		padding: 0upx;
		clear: both;
		float: left;
		background-color: #ffffff;
		border-radius: 0upx;
		font-size: 8upx;
	}
	.application_for_withdrawal_71 .application_for_withdrawal_74 {
		white-space: normal;
		width: 181upx;
		height: 34upx;
		padding: 0upx;
		clear: both;
		margin-top: 30upx;
		margin-left: 34upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 32upx;
		line-height: 34upx;
	}
	.application_for_withdrawal_71 .application_for_withdrawal_75 {
		white-space: normal;
		width: 647upx;
		height: 44upx;
		padding: 0upx;
		clear: both;
		margin-top: 68upx;
		margin-left: 34upx;
		float: left;
		border-radius: 0upx;
		font-size: 43upx;
		line-height: 44upx;
	}
	.application_for_withdrawal_71 .application_for_withdrawal_75 .application_for_withdrawal_76 {
		white-space: normal;
		width: auto;
		height: 44upx;
		padding: 0upx;
		margin-top: 0upx;
		margin-left: 0upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 43upx;
		line-height: 44upx;
	}
	.application_for_withdrawal_71 .application_for_withdrawal_75 .application_for_withdrawal_77 {
		white-space: normal;
		width: auto;
		height: 44upx;
		min-height: 44upx;
		padding: 0upx;
		margin-top: 0upx;
		margin-left: 25upx;
		float: left;
		border-radius: 0upx;
		color: #c8c8c8;
		font-size: 43upx;
		line-height: 43upx;
	}
	.application_for_withdrawal_71 .application_for_withdrawal_81 {
		white-space: normal;
		width: 704upx;
		height: 36upx;
		padding: 0upx;
		clear: both;
		margin-top: 85upx;
		margin-left: 32upx;
		float: left;
		border-radius: 0upx;
		font-size: 29upx;
		line-height: 36upx;
	}
	.application_for_withdrawal_71 .application_for_withdrawal_81 .application_for_withdrawal_82 {
		white-space: normal;
		width: 377upx;
		height: 36upx;
		padding: 0upx;
		margin-top: 0upx;
		margin-left: 0upx;
		float: left;
		border-radius: 0upx;
		color: #c8c8c8;
		font-size: 29upx;
		line-height: 36upx;
	}
	.application_for_withdrawal_71 .application_for_withdrawal_81 .application_for_withdrawal_83 {
		white-space: normal;
		width: 128upx;
		height: 36upx;
		padding: 0upx;
		margin-top: 0upx;
		margin-left: 186upx;
		float: left;
		border-radius: 0upx;
		color: #ff4342;
		font-size: 29upx;
		line-height: 36upx;
	}
	.application_for_withdrawal_71 .payType {
		white-space: normal;
		width: 683upx;
		height: 50upx;
		padding: 0upx;
		clear: both;
		margin-top: 64upx;
		margin-left: 33upx;
		float: left;
		border-radius: 0upx;
		font-size: 49upx;
		line-height: 50upx;
	}
	.application_for_withdrawal_71 .payType .application_for_withdrawal_85 {
		white-space: normal;
		width: 46upx;
		height: 47upx;
		padding: 0upx;
		margin-top: 3upx;
		margin-left: 2upx;
		float: left;
		border-radius: 0upx;
		font-size: 48upx;
		line-height: 47upx;
	}
	.application_for_withdrawal_71 .payType .application_for_withdrawal_86 {
		white-space: normal;
		width: 61upx;
		height: 28upx;
		padding: 0upx;
		margin-top: 11upx;
		margin-left: 23upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 27upx;
		line-height: 28upx;
	}
	.application_for_withdrawal_71 .payType .application_for_withdrawal_87 {
		white-space: normal;
		width: 43upx;
		height: 44upx;
		padding: 0upx;
		margin-top: 2upx;
		margin-left: 4upx;
		float: left;
		border-radius: 0upx;
		font-size: 43upx;
		line-height: 44upx;
	}
	.application_for_withdrawal_71 .payType .application_for_withdrawal_88 {
		white-space: normal;
		width: 47upx;
		height: 47upx;
		padding: 0upx;
		margin-top: 3upx;
		margin-left: 105upx;
		float: left;
		border-radius: 0upx;
		font-size: 49upx;
		line-height: 47upx;
	}
	.application_for_withdrawal_71 .payType .application_for_withdrawal_89 {
		white-space: normal;
		width: 81upx;
		height: 29upx;
		padding: 0upx;
		margin-top: 11upx;
		margin-left: 22upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 27upx;
		line-height: 29upx;
	}
	.application_for_withdrawal_71 .payType .application_for_withdrawal_90 {
		white-space: normal;
		width: 43upx;
		height: 43upx;
		padding: 0upx;
		margin-top: 3upx;
		margin-left: 11upx;
		float: left;
		border-radius: 0upx;
		font-size: 42upx;
		line-height: 43upx;
	}
	.application_for_withdrawal_71 .btSubmit {
		white-space: normal;
		width: 679upx;
		height: 92upx;
		padding: 0upx;
		clear: both;
		margin-top: 63upx;
		margin-left: 35upx;
		float: left;
		background-color: #ff4342;
		text-align: center;
		justify-content: center;
		border-radius: 10upx;
		cursor: pointer;
		color: #ffffff;
		font-size: 27upx;
		line-height: 92upx;
	}
	.application_for_withdrawal_71 .btSubmit_label {
		float: left;
	}
	.application_for_withdrawal_71 .btSubmit_button {
		float: left;
		color: #000000;
		font-size: 30rpx;
		text-align: center;
		line-height: 30rpx;
		border-color: #e1e1e1;
		border-width: 1rpx;
		border-style: solid;
		border-radius: 5rpx;
		padding: 10rpx;
		margin: 15rpx;
	}
	.application_for_withdrawal_71 .btSubmit_button_select {
		float: left;
		color: #ff8000;
		font-size: 30rpx;
		text-align: center;
		line-height: 30rpx;
		border-color: #ff8000;
		border-width: 1rpx;
		border-style: solid;
		border-radius: 5rpx;
		padding: 10rpx;
		margin: 15rpx;
	}
	.application_for_withdrawal_71 .btSubmit_title {
		float: left;
	}
</style>
