Handy_Cao hai 1 mes
pai
achega
d3032144fc
Modificáronse 1 ficheiros con 34 adicións e 58 borrados
  1. 34 58
      src/packages/digital/views/contract/goods/detail/index.vue

+ 34 - 58
src/packages/digital/views/contract/goods/detail/index.vue

@@ -39,7 +39,7 @@
                         <app-select v-model="formData.PriceMode" :options="options" />
                     </template>
                 </Field>
-                <Field v-if="formData.PriceMode === EPriceMode.PRICEMODE_LIMIT" name="OrderPrice"
+                <Field v-if="formData.PriceMode === PriceMode.Limit" name="OrderPrice"
                     :rules="formRules.OrderPrice" :label="'价格' + enumName">
                     <template #input>
                         <app-stepper v-model="formData.OrderPrice" :min="0" :decimal-length="quote?.decimalplace"
@@ -55,9 +55,9 @@
                 <Cell title="开仓价值" :value="formatDecimal(openAmount) + enumName" />
             </CellGroup>
             <CellGroup inset>
-                <Cell title="可用余额" :value="calculations.availableBalance" />
-                <Cell title="可开数量" :value="calculations.sellQty" />
-                <Cell title="预估手续费" :value="formatDecimal(serivcefee)" />
+                <Cell title="可用余额" :value="formatDecimal(calculations.maxBalance)" />
+                <Cell title="可开数量" :value="formatDecimal(calculations.maxBuyQty, 0)" />
+                <Cell title="预估手续费" :value="formatDecimal(calculations.buyEstimatedFee)" />
             </CellGroup>
             <!-- 任务 #7130 -->
             <div class="order-tpsl" v-if="quote?.tpslflag">
@@ -138,13 +138,14 @@
 <script lang="ts" setup>
 import { shallowRef, computed, onMounted, onActivated } from 'vue'
 import { Form, FormInstance, Button, CellGroup, Field, Cell, Tab, Tabs, FieldRule, Col, Row, Slider, Checkbox } from 'vant'
-import { EPriceMode, EValidType, EOrderOperateType, EBuildType } from '@/constants/client'
+import { EValidType, EOrderOperateType, EBuildType } from '@/constants/client'
 import { formatDecimal, parsePercent } from '@/filters'
 import { useNavigation } from '@mobile/router/navigation'
 import { useFuturesStore, useSBYJOrderStore, useUserStore, useAccountStore } from '@/stores'
 import { fullloading, dialog } from '@/utils/vant'
 import { useOrder } from '@/business/trade'
-import { BuyOrSell, getGoodsCurrencyItemName } from '@/constants/order'
+import { BuyOrSell, getGoodsCurrencyItemName, PriceMode } from '@/constants/order'
+import { useSpotAccountStore } from '../../../wallet/components/spot/composables'
 import AppSelect from '@mobile/components/base/select/index.vue'
 import AppStepper from '@mobile/components/base/stepper/index.vue'
 import ContractPosition from '../../components/position/list/index.vue'
@@ -154,6 +155,7 @@ import ContractAccount from '../../components/account/index.vue'
 const { router, getQueryStringToNumber, getGlobalUrlParams } = useNavigation()
 const goodsId = getQueryStringToNumber('id')
 const futuresStore = useFuturesStore()
+const spotAccountStore = useSpotAccountStore()
 const tabIndex = shallowRef(0)
 
 const formRef = shallowRef<FormInstance>()
@@ -168,14 +170,17 @@ const stopLossRatio = shallowRef(0) // 止损比例
 const sliderStep = 0.01 // 滑块步长
 
 const { getSBYJMyOrders } = useSBYJOrderStore()
-const quote = computed(() => futuresStore.getQuoteItem({ goodsid: goodsId }))
 const goods = computed(() => futuresStore.getGoods(goodsId ?? 0)) ?? {}
 
+const quote = computed(() => futuresStore.getQuoteItem({ goodsid: goodsId }))
+const baseAccount = computed(() => spotAccountStore.getAccountItem({ currencyid: quote.value?.goodscurrencyid })) // 基础货币账户
+const quoteAccount = computed(() => spotAccountStore.getAccountItem({ currencyid: quote.value?.currencyid })) // 计价货币账户
+
 const options = computed(() => {
     return [{
-        label: '限价单', value: EPriceMode.PRICEMODE_LIMIT
+        label: '市价单', value: PriceMode.Market
     }, {
-        label: '市价单', value: EPriceMode.PRICEMODE_MARKET
+        label: '限价单', value: PriceMode.Limit
     }]
 })
 
