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 |  284 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 224 insertions(+), 60 deletions(-)

diff --git a/src/page/trading/buy.vue b/src/page/trading/buy.vue
index 4f8914c..dbc81ee 100644
--- a/src/page/trading/buy.vue
+++ b/src/page/trading/buy.vue
@@ -92,7 +92,6 @@
             <div class="top_input">
               <input
                 type="number"
-                onkeyup="value=value.replace(/[^\d]/g,'')"
                 v-model="num"
                 @input="numInput"
               />
@@ -107,12 +106,12 @@
               </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 }}</span>
             </div>
-          </div>
+          </div> -->
           <div class="tr_rs">
             <div class="top_bzz" style="padding-bottom: 0.2rem">
               <span style="text-align: left">
@@ -124,9 +123,15 @@
             </div>
 
             <div class="bottom_bzz">
-              <span>
+              <span v-if="priceTabsCurrentIndex == 0">
                 {{
-                  ((nowPrice / selectCycle.replace("X", "")) * num)
+                  (nowPrice * selectCycle.replace("X", "") * num)
+                    | _toLocaleString
+                }}
+              </span>
+              <span v-else>
+                {{
+                  (nums * selectCycle.replace("X", "") * num)
                     | _toLocaleString
                 }}
               </span>
@@ -147,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>
@@ -161,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>
@@ -176,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>
@@ -208,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",
@@ -249,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,
@@ -276,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: [
         {
@@ -298,6 +343,7 @@
       gid: "",
     };
   },
+
   mounted() {
     this.bayType = this.$route.query.bayType;
     this.gid = this.$route.query.gid;
@@ -325,20 +371,31 @@
     },
   },
   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;
-      }
+      // 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();
@@ -362,21 +419,22 @@
       this.priceTabsCurrentIndex = index;
     },
     jjjisua() {
-      let numbs = Math.floor(
-        this.moneyData.availableBalance /
-          this.nowPrice /
-          this.selectCycle.replace("X", "")
-      );
+      // 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;
-      }
+      // 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 {
@@ -403,44 +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.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();
       }
@@ -548,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) {
@@ -638,7 +747,10 @@
             i++
           ) {
             let val = this.$store.state.userInfo.siteLever.split("/")[i];
-            let item = { label: val, name: val + "X" };
+            let item = {
+              label: val,
+              name: val + "X",
+            };
             this.siteLeverList.push(item);
           }
           console.log(this.siteLeverList, " this.selectCycle");
@@ -660,6 +772,7 @@
       }
     },
   },
+  components: { ActionSheet, [Notify.Component.name]: Notify.Component },
 };
 </script>
 
@@ -955,6 +1068,7 @@
 .btn_buy {
   width: 100%;
   height: auto;
+  bottom: 0;
   background: #fff;
   padding: 0.8rem 0.8rem;
   display: flex;
@@ -1069,6 +1183,7 @@
     transform: skew(-10deg, 0deg);
   }
 }
+
 /deep/.van-overlay {
   z-index: 10000 !important;
 }
@@ -1076,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