"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_auth = require("../../utils/auth.js"); const utils_api = require("../../utils/api.js"); const _sfc_main = { __name: "strong", setup(__props) { const isPurchased = common_vendor.ref(false); const showModal = common_vendor.ref(false); const selectedPlan = common_vendor.ref("yearly"); const stockList = common_vendor.ref([ { name: "航天发展", code: "000547" }, { name: "贵州茅台", code: "600519" } ]); const startMonth = common_vendor.ref("2025-01"); const endMonth = common_vendor.ref("2025-11"); const formatMonth = (monthStr) => { if (!monthStr) return "请选择"; const [year, month] = monthStr.split("-"); return `${year}年${month}月`; }; const checkPurchaseStatus = () => { try { const purchaseInfo = common_vendor.index.getStorageSync("strong_pool_purchase"); if (purchaseInfo) { const now = Date.now(); const expireTime = purchaseInfo.expireTime; if (now < expireTime) { isPurchased.value = true; } else { common_vendor.index.removeStorageSync("strong_pool_purchase"); isPurchased.value = false; } } else { isPurchased.value = false; } } catch (e) { console.error("检查购买状态失败:", e); isPurchased.value = false; } }; const showPurchaseModal = () => { console.log("点击立即解锁"); if (!utils_auth.isLoggedIn()) { console.log("未登录,跳转到登录页"); common_vendor.index.showModal({ title: "登录提示", content: "此功能需要登录后使用,是否前往登录?", confirmText: "去登录", cancelText: "取消", success: (res) => { if (res.confirm) { common_vendor.index.navigateTo({ url: "/pages/login/login" }); } } }); return; } console.log("已登录,显示购买弹窗"); showModal.value = true; }; const closePurchaseModal = () => { showModal.value = false; }; const handlePurchase = () => { if (!selectedPlan.value) { common_vendor.index.showToast({ title: "请选择订阅方案", icon: "none" }); return; } const now = Date.now(); let expireTime = now; if (selectedPlan.value === "yearly") { expireTime = now + 365 * 24 * 60 * 60 * 1e3; } const purchaseInfo = { plan: selectedPlan.value, purchaseTime: now, expireTime }; common_vendor.index.setStorageSync("strong_pool_purchase", purchaseInfo); isPurchased.value = true; closePurchaseModal(); common_vendor.index.showToast({ title: "解锁成功", icon: "success" }); }; const onStartMonthChange = (e) => { startMonth.value = e.detail.value; console.log("[强势池] 选择开始月份:", startMonth.value); }; const onEndMonthChange = (e) => { endMonth.value = e.detail.value; console.log("[强势池] 选择结束月份:", endMonth.value); }; const onHistorySearch = () => { if (!startMonth.value || !endMonth.value) { common_vendor.index.showToast({ title: "请选择开始和结束月份", icon: "none" }); return; } if (startMonth.value > endMonth.value) { common_vendor.index.showToast({ title: "开始月份不能晚于结束月份", icon: "none" }); return; } console.log("[强势池] 查询历史数据区间:", startMonth.value, "至", endMonth.value); common_vendor.index.showToast({ title: `查询${formatMonth(startMonth.value)}至${formatMonth(endMonth.value)}`, icon: "none", duration: 2e3 }); }; const addToMyStocks = async (stock) => { try { const myStocks = common_vendor.index.getStorageSync("my_stocks") || []; const exists = myStocks.some((item) => item.code === stock.code); if (exists) { common_vendor.index.showToast({ title: "该股票已在列表中", icon: "none" }); return; } common_vendor.index.showLoading({ title: "获取行情..." }); let priceChange = null; let changePercent = null; try { const quoteRes = await utils_api.getStockQuotes(stock.code); console.log("[强势池] 行情数据:", quoteRes); if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) { const quoteData = quoteRes.data[0]; priceChange = quoteData.priceChange; changePercent = quoteData.changePercent; } } catch (e) { console.error("获取行情数据失败:", e); } common_vendor.index.hideLoading(); myStocks.push({ name: stock.name, code: stock.code, priceChange, changePercent, addTime: Date.now() }); common_vendor.index.setStorageSync("my_stocks", myStocks); common_vendor.index.showToast({ title: "添加成功", icon: "success" }); } catch (e) { common_vendor.index.hideLoading(); console.error("添加股票失败:", e); common_vendor.index.showToast({ title: "添加失败", icon: "none" }); } }; const removeFromMyStocks = (stock) => { try { let myStocks = common_vendor.index.getStorageSync("my_stocks") || []; const index = myStocks.findIndex((item) => item.code === stock.code); if (index === -1) { common_vendor.index.showToast({ title: "该股票不在列表中", icon: "none" }); return; } myStocks.splice(index, 1); common_vendor.index.setStorageSync("my_stocks", myStocks); common_vendor.index.showToast({ title: "移除成功", icon: "success" }); } catch (e) { console.error("移除股票失败:", e); common_vendor.index.showToast({ title: "移除失败", icon: "none" }); } }; common_vendor.onLoad(() => { const loginStatus = utils_auth.isLoggedIn(); console.log("[强势池] 登录状态:", loginStatus); checkPurchaseStatus(); }); common_vendor.onShow(() => { const loginStatus = utils_auth.isLoggedIn(); console.log("[强势池] 登录状态:", loginStatus); checkPurchaseStatus(); common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" }); }); return (_ctx, _cache) => { return common_vendor.e({ a: !isPurchased.value }, !isPurchased.value ? { b: common_vendor.o(showPurchaseModal) } : { c: common_vendor.f(stockList.value, (stock, index, i0) => { return { a: common_vendor.t(stock.name), b: common_vendor.t(stock.code), c: common_vendor.o(($event) => addToMyStocks(stock), index), d: common_vendor.o(($event) => removeFromMyStocks(stock), index), e: index }; }) }, { d: common_vendor.t(formatMonth(startMonth.value)), e: startMonth.value, f: common_vendor.o(onStartMonthChange), g: common_vendor.t(formatMonth(endMonth.value)), h: endMonth.value, i: common_vendor.o(onEndMonthChange), j: common_vendor.o(onHistorySearch), k: showModal.value }, showModal.value ? { l: common_vendor.o(closePurchaseModal), m: common_vendor.o(handlePurchase), n: common_vendor.o(() => { }), o: common_vendor.o(closePurchaseModal) } : {}); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]); wx.createPage(MiniProgramPage);