From cb9eeec0baa75abb9c5e961aeb8e0c519a951f64 Mon Sep 17 00:00:00 2001
From: dcc <dcc@163.com>
Date: Tue, 16 Jul 2024 10:18:32 +0800
Subject: [PATCH] 123

---
 src/page/trading/buy.vue |  344 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 259 insertions(+), 85 deletions(-)

diff --git a/src/page/trading/buy.vue b/src/page/trading/buy.vue
index bbeccae..dbc81ee 100644
--- a/src/page/trading/buy.vue
+++ b/src/page/trading/buy.vue
@@ -8,7 +8,7 @@
           </div>
           <div class="right_title">
             <div class="t_t" style="white-space: nowrap">
-              <span>{{ name }}</span>
+              <span>{{ name }}({{ gid }})</span>
             </div>
             <div class="b_t">
               <span>{{ spell }}</span>
@@ -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>
@@ -92,8 +92,8 @@
             <div class="top_input">
               <input
                 type="number"
-                onkeyup="value=value.replace(/[^\d]/g,'')"
                 v-model="num"
+                @input="numInput"
               />
             </div>
             <div class="right_sw flexJy" style="width: auto">
@@ -101,24 +101,17 @@
                 <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>
           </div>
-          <div class="tr_rs gg" @click="showGg = true">
+          <!-- <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>
+          </div> -->
           <div class="tr_rs">
             <div class="top_bzz" style="padding-bottom: 0.2rem">
               <span style="text-align: left">
@@ -130,11 +123,20 @@
             </div>
 
             <div class="bottom_bzz">
-              <span>{{ ((nowPrice / selectCycle) * num).toFixed(2) }}</span>
+              <span v-if="priceTabsCurrentIndex == 0">
+                {{
+                  (nowPrice * selectCycle.replace("X", "") * num)
+                    | _toLocaleString
+                }}
+              </span>
+              <span v-else>
+                {{
+                  (nums * selectCycle.replace("X", "") * num)
+                    | _toLocaleString
+                }}
+              </span>
               <span style="white-space: nowarp">
-                <!-- moneyData.symbol + " " + -->
-
-                {{ moneyData.availableBalance || "0.00" }}
+                {{ moneyData.availableBalance | _toLocaleString }}
               </span>
             </div>
           </div>
@@ -150,10 +152,14 @@
           </div>
         </div>
         <div class="zy" v-show="checkedZy">
+          <!-- <div class="left_zy">
+            <input v-model="profitTarget" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
+              @input="zyInt" />
+          </div> -->
           <div class="left_zy">
             <input
-              v-model="profitTarget"
-              onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
+              v-model.number="profitTarget"
+              inputmode="numeric"
               @input="zyInt"
             />
           </div>
@@ -164,7 +170,11 @@
             <div class="addorj"></div>
             <div
               class="addorj"
-              @click="profitTarget = (Number(profitTarget) + 1).toFixed(2)"
+              @click="
+                tabsCurrentIndex == 0
+                  ? (profitTarget = (Number(profitTarget) + 1).toFixed(2))
+                  : (profitTarget = (Number(profitTarget) + 1).toFixed(2))
+              "
             >
               <img src="@/assets/img/ic_number_add.png" />
             </div>
@@ -179,15 +189,14 @@
           </div>
         </div>
         <div class="zy" v-show="checkedZs">
+          <!-- <div class="left_zy">
+            <input v-model="zhisun" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" @input="zsInt" />
+          </div> -->
           <div class="left_zy">
-            <input
-              v-model="zhisun"
-              onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
-              @input="zsInt"
-            />
+            <input inputmode="numeric" v-model.number="zhisun" @input="zsInt" />
           </div>
           <div class="right_sw" style="width: auto">
-            <div class="addorj" @click="zhisun--">
+            <div class="addorj" @click="zSjian">
               <img src="@/assets/img/ic_number_jian.png" />
             </div>
             <div class="addorj"></div>
@@ -196,14 +205,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' : ''">
@@ -219,12 +220,34 @@
       close-on-click-action
       @select="onSelect"
     />
+    <van-popup
+      v-model="show"
+      :style="{
+        minHeight: '20%',
+        borderTopLeftRadius: '10px',
+        borderTopRightRadius: '10px',
+      }"
+      position="bottom"
+    >
+      <div class="popup-box">
+        <div class="input-box">
+          <div class="laber">{{ $t("秘钥") }}:</div>
+          <input type="text" :maxlength="9" v-model="password" />
+        </div>
+
+        <van-button class="but" type="info" @click="setBuy">
+          {{ $t("立即购买") }}
+        </van-button>
+      </div>
+    </van-popup>
   </div>
 </template>
 
 <script>
+import { ActionSheet } from "vant";
 import * as api from "@/axios/api";
 import { mapActions } from "vuex";
