|
|
@@ -1,23 +1,20 @@
|
|
|
<!-- 我的持仓-订单持仓 -->
|
|
|
<template>
|
|
|
- <app-pull-refresh ref="pullRefreshRef" v-model:loading="loading" v-model:error="error" v-model:pageIndex="pageIndex"
|
|
|
- :page-count="pageCount" @refresh="run">
|
|
|
+ <app-pull-refresh ref="pullRefreshRef" v-model:loading="loading" @refresh="onRefresh">
|
|
|
<div class="g-order-list">
|
|
|
- <div class="g-order-list__box" v-for="(item, index) in dataList" :key="index">
|
|
|
+ <div class="g-order-list__box" v-for="(item, index) in positionList" :key="index">
|
|
|
<div class="g-order-list__titlebar">
|
|
|
<div class="left">
|
|
|
<h4>{{ item.goodscode }}/{{ item.goodsname }}</h4>
|
|
|
</div>
|
|
|
<div class="right">
|
|
|
- <span :class="!item.buyorsell ? 'g-price-up' : 'g-price-down'">{{ getBuyOrSellName(item.buyorsell)
|
|
|
- }}</span>
|
|
|
+ <span :class="!item.buyorsell ? 'g-price-up' : 'g-price-down'">
|
|
|
+ {{ getBuyOrSellName(item.buyorsell) }}
|
|
|
+ </span>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="g-order-list__content">
|
|
|
<ul>
|
|
|
- <li :class="lastColor(item.goodscode)">{{ last(item.goodscode) }}</li>
|
|
|
- </ul>
|
|
|
- <ul>
|
|
|
<li>
|
|
|
<span>持有数量</span>
|
|
|
<span>{{ formatDecimal(item.curpositionqty) }}</span>
|
|
|
@@ -40,8 +37,9 @@
|
|
|
</li>
|
|
|
<li>
|
|
|
<span>参考损益</span>
|
|
|
- <span :class="getAmountColor(closepl(item))">{{ formatDecimal(closepl(item))
|
|
|
- }}</span>
|
|
|
+ <span :class="handlePriceColor(item.closepl, 0)">
|
|
|
+ {{ formatDecimal(item.closepl) }}
|
|
|
+ </span>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
@@ -60,60 +58,29 @@
|
|
|
import { shallowRef, defineAsyncComponent } from 'vue'
|
|
|
import { Button } from 'vant'
|
|
|
import { useComponent } from '@/hooks/component'
|
|
|
-import { useRequest } from '@/hooks/request'
|
|
|
-import { queryTradePosition } from '@/services/api/order'
|
|
|
import AppPullRefresh from '../../../../../../components/base/pull-refresh/index.vue'
|
|
|
-import { getBuyOrSellName, BuyOrSell } from '@/constants/order'
|
|
|
-import { formatDecimal, handleNumberValue } from '@/filters'
|
|
|
-import { useFuturesStore } from '@/stores'
|
|
|
-import { getAmountColor } from '@/utils/vant';
|
|
|
+import { getBuyOrSellName } from '@/constants/order'
|
|
|
+import { formatDecimal, handleNumberValue, handlePriceColor } from '@/filters'
|
|
|
+import { usePosition } from '@/business/position'
|
|
|
+import eventBus from '@/services/bus'
|
|
|
|
|
|
const componentMap = new Map<string, unknown>([
|
|
|
['close', defineAsyncComponent(() => import('../close/Index.vue'))],
|
|
|
['delivery', defineAsyncComponent(() => import('../delivery/Index.vue'))]
|
|
|
])
|
|
|
|
|
|
-const futuresStore = useFuturesStore()
|
|
|
-
|
|
|
-const dataList = shallowRef<Model.TradePositionRsp[]>([])
|
|
|
+const { positionList, loading } = usePosition(50)
|
|
|
const selectedRow = shallowRef<Model.TradePositionRsp>()
|
|
|
-const error = shallowRef(false)
|
|
|
const pullRefreshRef = shallowRef()
|
|
|
|
|
|
-const last = (goodsCode: string) => {
|
|
|
- return futuresStore.getQuotePrice(goodsCode)
|
|
|
-}
|
|
|
-
|
|
|
-const lastColor = (goodsCode: string) => {
|
|
|
- return futuresStore.getQuoteInfo(goodsCode).value?.lastColor
|
|
|
-}
|
|
|
-
|
|
|
-/// 计算参考损益
|
|
|
-const closepl = (item: Model.TradePositionRsp) => {
|
|
|
- const { last = 0 } = futuresStore.getQuoteInfo(item.goodscode).value ?? {}
|
|
|
- const { curpositionqty, curholderamount, agreeunit, buyorsell } = item
|
|
|
- return (last * curpositionqty * agreeunit - curholderamount) * (buyorsell === BuyOrSell.Buy ? 1 : -1)
|
|
|
-}
|
|
|
-
|
|
|
const { componentRef, componentId, openComponent, closeComponent } = useComponent(() => {
|
|
|
pullRefreshRef.value?.refresh()
|
|
|
})
|
|
|
|
|
|
-const { loading, pageIndex, pageCount, run } = useRequest(queryTradePosition, {
|
|
|
- params: {
|
|
|
- pagesize: 20,
|
|
|
- tradeMode: '50'
|
|
|
- },
|
|
|
- onSuccess: (res) => {
|
|
|
- if (pageIndex.value === 1) {
|
|
|
- dataList.value = []
|
|
|
- }
|
|
|
- dataList.value.push(...res.data)
|
|
|
- },
|
|
|
- onError: () => {
|
|
|
- error.value = true
|
|
|
- }
|
|
|
-})
|
|
|
+// 通知持仓列表刷新
|
|
|
+const onRefresh = () => {
|
|
|
+ eventBus.$emit('PosChangedNtf')
|
|
|
+}
|
|
|
|
|
|
const showComponent = (componentName: string, row: Model.TradePositionRsp) => {
|
|
|
selectedRow.value = row
|