<template>
	<uni-popup ref="popupRef">

		<view class="unopen-box">
			<text class="z-close iconfont" @click.stop="close">&#xe621;</text>
			<view class="unopen-title"> 
				<text>资金划转</text>
			</view>
			<slot name="accounthint"></slot>
			
			<view class="unopen-content">
				<view class="account-box">
					<slot name="accountbox"></slot>
				</view>
				<view class="capital-type">
					<text class="type-left">全部</text>
					<input class="type-input" type="number" v-model="moneyNum">
					<text class="type-rigth">USDT</text>
				</view>
				<view class="capital-nums">
					<text class="num-title">可划转金额：</text>
					<text class="num">{{ availableMoney }} USDT</text>
				</view>
				<view class="capital-btn" @click.stop="changeAccount">
					确定
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import { biName , setChangeAccount} from "./card.js" 
 
	// 合约 - 币币
	// 币币 - 合约 / 法币
	export default {
		name: "capitalSwitchModules",
		data() {
			return {
				moneyNum:''
			};
		},
		props:{
			availableMoney:{
				type:[Number , String],
				default:0
			},
			from_field:{
				type:String,
				default:''
			},
			to_field:{
				type:String,
				default:''
			},
		},
		watch:{
			activeBiType:{
				handler(newType , oldType){
					if(oldType === this.from_field){
						this.from_field = newType
					}
					if(oldType === this.to_field){
						this.to_field = newType
					};
				},
				immediate:true
			}
		},
	 
		computed: {
			...mapGetters([
				'contractAccount',
				'bibiAccount',
				'legalAccount'
			]),
			getBiName(){
				return function(key){
					return biName[key]
				}
			},
			getBiMoney(){
				return function(key){
					let nums = 0;
					switch(key){
						case 'lever':
						nums = this.contractAccount.usdt_totle
						break;
						case 'change':
						nums = this.bibiAccount.usdt_totle
						break;
						case 'legal':
						nums = this.legalAccount.usdt_totle
						break;
					};
					return nums || 0
				}
			}
		},
		mounted() {
	 
		},
		methods: {
			// 切换币
			switchBiType(){
				const k = this.from_field;
				this.from_field = this.to_field;
				this.to_field = k;
				// this.from_field:'legal',
				// to_field:'change'
			},
			open() {
				this.$nextTick(() => {
					this.$refs.popupRef.open();
				})
			},
			close() {
				this.$refs.popupRef.close();
			},
			changeAccount(){
				let data = {
					currency_id: 3,
					number:this.moneyNum,
					from_field:this.from_field,
					to_field:this.to_field
				}
				setChangeAccount(data).then(res => {
					this.$store.dispatch('possession/getPossession').then(res => {
						console.log('获取成功')
					}).catch(err => {
						console.log('获取shibai ')
					})
					
				}).catch(err => {
					
				}).finally(() => {
					this.close()
				})
			},
			 

		}
	}
</script>

<style lang="scss" scoped>
	 @import "~./switch.scss";
</style>