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/list/tradingList/data.list.vue |  281 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 212 insertions(+), 69 deletions(-)

diff --git a/src/page/list/tradingList/data.list.vue b/src/page/list/tradingList/data.list.vue
index e3e45d2..8990762 100644
--- a/src/page/list/tradingList/data.list.vue
+++ b/src/page/list/tradingList/data.list.vue
@@ -7,85 +7,132 @@
             {{ $t("hj313") }}
           </div>
         </van-col>
-        <van-col span="10">
+        <van-col span="3">
+          <div style="text-align: right">
+            {{ $t("市场") }}
+          </div>
+        </van-col>
+        <van-col span="7">
           <div style="text-align: right">
             {{ $t("hj314") }}
+            <span class="caret-wrapper">
+              <i
+                class="el-icon-caret-top"
+                style="font-size: 0.3rem"
+                @click="priceAscending"
+                :style="{ color: Ascend == 1 ? '#409eff' : '#8c9fad' }"
+              ></i>
+              <i
+                class="el-icon-caret-bottom"
+                style="font-size: 0.3rem"
+                @click="priceDescending"
+                :style="{ color: Ascend == 2 ? '#409eff' : '#8c9fad' }"
+              ></i>
+            </span>
           </div>
         </van-col>
         <van-col span="6">
           <div style="text-align: right">
             {{ $t("hj315") }}
+            <span class="caret-wrapper">
+              <i
+                class="el-icon-caret-top"
+                style="font-size: 0.3rem"
+                @click="riseFallAscending"
+                :style="{ color: Ascend == 3 ? '#409eff' : '#8c9fad' }"
+              ></i>
+              <i
+                class="el-icon-caret-bottom"
+                style="font-size: 0.3rem"
+                @click="riseFallDescending"
+                :style="{ color: Ascend == 4 ? '#409eff' : '#8c9fad' }"
+              ></i>
+            </span>
           </div>
         </van-col>
       </van-row>
     </div>
-
-    <van-list
-      style="margin-bottom: 50px"
-      v-model="loadings"
-      :finished="finished"
-      :finished-text="$t('hj43')"
-      :loading-text="$t('hj430')"
-      @load="onLoads"
-      :immediate-check="false"
+    <van-pull-refresh
+      v-model="refreshing"
+      :pulling-text="$t('hj430')"
+      :loosing-text="$t('hj430')"
+      @refresh="onRefresh"
     >
-      <div
-        class="item"
-        @click="handleGoToKlineDetail1(item, index)"
-        v-for="(item, index) in listArr"
-        :key="item.indexCode"
+      <van-list
+        style="margin-bottom: 50px"
+        v-model="loadings"
+        :finished="finished"
+        :finished-text="$t('hj43')"
+        :loading-text="$t('hj430')"
+        @load="onLoads"
+        :immediate-check="false"
       >
-        <van-row type="flex" align="center" gutter="20">
-          <van-col span="8">
-            <div>
-              <div class="tp">
-                <span class="collection" @click="optionszx(item)">
-                  <span
-                    class="shu"
-                    :class="item.isOption == '1' ? 'shublue' : ''"
-                  ></span>
-                </span>
-                <span
-                  class="title_color"
-                  style="
-                    overflow: hidden;
-                    -webkit-line-clamp: 1;
-                    text-overflow: ellipsis;
-                    display: -webkit-box;
-                    -webkit-box-orient: vertical;
-                  "
-                  >{{ item.name }}</span
-                >
+        <div
+          class="item"
+          @click="handleGoToKlineDetail1(item, index)"
+          v-for="(item, index) in listArr"
+          :key="item.indexCode"
+        >
+          <van-row type="flex" align="center" gutter="20">
+            <van-col span="8">
+              <div>
+                <div class="tp">
+                  <div class="collection" @click="optionszx(item)">
+                    <div
+                      class="shu"
+                      :class="item.isOption == '1' ? 'shublue' : ''"
+                    ></div>
+                  </div>
+                  <div
+                    class="title_color"
+                    style="
+                      width: 100%;
+                      overflow: hidden;
+                      text-overflow: ellipsis;
+                      white-space: nowrap;
+                    "
+                  >
+                    {{ item.name }}
+                  </div>
+                </div>
+                <div class="bt">
+                  <span>{{ item.spell }}</span>
+                </div>
               </div>
-              <div class="bt">
-                <span>{{ item.spell }}</span>
-              </div>
-            </div></van-col
-          >
+            </van-col>
 
-          <van-col span="10">
-            <div style="text-align: right">
-              <div class="tp">
-                <span class="price_color">{{ item.nowPrice | _toString }}</span>
+            <van-col span="3">
+              <div style="text-align: right">
+                {{ item.gid }}
               </div>
-              <div class="bt">
-                <span>{{ item.addTime }}</span>
+            </van-col>
+
+            <van-col span="7">
+              <div style="text-align: right">
+                <div class="tp">
+                  <span class="price_color">
+                    {{ item.nowPrice | _toLocaleString(false) }}
+                  </span>
+                </div>
+                <div class="bt">
+                  <span>{{ item.addTime }}</span>
+                </div>
               </div>
-            </div>
-          </van-col>
-          <van-col span="6">
-            <div style="text-align: right">
-              <div
-                class="tp right_bs"
-                :class="`${item.color > 0 ? 'green' : 'red'}`"
-              >
-                <span class="price_color">{{ item.hcrateP }}</span>
+            </van-col>
+            <van-col span="6">
+              <div style="text-align: right">
+                <div
+                  class="tp right_bs"
+                  :class="`${item.color > 0 ? 'green' : 'red'}`"
+                >
+                  <span class="price_color">{{ item.hcrateP }}</span>
+                </div>
               </div>
