From 33f72994ec445ea6c82813cca6b6780a765c14bc Mon Sep 17 00:00:00 2001
From: lxf <1371462558@qq.com>
Date: Wed, 30 Apr 2025 01:14:04 +0800
Subject: [PATCH] 平仓和卖出逻辑添加
---
src/page/trading/buy.vue | 110 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 91 insertions(+), 19 deletions(-)
diff --git a/src/page/trading/buy.vue b/src/page/trading/buy.vue
index 6df17c9..3b86e18 100644
--- a/src/page/trading/buy.vue
+++ b/src/page/trading/buy.vue
@@ -64,7 +64,7 @@
</div>
<div class="tabs_content">
<div class="num" v-show="priceTabsCurrentIndex == 1">
- <span>{{ $t("hj99") }}</span>
+ <span>{{ isSell ? $t("当价格满足条件时卖出") : $t("hj99") }}</span>
</div>
<div class="tr_es flexJy" v-show="priceTabsCurrentIndex == 1">
<div class="top_input">
@@ -202,7 +202,12 @@
</div>
</div>
</div> -->
- <div class="btn_buy" @click="gdOrSetBuy()">
+ <div
+ class="btn_buy"
+ @click="gdOrSetBuy()"
+ :disabled="isSell && !positiontionData.orderNum"
+ :class="{ 'disabled-btn': isSell && !positiontionData.orderNum }"
+ >
<!-- <div :class="tabsCurrentIndex == 0 ? 'maichu' : ''">#3b82f6 -->
<div class="maichu" style="background-color:#3b82f6">
<span v-if="isSell">{{ $t("hj78") }}</span>
@@ -225,6 +230,7 @@
<script>
import * as api from "@/axios/api";
+import { number } from "echarts/lib/export";
import { mapActions } from "vuex";
export default {
@@ -232,12 +238,10 @@
created() {
if (this.$route.query.t) {
this.tabsCurrentIndex = Number(this.$route.query.t);
- if (this.tabsCurrentIndex === 0) {
- this.isSell = true;
- }
- console.log(this.tabsCurrentIndex);
+
+ console.log("tabsCurrentIndex: ", this.tabsCurrentIndex);
}
- ss;
+
if (this.$route.query.m) {
this.nowPrice = Number(this.$route.query.m);
this.profitTarget = Number(this.$route.query.m);
@@ -323,14 +327,37 @@
],
moneyData: {},
gid: "",
- KLine: {}
+ KLine: {},
+ positiontionData: {
+ orderNum: 0
+ }
};
},
- mounted() {
+ async mounted() {
this.bayType = this.$route.query.bayType;
this.gid = this.$route.query.gid;
this.KLine = JSON.parse(window.localStorage.getItem("kLine"));
+ if (this.tabsCurrentIndex === 0) {
+ this.isSell = true;
+ // stockType 1黄金原油 2 股票
+ const data = await api.getPosition({
+ stock: this.$route.query.code || this.$route.query.name,
+ stockType: this.KLine.type === "HJ" ? 1 : 2
+ });
+ if (data.data) {
+ this.positiontionData = data.data;
+ } else {
+ if (data.status !== 0) {
+ this.$store.commit("elAlertShow", {
+ elAlertShow: true,
+ elAlertText: data.msg,
+ elAlertType: "warning"
+ });
+ }
+ }
+ }
+
if (this.bayType == "in") {
this.priceTabs = [this.$t("hj108"), this.$t("hj109")];
} else if (this.bayType == "qh") {
@@ -504,6 +531,9 @@
this.selectLever = val.label;
},
gdOrSetBuy() {
+ // 无持仓的时候不能下单
+ if (this.isSell && !this.positiontionData.orderNum) return;
+
if (this.priceTabsCurrentIndex == 0) {
this.setBuy();
} else {
@@ -543,10 +573,28 @@
let data;
if (this.KLine.type === "HJ") {
opts.name = this.KLine.name;
- data = await api.hjyyAddOrder(opts);
- } else {
- data = await api.guadan(opts);
+ opts.lever = 100;
}
+ if (this.isSell) {
+ let sellDate = {
+ positionSn: this.positiontionData.positionSn,
+ number: this.num,
+ name: opts.name
+ };
+ if (this.priceTabsCurrentIndex == 1) {
+ sellDate.targetPrice = this.nums;
+ sellDate.lever = opts.lever;
+ }
+ // 挂单 卖出
+ data = await api.sell(sellDate);
+ } else {
+ if (this.KLine.type === "HJ") {
+ data = await api.hjyyAddOrder(opts);
+ } else {
+ data = await api.guadan(opts);
+ }
+ }
+
this.buying = false;
if (data.status === 0) {
this.$store.commit("elAlertShow", {
@@ -591,9 +639,9 @@
// buyNum: (this.num.match(/\d+/g))[0] * 100, // 单位为手
lever: this.selectLever
};
- if (this.KLine.type === "HJ") {
- opts.lever = this.selectLever * 100;
- }
+ // if (this.KLine.type === "HJ") {
+ // opts.lever = this.num * 100;
+ // }
console.log(this.selectLever, "this.selectLever ");
if (this.tabsCurrentIndex == 0) {
opts.buyType = 1;
@@ -624,14 +672,32 @@
opts.stockId = this.id;
let data;
- console.log("bayType: ", this.KLine);
-
+ console.log("bayType: ", this.KLine, this.isSell);
if (this.KLine.type == "HJ") {
opts.name = this.KLine.name;
+ opts.lever = this.num * 100;
+ }
- data = await api.goldCrudeOilbuy(opts);
+ if (this.isSell) {
+ let sellDate = {
+ positionSn: this.positiontionData.positionSn,
+ number: this.num,
+ name: opts.name
+ };
+ if (this.priceTabsCurrentIndex == 1) {
+ sellDate.targetPrice = this.nums;
+ sellDate.lever = opts.lever;
+ }
+ // 卖出
+ data = await api.sell(sellDate);
} else {
- data = await api.buy(opts);
+ if (this.KLine.type == "HJ") {
+ opts.name = this.KLine.name;
+ opts.lever = 100;
+ data = await api.goldCrudeOilbuy(opts);
+ } else {
+ data = await api.buy(opts);
+ }
}
this.buying = false;
@@ -1166,4 +1232,10 @@
/deep/.van-popup {
z-index: 10001 !important;
}
+
+.disabled-btn {
+ opacity: 0.5;
+ pointer-events: none;
+ cursor: not-allowed;
+}
</style>
--
Gitblit v1.9.3