|
|
@@ -0,0 +1,227 @@
|
|
|
+<!-- 挂牌点价-持仓明细-平仓 -->
|
|
|
+<template>
|
|
|
+ <app-drawer :title="t('operation.close')" :width="800" v-model:show="show" :loading="loading" :refresh="refresh">
|
|
|
+ <el-form ref="formRef" class="el-form--horizontal" label-width="120px" :model="formData" :rules="formRules">
|
|
|
+ <el-form-item :label="t('position.transfer.goodsname')">
|
|
|
+ <span>{{ selectedRow.goodscode }}/{{ selectedRow.goodsname }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="t('position.transfer.buyorsell')">
|
|
|
+ <span>{{ getBuyOrSellName(selectedRow.buyorsell) }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="t('position.transfer.buycurholderamount')">
|
|
|
+ <span>{{ formatDecimal(selectedRow.holderamount) }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="t('position.transfer.holderqty')">
|
|
|
+ <span>{{ selectedRow.holderqty }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="t('position.transfer.holderprice')">
|
|
|
+ <span>{{ formatDecimal(selectedRow.holderprice, selectedRow.decimalplace) }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="t('position.goods.freezeqty')">
|
|
|
+ <span>{{ selectedRow.freezeqty }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="t('position.transfer.enableqty')">
|
|
|
+ <span>{{ maxQty }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="t('position.transfer.closepl')">
|
|
|
+ <span :class="handlePriceColor(closepl)">{{ formatDecimal(closepl, selectedRow.decimalplace) }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="PriceMode" :label="t('quote.pricing.pricemode')">
|
|
|
+ <el-radio-group v-model="formData.PriceMode">
|
|
|
+ <el-radio v-for="(item, index) in getPricemode2List()" :key="index" :label="item.value">
|
|
|
+ {{ item.label }}
|
|
|
+ </el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="MarketMaxSub" :label="t('quote.pricing.marketmaxsub1')" v-if="formData.PriceMode === PriceMode.Market">
|
|
|
+ <el-input-number ref="priceRef" :placeholder="t('common.pleaseenter')" :min="0" :max="999" v-model="formData.MarketMaxSub" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="OrderPrice" :label="t('position.transfer.transferprice')" v-if="formData.PriceMode === PriceMode.Limit">
|
|
|
+ <el-input-number :placeholder="t('position.transfer.tips3')" v-model="formData.OrderPrice" :step="quote?.decimalvalue"
|
|
|
+ :precision="quote?.decimalplace" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="OrderQty" :label="t('position.transfer.transferqty')">
|
|
|
+ <div class="g-qty-group">
|
|
|
+ <el-input-number :placeholder="t('position.transfer.tips4')" v-model="formData.OrderQty" :precision="0" :max="maxQty"
|
|
|
+ :min="0" />
|
|
|
+ <el-radio-group size="small" v-model="qtyStep" @change="onRadioChange">
|
|
|
+ <el-radio v-for="(value, index) in qtyStepList" :key="index" :label="value" border
|
|
|
+ style="width: 25%;">
|
|
|
+ {{ parsePercent(value, 0) }}
|
|
|
+ </el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <el-button type="info" @click="onCancel(false)">{{ t('operation.cancel') }}</el-button>
|
|
|
+ <el-button type="primary" @click="onCloseSumit">{{ t('operation.submit') }}</el-button>
|
|
|
+ </template>
|
|
|
+ </app-drawer>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import { ref, PropType, computed, onMounted } from 'vue'
|
|
|
+import { ElMessage, FormInstance, FormRules } from 'element-plus'
|
|
|
+import { useOrder } from '@/business/trade'
|
|
|
+import { formatDecimal, handlePriceColor, handleRequestBigNumber, parsePercent } from '@/filters'
|
|
|
+import { getBuyOrSellName, BuyOrSell, getPricemode2List, PriceMode } from '@/constants/order'
|
|
|
+import { useFuturesStore, usePositionStore, i18n, useSettingStore, useUserStore } from '@/stores'
|
|
|
+import { EBuildType, EDelistingType, EListingSelectType, EValidType, EOrderOperateType } from '@/constants/client'
|
|
|
+import AppDrawer from '@pc/components/base/drawer/index.vue'
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ selectedRow: {
|
|
|
+ type: Object as PropType<Model.TradeHolderDetailRsp>,
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+const futuresStore = useFuturesStore()
|
|
|
+const positionStore = usePositionStore()
|
|
|
+const userStore = useUserStore()
|
|
|
+const settingStore = useSettingStore()
|
|
|
+// 价格类型
|
|
|
+const orderPriceType = computed(() => settingStore.getSettingValue('orderPriceType'))
|
|
|
+const quote = futuresStore.getGoodsQuote(props.selectedRow.goodscode)
|
|
|
+const { t } = i18n.global
|
|
|
+const qtyStepList = [0.25, 0.5, 0.75, 1] // 数量步长列表
|
|
|
+const qtyStep = ref(1) // 数量步长
|
|
|
+const { formSubmit, formData, loading } = useOrder()
|
|
|
+const show = ref(true)
|
|
|
+const refresh = ref(false)
|
|
|
+const formRef = ref<FormInstance>()
|
|
|
+
|
|
|
+// 可用数量
|
|
|
+const maxQty = computed(() => {
|
|
|
+ const record = positionStore.positionList.find((e) => e.goodsid === props.selectedRow.goodsid && e.buyorsell === props.selectedRow.buyorsell)
|
|
|
+ const qty = props.selectedRow.holderqty - props.selectedRow.freezeqty
|
|
|
+ return Math.min(record?.enableqty ?? 0, qty)
|
|
|
+})
|
|
|
+
|
|
|
+// 损益
|
|
|
+const closepl = computed(() => {
|
|
|
+ const { presettle = 0, last = 0 } = quote.value ?? {}
|
|
|
+ const { holderqty, holderamount, agreeunit, buyorsell, currencyid, tacurrencyid } = props.selectedRow
|
|
|
+ const price = last || presettle // 没有最新价取昨结价
|
|
|
+
|
|
|
+ // 查找汇率
|
|
|
+ let exchangerate = 1
|
|
|
+ if (currencyid !== tacurrencyid) {
|
|
|
+ const currency = userStore.userData.exchangeRateConfigs.find((e) => e.descurrencyid === tacurrencyid && e.oricurrencyid === currencyid)
|
|
|
+ exchangerate = currency?.exchangerate ?? 0
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算市值 = 现价 * 数量 * 合约单位
|
|
|
+ const marketValue = price ? price * holderqty * agreeunit * exchangerate : 0
|
|
|
+ return price ? (marketValue - holderamount) * (buyorsell === BuyOrSell.Buy ? 1 : -1) : 0
|
|
|
+})
|
|
|
+
|
|
|
+const formRules: FormRules = {
|
|
|
+ OrderPrice: [{
|
|
|
+ message: t('position.transfer.tips3'),
|
|
|
+ validator: () => {
|
|
|
+ return !!formData.OrderPrice
|
|
|
+ }
|
|
|
+ }],
|
|
|
+ MarketMaxSub: [{
|
|
|
+ type: 'number',
|
|
|
+ validator: (rule, value, callback) => {
|
|
|
+ if (value) {
|
|
|
+ callback()
|
|
|
+ } else {
|
|
|
+ callback(new Error(t('quote.pricing.tips3')))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }],
|
|
|
+ OrderQty: [{
|
|
|
+ message: t('position.transfer.tips4'),
|
|
|
+ validator: () => {
|
|
|
+ return !!formData.OrderQty
|
|
|
+ }
|
|
|
+ }],
|
|
|
+}
|
|
|
+
|
|
|
+const onCancel = (isRefresh = false) => {
|
|
|
+ show.value = false
|
|
|
+ refresh.value = isRefresh
|
|
|
+}
|
|
|
+
|
|
|
+const getOrderPrice = () => {
|
|
|
+ const { last, bid, ask, presettle = 0 } = quote.value ?? {}
|
|
|
+ const price = last || presettle
|
|
|
+ // 1=现价,2=对手价,3=实时价,4=实时对手价
|
|
|
+ switch (orderPriceType.value) {
|
|
|
+ case 1:
|
|
|
+ case 3:
|
|
|
+ return price
|
|
|
+ case 2:
|
|
|
+ case 4:
|
|
|
+ if (formData.BuyOrSell === BuyOrSell.Buy) {
|
|
|
+ return ask || price
|
|
|
+ } else {
|
|
|
+ return bid || price
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const marketPrice = computed(() => {
|
|
|
+ const { ask = 0, bid = 0 } = quote.value ?? {}
|
|
|
+ return formData.BuyOrSell === BuyOrSell.Buy ? ask : bid
|
|
|
+})
|
|
|
+
|
|
|
+const onCloseSumit = () => {
|
|
|
+ formRef.value?.validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ const { marketid, goodsid, buyorsell, tradeid } = props.selectedRow
|
|
|
+ /// 市场ID
|
|
|
+ formData.Header = { MarketID: marketid, GoodsID: goodsid }
|
|
|
+ formData.MarketID = marketid
|
|
|
+ if (formData.PriceMode === PriceMode.Market) { formData.OrderPrice = marketPrice.value }
|
|
|
+ formData.BuyOrSell = buyorsell === BuyOrSell.Buy ? BuyOrSell.Sell : BuyOrSell.Buy
|
|
|
+ formData.GoodsID = goodsid
|
|
|
+ formData.ListingSelectType = EListingSelectType.LISTINGSELECTTYPE_DELISTINGTHENLISTING
|
|
|
+ formData.DelistingType = EDelistingType.DELISTINGTYPE_PRICE
|
|
|
+ formData.BuildType = EBuildType.BUILDTYPE_CLOSE
|
|
|
+ formData.TimevalidType = EValidType.VALIDTYPE_DR
|
|
|
+ formData.OperateType = EOrderOperateType.ORDEROPERATETYPE_HOLDER_CLOSE
|
|
|
+ formData.RelatedID = handleRequestBigNumber(tradeid)
|
|
|
+
|
|
|
+ formSubmit().then(() => {
|
|
|
+ if (settingStore.getSettingValue('showOrderSuccessMessage')) {
|
|
|
+ ElMessage.success(t('position.transfer.tips2'))
|
|
|
+ }
|
|
|
+ onCancel(true)
|
|
|
+ }).catch((err) => {
|
|
|
+ if (settingStore.getSettingValue('showOrderFailMessage')) {
|
|
|
+ ElMessage.error(t('common.submitfailure') + err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const onRadioChange = (value: number) => {
|
|
|
+ formData.OrderQty = Math.trunc(maxQty.value * value) || 1
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ const { bid, ask, presettle = 0 } = quote.value ?? {}
|
|
|
+ switch (props.selectedRow.buyorsell) {
|
|
|
+ case BuyOrSell.Buy:
|
|
|
+ formData.OrderPrice = ask || presettle
|
|
|
+ break
|
|
|
+ case BuyOrSell.Sell:
|
|
|
+ formData.OrderPrice = bid || presettle
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ formData.OrderPrice = presettle
|
|
|
+ }
|
|
|
+ formData.OrderPrice = getOrderPrice()
|
|
|
+ formData.OrderQty = maxQty.value
|
|
|
+ formData.PriceMode = PriceMode.Market
|
|
|
+ formData.MarketMaxSub = 100.0
|
|
|
+})
|
|
|
+</script>
|