+import { Notify } from "vant";
 
 export default {
   name: "trBuy",
@@ -260,10 +283,12 @@
   },
   data() {
     return {
+      password: "",
+      show: false,
       tradingArr: [this.$t("hj84"), this.$t("hj85")],
       tabsCurrentIndex: 0,
-      // priceTabs: [this.$t("hj108"), this.$t("hj109")],
-      priceTabs: [this.$t("hj108")],
+      priceTabs: [this.$t("hj108"), this.$t("hj109")],
+      // priceTabs: [this.$t("hj108")],
       priceTabsCurrentIndex: 0,
       num: 1,
       nums: 1,
@@ -274,7 +299,8 @@
       name: "",
       spell: "",
       settingInfo: [],
-      selectCycle: 1,
+      selectCycle: "1X",
+      selectLever: 1,
       siteLeverList: [],
       checkedZy: false,
       checkedZs: false,
@@ -286,9 +312,18 @@
       bayType: "",
       id: "",
       actions: [
-        { name: "100X", subname: this.$t("hj102") },
-        { name: "200X", subname: this.$t("hj102") },
-        { name: "300X", subname: this.$t("hj102") },
+        {
+          name: "100X",
+          subname: this.$t("hj102"),
+        },
+        {
+          name: "200X",
+          subname: this.$t("hj102"),
+        },
+        {
+          name: "300X",
+          subname: this.$t("hj102"),
+        },
       ],
       profitArr: [
         {
@@ -305,10 +340,13 @@
         },
       ],
       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") {
@@ -333,8 +371,32 @@
     },
   },
   methods: {
+    zSjian() {
+      var newzishu = (Number(this.zhisun) - 1).toFixed(2);
+      if (Number(newzishu) < 1) {
+      } else {
+        this.zhisun = newzishu;
+      }
+    },
     ...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);
