<template>
	<view class="">
		<switchPopup ref="switchPopupRef" :availableMoney="getBiMoney(from_field)" :from_field="from_field" :to_field="to_field">
			<template #accountbox>
				<view class="account-item" @click.stop="from_field !== 'change' ? selectBiType(from_field) : ''">
					<text class="account-item-lable">{{ getBiName(from_field) }}账户</text>
					<text class="iconfont" v-show="from_field !== 'change'">&#xe601;</text>
				</view>
				<view class="account-link" @click.stop="switchBiType">
					<text class="iconfont">&#xe607;</text>
					<text>划转</text>
				</view>
				<view class="account-item" @click.stop="to_field !== 'change' ? selectBiType(to_field) : ''">
					<text class="account-item-lable">{{ getBiName(to_field) }}账户</text>
					<text class="iconfont" v-show="to_field !== 'change'">&#xe601;</text>
				</view>
			</template>
		</switchPopup>
		<settingBi ref="settingBiRef" :activeBiType.sync="activeBiType"/>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import {
		biName
	} from "../card.js"
	import settingBi from "./setting-bi.vue"
	import switchPopup from "../switch.vue"
	// 合约 - 币币
	// 币币 - 合约 / 法币
	export default {
		name: "capitalSwitchModules",
		data() {
			return {
				from_field: 'change',
				to_field: 'lever',
				activeBiType: ''
			};
		},
		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
			}
		},
		components: {
			settingBi,
			switchPopup
		},
		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.switchPopupRef.open();
				})
			},
	 
		 
			selectBiType(val) {
				this.activeBiType = val
				console.log('selectBiType = ', this.activeBiType)
				this.$nextTick(() => {
					this.$refs.settingBiRef.open()
				})
			}

		}
	}
</script>

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