|
|
@@ -5,7 +5,8 @@
|
|
|
<app-navbar title="挂牌" @back="closed" />
|
|
|
</template>
|
|
|
<component :is="Price" v-bind="{ goodsCode }" />
|
|
|
- <component :is="Forex" v-bind="{ goodsCode, showMore: false }" />
|
|
|
+ <component :is="Forex" v-bind="{ goodsCode, showMore: false }" @buyclick="onBuyClick"
|
|
|
+ @sellclick="onSellClick" />
|
|
|
<Form ref="formRef" class="g-form__container" @submit="onSubmit">
|
|
|
<CellGroup inset>
|
|
|
<Field name="OrderPrice" :rules="formRules.OrderPrice" label="价格">
|
|
|
@@ -27,6 +28,11 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
</Field>
|
|
|
+ <Field label="可用资金">
|
|
|
+ <template #input>
|
|
|
+ <span>{{ accountStore.avaiableMoney.toFixed(2) }}</span>
|
|
|
+ </template>
|
|
|
+ </Field>
|
|
|
</CellGroup>
|
|
|
</Form>
|
|
|
<template #footer>
|
|
|
@@ -36,8 +42,16 @@
|
|
|
<Button type="primary" block round @click="onBeforeSubmit(BuyOrSell.Sell)">订立卖出</Button>
|
|
|
</template>
|
|
|
<template v-if="buildType === EBuildType.BUILDTYPE_CLOSE">
|
|
|
- <Button type="primary" block round @click="onBeforeSubmit(BuyOrSell.Buy)">转让买入</Button>
|
|
|
- <Button type="primary" block round @click="onBeforeSubmit(BuyOrSell.Sell)">转让卖出</Button>
|
|
|
+ <Button type="primary" :disabled="(sellQty === 0) || (orderQty > sellQty)" block round
|
|
|
+ @click="onBeforeSubmit(BuyOrSell.Buy)">
|
|
|
+ <span>转让买入</span>
|
|
|
+ <span>({{ sellQty }})</span>
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" :disabled="(buyQty === 0) || (orderQty > buyQty)" block round
|
|
|
+ @click="onBeforeSubmit(BuyOrSell.Sell)">
|
|
|
+ <span>转让卖出</span>
|
|
|
+ <span>({{ buyQty }})</span>
|
|
|
+ </Button>
|
|
|
</template>
|
|
|
</div>
|
|
|
</template>
|
|
|
@@ -48,11 +62,13 @@
|
|
|
<script lang="ts" setup>
|
|
|
import { shallowRef, defineAsyncComponent, onMounted, computed } from 'vue'
|
|
|
import { Form, FormInstance, Button, CellGroup, FieldRule, Field, Stepper, RadioGroup, Radio } from 'vant'
|
|
|
+import { fullloading, dialog } from '@/utils/vant'
|
|
|
import { getGoodsUnitName } from '@/constants/unit'
|
|
|
import { BuyOrSell } from '@/constants/order'
|
|
|
import { useOrder } from '@/business/trade'
|
|
|
-import { fullloading, dialog } from '@/utils/vant'
|
|
|
-import { useFuturesStore } from '@/stores'
|
|
|
+import { useRequest } from '@/hooks/request'
|
|
|
+import { queryTradePosition } from '@/services/api/order'
|
|
|
+import { useAccountStore, useFuturesStore } from '@/stores'
|
|
|
import { EPriceMode, EListingSelectType, EDelistingType, EBuildType, EValidType, EOrderOperateType } from '@/constants/client'
|
|
|
import AppModal from '@/components/base/modal/index.vue'
|
|
|
|
|
|
@@ -71,6 +87,7 @@ const props = defineProps({
|
|
|
})
|
|
|
|
|
|
const { formData, formSubmit } = useOrder()
|
|
|
+const accountStore = useAccountStore()
|
|
|
const futuresStore = useFuturesStore()
|
|
|
const quote = futuresStore.getQuoteInfo(props.goodsCode)
|
|
|
const formRef = shallowRef<FormInstance>()
|
|
|
@@ -79,6 +96,15 @@ const refresh = shallowRef(true) // 是否刷新父组件数据
|
|
|
const orderQty = shallowRef(1) // 数量
|
|
|
const qtyStep = shallowRef(1) // 数量步长
|
|
|
|
|
|
+const { dataList: positionList } = useRequest(queryTradePosition, {
|
|
|
+ params: {
|
|
|
+ tradeMode: '50'
|
|
|
+ },
|
|
|
+})
|
|
|
+
|
|
|
+// 合约乘数
|
|
|
+const agreeunit = computed(() => quote.value?.agreeunit ?? 0)
|
|
|
+
|
|
|
// 价格步长
|
|
|
const priceStep = computed(() => {
|
|
|
const { quoteminunit = 0, decimalplace = 0 } = quote.value ?? {}
|
|
|
@@ -90,17 +116,34 @@ const priceStep = computed(() => {
|
|
|
|
|
|
// 数量步长列表
|
|
|
const qtyStepList = computed(() => {
|
|
|
- const { agreeunit = 0 } = quote.value ?? {}
|
|
|
return [
|
|
|
- agreeunit * 1,
|
|
|
- agreeunit * 5,
|
|
|
- agreeunit * 10,
|
|
|
- agreeunit * 20,
|
|
|
- agreeunit * 30,
|
|
|
- agreeunit * 50,
|
|
|
+ agreeunit.value * 1,
|
|
|
+ agreeunit.value * 5,
|
|
|
+ agreeunit.value * 10,
|
|
|
+ agreeunit.value * 20,
|
|
|
+ agreeunit.value * 30,
|
|
|
+ agreeunit.value * 50,
|
|
|
]
|
|
|
})
|
|
|
|
|
|
+// 买方向持仓数量
|
|
|
+const buyQty = computed(() => {
|
|
|
+ const item = positionList.value.find((e) => e.goodscode === props.goodsCode && e.buyorsell === BuyOrSell.Buy)
|
|
|
+ if (item) {
|
|
|
+ return item.enableqty * agreeunit.value
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+})
|
|
|
+
|
|
|
+// 卖方向持仓数量
|
|
|
+const sellQty = computed(() => {
|
|
|
+ const item = positionList.value.find((e) => e.goodscode === props.goodsCode && e.buyorsell === BuyOrSell.Sell)
|
|
|
+ if (item) {
|
|
|
+ return item.enableqty * agreeunit.value
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+})
|
|
|
+
|
|
|
// 表单验证规则
|
|
|
const formRules: { [key in keyof Proto.OrderReq]?: FieldRule[] } = {
|
|
|
OrderPrice: [{
|
|
|
@@ -112,17 +155,78 @@ const formRules: { [key in keyof Proto.OrderReq]?: FieldRule[] } = {
|
|
|
OrderQty: [{
|
|
|
validator: () => {
|
|
|
if (orderQty.value) {
|
|
|
- const { agreeunit = 0 } = quote.value ?? {}
|
|
|
- return orderQty.value % agreeunit === 0 ? true : '只能输入合约乘数的整数倍'
|
|
|
+ return orderQty.value % agreeunit.value === 0 ? true : '只能输入合约乘数的整数倍'
|
|
|
}
|
|
|
return '请输入数量'
|
|
|
}
|
|
|
}],
|
|
|
}
|
|
|
|
|
|
+const onBuyClick = (index: number) => {
|
|
|
+ const { bid = 0, bid2 = 0, bid3 = 0, bid4 = 0, bid5 = 0, bidvolume = 0, bidvolume2 = 0, bidvolume3 = 0, bidvolume4 = 0, bidvolume5 = 0 } = quote.value ?? {}
|
|
|
+ switch (index) {
|
|
|
+ case 1: {
|
|
|
+ formData.OrderPrice = bid
|
|
|
+ orderQty.value = bidvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 2: {
|
|
|
+ formData.OrderPrice = bid2 || bid
|
|
|
+ orderQty.value = bidvolume2 || bidvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 3: {
|
|
|
+ formData.OrderPrice = bid3 || bid
|
|
|
+ orderQty.value = bidvolume3 || bidvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 4: {
|
|
|
+ formData.OrderPrice = bid4 || bid
|
|
|
+ orderQty.value = bidvolume4 || bidvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 5: {
|
|
|
+ formData.OrderPrice = bid5 || bid
|
|
|
+ orderQty.value = bidvolume5 || bidvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const onSellClick = (index: number) => {
|
|
|
+ const { ask = 0, ask2 = 0, ask3 = 0, ask4 = 0, ask5 = 0, askvolume = 0, askvolume2 = 0, askvolume3 = 0, askvolume4 = 0, askvolume5 = 0 } = quote.value ?? {}
|
|
|
+ switch (index) {
|
|
|
+ case 1: {
|
|
|
+ formData.OrderPrice = ask
|
|
|
+ orderQty.value = askvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 2: {
|
|
|
+ formData.OrderPrice = ask2 || ask
|
|
|
+ orderQty.value = askvolume2 || askvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 3: {
|
|
|
+ formData.OrderPrice = ask3 || ask
|
|
|
+ orderQty.value = askvolume3 || askvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 4: {
|
|
|
+ formData.OrderPrice = ask4 || ask
|
|
|
+ orderQty.value = askvolume4 || askvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case 5: {
|
|
|
+ formData.OrderPrice = ask5 || ask
|
|
|
+ orderQty.value = askvolume5 || askvolume
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 提交挂牌
|
|
|
const onSubmit = () => {
|
|
|
- const { marketid = 0, goodsid = 0, agreeunit = 0 } = quote.value ?? {}
|
|
|
+ const { marketid = 0, goodsid = 0 } = quote.value ?? {}
|
|
|
/// 获取对应的市场ID
|
|
|
formData.MarketID = marketid
|
|
|
formData.PriceMode = EPriceMode.PRICEMODE_LIMIT
|
|
|
@@ -133,7 +237,7 @@ const onSubmit = () => {
|
|
|
formData.ValidType = EValidType.VALIDTYPE_DR
|
|
|
formData.OperateType = EOrderOperateType.ORDEROPERATETYPE_NORMAL
|
|
|
formData.BuildType = props.buildType
|
|
|
- formData.OrderQty = orderQty.value / agreeunit // 数量÷合约乘数
|
|
|
+ formData.OrderQty = orderQty.value / agreeunit.value // 数量÷合约乘数
|
|
|
|
|
|
fullloading((hideLoading) => {
|
|
|
formSubmit().then(() => {
|