"use strict"; const common_vendor = require("../../common/vendor.js"); const common_http = require("../../common/http.js"); const common_constants = require("../../common/constants.js"); const _sfc_main = { data() { return { kpi: { todaySales: "0.00", monthSales: "0.00", monthProfit: "0.00", stockCount: "0" }, activeTab: "home", notices: [], loadingNotices: false, noticeError: "", features: [ { key: "product", title: "货品", img: "/static/icons/product.png", emoji: "📦" }, { key: "customer", title: "客户", img: "/static/icons/customer.png", emoji: "👥" }, { key: "sale", title: "销售", img: "/static/icons/sale.png", emoji: "💰" }, { key: "account", title: "账户", img: "/static/icons/account.png", emoji: "💳" }, { key: "supplier", title: "供应商", img: "/static/icons/supplier.png", emoji: "🚚" }, { key: "purchase", title: "进货", img: "/static/icons/purchase.png", emoji: "🛒" }, { key: "otherPay", title: "其他支出", img: "/static/icons/other-pay.png", emoji: "💸" }, { key: "vip", title: "VIP会员", img: "/static/icons/vip.png", emoji: "👑" }, { key: "report", title: "报表", img: "/static/icons/report.png", emoji: "📊" }, { key: "more", title: "更多", img: "/static/icons/more.png", emoji: "⋯" } ] }; }, onLoad() { this.fetchMetrics(); this.fetchNotices(); }, methods: { async fetchMetrics() { try { const d = await common_http.get("/api/dashboard/overview"); const toNum = (v) => typeof v === "number" ? v : Number(v || 0); this.kpi = { ...this.kpi, todaySales: toNum(d && d.todaySalesAmount).toFixed(2), monthSales: toNum(d && d.monthSalesAmount).toFixed(2), monthProfit: toNum(d && d.monthGrossProfit).toFixed(2), stockCount: String((d && d.stockTotalQuantity) != null ? d.stockTotalQuantity : 0) }; } catch (e) { } }, async fetchNotices() { this.loadingNotices = true; this.noticeError = ""; try { const list = await common_http.get("/api/notices"); this.notices = Array.isArray(list) ? list.map((n) => ({ text: n.content || n.title || "", tag: n.tag || "" })) : []; } catch (e) { this.noticeError = e && e.message || "公告加载失败"; } finally { this.loadingNotices = false; } }, onFeatureTap(item) { if (item.key === "product") { common_vendor.index.switchTab({ url: "/pages/product/list" }); return; } if (item.key === "sale") { try { common_vendor.index.setStorageSync("ORDER_DEFAULT_PARAMS", { biz: "sale", type: "out" }); } catch (e) { } common_vendor.index.switchTab({ url: "/pages/order/create" }); return; } if (item.key === "customer") { common_vendor.index.navigateTo({ url: "/pages/customer/select" }); return; } if (item.key === "account") { common_vendor.index.navigateTo({ url: "/pages/account/select" }); return; } if (item.key === "supplier") { common_vendor.index.navigateTo({ url: "/pages/supplier/select" }); return; } if (item.key === "purchase") { try { common_vendor.index.setStorageSync("ORDER_DEFAULT_PARAMS", { biz: "purchase", type: "in" }); } catch (e) { } common_vendor.index.switchTab({ url: "/pages/order/create" }); return; } if (item.key === "report") { common_vendor.index.navigateTo({ url: common_constants.ROUTES.report }); return; } if (item.key === "otherPay") { try { common_vendor.index.setStorageSync("ORDER_DEFAULT_PARAMS", { biz: "expense" }); } catch (e) { } common_vendor.index.switchTab({ url: "/pages/order/create" }); return; } common_vendor.index.showToast({ title: item.title + "(开发中)", icon: "none" }); }, goProduct() { common_vendor.index.switchTab({ url: "/pages/product/list" }); }, onCreateOrder() { common_vendor.index.switchTab({ url: "/pages/order/create" }); }, goDetail() { try { common_vendor.index.__f__("log", "at pages/index/index.vue:177", "[index] goDetail → /pages/detail/index"); } catch (e) { } common_vendor.index.switchTab({ url: "/pages/detail/index" }); }, goMe() { common_vendor.index.switchTab({ url: "/pages/my/index" }); }, onNoticeTap(n) { common_vendor.index.showModal({ title: "广告", content: n && (n.text || n.title || n.content) || "", showCancel: false }); }, onIconError(item) { item.img = ""; } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: $data.loadingNotices }, $data.loadingNotices ? {} : $data.noticeError ? { c: common_vendor.t($data.noticeError) } : !$data.notices.length ? {} : { e: common_vendor.f($data.notices, (n, idx, i0) => { return common_vendor.e({ a: common_vendor.t(n.text), b: n.tag }, n.tag ? { c: common_vendor.t(n.tag) } : {}, { d: common_vendor.o(($event) => $options.onNoticeTap(n), idx), e: idx }); }) }, { b: $data.noticeError, d: !$data.notices.length, f: common_vendor.t($data.kpi.todaySales), g: common_vendor.t($data.kpi.monthSales), h: common_vendor.t($data.kpi.monthProfit), i: common_vendor.t($data.kpi.stockCount), j: common_vendor.f($data.features, (item, k0, i0) => { return common_vendor.e({ a: item.img }, item.img ? { b: item.img, c: common_vendor.o(($event) => $options.onIconError(item), item.key) } : item.emoji ? { e: common_vendor.t(item.emoji) } : {}, { d: item.emoji, f: common_vendor.t(item.title), g: item.key, h: common_vendor.o(($event) => $options.onFeatureTap(item), item.key) }); }) }); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map