<template>
	<view class="integralTransforms">
		<view class="header">
			<text class="title">{{ jifen || '0.00' }}</text><br>
			<text>可转换积分</text>
		</view>
		<view class="account">
			<text class="title">收款人UID</text>
			<input type="number" placeholder="请输入收款人UID" v-model="account" />
		</view>
		<view class="num">
			<text class="title">转账数量</text>
			<view class="">
				<text class="ti">￥</text>
				<input type="number" v-model.number="num" placeholder="请输入转账数量" />
			</view>
		</view>
		<view class="button" @click="submit">
			提交申请
		</view>
	</view>
</template>

<script>
// import { goPay } from '@/api/finance.js';
import { spreadCommission, userBalance } from '@/api/wallet.js';
import { mapState, mapMutations } from 'vuex';
	
	export default {
		data() {
			return {
				password:'',//交易密码
				jifen:'',//可转积分
				num: '', //转账数量
				account: '', //收款人账户
				type:''
			}
		},
		methods: {
			
			submit() {
				let obj = this
				if(obj.account == ''){
					obj.$api.msg('请输入对方账号ID')
					return
				}
				if(obj.num ==''){
					obj.$api.msg('请输入转账数量')
					return
				}
				if(obj.account == this.userInfo.uid){
					obj.$api.msg('请勿转账给自己')
					return
				}
				goPay({
					num: obj.num,
					uid: obj.account,
				}).then(data =>{
					console.log(data,'转账')
					obj.num = ''
					obj.account = ''
					obj.$api.msg('转账成功')
				})
				
				
			}
		},
		computed: {

			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
		},
		onLoad(option) {
		
			// 获取用户余额
			userBalance({}).then(({ data }) => {
				this.jifen = data.now_money;
			});
		},
		watch: {
			num() {
				if (this.num > this.jifen) {
					this.num = this.jifen
				}
			}
		}
	}
</script>

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

		.header,
		.account,
		.num {
			background-color: #fff;
			margin: 20rpx 0;
			padding: 30rpx;

			input {
				margin-top: 10rpx;
			}

			.title {
				font-size: 30rpx;
				color: #333333;
				font-family: PingFang-SC-Regular;
			}
		}

		.header {
			text-align: center;

			text:nth-child(1) {
				font-size: 45rpx;
			}

			text:nth-child(3) {
				font-size: 30rpx;
				color: #666666;
			}
		}

		.num {
			.ti {
				float: left;
			}
		}

		.button {
			width: 520rpx;
			margin: 60rpx auto;
			padding: 20rpx;
			text-align: center;
			border-radius: 10rpx;
			background: #FF4C4C;
			color: #fff;
		}
	}
</style>