-            </div>
-          </van-col>
-        </van-row>
-      </div>
-    </van-list>
+            </van-col>
+          </van-row>
+        </div>
+      </van-list>
+    </van-pull-refresh>
 
     <dazy ref="dazy" />
   </div>
@@ -95,6 +142,7 @@
 import * as api from "@/axios/api";
 import handleDt from "@/utils/deTh";
 import dazy from "./dazy.vue";
+import { WhrWebSocket } from "@/utils/WhrWebSocket";
 
 export default {
   components: { dazy },
@@ -150,6 +198,9 @@
       listArr: [],
       pageNumVal: 1,
       getInterval: null,
+      num: 1,
+      refreshing: false,
+      Ascend: 0, //颜色问题
     };
   },
 
@@ -157,11 +208,29 @@
     this.listArr = [];
     this.pageNumVal = 1;
     this.getStock(this.active, this.zxactive, 1);
-    this.getInterval = setInterval(() => {
-      this.getStock(this.active, this.zxactive, 1);
-    }, 5000);
+    this.initWebSocket();
+    // this.getInterval = setInterval(() => {
+    //   this.getStock(this.active, this.zxactive, 1);
+    // }, 5000);
   },
   methods: {
+    priceAscending() {
+      this.Ascend = 1;
+      this.listArr.sort((a, b) => a.nowPrice - b.nowPrice);
+    },
+    priceDescending() {
+      this.Ascend = 2;
+      this.listArr.sort((a, b) => b.nowPrice - a.nowPrice);
+    },
+    riseFallAscending() {
+      this.Ascend = 3;
+      this.listArr.sort((a, b) => a.hcrate - b.hcrate);
+    },
+    riseFallDescending() {
+      this.Ascend = 4;
+      this.listArr.sort((a, b) => b.hcrate - a.hcrate);
+    },
+
     filterSH(val) {
       if (val === "sh") {
         return 1;
@@ -218,7 +287,7 @@
       let pageNumVal = c || this.pageNumVal;
       let opt = {
         pageNum: pageNumVal,
-        pageSize: 100,
+        pageSize: 20 * this.num,
         stockPlate: "",
         keyWords: this.sousuo,
         stockType: stockType,
@@ -243,24 +312,82 @@
             if (this.active === data.data.stockType) {
               this.listArr = data.data.list;
               this.loadings = false;
-              this.finished = true;
+              // this.finished = true;
+              if (
+                !this.listArr.length ||
+                (this.listArr.length && this.listArr.length % 20)
+              ) {
+                this.finished = true;
+              }
             }
           } else {
             if (this.zxactive === data.data.stockType) {
               this.listArr = data.data.list;
               this.loadings = false;
-              this.finished = true;
+              // this.finished = true;
+              if (
+                !this.listArr.length ||
+                (this.listArr.length && this.listArr.length % 20)
+              ) {
+                this.finished = true;
+              }
             }
+          }
+          if (this.Ascend == 1) {
+            this.listArr.sort((a, b) => a.nowPrice - b.nowPrice);
+          } else if (this.Ascend == 2) {
+            this.listArr.sort((a, b) => b.nowPrice - a.nowPrice);
+          } else if (this.Ascend == 3) {
+            this.listArr.sort((a, b) => a.hcrate - b.hcrate);
+          } else if (this.Ascend == 4) {
+            this.listArr.sort((a, b) => b.hcrate - a.hcrate);
           }
         }
       } else {
         this.finished = true;
       }
     }, 500),
+
+    onRefresh() {
+      // 清空列表数据
+      this.finished = false;
+
+      // 重新加载数据
+      // 将 loading 设置为 true,表示处于加载状态
+      this.loading = true;
+      if (this.refreshing) {
+        // this.listArr = [];
+        this.refreshing = false;
+      }
+      this.getStock();
+    },
+
+    initWebSocket() {
+      console.log("initWebSocket");
+      this.Trade = new WhrWebSocket({
+        path: `wss://ws.is4vc.com/websocket-server`,
+        onmessage: this.getTradeMessage,
+      });
+
+      this.Trade.init();
+    },
+    getTradeMessage({ data }) {
+      let result = JSON.parse(data);
+      let pid = result.pid;
+      let userToUpdate = this.listArr.find((item) => item.code == pid);
+      if (userToUpdate) {
+        // 更新对象数据
+        userToUpdate.nowPrice = result.last;
+        userToUpdate.hcrateP = result.pcp;
+      }
+    },
+
     onLoads() {
+      console.log("onLoads");
       // this.pageNumVal++;
-      // this.loadings = true;
-      // this.getStock();
+      this.loadings = true;
+      this.num += 1;
+      this.getStock();
     },
     optionszx() {},
   },
@@ -290,6 +417,7 @@
   // display: flex;
   // justify-content: space-between;
   border-bottom: 1px solid #f0f2f3;
+
   .right_bs {
     text-align: center;
     border-radius: 0.05333rem;
@@ -309,10 +437,12 @@
   .green {
     background-color: rgb(3, 173, 143);
   }
+
   .red {
     background-color: rgb(208, 75, 100);
   }
 }
+
 .center_price {
   font-style: normal;
   font-weight: 500;
@@ -324,6 +454,7 @@
   flex: 1;
   margin-right: 20px;
 }
+
 .title_color {
   font-style: normal;
   font-weight: 500;
@@ -333,4 +464,16 @@
   text-align: left;
   color: #14181f;
 }
+
+.caret-wrapper {
+  display: inline-flex;
+  flex-direction: column;
+  align-items: center;
+  height: 0.6rem;
+  width: 0.5rem;
+  vertical-align: middle;
+  cursor: pointer;
+  overflow: initial;
+  position: relative;
+}
 </style>
\ No newline at end of file

--
Gitblit v1.9.3