<template>
	<view class="integralTransforms">
		<view class="header">
			<text class="title">{{ jifen || '0.00' }}</text><br>
			<text>可转换余额</text>
		</view>
		<view class="account">
			<text class="title">收款人账户</text>
			<input type="number" placeholder="请输入收款人账户" 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="num">
			<text class="title">交易密码</text>
			<view class="">
				<text class="ti">￥</text>
				<input type="password" v-model.number="password" placeholder="请输入交易密码" />
			</view>
		</view>
		<view class="button" @click="submit">
			提交申请
		</view>
	</view>
</template>

<script>
import { goPay,moneyLog, recharge, wallet } from '@/api/finance.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.password == ''){
					obj.$api.msg("请输入交易密码")
				}
				if(obj.account == this.userInfo.uid){
					obj.$api.msg('请勿转账给自己')
					return
				}
				goPay({
					
					type: 'SCJF',
					num: obj.num,
					to_uid: obj.account,
					trade_psw: obj.password,
					// to_user_account: obj.account
				}).then(data =>{
					console.log(data,'转账')
					obj.num = ''
					obj.account = ''
					obj.password = ''
					uni.navigateTo({
						url:'/pages/money/success'
					})
				})
				
				
			}
		},
		computed: {

			//积分
			// integral() {
			// 	return this.$store.state.user.userInfo.integral
			// 	console.log(UserInfo)
			// },
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
		},
		onLoad(option) {
		
			console.log(this.userInfo)
			wallet({}).then(({data}) => {
				const obj = this
				const arr = Object.keys(data.back)
				console.log(data.back)
				arr.forEach(e => {
					if(e =='SCJF'){
						obj.jifen = (data.back[e].money.money * 1)
						console.log(obj.jifen)
					}
					
				})
			})
		},
		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: linear-gradient(90deg, #438BED 0%, #44BFEC 100%);
			color: #fff;
		}
	}
</style>