@@ -276,61 +281,44 @@ const tpsl = 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 buyFeeValue = futuresStore.getFeeValue(quote.value, 101)
+    const sellFeeValue = futuresStore.getFeeValue(quote.value, 102)
+
     const { last = 0, agreeunit = 0 } = quote.value ?? {}
     const { OrderPrice = 0, OrderQty = 0 } = formData
 
-    const { balance = 0.0 } = accountStore.currentAccount
-
-    const price = formData.PriceMode === EPriceMode.PRICEMODE_MARKET ? last : OrderPrice
+    const price = formData.PriceMode === PriceMode.Market ? last : OrderPrice
+    const amount = OrderQty * agreeunit
 
     // 预估金额
-    const estimatedAmount = price * OrderQty * agreeunit
+    const estimatedAmount = price * amount
 
     // 可用余额
-    const availableBalance = balance
-    // 可用数量
-    const availableQty = availableBalance / agreeunit
+    const maxBalance = spotAccountStore.getAvailableBalance(quoteAccount.value)
     // 预估手续费
-    const buyEstimatedFee = 0
+    const buyEstimatedFee = (buyFeeValue.FeeAlgorithm === 2 ? amount : estimatedAmount) * buyFeeValue.feeValue
+    // 可买数量
+    const maxBuyQty = price ? (maxBalance - buyEstimatedFee) / (price * agreeunit) : 0
 
     // 可卖数量
-    const sellQty = 0
+    const maxSellQty = spotAccountStore.getAvailableBalance(baseAccount.value)
     // 可获金额
-    const availableAmount = price * sellQty * agreeunit
+    const maxAmount = price * maxSellQty * agreeunit
     // 预估手续费
-    const sellEstimatedFee = 0
+    const sellEstimatedFee = (sellFeeValue.FeeAlgorithm === 2 ? amount : estimatedAmount) * sellFeeValue.feeValue
 
     return {
         estimatedAmount,
-        availableBalance,
-        availableQty,
+        maxBalance,
+        maxBuyQty,
         buyEstimatedFee,
-        availableAmount,
-        sellQty,
+        maxAmount,
+        maxSellQty,
         sellEstimatedFee
     }
 })
@@ -348,7 +336,7 @@ const routerToChart = () => {
 const openAmount = computed(() => {
     const { agreeunit = 0.0 } = goods.value ?? {}
     const orderQty = formData.OrderQty ?? 0.0
-    if (formData.PriceMode === EPriceMode.PRICEMODE_MARKET) {
+    if (formData.PriceMode === PriceMode.Market) {
         const price = (formData.BuyOrSell === BuyOrSell.Buy ? quote.value?.ask : quote.value?.bid) ?? 0.0
         return price * orderQty * agreeunit
     } else {
@@ -386,22 +374,11 @@ const formRules: { [key: string]: FieldRule[] } = {
 
 // 下单
 const onSubmit = () => {
-    // 计算提示信息
-    // const { marketid = 0, goodsid = 0, goodunitid = 0 } = quote.value ?? {}
-    // const { marginalgorithm = 0, transferdepositratio = 0.0 } = goods ?? {}
-    // const totalamount = orderQty.value*(formData.OrderPrice ?? 0)
-    // const orderPrice = `定价价格:${formData.OrderPrice ?? 0}\n`
-    // const qty = `订单数量:${orderQty.value}${getGoodsUnitName(goodunitid)}\n`
-    // const orderamount = `订单总额:${formatDecimal(totalamount)}\n`
-    // console.log(marginalgorithm, transferdepositratio)
-    // const margin = `预付定金:${formatDecimal(marginalgorithm === 1 ? totalamount*transferdepositratio : orderQty.value*transferdepositratio)}\n`
-    // const message = orderPrice + qty + orderamount + margin
-
-    const { marketid = 0, goodsid = 0, tpslflag = 0 } = quote.value ?? {}
     dialog({
         message: '确认要提交吗?',
         showCancelButton: true,
     }).then(() => {
+        const { marketid = 0, goodsid = 0, tpslflag = 0 } = quote.value ?? {}
         /// 获取对应的市场ID
         formData.MarketID = marketid
         formData.GoodsID = goodsid
@@ -436,9 +413,8 @@ onMounted(() => {
         const { tpslflag = 0, tpratiodefault = 0, slratiodefault = 0 } = quote.value ?? {}
 
         formData.BuyOrSell = BuyOrSell.Buy
-        formData.PriceMode = EPriceMode.PRICEMODE_MARKET
+        formData.PriceMode = PriceMode.Market
         formData.OrderPrice = formData.BuyOrSell === BuyOrSell.Buy ? quote.value.ask : quote.value.bid
-        formData.PriceMode = EPriceMode.PRICEMODE_MARKET
 
         if (tpslflag) {
             formData.TPFlag = 1