Files
PartsInquiry/frontend/unpackage/dist/dev/mp-weixin/pages/index/index.js
2025-09-20 12:05:53 +08:00

171 lines
6.3 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const common_assets = require("../../common/assets.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.navigateTo({ url: "/pages/product/list" });
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;
}
common_vendor.index.showToast({ title: item.title + "(开发中)", icon: "none" });
},
goProduct() {
this.activeTab = "product";
common_vendor.index.navigateTo({ url: "/pages/product/list" });
},
onCreateOrder() {
common_vendor.index.navigateTo({ url: "/pages/order/create" });
},
goDetail() {
this.activeTab = "detail";
try {
common_vendor.index.__f__("log", "at pages/index/index.vue:179", "[index] goDetail → /pages/detail/index");
} catch (e) {
}
common_vendor.index.navigateTo({ url: "/pages/detail/index" });
},
goReport() {
this.activeTab = "report";
common_vendor.index.navigateTo({ url: "/pages/report/entry" });
},
goMe() {
this.activeTab = "me";
common_vendor.index.navigateTo({ 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: common_assets._imports_0,
b: common_vendor.t($data.kpi.todaySales),
c: common_vendor.t($data.kpi.monthSales),
d: common_vendor.t($data.kpi.monthProfit),
e: common_vendor.t($data.kpi.stockCount),
f: $data.loadingNotices
}, $data.loadingNotices ? {} : $data.noticeError ? {
h: common_vendor.t($data.noticeError)
} : !$data.notices.length ? {} : {
j: 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
});
})
}, {
g: $data.noticeError,
i: !$data.notices.length,
k: 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)
});
}),
l: $data.activeTab === "home" ? 1 : "",
m: common_vendor.o(($event) => $data.activeTab = "home"),
n: $data.activeTab === "product" ? 1 : "",
o: common_vendor.o((...args) => $options.goProduct && $options.goProduct(...args)),
p: common_vendor.o((...args) => $options.onCreateOrder && $options.onCreateOrder(...args)),
q: $data.activeTab === "detail" ? 1 : "",
r: common_vendor.o((...args) => $options.goDetail && $options.goDetail(...args)),
s: $data.activeTab === "report" ? 1 : "",
t: common_vendor.o((...args) => $options.goReport && $options.goReport(...args)),
v: $data.activeTab === "me" ? 1 : "",
w: common_vendor.o((...args) => $options.goMe && $options.goMe(...args))
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map