zzzz
2024-04-26 f989b0f6b7c1190a719d22a2aeec0e8914c2db07
src/page/trading/buy.vue
@@ -8,10 +8,10 @@
          </div>
          <div class="right_title">
            <div class="t_t" style="white-space: nowrap">
              <span>{{ name | getName }}</span>
              <span>{{ name }}({{ gid }})</span>
            </div>
            <div class="b_t">
              <span>{{ code }}</span>
              <span>{{ spell }}</span>
            </div>
          </div>
        </div>
@@ -19,7 +19,7 @@
          <div class="cot">
            <div class="lefts">
              <div class="top_new">
                <span>{{ nowPrice }}</span>
                <span>{{ nowPrice | _toLocaleString }}</span>
              </div>
              <div class="bottom_es">
                <span>{{ $t("hj98") }}</span>
@@ -94,6 +94,7 @@
                type="number"
                onkeyup="value=value.replace(/[^\d]/g,'')"
                v-model="num"
                @input="numInput"
              />
            </div>
            <div class="right_sw flexJy" style="width: auto">
@@ -101,14 +102,7 @@
                <img src="@/assets/img/ic_number_jian.png" />
              </div>
              <div class="addorj"></div>
              <div
                class="addorj"
                @click="
                  typeof num == 'string'
                    ? (num = Number(Number(num) + 1))
                    : (num = Number(Number(num) + 1))
                "
              >
              <div class="addorj" @click="jjjisua">
                <img src="@/assets/img/ic_number_add.png" />
              </div>
            </div>
@@ -116,17 +110,13 @@
          <div class="tr_rs gg" @click="showGg = true">
            <div class="top_bzz">
              <span>{{ $t("hj101") }}</span>
              <span>{{ selectCycle + "X" }}</span>
              <span>{{ selectCycle }}</span>
            </div>
            <!-- <div class="bottom_bzz">
                <span>{{  }}</span>
                <span>{{  }}</span>
              </div> -->
          </div>
          <div class="tr_rs">
            <div class="top_bzz" style="padding-bottom: 0.2rem">
              <span style="text-align: left">
                {{ $t("hj102") }}({{ moneyData.symbol || "$" }})
                {{ $t("交易总额") }}({{ moneyData.symbol || "$" }})
              </span>
              <span style="text-align: right">
                {{ $t("hj103") }}({{ moneyData.symbol || "$" }})
@@ -134,11 +124,14 @@
            </div>
            <div class="bottom_bzz">
              <span>{{ ((nowPrice / selectCycle) * num).toFixed(2) }}</span>
              <span>
                {{
                  ((nowPrice / selectCycle.replace("X", "")) * num)
                    | _toLocaleString
                }}
              </span>
              <span style="white-space: nowarp">
                <!-- moneyData.symbol + " " + -->
                {{ moneyData.availableBalance || "0.00" }}
                {{ moneyData.availableBalance | _toLocaleString }}
              </span>
            </div>
          </div>
@@ -200,14 +193,6 @@
            </div>
          </div>
        </div>
        <!-- <div class="zy">
            <div class="left_zy">
              <span>追踪止损</span>
            </div>
            <div class="right_sw">
              <van-switch v-model="profitArr[2].checked" />
            </div>
          </div> -->
      </div>
      <div class="btn_buy" @click="gdOrSetBuy()">
        <div :class="tabsCurrentIndex == 0 ? 'maichu' : ''">
@@ -252,6 +237,9 @@
    if (this.$route.query.name) {
      this.name = this.$route.query.name;
    }
    if (this.$route.query.spell) {
      this.spell = this.$route.query.spell;
    }
    if (this.$route.query.type) {
      this.type = this.$route.query.type;
    }
@@ -273,8 +261,10 @@
      type: 0,
      code: "",
      name: "",
      spell: "",
      settingInfo: [],
      selectCycle: 1,
      selectCycle: "1X",
      selectLever: 1,
      siteLeverList: [],
      checkedZy: false,
      checkedZs: false,
