Files
JiaZhiQianYan/unpackage/dist/dev/mp-weixin/pages/geGuCenter/detail.js
2026-02-04 17:43:41 +08:00

239 lines
7.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../../common/vendor.js");
const request_api = require("../../request/api.js");
const common_assets = require("../../common/assets.js");
const _sfc_main = {
data() {
return {
navH: common_vendor.inject("navHeight"),
contentTop: "",
allStockData: [],
filteredData: [],
currentDate: "",
// 最终要赋值的日期
searchResultTop: "",
//搜索结果
contentTop: "",
keywords: "",
//搜索关键字
searchShow: false,
//是否展示搜索结果
searchResultList: [],
//搜索结果
selectSearchStockInfo: null,
//选中的搜索股票信息
topLists: [
{
title: "超大盘股",
value: ">1000亿"
},
{
title: "大盘股",
value: "500-1000亿"
},
{
title: "中盘股",
value: "100-500亿"
}
],
list2Index: 0
};
},
onLoad(e) {
this.currentDate = e.currentDate;
this.searchResultTop = this.navH + (20 + 70) / 750 * common_vendor.inject("windowWidth");
this.contentTop = this.navH + (20 + 70 + 25) / 750 * common_vendor.inject("windowWidth");
this.marketHeatmap();
},
methods: {
/**
* 点击搜索
*/
clickSearch() {
if (this.keywords) {
this.getSearchStockInfoListData();
} else
this.selectSearchStockInfo = null;
},
/**
* 点击搜索结果背景
*/
clickSearchResultBg() {
this.searchShow = false;
},
/**
* 点击搜索结果列表项
*/
clickSearchResultListItem(item) {
this.selectSearchStockInfo = item;
this.searchShow = false;
this.getStockBasicInfoData();
},
/**
* 根据输入内容获取搜索列表项
*/
getSearchStockInfoListData() {
let param = { q: this.keywords, limit: 10 };
request_api.searchStockInfo(param).then((res) => {
this.searchResultList = res.data;
this.searchShow = this.searchResultList.length > 0;
}).catch((error) => {
});
},
/**
* 获取股票基本信息
*/
getStockBasicInfoData() {
let code = this.stockCode;
if (this.selectSearchStockInfo) {
code = this.selectSearchStockInfo.stock_code;
}
common_vendor.index.navigateTo({
url: "/pagesStock/stockCenterDetails/stockCenterDetails?code=" + code
});
},
handleTypeClick(index) {
this.list2Index = index;
this.marketHeatmap();
},
getTableItem(obj) {
const marketCap = obj.market_cap ? obj.market_cap.toFixed(2) : "0.00";
const amount = obj.amount ? obj.amount.toFixed(2) : "0.00";
const changePercent = obj.change_percent ? Number(obj.change_percent) : 0;
let changePercentStr = "";
let changeType = "";
if (changePercent > 0) {
changePercentStr = `+${changePercent}%`;
changeType = "positive";
} else if (changePercent < 0) {
changePercentStr = `${changePercent}%`;
changeType = "negative";
} else {
changePercentStr = "0%";
changeType = "zero";
}
return [
[obj.stock_name, obj.stock_code],
[changePercentStr, "", changeType],
// 第三个元素存类型标记
[`${marketCap}亿元`],
[`${amount}亿元`],
[obj.industry || "暂无"]
// 处理行业为空的情况
];
},
marketHeatmap() {
let param = {
limit: 500
};
if (this.currentDate && this.currentDate !== "undefined" && this.currentDate.trim() !== "") {
param.date = this.currentDate;
}
request_api.marketHeatmap(param).then((res) => {
this.allStockData = res.data || [];
this.filterStockByMarketCap();
}).catch((error) => {
});
},
// 根据市值区间筛选数据
filterStockByMarketCap() {
const {
list2Index,
allStockData
} = this;
let filtered = [];
switch (list2Index) {
case 0:
filtered = allStockData.filter((item) => item.market_cap > 1e3);
break;
case 1:
filtered = allStockData.filter((item) => item.market_cap >= 500 && item.market_cap <= 1e3);
break;
case 2:
filtered = allStockData.filter((item) => item.market_cap >= 100 && item.market_cap <= 500);
break;
default:
filtered = allStockData;
}
this.filteredData = filtered;
},
itemDetails(item) {
common_vendor.index.navigateTo({
url: "/pagesStock/stockCenterDetails/stockCenterDetails?code=" + item.stock_code
});
}
}
};
if (!Array) {
const _easycom_navBar2 = common_vendor.resolveComponent("navBar");
_easycom_navBar2();
}
const _easycom_navBar = () => "../../components/navBar/navBar.js";
if (!Math) {
_easycom_navBar();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.p({
leftText: "详情",
hideNavBg: true
}),
b: common_assets._imports_0,
c: common_assets._imports_1,
d: common_vendor.o([($event) => $data.keywords = $event.detail.value, ($event) => $options.clickSearch()]),
e: $data.keywords,
f: common_vendor.s("top:" + $data.navH + "px;"),
g: $data.searchShow
}, $data.searchShow ? {
h: common_vendor.f($data.searchResultList, (item, index, i0) => {
return {
a: common_vendor.t(item.stock_code),
b: common_vendor.t(item.stock_name),
c: index,
d: common_vendor.o(($event) => $options.clickSearchResultListItem(item), index)
};
}),
i: common_vendor.s("top:" + $data.searchResultTop + "px;"),
j: common_vendor.o(($event) => $options.clickSearchResultBg())
} : {}, {
k: common_vendor.f($data.topLists, (item, index, i0) => {
return {
a: common_vendor.t(item.title),
b: $data.list2Index == index ? "#BB8520" : "#070707",
c: common_vendor.t(item.value),
d: $data.list2Index == index ? "#BB8520" : "#070707",
e: common_vendor.o(($event) => $options.handleTypeClick(index), index),
f: index,
g: $data.list2Index == index ? "1rpx solid #F2C369" : "none"
};
}),
l: common_vendor.f(["股票名称", "涨跌幅", "市值", "成交额", "行业"], (item, index, i0) => {
return {
a: common_vendor.t(item),
b: index
};
}),
m: common_vendor.f($data.filteredData, (obj, j, i0) => {
return {
a: common_vendor.f($options.getTableItem(obj), (item, index, i1) => {
return common_vendor.e({
a: common_vendor.t(item[0]),
b: index == 0
}, index == 0 ? {
c: common_vendor.t(item[1])
} : {}, {
d: index,
e: index == 0 ? "#222222" : index == 1 ? item[2] === "positive" ? "#EC3440" : "#01AB5D" : "#666666"
});
}),
b: common_vendor.o(($event) => $options.itemDetails(obj)),
c: j % 2 == 0 ? "#fff" : "#FAFAFC"
};
}),
n: common_vendor.s("top:" + $data.contentTop + "px;")
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/geGuCenter/detail.js.map