|
|
@@ -1,137 +0,0 @@
|
|
|
-<!-- 掉期市场-持仓汇总-平仓 -->
|
|
|
-<template>
|
|
|
- <app-drawer :title="`${position.goodscode}/${position.goodsname}`" v-model:show="show" :width="1100" :loading="loading"
|
|
|
- :refresh="refresh">
|
|
|
- <app-table :data="computedList" v-model:columns="tableColumns" :loading="loading" :row-key="rowKey"
|
|
|
- :expand-row-keys="expandKeys" @row-click="rowClick">
|
|
|
- <!-- 方向 -->
|
|
|
- <template #buyorsell="{ value }">
|
|
|
- {{ getBuyOrSellName(value) }}
|
|
|
- </template>
|
|
|
- <!-- 持仓金额 -->
|
|
|
- <template #holderamount="{ value }">
|
|
|
- {{ formatDecimal(value) }}
|
|
|
- </template>
|
|
|
- <!-- 可用数量 -->
|
|
|
- <template #enableqty="{ row }">
|
|
|
- {{ row.holderqty - row.freezeqty }}
|
|
|
- </template>
|
|
|
- <!-- 到期日 -->
|
|
|
- <template #expiredate="{ value }">
|
|
|
- {{ formatDate(value, 'YYYY/MM/DD') }}
|
|
|
- </template>
|
|
|
- <!-- 平仓盈亏 -->
|
|
|
- <template #closepl="{ row }">
|
|
|
- <span :class="handlePriceColor(row.closepl)">{{ formatDecimal(row.closepl, quote?.decimalplace) }}</span>
|
|
|
- </template>
|
|
|
- <!-- 操作 -->
|
|
|
- <template #operate="{ row }">
|
|
|
- <div class="buttonbar" v-if="useStore.userType === 5 && [1, 3].includes(quote?.goodstradetype ?? 0)">
|
|
|
- <el-button type="danger" size="small" @click="onCloseSubmit(row)">平仓</el-button>
|
|
|
- </div>
|
|
|
- <span v-else>--</span>
|
|
|
- </template>
|
|
|
- </app-table>
|
|
|
- <template #footer>
|
|
|
- <el-button type="info" @click="show = false">取消</el-button>
|
|
|
- </template>
|
|
|
- </app-drawer>
|
|
|
-</template>
|
|
|
-
|
|
|
-<script lang="ts" setup>
|
|
|
-import { shallowRef, ref, PropType, computed } from 'vue'
|
|
|
-import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
-import { useComposeTable } from '@pc/components/base/table'
|
|
|
-import { useRequest } from '@/hooks/request'
|
|
|
-import { useHolderClose } from '@/business/trade'
|
|
|
-import { queryTradeHolderDetail } from '@/services/api/order'
|
|
|
-import { formatDate, formatDecimal, handlePriceColor, handleRequestBigNumber, round } from '@/filters'
|
|
|
-import { getBuyOrSellName } from '@/constants/order'
|
|
|
-import { ETradeMode } from '@/constants/client'
|
|
|
-import AppDrawer from '@pc/components/base/drawer/index.vue'
|
|
|
-import AppTable from '@pc/components/base/table/index.vue'
|
|
|
-import { useFuturesStore, useUserStore } from '@/stores'
|
|
|
-import { BuyOrSell } from '@/constants/order'
|
|
|
-
|
|
|
-const props = defineProps({
|
|
|
- position: {
|
|
|
- type: Object as PropType<Model.TradePositionRsp>,
|
|
|
- required: true,
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
-const { rowKey, expandKeys, rowClick } = useComposeTable<Model.TradeHolderDetailRsp>({ rowKey: 'tradeid' })
|
|
|
-
|
|
|
-const { holderCloseSubmit, formData } = useHolderClose()
|
|
|
-const show = ref(true)
|
|
|
-const refresh = ref(false)
|
|
|
-const useStore = useUserStore()
|
|
|
-const futuresStore = useFuturesStore()
|
|
|
-
|
|
|
-const refQuote = futuresStore.getGoodsQuote(props.position.refgoodscode)
|
|
|
-const quote = futuresStore.getGoodsQuote(props.position.goodscode)
|
|
|
-
|
|
|
-const { dataList, loading, run } = useRequest(queryTradeHolderDetail, {
|
|
|
- params: {
|
|
|
- /// 交易模式, 格式 1,2,3
|
|
|
- trademodes: ETradeMode.TRADEMODE_TJMD.toString(),
|
|
|
- /// marketid
|
|
|
- marketids: props.position.marketid.toString(),
|
|
|
- /// 商品id
|
|
|
- goodsid: props.position.goodsid,
|
|
|
- /// 买卖方向 0-买 1-卖
|
|
|
- buyorsell: props.position.buyorsell
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
-const computedList = computed(() => dataList.value.map((item) => {
|
|
|
- const last = refQuote.value?.last || quote.value?.last || 0 // 有 refgoodscode 的优先取 refgoodscode 行情
|
|
|
- const presettle = quote.value?.presettle || 0
|
|
|
- const price = last || presettle // 没有最新价取昨结价
|
|
|
-
|
|
|
- // 计算市值 = 现价 * 数量 * 合约单位
|
|
|
- const marketValue = price ? price * item.holderqty * item.agreeunit : 0
|
|
|
- const roundedMarketValue = round(marketValue, quote.value?.decimalplace)
|
|
|
- // 计算浮动盈亏
|
|
|
- const closepl = price ? (roundedMarketValue - item.holderamount) * (item.buyorsell === BuyOrSell.Buy ? 1 : -1) : 0
|
|
|
-
|
|
|
- return {
|
|
|
- ...item,
|
|
|
- closepl
|
|
|
- }
|
|
|
-}))
|
|
|
-
|
|
|
-const tableColumns = shallowRef<Model.TableColumn[]>([
|
|
|
- { field: 'tradeid', label: '单号' },
|
|
|
- { field: 'buyorsell', label: '方向' },
|
|
|
- { field: 'holderqty', label: '持有量' },
|
|
|
- { field: 'freezeqty', label: '冻结量' },
|
|
|
- { field: 'enableqty', label: '可用量' },
|
|
|
- { field: 'holderprice', label: '订单价格' },
|
|
|
- { field: 'holderamount', label: '订单金额' },
|
|
|
- { field: 'closepl', label: '参考损益' },
|
|
|
- { field: 'expiredate', label: '到期日' },
|
|
|
- { field: 'operate', label: '操作', fixed: 'right', width: 100 }
|
|
|
-])
|
|
|
-
|
|
|
-const onCloseSubmit = (row: Model.TradeHolderDetailRsp) => {
|
|
|
- ElMessageBox.confirm(
|
|
|
- '是否立即平仓?',
|
|
|
- '提示'
|
|
|
- ).then(() => {
|
|
|
- const { marketid, goodsid, buyorsell, tradeid } = row
|
|
|
- formData.Header = { MarketID: marketid, GoodsID: goodsid }
|
|
|
- formData.GoodsID = goodsid
|
|
|
- formData.BuyOrSell = buyorsell
|
|
|
- formData.MarketID = marketid
|
|
|
- formData.TradeID = handleRequestBigNumber(tradeid)
|
|
|
-
|
|
|
- holderCloseSubmit().then(() => {
|
|
|
- ElMessage.success('提交成功')
|
|
|
- run()
|
|
|
- }).catch((err) => {
|
|
|
- ElMessage.error('提交失败:' + err)
|
|
|
- })
|
|
|
- })
|
|
|
-}
|
|
|
-</script>
|