+    },
+    handleDoubleClick(event) {
+      console.log(1);
+      // console.log('Input field was double-clicked', event);
+    },
     async getMoneyData() {
       let data = await api.getMoney();
       let type = this.bayType === "SZHB" ? "US" : this.bayType;
@@ -356,7 +418,23 @@
     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() {
+      console.log(this.num);
       if (typeof this.num === "string") {
         this.num = 1;
       } else {
@@ -383,43 +461,94 @@
       }
     },
     zYjian() {
-      if ((Number(this.profitTarget) - 1).toFixed(2) < this.nowPrice) {
-        this.profitTarget = this.nowPrice;
+      var newzishu = (Number(this.profitTarget) - 1).toFixed(2);
+      if (Number(newzishu) < 1) {
       } else {
-        this.profitTarget = (Number(this.profitTarget) - 1).toFixed(2);
+        this.profitTarget = newzishu;
       }
+      // this.profitTarget = (Number(this.profitTarget) - 1).toFixed(2);
+      // if(this.tabsCurrentIndex==0){
+      //   console.log( this.nowPrice);
+      //   if ((Number(this.profitTarget) - 1).toFixed(2) < this.nowPrice) {
+      //     this.profitTarget = (Number(this.profitTarget) - 1).toFixed(2);
+      //   } else {
+      //     this.profitTarget = this.nowPrice;
+      //   }
+      // }else{
+      //   console.log(123);
+      //   if ((Number(this.profitTarget) - 1).toFixed(2) < this.nowPrice) {
+      //     this.profitTarget = this.nowPrice;
+      //   } else {
+      //     this.profitTarget = (Number(this.profitTarget) - 1).toFixed(2);
+      //   }
+      // }
     },
     zSjia() {
-      if ((Number(this.zhisun) + 1).toFixed(2) > this.nowPrice) {
-        this.zhisun = this.nowPrice;
-      } else {
-        this.zhisun++;
-      }
+      this.zhisun++;
+      // if ((Number(this.zhisun) + 1).toFixed(2) > this.nowPrice) {
+      //   this.zhisun = this.nowPrice;
+      // } else {
+      //   this.zhisun++;
+      // }
     },
     zsInt(e) {
-      if (typeof e.target.value === "string") {
-        this.zhisun = this.nowPrice;
-      } else {
-        if (Number(e.target.value) > this.nowPrice) {
-          this.zhisun = this.nowPrice;
-        }
-      }
+      console.log(e);
+      // if (typeof e.target.value === "string") {
+      //   this.zhisun = this.nowPrice;
+      // } else {
+      //   if (Number(e.target.value) > this.nowPrice) {
+      //     this.zhisun = this.nowPrice;
+      //   }
+      // }
     },
     zyInt(e) {
-      if (typeof e.target.value === "string") {
-        this.profitTarget = this.nowPrice;
-      } else {
-        if (Number(e.target.value) < Number(this.nowPrice)) {
-          this.profitTarget = Number(this.nowPrice);
-        }
-      }
+      console.log(e);
+      // if (typeof e.target.value === "string") {
+      //   this.profitTarget = this.nowPrice;
+      // } else {
+      //   if (Number(e.target.value) < Number(this.nowPrice)) {
+      //     this.profitTarget = Number(this.nowPrice);
+      //   }
+      // }
     },
     onSelect(val) {
-      this.selectCycle = val.gg;
+      this.selectCycle = val.name;
+      this.selectLever = val.label;
+    },
+    async checkcheckStockVip() {
+      // this.$refs.closeDialog.show = true;
+      const opts = {
+        stockId: this.id,
+        buyNum: this.num,
+        lever: this.selectLever,
+      }
+      if (this.checkedZs) {
+        opts.stopLoss = this.zhisun;
+      }
+      if (this.checkedZy) {
+        opts.profitTarget = this.profitTarget;
+      }
+      if (this.tabsCurrentIndex == 0) {
+        opts.buyType = 1;
+      } else {
+        opts.buyType = 0;
+      }
+      let data = await api.checkStockVip(opts);
+      console.log(data, "data");
+      if (data.data == 0) {
+        this.password = "";
+        this.setBuy();
+      } else if (data.data == 1) {
+        this.password = "";
+        Notify({ type: "success", message: this.$t("购买申请成功") });
+        this.$router.push("/warehouse?index=1&buyType=" + this.bayType);
+      } else {
+        this.show = true;
+      }
     },
     gdOrSetBuy() {
       if (this.priceTabsCurrentIndex == 0) {
-        this.setBuy();
+        this.checkcheckStockVip();
       } else {
         this.gdBuy();
       }
@@ -437,9 +566,11 @@
       let opts = {
         stockId: this.code,
         buyNum: this.num,
-        lever: 1,
+        lever: this.selectLever,
         targetPrice: this.nums,
       };
+      console.log(this.selectLever, "this.selectLever ");
+
       if (this.tabsCurrentIndex == 0) {
         opts.buyType = 1;
       } else {
@@ -471,7 +602,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 +626,9 @@
         // 买入是买涨buyType:0, 卖出是买跌buyType:1,卖出的状态是0,买入的状态是1
         buyNum: this.num, // 单位为手
         // buyNum: (this.num.match(/\d+/g))[0] * 100, // 单位为手
-        lever: 1,
+        lever: this.selectLever,
       };
+      console.log(this.selectLever, "this.selectLever ");
       if (this.tabsCurrentIndex == 0) {
         opts.buyType = 1;
       } else {
@@ -524,6 +656,7 @@
     // 股票买入
     async gpBuy(opts) {
       opts.stockId = this.id;
+      opts.password = this.password;
       let data = await api.buy(opts);
       this.buying = false;
       if (data.status === 0) {
@@ -599,14 +732,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;
@@ -614,24 +747,13 @@
             i++
           ) {
             let val = this.$store.state.userInfo.siteLever.split("/")[i];
-            let item = { label: val + this.$t("hj112"), value: val };
-            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 = {
+              label: val,
               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,6 +772,7 @@
       }
     },
   },
+  components: { ActionSheet, [Notify.Component.name]: Notify.Component },
 };
 </script>
 
@@ -945,6 +1068,7 @@
 .btn_buy {
   width: 100%;
   height: auto;
+  bottom: 0;
   background: #fff;
   padding: 0.8rem 0.8rem;
   display: flex;
@@ -1059,6 +1183,7 @@
     transform: skew(-10deg, 0deg);
   }
 }
+
 /deep/.van-overlay {
   z-index: 10000 !important;
 }
@@ -1066,4 +1191,53 @@
 /deep/.van-popup {
   z-index: 10001 !important;
 }
+
+.popup-box {
+  padding: 30px 20px;
+  .input-box {
+    height: 1.3rem;
+    background: #f3f3f3;
+    border-radius: 0.15rem;
+
+    line-height: 1.3rem;
+    padding-left: 10px;
+    display: flex;
+    padding-left: 0.2rem;
+    font-size: 0.3975rem;
+    .laber {
+      margin-right: 10px;
+    }
+    // margin-top: 0.8rem;
+  }
+  .but {
+    width: 100%;
+    height: 1.3rem;
+    border-radius: 0.15rem;
+    background: #5c288c;
+    color: #fff;
+    font-size: 0.4615rem;
+    margin-top: 0.5rem;
+  }
+  .shijian {
+    width: 100%;
+    margin-top: 0.5rem;
+    margin-bottom: 0.5rem;
+    .xgsj {
+      margin-top: 10px;
+      font-size: 0.3875rem;
+      // font-weight: 600;
+      display: -webkit-box;
+      display: -ms-flexbox;
+      display: flex;
+      height: 50%;
+      -webkit-box-align: center;
+      -ms-flex-align: center;
+      align-items: center;
+      .sjtlt {
+        width: 33%;
+        margin-left: 0.4rem;
+      }
+    }
+  }
+}
 </style>

--
Gitblit v1.9.3