You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

494 lines
11 KiB

4 weeks ago
4 weeks ago
  1. <!-- @format -->
  2. <template>
  3. <view class="main">
  4. <!-- 自定义导航栏 -->
  5. <view class="header_fixed" :style="{ top: iSMT + 'px' }">
  6. <view class="header-content">
  7. <view class="header-left" @click="goBack">
  8. <text class="back-text"></text>
  9. </view>
  10. <view class="header-center">
  11. <text class="header-title">{{ marketTitle }}</text>
  12. </view>
  13. <view class="header-right">
  14. <image src="/static/marketSituation-image/search.png" class="header-icon" mode="aspectFit"></image>
  15. <text class="more-text">···</text>
  16. </view>
  17. </view>
  18. <!-- 表头 -->
  19. <view class="table-header">
  20. <view class="header-item name-column">
  21. <text class="header-text">名称</text>
  22. </view>
  23. <view class="header-item price-column" @click="sortByPrice">
  24. <text class="header-text">最新</text>
  25. <text class="sort-icon">{{ sortType === "price" ? (sortOrder === "asc" ? "↑" : "↓") : "↕" }}</text>
  26. </view>
  27. <view class="header-item change-column" @click="sortByChange">
  28. <text class="header-text">涨幅</text>
  29. <text class="sort-icon">{{ sortType === "change" ? (sortOrder === "asc" ? "↑" : "↓") : "↕" }}</text>
  30. </view>
  31. </view>
  32. </view>
  33. <!-- 内容区域 -->
  34. <scroll-view class="content" :style="{ top: contentTopPosition + 'px' }" scroll-y="true">
  35. <!-- 股票列表 -->
  36. <view class="stock-list">
  37. <view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index" @click="viewIndexDetail(stock)">
  38. <view class="stock-cell name-column">
  39. <view class="stock-name">{{ stock.stockName }}</view>
  40. <view class="stock-code">{{ stock.stockCode }}</view>
  41. </view>
  42. <view class="stock-cell price-column">
  43. <text class="stock-price" :class="stock.isRising ? 'rising' : 'falling'">
  44. {{ typeof stock.price === "number" ? stock.price.toFixed(2) : stock.price }}
  45. </text>
  46. </view>
  47. <view class="stock-cell change-column">
  48. <text class="stock-change" :class="stock.isRising ? 'rising' : 'falling'">
  49. {{ stock.change || stock.changePercent }}
  50. </text>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 底部安全区域 -->
  55. <!-- <view class="bottom-safe-area"></view> -->
  56. </scroll-view>
  57. </view>
  58. <!-- 底部导航栏 -->
  59. <!-- <footerBar class="static-footer" :type="'marketSituation'"></footerBar> -->
  60. </template>
  61. <script setup>
  62. import { ref, computed, onMounted, watch } from "vue";
  63. import { onLoad } from "@dcloudio/uni-app";
  64. import footerBar from "@/components/footerBar.vue";
  65. import { getRegionalGroupListAPI } from "../../api/marketSituation/marketSituation.js";
  66. // 响应式数据
  67. const iSMT = ref(0);
  68. const contentHeight = ref(0);
  69. const headerHeight = ref(80);
  70. const marketTitle = ref();
  71. const sortType = ref(""); // 排序类型:'price' 或 'change'
  72. const sortOrder = ref("desc"); // 排序顺序:'asc' 或 'desc'
  73. const regionalGroupArray = ref([]);
  74. // 股票数据
  75. const stockList = ref([
  76. {
  77. stockName: "Telecommunication",
  78. stockCode: "888607",
  79. price: 1349.47,
  80. change: "+7.67%",
  81. isRising: true,
  82. },
  83. {
  84. stockName: "Other",
  85. stockCode: "888607",
  86. price: 1349.47,
  87. change: "+6.67%",
  88. isRising: true,
  89. },
  90. {
  91. stockName: "Consumer Discretio...",
  92. stockCode: "888610",
  93. price: 1349.47,
  94. change: "+5.67%",
  95. isRising: true,
  96. },
  97. {
  98. stockName: "Telecommunication",
  99. stockCode: "888607",
  100. price: 1349.47,
  101. change: "+4.67%",
  102. isRising: true,
  103. },
  104. {
  105. stockName: "Other",
  106. stockCode: "888611",
  107. price: 1359.47,
  108. change: "+3.67%",
  109. isRising: true,
  110. },
  111. {
  112. stockName: "Consumer Discretio...",
  113. stockCode: "888610",
  114. price: 1349.47,
  115. change: "+2.67%",
  116. isRising: true,
  117. },
  118. {
  119. stockName: "Telecommunication",
  120. stockCode: "888607",
  121. price: 1349.47,
  122. change: "+1.67%",
  123. isRising: true,
  124. },
  125. {
  126. stockName: "Other",
  127. stockCode: "888611",
  128. price: 1009.98,
  129. change: "-1.67%",
  130. isRising: false,
  131. },
  132. {
  133. stockName: "Consumer Discretio...",
  134. stockCode: "888610",
  135. price: 1009.98,
  136. change: "-0.67%",
  137. isRising: false,
  138. },
  139. {
  140. stockName: "Telecommunication",
  141. stockCode: "888607",
  142. price: 1009.98,
  143. change: "-0.67%",
  144. isRising: false,
  145. },
  146. {
  147. stockName: "Other",
  148. stockCode: "888611",
  149. price: 1009.98,
  150. change: "-1.67%",
  151. isRising: false,
  152. },
  153. {
  154. stockName: "Consumer Discretio...",
  155. stockCode: "888610",
  156. price: 1009.98,
  157. change: "-4.67%",
  158. isRising: false,
  159. },
  160. {
  161. stockName: "Consumer Discretio...",
  162. stockCode: "888610",
  163. price: 1009.98,
  164. change: "-3.67%",
  165. isRising: false,
  166. },
  167. {
  168. stockName: "Consumer Discretio...",
  169. stockCode: "888610",
  170. price: 1009.98,
  171. change: "-3.67%",
  172. isRising: false,
  173. },
  174. ]);
  175. // 计算属性
  176. const contentTopPosition = computed(() => {
  177. return iSMT.value + headerHeight.value;
  178. });
  179. const sortedStockList = computed(() => {
  180. console.log("计算sortedStockList,原始数据长度:", stockList.value.length);
  181. let list = [...stockList.value];
  182. if (sortType.value === "price") {
  183. list.sort((a, b) => {
  184. return sortOrder.value === "asc" ? a.price - b.price : b.price - a.price;
  185. });
  186. } else if (sortType.value === "change") {
  187. list.sort((a, b) => {
  188. const aChange = parseFloat(a.change.replace(/[+%-]/g, ""));
  189. const bChange = parseFloat(b.change.replace(/[+%-]/g, ""));
  190. return sortOrder.value === "asc" ? aChange - bChange : bChange - aChange;
  191. });
  192. }
  193. console.log("排序后数据长度:", list.length);
  194. return list;
  195. });
  196. const getRegionalGroupList = async () => {
  197. try {
  198. const result = await getRegionalGroupListAPI({
  199. name: marketTitle.value,
  200. });
  201. regionalGroupArray.value = result.data;
  202. } catch (e) {
  203. console.error("获取区域分组列表失败:", e);
  204. }
  205. };
  206. // 页面加载时接收参数
  207. onLoad(async (options) => {
  208. if (options && options.market) {
  209. marketTitle.value = options.market;
  210. await getRegionalGroupList();
  211. }
  212. });
  213. // 方法
  214. const goBack = () => {
  215. uni.navigateBack();
  216. };
  217. // 方法:查看指数详情
  218. const viewIndexDetail = (item) => {
  219. console.log("查看指数详情:", item.stockName);
  220. // uni.showToast({
  221. // title: `查看 ${item.stockName} 详情`,
  222. // icon: 'none',
  223. // duration: 2000
  224. // })
  225. // 这里可以跳转到具体的指数详情页面
  226. uni.navigateTo({
  227. url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
  228. });
  229. };
  230. const sortByPrice = () => {
  231. if (sortType.value === "price") {
  232. sortOrder.value = sortOrder.value === "asc" ? "desc" : "asc";
  233. } else {
  234. sortType.value = "price";
  235. sortOrder.value = "desc";
  236. }
  237. };
  238. const sortByChange = () => {
  239. if (sortType.value === "change") {
  240. sortOrder.value = sortOrder.value === "asc" ? "desc" : "asc";
  241. } else {
  242. sortType.value = "change";
  243. sortOrder.value = "desc";
  244. }
  245. };
  246. onMounted(() => {
  247. // 获取状态栏高度
  248. iSMT.value = uni.getSystemInfoSync().statusBarHeight;
  249. // 动态计算header实际高度
  250. uni
  251. .createSelectorQuery()
  252. .select(".header_fixed")
  253. .boundingClientRect((rect) => {
  254. if (rect) {
  255. headerHeight.value = rect.height;
  256. console.log("Header实际高度:", headerHeight.value, "px");
  257. }
  258. })
  259. .exec();
  260. });
  261. // 监听headerHeight变化,重新计算contentHeight
  262. watch(headerHeight, (newHeight) => {
  263. if (newHeight > 0) {
  264. const systemInfo = uni.getSystemInfoSync();
  265. const windowHeight = systemInfo.windowHeight;
  266. const statusBarHeight = systemInfo.statusBarHeight || 0;
  267. const footerHeight = 100;
  268. contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight;
  269. console.log("重新计算contentHeight:", contentHeight.value);
  270. }
  271. });
  272. </script>
  273. <style scoped>
  274. .main {
  275. width: 100%;
  276. height: 100vh;
  277. background-color: #f5f5f5;
  278. position: relative;
  279. }
  280. /* 自定义导航栏 */
  281. .header_fixed {
  282. position: fixed;
  283. top: 0;
  284. left: 0;
  285. right: 0;
  286. z-index: 1000;
  287. background-color: #ffffff;
  288. border-bottom: 1px solid #f0f0f0;
  289. }
  290. .header-content {
  291. display: flex;
  292. align-items: center;
  293. justify-content: space-between;
  294. height: 44px;
  295. padding: 0 15px;
  296. }
  297. .header-left,
  298. .header-right {
  299. width: 60px;
  300. display: flex;
  301. align-items: center;
  302. }
  303. .header-left {
  304. justify-content: flex-start;
  305. }
  306. .header-right {
  307. justify-content: flex-end;
  308. gap: 10px;
  309. }
  310. .back-text {
  311. font-size: 24px;
  312. color: #333333;
  313. font-weight: 500;
  314. line-height: 1;
  315. }
  316. .header-center {
  317. flex: 1;
  318. display: flex;
  319. align-items: center;
  320. justify-content: center;
  321. }
  322. .header-title {
  323. font-size: 18px;
  324. font-weight: 600;
  325. color: #333333;
  326. }
  327. .header-icon {
  328. width: 20px;
  329. height: 20px;
  330. }
  331. .more-text {
  332. font-size: 20px;
  333. color: #666666;
  334. font-weight: bold;
  335. }
  336. /* 内容区域 */
  337. .content {
  338. position: fixed;
  339. left: 0;
  340. right: 0;
  341. bottom: 0;
  342. background-color: #ffffff;
  343. }
  344. /* 表头样式 */
  345. .table-header {
  346. display: flex;
  347. padding: 12px 15px;
  348. background-color: #f8f9fa;
  349. border-bottom: 1px solid #e9ecef;
  350. }
  351. .header-item {
  352. display: flex;
  353. align-items: center;
  354. justify-content: center;
  355. cursor: pointer;
  356. }
  357. .header-item.name-column {
  358. flex: 2;
  359. justify-content: flex-start;
  360. }
  361. .header-item.price-column,
  362. .header-item.change-column {
  363. flex: 1;
  364. justify-content: center;
  365. }
  366. .header-text {
  367. font-size: 14px;
  368. color: #666666;
  369. font-weight: 500;
  370. }
  371. .sort-icon {
  372. margin-left: 4px;
  373. font-size: 12px;
  374. color: #999999;
  375. }
  376. /* 股票列表 */
  377. .stock-list {
  378. background-color: #ffffff;
  379. }
  380. .stock-row {
  381. display: flex;
  382. align-items: center;
  383. padding: 12px 15px;
  384. border-bottom: 1px solid #f5f5f5;
  385. }
  386. .stock-row:active {
  387. background-color: #f8f8f8;
  388. }
  389. .stock-cell {
  390. display: flex;
  391. flex-direction: column;
  392. align-items: center;
  393. }
  394. .stock-cell.name-column {
  395. flex: 2;
  396. align-items: flex-start;
  397. }
  398. .stock-cell.price-column,
  399. .stock-cell.change-column {
  400. flex: 1;
  401. align-items: center;
  402. }
  403. .stock-name {
  404. font-size: 15px;
  405. color: #333333;
  406. font-weight: 500;
  407. line-height: 1.2;
  408. margin-bottom: 2px;
  409. }
  410. .stock-code {
  411. font-size: 11px;
  412. color: #999999;
  413. line-height: 1.2;
  414. }
  415. .stock-price {
  416. font-size: 15px;
  417. font-weight: 600;
  418. line-height: 1.2;
  419. }
  420. .stock-change {
  421. font-size: 13px;
  422. font-weight: 500;
  423. line-height: 1.2;
  424. }
  425. .rising {
  426. color: #00c851;
  427. }
  428. .falling {
  429. color: #ff4444;
  430. }
  431. /* 底部安全区域 */
  432. /* .bottom-safe-area {
  433. height: 20px;
  434. } */
  435. /* 底部导航栏 */
  436. /* .static-footer {
  437. position: fixed;
  438. bottom: 0;
  439. left: 0;
  440. right: 0;
  441. z-index: 1000;
  442. } */
  443. </style>