withdrawal.vue 9.5 KB
<template>
	<view class="">
		<image  class="bg" src="/static/takeMoneyBg.png" mode=""></image>
		<view class="top">
			<view >账户余额:</view>
			<view > <text style="32rpx">¥</text>{{money}}</view>
		</view>
		<view class="center">
			<view class="title" v-if="type==1">提现金额</view>
			<view class="inputPrice" v-if="type==1">
				<view class="">
					¥<input type="text" @input="checkNumber" v-model="form.price"/>
				</view>
				<view class="right" @click="takePrice">全部提现</view>
			</view>
			
			<!-- 支付要输入的信息 -->
			<view class="payInput"  v-if="form.withdraw_type==2">
				<view class="list">
					<view class="input" >支付宝收款姓名:</view>
					<input type="text" v-model="form.withdraw_name" placeholder="请输入" value="" />
				</view>
				<view class="list">
					<view class="input">支付宝绑定的账号:</view>
					<input type="text" v-model="form.withdraw_mobile" maxlength="11" placeholder="请输入" value="" />
				</view>
			</view>
			<view class="payInput"  v-if="form.withdraw_type==3">
				<view class="list">
					<view class="input">提现银行:</view>
					<input type="text" v-model="form.bank_name" placeholder="请选择" value="" />
				</view>
				<view class="list">
					<view class="input">银行卡号:</view>
					<input type="number" v-model="form.bank_num"  placeholder="请输入" value="" />
				</view>
				<view class="list">
					<view class="input">持卡人姓名:</view>
					<input type="number" v-model="form.name" maxlength="11" placeholder="请输入" value="" />
				</view>
			</view>
			<view class="line" v-if="type==1"></view>
			<view class="title" style="margin-top: 30rpx;">提现方式</view>
			
			<!-- 提现方式 -->
			<view class="payType">
				<view class="list" @click="toggleType(1)">
					<view class="left flexA">
						<image src="/static/wechat.png" mode=""></image>
						微信
					</view>
					<view class="right">
						<image v-if="form.withdraw_type==1" src="/static/checked.png" mode=""></image>
						<image v-else  src="/static/notCheck.png" mode=""></image>
					</view>
				</view>
				<view class="list" @click="toggleType(2)">
					<view class="left flexA">
						<image src="/static/zhifubao.png" mode=""></image>
						支付宝
					</view>
					<view class="right">
						<image v-if="form.withdraw_type==2" src="/static/checked.png" mode=""></image>
						<image v-else  src="/static/notCheck.png" mode=""></image>
					</view>
				</view>
				<view class="list" @click="toggleType(3)">
					<view class="left flexA">
						<image src="/static/yinlian.png" mode=""></image>
						银行卡支付
					</view>
					<view class="right">
						<image v-if="form.withdraw_type==3" src="/static/checked.png" mode=""></image>
						<image v-else  src="/static/notCheck.png" mode=""></image>
					</view>
				</view>
			</view>
			
			<view class="Withdrawal flexC" @click="takeMoney">提现</view>
			<view class="tips">
				温馨提示:为了平台更好的服务于平台用户,提示时平台将会提取交易金额的10%手续费用于维持平台的运营工作
			</view>
			
		</view>
	</view>
</template>

