Handy_Cao il y a 1 mois
Parent
commit
24c566e078

+ 2 - 1
src/packages/digital/views/contract/components/position/close/index.vue

@@ -20,12 +20,13 @@
                             </span>
                         </template>
                     </Cell>
-                    <Field name="OrderPrice" :rules="formRules.OrderPrice" label="价格">
+                    <Field v-if="formData.PriceMode === EPriceMode.PRICEMODE_LIMIT" name="OrderPrice" :rules="formRules.OrderPrice" label="价格">
                         <template #input>
                             <app-stepper v-model="formData.OrderPrice" min="0.0" :decimal-length="quote?.decimalplace"
                             :step="quote?.decimalvalue" :auto-fixed="false" />
                         </template>
                     </Field>
+                    <Cell v-else value="市价最优"></Cell>
                     <Field label="限单价" is-link>
                         <template #input>
                             <app-select v-model="formData.PriceMode" :options="options" />

+ 65 - 14
src/packages/digital/views/contract/goods/detail/index.vue

@@ -10,6 +10,7 @@
                         <template #label>
                             <span>{{ quote?.presettle }}</span>
                             <span>{{ parsePercent(quote?.change) }}</span>
+                            <span>{{ getGoodsCurrencyName(goods.currencyid) }}</span>
                         </template>
                         <template #right-icon>
                             <span @click="routerToChart">图表</span>
@@ -47,18 +48,18 @@
                             :step="quote?.decimalvalue" :auto-fixed="false" />
                     </template>
                 </Field>
-                <Cell v-else vlaue="最优市价" />
+                <Cell v-else value="最优市价" />
                 <Field name="OrderQty" :rules="formRules.OrderQty" label="数量">
                     <template #input>
                         <app-stepper v-model="formData.OrderQty" min="0.0" :auto-fixed="false" integer />
                     </template>
                 </Field>
-                <Field label="开仓价值" readonly v-model="openAmount"></Field>
+                <Cell title="开仓价值" :value="openAmount" />
             </CellGroup>
             <CellGroup>
-                <Cell title="可用余额" :value="taAccount?.balance" />
-                <Cell title="可开数量" value="0" />
-                <Cell title="预估手续费" value="0" />
+                <Cell title="可用余额" :value="calculations.availableBalance" />
+                <Cell title="可开数量" :value="calculations.sellQty" />
+                <Cell title="预估手续费" :value="serivcefee" />
             </CellGroup>
         </Form>
         <Row class="g-layout-block g-layout-block--inset">
@@ -86,15 +87,16 @@ import { Form, Button, CellGroup, Field, Cell, Tab, Tabs, FieldRule, Col, Row }
 import { EPriceMode, EValidType, EOrderOperateType, EBuildType } from '@/constants/client'
 import { parsePercent } from '@/filters'
 import { useNavigation } from '@mobile/router/navigation'
-import { useFuturesStore, useSBYJOrderStore, useAccountStore } from '@/stores'
+import { useFuturesStore, useSBYJOrderStore } from '@/stores'
 import { fullloading, dialog } from '@/utils/vant'
 import { useOrder } from '@/business/trade'
+import { useSpotAccountStore } from '../../../wallet/components/spot/composables'
 import AppStepper from '@mobile/components/base/stepper/index.vue'
 import AppSelect from '@mobile/components/base/select/index.vue'
 import ContractPosition from '../../components/position/index.vue'
 import ContractOrder from '../../components/order/index.vue'
 import ContractAccount from '../../components/account/index.vue'
-import { BuyOrSell } from '@/constants/order'
+import { BuyOrSell, getGoodsCurrencyName } from '@/constants/order'
 
 const { router, getQueryStringToNumber } = useNavigation()
 const goodsId = getQueryStringToNumber('id')
@@ -106,13 +108,6 @@ const { getSBYJMyOrders } = useSBYJOrderStore()
 const quote = computed(() => futuresStore.getQuoteInfo({ goodsid: goodsId }))
 const goods = computed(() => futuresStore.getGoods(goodsId ?? 0 )) ?? {}
 
-const accountStore = useAccountStore()
-const { accountComputedList } = accountStore.$toRefs()
-
-const taAccount = computed(() => {
-    return accountComputedList.value.find( e => e.currencyid === goods.value?.currencyid)
-})
-
 const options = computed(() => {
     return [{
         label: '限价单', value: EPriceMode.PRICEMODE_LIMIT
@@ -121,6 +116,62 @@ const options = computed(() => {
     }]
 })
 
+const spotAccountStore = useSpotAccountStore()
+const baseAccount = computed(() => spotAccountStore.getAccountItem({ currencyid: quote.value?.goodscurrencyid })) // 基础货币账户
+const quoteAccount = computed(() => spotAccountStore.getAccountItem({ currencyid: quote.value?.currencyid })) // 计价货币账户
+
+// 预估手续费(小数位根据币种小数位格式化):
+// 手续费设置(固定) 时:预估手续费 = 数量 * 合约乘数 * 固定值
+// 手续费设置(比率) 时:预估手续费 = 价格 * 数量 * 合约乘数 * 比率值
+const serivcefee = computed(() => {
+    const { tradefees = [], agreeunit = 0 } = quote.value ?? {}
+    const { FeeAlgorithm = 1, ExchangeValue = 0.0, MemberDefaultValue = 0.0 } = tradefees.find((e) => e.FeeID === 101) ?? {}
+    const { OrderQty = 0, OrderPrice = 0.0 } = formData
+    // 固定
+    if (FeeAlgorithm === 2) {
+        return OrderQty * agreeunit * (ExchangeValue + MemberDefaultValue)
+    }
+    // 比例
+    return OrderPrice * agreeunit * OrderQty * (ExchangeValue + MemberDefaultValue)
+})
+
+// 可开数量(整数,向下取整):
+// 保证金设置(固定) 时:可开数量 = 可用余额 / (合约乘数 * 固定值)
+// 保证金设置(比率) 时:可开数量 = 可用余额 / (价格 * 合约乘数 * 比率值)
+const calculations = computed(() => {
+    const { last = 0, agreeunit = 0 } = quote.value ?? {}
+    const { OrderPrice = 0, OrderQty = 0 } = formData
+
+    const price = formData.PriceMode === EPriceMode.PRICEMODE_MARKET ? last : OrderPrice
+
+    // 预估金额
+    const estimatedAmount = price * OrderQty * agreeunit
+
+    // 可用余额
+    const availableBalance = spotAccountStore.getAvailableBalance(quoteAccount.value)
+    // 可用数量
+    const availableQty = availableBalance / agreeunit
+    // 预估手续费
+    const buyEstimatedFee = 0
+
+    // 可卖数量
+    const sellQty = spotAccountStore.getAvailableBalance(baseAccount.value)
+    // 可获金额
+    const availableAmount = price * sellQty * agreeunit
+    // 预估手续费
+    const sellEstimatedFee = 0
+
+    return {
+        estimatedAmount,
+        availableBalance,
+        availableQty,
+        buyEstimatedFee,
+        availableAmount,
+        sellQty,
+        sellEstimatedFee
+    }
+})
+
 const routerToChart = () => {
     router.push({
         name: 'contract-goods-chart',