@@ -305,10 +295,12 @@
        },
      ],
      moneyData: {},
      gid: "",
    };
  },
  mounted() {
    this.bayType = this.$route.query.bayType;
    this.gid = this.$route.query.gid;
    if (this.bayType == "in") {
      this.priceTabs = [this.$t("hj108"), this.$t("hj109")];
    } else if (this.bayType == "qh") {
@@ -334,7 +326,20 @@
  },
  methods: {
    ...mapActions(["setUseInfo"]),
    numInput(e) {
      // this.nowPrice / this.selectCycle.replace("X", "")
      // this.moneyData.availableBalance
      let numbs = Math.floor(
        this.moneyData.availableBalance /
          this.nowPrice /
          this.selectCycle.replace("X", "")
      );
      if (e.target.value >= numbs) {
        this.num = numbs;
      }
      // if()
      console.log(e.target.value);
    },
    async getMoneyData() {
      let data = await api.getMoney();
      let type = this.bayType === "SZHB" ? "US" : this.bayType;
@@ -355,6 +360,21 @@
    },
    handleTabsClick(item, index) {
      this.priceTabsCurrentIndex = index;
    },
    jjjisua() {
      let numbs = Math.floor(
        this.moneyData.availableBalance /
          this.nowPrice /
          this.selectCycle.replace("X", "")
      );
      typeof this.num == "string"
        ? (this.num = Number(Number(this.num) + 1))
        : (this.num = Number(Number(this.num) + 1));
      console.log(this.num, numbs);
      if (this.num >= numbs) {
        this.num = numbs;
      }
    },
    jyslJian() {
      if (typeof this.num === "string") {
@@ -415,7 +435,8 @@
      }
    },
    onSelect(val) {
      this.selectCycle = val.gg;
      this.selectCycle = val.name;
      this.selectLever = val.label;
    },
    gdOrSetBuy() {
      if (this.priceTabsCurrentIndex == 0) {
@@ -437,9 +458,11 @@
      let opts = {
        stockId: this.code,
        buyNum: this.num,
        lever: this.selectCycle ? this.selectCycle : 0,
        lever: this.selectLever,
        targetPrice: this.nums,
      };
      console.log(this.selectLever, "this.selectLever ");
      if (this.tabsCurrentIndex == 0) {
        opts.buyType = 1;
      } else {
@@ -461,7 +484,7 @@
          elAlertType: "success",
        });
        this.getUserInfo();
        this.$router.push("/warehouse?index=1");
        this.$router.push("/warehouse?index=1&buyType=" + this.bayType);
      } else {
        this.$store.commit("elAlertShow", {
          elAlertShow: true,
@@ -471,7 +494,7 @@
    },
    // 买卖
    setBuy() {
      if (!this.$store.state.userInfo.idCard) {
      if (this.$store.state.userInfo.isActive !== 2) {
        this.$store.commit("elAlertShow", {
          elAlertShow: true,
          elAlertText: this.$t("hj111"),
@@ -495,8 +518,9 @@
        // 买入是买涨buyType:0, 卖出是买跌buyType:1,卖出的状态是0,买入的状态是1
        buyNum: this.num, // 单位为手
        // buyNum: (this.num.match(/\d+/g))[0] * 100, // 单位为手
        lever: this.selectCycle ? this.selectCycle : 0,
        lever: this.selectLever,
      };
      console.log(this.selectLever, "this.selectLever ");
      if (this.tabsCurrentIndex == 0) {
        opts.buyType = 1;
      } else {
@@ -539,13 +563,7 @@
        } else {
          buyType = 0;
        }
        if (this.bayType == "US") {
          this.$router.push("/warehouse?index=1&buyType=" + buyType);
        } else if (this.bayType == "MAS") {
          this.$router.push("/warehouse?index=0&buyType=" + buyType);
        } else {
          this.$router.push("/warehouse");
        }
        this.$router.push("/warehouse?index=1&buyType=" + this.bayType);
      } else {
        if (data.msg.indexOf("不在交易时段内") > -1) {
          this.$store.commit("elAlertShow", {
@@ -572,7 +590,7 @@
          elAlertType: "success",
        });
        this.getUserInfo();
        this.$router.push("/warehouse?index=0");
        this.$router.push("/warehouse?index=1&buyType=" + this.bayType);
      } else {
        this.$store.commit("elAlertShow", {
          elAlertShow: true,
@@ -605,14 +623,14 @@
        // data.data.siteLever根据/分割成数组
        // this.siteLeverList = data.data.siteLever.split('/')
        this.selectCycle = data.data.siteLever;
        if (
          this.$store.state.userInfo !== undefined &&
          this.$store.state.userInfo !== null &&
          this.$store.state.userInfo.phone !== "" &&
          this.$store.state.userInfo.siteLever != null
        ) {
          this.selectCycle = this.$store.state.userInfo.siteLever.split("/")[0];
          this.selectCycle =
            this.$store.state.userInfo.siteLever.split("/")[0] + "X";
          this.siteLeverList = [];
          for (
            let i = 0;
@@ -620,24 +638,10 @@
            i++
          ) {
            let val = this.$store.state.userInfo.siteLever.split("/")[i];
            let item = { label: val + this.$t("hj112"), value: val };
            let item = { label: val, name: val + "X" };
            this.siteLeverList.push(item);
          }
        } else {
          this.selectCycle = data.data.siteLever.split("/")[0];
          this.siteLeverList = [];
          for (let i = 0; i < data.data.siteLever.split("/").length; i++) {
            let val = data.data.siteLever.split("/")[i];
            var ccet = (Number(this.nowPrice) / Number(val)).toFixed(2);
            // let item = { label: val + '倍', value: val ,bzj:ccet}
            let item = {
              name: val + "X",
              subname: this.$t("hj102") + ":" + (ccet * 100).toFixed(2),
              gg: val,
              bzj: ccet,
            };
            this.siteLeverList.push(item);
          }
          console.log(this.siteLeverList, " this.selectCycle");
        }
      } else {
        this.$store.commit("elAlertShow", {
@@ -650,7 +654,7 @@
  filters: {
    getName(name) {
      if (name.length > 15) {
        return name.substring(0, 14);
        return name;
      } else {
        return name;
      }