<script>
	import {toa} from '@/utils/toast.js'
	import { getUserInfo,takeMoney,takeBail } from '@/api/mine.js'
	export default{
		data() {
			return {
				payType:'1',
				money:0,
				price:'',
				form:{
					price:'', //	integer	否	提现金额
					withdraw_type:1, //	integer	是	提现方式:1=微信2=支付宝3=银行卡
					withdraw_name:'', //	string	否	支付宝收款姓名
					withdraw_mobile:'', //	string	否	支付宝绑定的手机号
					bank_name:'', //	string	否	提现银行
					bank_num:'', //	string	否	银行卡号
					name:'', //	string	否	持卡人姓名
				},
				type:1
			}
		},
		onLoad(e) {
			// 1 是余额  2是保证金
			this.type=  e.type
		},
		onShow() {
				this.getUserInfo()
		},
		methods: {
			async getUserInfo(){
			  try {
			    const res = await getUserInfo()
				if(this.type==1){
				   this.money = res.user.money
				}else {
					this.money = res.user.score
					this.form.price =  res.user.score
				}
			    console.log('getUserInfo', res)
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('getUserInfo', err)
			  }
			},
			
			// 切换支付方式
			toggleType(type){
				this.form.withdraw_type = type
			},
			
			// 提现全部按钮
			takePrice(){
				if(this.money<=0) return toa.toast('账户余额不足')
				this.form.price = this.money
			},
			checkNumber(e) {
				let val = e.target.value.replace(/(^\s*)|(\s*$)/g, "")
				var reg = /[^\d.]/g
							
				// 只能是数字和小数点,不能是其他输入
				val = val.replace(reg, "")
				// // 保证第一位只能是数字,不能是点
				val = val.replace(/^\./g, "");
				// // 小数只能出现1位
				val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				// // 小数点后面保留2位
				val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
				// console.log(val);
				this.$nextTick(() => {
					this.form.price = val;
				})
			},
			
			// 提现功能按钮
			 takeMoney(){
				if(this.money<=0) return toa.toast('账户余额不足')
				if(!this.money) return toa.toast('请输入提现金额')
				if(this.form.withdraw_type==1 && this.form.price<1) return toa.toast('微信提现最少提现1元') 
				if(this.form.withdraw_type==2 && !this.form.withdraw_name  ) return toa.toast('请输入支付宝收款姓名') 
				if(this.form.withdraw_type==2 && !this.form.withdraw_mobile ) return toa.toast('请输入支付宝收款手机号') 
				if(this.form.withdraw_type==3 && !this.form.bank_name  ) return toa.toast('请输入银行卡提现银行')
				if(this.form.withdraw_type==3 && !this.form.bank_num ) return toa.toast('请输入银行卡号')
				if(this.form.withdraw_type==3 && !this.form.name ) return toa.toast('请输入持卡人姓名')
				console.log(this.form);
				if(this.type==1){
					if(this.form.withdraw_type==1){
						toa.toast('微信提现暂未开放,敬请期待')
					}else {
						this.toTakeMoney()
					}
				}else {
					if(this.form.withdraw_type==1){
						toa.toast('微信提现暂未开放,敬请期待')
					}else {
						this.takeBail()
					}
				}
				
				  
			},
			async toTakeMoney(){
				try {
				  const res = await takeMoney(this.form)
				  setTimeout(()=>{
					  toa.success('提现提交成功,请等待审核')
				  },200)
				  for (let key in this.form) {
				  	this.form[key]=''
				  }
				  this.form.withdraw_type = 1
				  this.getUserInfo()
				  console.log('takeMoney', res)
				  // 保存数据
				} catch (err) {
								 	uni.showToast({ title:err,icon:'none' })
				  console.log('takeMoney', err)
				}
			},
			async takeBail(){
				try {
				  const res = await takeBail(this.form)
				  setTimeout(()=>{
					  toa.success('提现提交成功,请等待审核')
				  },200)
				  for (let key in this.form) {
				  	this.form[key]=''
				  }
				  this.form.withdraw_type = 1
				  this.getUserInfo()
				  console.log('takeMoney', res)
				  // 保存数据
				} catch (err) {
					uni.showToast({ title:err,icon:'none' })
				  console.log('takeMoney', err)
				}
			}
			
		},
	}
</script>

<style lang="less">
	page {
		background: #f6f6f6;
	}
	.bg {
		overflow: hidden;
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 366rpx;
	}
	.top {
		position: absolute;
		left: 32rpx;
		top: 64rpx;
		view:nth-child(1) {
			 color: rgba(0,0,0,0.4);
			 font-size: 28rpx;
		}
		view:nth-child(2) {
			 color: rgba(0,0,0,0.9);
			 font-size: 64rpx;
			 font-weight: 700;
		}
	}
	.center {
		position: absolute;
		width: 686rpx;
		left: 50%;
		top: 220rpx;
		border-radius: 24rpx;
		padding: 40rpx 30rpx;
		transform: translateX(-50%);
		background: #fff;
		box-sizing: border-box;
		.line {
			margin: 32rpx 0;
			width: 622rpx;
			height: 1rpx;
			background: rgba(240,242,245,1);
		}
		// 收到的信息
		.payInput {
			.list {
				display: flex;
				justify-content: space-between;
				font-size: 28rpx;
				margin: 32rpx 0;
				.input {
					flex: 1;
					font-weight: 700;
				}
				input {
					text-align: right;
					width:300rpx;
				}
			}
		}
		.title {
			font-weight: 700;
			margin-bottom: 32rpx;
			font-weight: 700;
		}
		.inputPrice {
			display: flex;
			justify-content: space-between;
			align-items: center;
			view {
				font-weight: 700;
				display: flex;
				align-items: center;
				 font-size: 52rpx;
				input {
					margin-left: 20rpx;
					font-weight: 400;
				}
			}
			.right {
				 color: rgba(33,83,212,1);
				  font-size: 28rpx;
				 font-weight: 400;
			}
		}
	}
	.payType {
		.list{
			margin-bottom: 32rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		.left {
			image {
				margin-right: 24rpx;
				width: 48rpx;
				height: 48rpx;
			}
		}
		.right {
			image {
				width: 36rpx;
				height: 36rpx;
			}
		}
	}
	.Withdrawal {
		margin: 100rpx auto 0;
		width: 622rpx;
		height: 88rpx;
		 color: rgba(0,0,0,0.9);
		 font-size: 32rpx;
		 font-weight: 700;
		border-radius: 28rpx;
		background: linear-gradient(90deg, rgba(255,230,89,1) 0%, rgba(255,216,0,1) 100%);
	}
	.tips {
		margin-top: 16rpx;
		 color: rgba(0,0,0,0.4);
		 font-size: 24rpx;
	}
</style>