<template>
|
<div class="funds-contract">
|
<div class="sub-tabs">
|
<div @click="onTap(0)" :class="{ active: tapIndex === 0 }" class="sub-tab-item">{{ $t('永续合约') }}</div>
|
<div @click="onTap(1)" :class="{ active: tapIndex === 1 }" class="sub-tab-item">{{ $t('交割合约') }}</div>
|
</div>
|
|
<div class="balance-hero">
|
<div class="balance-hero-top">
|
<div class="balance-label">
|
<span>{{ $t('总资产') }}(USDT)</span>
|
<div class="eye-btn" @click.stop="changeEyes">
|
<img :src="handleImage('../../../assets/image/assets-center/eye-open.png')" v-show="!eyetel" />
|
<img :src="handleImage('../../../assets/image/assets-center/eye-close.png')" v-show="eyetel" />
|
</div>
|
</div>
|
<div class="history-btn" @click="goHistory">
|
<img :src="handleImage('../../../assets/image/assets-center/Subtract.png')" />
|
</div>
|
</div>
|
<div class="balance-amount" v-if="!eyetel">
|
{{ tapIndex === 0 ? funds.money_contract : funds.money_futures }}
|
</div>
|
<div class="balance-amount" v-else>********</div>
|
<div class="balance-fiat" v-if="!eyetel">
|
≈{{ currency.currency_symbol }}{{
|
(tapIndex === 0 ? funds.money_contract : funds.money_futures)
|
? (((tapIndex === 0 ? funds.money_contract : funds.money_futures) * currency.rate).toFixed(2))
|
: ' --'
|
}}
|
</div>
|
<div class="balance-fiat" v-else>≈{{ currency.currency_symbol }} ********</div>
|
|
<div class="stats-grid">
|
<div class="stat-block">
|
<div class="stat-block-label">{{ tapIndex === 0 ? $t('保证金余额') : $t('全部未实现盈亏') }}(USDT)</div>
|
<div class="stat-block-value" v-if="!eyetel">
|
{{ tapIndex === 0 ? funds.money_contract_deposit : funds.money_futures_profit }}
|
</div>
|
<div class="stat-block-value" v-else>********</div>
|
</div>
|
<div class="stat-block">
|
<div class="stat-block-label">{{ $t('钱包余额(USDT)') }}</div>
|
<div class="stat-block-value" v-if="!eyetel">{{ funds.money_wallet }}</div>
|
<div class="stat-block-value" v-else>********</div>
|
</div>
|
<div class="stat-block" v-if="tapIndex === 0">
|
<div class="stat-block-label">{{ $t('全部未实现盈亏') }}(USDT)</div>
|
<div class="stat-block-value" v-if="!eyetel">{{ funds.money_contract_profit }}</div>
|
<div class="stat-block-value" v-else>********</div>
|
</div>
|
</div>
|
</div>
|
|
<div class="position-section">
|
<template v-if="tapIndex === 0">
|
<PerpetualPositionList :list-data="orderHold" @sell="onRecall" />
|
</template>
|
<template v-else>
|
<futrue-hold-list :list-data="futrueHold" />
|
</template>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import { _getAllAssets } from "@/service/user.api.js";
|
import { mapGetters } from "vuex";
|
import PerpetualPositionList from '../perpetual-position-list/index.vue';
|
import futrueHoldList from '../deliveryContract/hold.vue'
|
import { _futrueOrderList, contractOrder } from "@/service/trade.api";
|
export default {
|
name: "contract",
|
components: {
|
PerpetualPositionList,
|
futrueHoldList
|
},
|
data() {
|
return {
|
orderHold: [], // 永续持有仓位
|
futrueHold: [], // 交割持有仓位
|
tapIndex: 0,
|
eyetel: false,
|
total: "",
|
timer: null,
|
timer2: null
|
}
|
},
|
props: ['funds', 'index'],
|
computed: {
|
...mapGetters('home', ['currency'])
|
},
|
watch: {
|
index: {
|
handler: function (val) {
|
console.log(val)
|
this.tapIndex = val / 1
|
},
|
immediate: true
|
}
|
},
|
created() {
|
this.fetch()
|
},
|
methods: {
|
handleImage(url) {
|
return new URL(url, import.meta.url).href
|
},
|
goHistory() {
|
if (this.tapIndex === 0) {
|
this.$router.push({ path: '/cryptos/perpetualHistory', query: { goback: 1 } })
|
} else {
|
this.$router.push({ path: '/cryptos/deliveryContractHistory', query: { goback: 1 } })
|
}
|
},
|
onTap(index) {
|
this.tapIndex = index
|
this.fetch()
|
},
|
fetch() {
|
this.clearTimer()
|
if (this.tapIndex === 0) {
|
this.fetchOrderListHold()
|
} else {
|
this.fetchFutrueHoldList()
|
}
|
},
|
onRecall() { // 撤单or 平仓 evt
|
// this.clearTimer()
|
// this[this.curTab](this.symbol)
|
// this.fetchOrderListHold()
|
},
|
clearTimer() {
|
clearInterval(this.timer)
|
clearInterval(this.timer2)
|
this.timer = null
|
this.timer2 = null
|
},
|
fetchOrderListHold() { // 获取永续当前持仓
|
let obj = {
|
type: 'orders',
|
page_no: 1,
|
symbolType: 'cryptos'
|
}
|
contractOrder(obj).then(data => {
|
this.orderHold = data
|
})
|
//TODO:轮询
|
this.timer = setInterval(() => {
|
contractOrder(obj).then(data => {
|
this.orderHold = data
|
})
|
}, 2000)
|
},
|
fetchFutrueHoldList() { // 获取交割当前持仓
|
_futrueOrderList().then(data => {
|
this.futrueHold = data
|
})
|
console.log('fetchFutrueHoldList')
|
this.timer2 = setInterval(() => {
|
_futrueOrderList().then(data => {
|
this.futrueHold = data
|
})
|
}, 2000)
|
},
|
changeEyes() {
|
console.log('666')
|
this.eyetel = !this.eyetel;
|
},
|
getData() {
|
console.log('sss')
|
_getAllAssets().then((data) => {
|
this.total = data.total;
|
this.status = data.status;
|
});
|
},
|
},
|
beforeUnmount() {
|
this.clearTimer()
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
@import "@/assets/init.scss";
|
|
.funds-contract {
|
padding-top: 16px;
|
padding-bottom: 40px;
|
}
|
|
.sub-tabs {
|
display: flex;
|
gap: 16px;
|
margin-bottom: 24px;
|
}
|
|
.sub-tab-item {
|
flex: 1;
|
text-align: center;
|
padding: 20px 16px;
|
border-radius: 16px;
|
font-size: 28px;
|
transition: all 0.2s ease;
|
@include themify() {
|
background: themed('cont_background');
|
color: themed('text_color1');
|
}
|
|
&.active {
|
color: #fff;
|
background: linear-gradient(135deg, #1a6dff 0%, #004aee 100%);
|
font-weight: 600;
|
box-shadow: 0 6px 16px rgba(0, 74, 238, 0.28);
|
}
|
}
|
|
.balance-hero {
|
padding: 36px 32px;
|
border-radius: 24px;
|
background: linear-gradient(135deg, #1a6dff 0%, #004aee 55%, #0035b8 100%);
|
color: #fff;
|
box-shadow: 0 16px 40px rgba(0, 74, 238, 0.28);
|
margin-bottom: 28px;
|
}
|
|
.balance-hero-top {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 16px;
|
}
|
|
.balance-label {
|
display: flex;
|
align-items: center;
|
gap: 16px;
|
font-size: 26px;
|
opacity: 0.9;
|
}
|
|
.eye-btn img {
|
width: 36px;
|
height: 22px;
|
}
|
|
.history-btn img {
|
width: 36px;
|
height: 42px;
|
opacity: 0.85;
|
}
|
|
.balance-amount {
|
font-size: 56px;
|
font-weight: 700;
|
line-height: 1.15;
|
}
|
|
.balance-fiat {
|
margin-top: 8px;
|
font-size: 26px;
|
opacity: 0.85;
|
}
|
|
.stats-grid {
|
display: flex;
|
flex-wrap: wrap;
|
gap: 12px;
|
margin-top: 28px;
|
padding-top: 24px;
|
border-top: 1px solid rgba(255, 255, 255, 0.2);
|
}
|
|
.stat-block {
|
flex: 1;
|
min-width: 40%;
|
padding: 16px;
|
border-radius: 14px;
|
background: rgba(255, 255, 255, 0.12);
|
}
|
|
.stat-block-label {
|
font-size: 22px;
|
opacity: 0.85;
|
line-height: 1.3;
|
}
|
|
.stat-block-value {
|
margin-top: 8px;
|
font-size: 28px;
|
font-weight: 600;
|
}
|
|
.position-section {
|
margin-top: 8px;
|
}
|
</style>
|