291 lines
11 KiB
JavaScript
291 lines
11 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_http = require("../../common/http.js");
|
|
const common_constants = require("../../common/constants.js");
|
|
const common_config = require("../../common/config.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
KPI_ICONS: common_config.KPI_ICONS,
|
|
KPI_LABELS: common_constants.KPI_LABELS,
|
|
kpi: { todaySales: "0.00", monthSales: "0.00", monthProfit: "0.00", stockCount: "0" },
|
|
activeTab: "home",
|
|
notices: [],
|
|
loadingNotices: false,
|
|
noticeError: "",
|
|
consultLabel: "咨询",
|
|
consultDialogVisible: false,
|
|
consultMessage: "",
|
|
features: [
|
|
{ key: "product", title: "货品", img: "/static/icons/product.png", emoji: "📦" },
|
|
{ key: "customer", title: "客户", img: "/static/icons/webwxgetmsgimg.png", emoji: "👥" },
|
|
{ key: "sale", title: "销售", img: "/static/icons/webwxgetmsgimg.jpg", emoji: "💰" },
|
|
{ key: "account", title: "账户", img: "/static/icons/icons8-profile-50.png", emoji: "💳" },
|
|
{ key: "supplier", title: "供应商", img: "/static/icons/icons8-supplier-50.png", emoji: "🚚" },
|
|
{ key: "purchase", title: "进货", img: "/static/icons/icons8-dollar-ethereum-exchange-50.png", emoji: "🛒" },
|
|
{ key: "otherPay", title: "其他支出", img: "/static/icons/icons8-expenditure-64.png", emoji: "💸" },
|
|
{ key: "vip", title: "VIP会员", img: "/static/icons/icons8-vip-48.png", emoji: "👑" },
|
|
{ key: "report", title: "报表", img: "/static/icons/icons8-graph-report-50.png", emoji: "📊" }
|
|
]
|
|
};
|
|
},
|
|
onLoad() {
|
|
const hasToken = (() => {
|
|
try {
|
|
return !!common_vendor.index.getStorageSync("TOKEN");
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
})();
|
|
if (!hasToken) {
|
|
this.kpi = { todaySales: "0.00", monthSales: "0.00", monthProfit: "0.00", stockCount: "0" };
|
|
this.notices = [];
|
|
common_vendor.index.showToast({ title: "请登录使用该功能", icon: "none" });
|
|
return;
|
|
}
|
|
this.fetchMetrics();
|
|
this.fetchNotices();
|
|
this.fetchLatestConsult();
|
|
},
|
|
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 fetchLatestConsult() {
|
|
try {
|
|
const d = await common_http.get("/api/consults");
|
|
if (d && d.replied)
|
|
this.consultLabel = "已回复";
|
|
else
|
|
this.consultLabel = "咨询";
|
|
this._latestConsult = d;
|
|
} catch (e) {
|
|
this.consultLabel = "咨询";
|
|
}
|
|
},
|
|
onConsultTap() {
|
|
if (this.consultLabel === "已回复" && this._latestConsult && this._latestConsult.id) {
|
|
const msg = this._latestConsult.latestReply ? this._latestConsult.latestReply : this._latestConsult.message || "";
|
|
common_vendor.index.showModal({ title: "咨询回复", content: msg || "暂无内容", showCancel: false, success: async (res) => {
|
|
if (!res || res.confirm !== true)
|
|
return;
|
|
try {
|
|
const r = await common_http.put(`/api/consults/${this._latestConsult.id}/ack`, {});
|
|
this.consultLabel = "咨询";
|
|
this._latestConsult = null;
|
|
setTimeout(() => this.fetchLatestConsult(), 200);
|
|
} catch (e) {
|
|
try {
|
|
common_vendor.index.showToast({ title: e && e.message || "已读同步失败", icon: "none" });
|
|
} catch (_) {
|
|
}
|
|
}
|
|
} });
|
|
return;
|
|
}
|
|
this.consultMessage = "";
|
|
this.consultDialogVisible = true;
|
|
},
|
|
closeConsultDialog() {
|
|
this.consultDialogVisible = false;
|
|
},
|
|
async submitConsult() {
|
|
const text = String(this.consultMessage || "").trim();
|
|
if (!text) {
|
|
common_vendor.index.showToast({ title: "请输入咨询内容", icon: "none" });
|
|
return;
|
|
}
|
|
try {
|
|
await common_http.post("/api/consults", { message: text });
|
|
this.consultDialogVisible = false;
|
|
common_vendor.index.showToast({ title: "已提交", icon: "success" });
|
|
setTimeout(() => this.fetchLatestConsult(), 300);
|
|
} catch (e) {
|
|
common_vendor.index.showToast({ title: e && e.message || "提交失败", icon: "none" });
|
|
}
|
|
},
|
|
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 === "vip") {
|
|
common_vendor.index.navigateTo({ url: "/pages/my/vip" });
|
|
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:265", "[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
|
|
});
|
|
},
|
|
onPartsSearchTap() {
|
|
try {
|
|
common_vendor.index.setStorageSync("PRODUCT_SEARCH_CONFIG", JSON.stringify({
|
|
openTab: "search",
|
|
mode: "template"
|
|
}));
|
|
} catch (e) {
|
|
common_vendor.index.__f__("error", "at pages/index/index.vue:285", "[index] 设置存储标志失败:", e);
|
|
}
|
|
common_vendor.index.switchTab({ url: "/pages/product/list" });
|
|
},
|
|
onIconError(item) {
|
|
item.img = "";
|
|
}
|
|
}
|
|
};
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return common_vendor.e({
|
|
a: common_vendor.t($data.consultLabel),
|
|
b: common_vendor.o((...args) => $options.onConsultTap && $options.onConsultTap(...args)),
|
|
c: $data.KPI_ICONS.todaySales,
|
|
d: common_vendor.t($data.KPI_LABELS.todaySales),
|
|
e: common_vendor.t($data.kpi.todaySales),
|
|
f: $data.KPI_ICONS.monthSales,
|
|
g: common_vendor.t($data.KPI_LABELS.monthSales),
|
|
h: common_vendor.t($data.kpi.monthSales),
|
|
i: $data.KPI_ICONS.monthProfit,
|
|
j: common_vendor.t($data.KPI_LABELS.monthProfit),
|
|
k: common_vendor.t($data.kpi.monthProfit),
|
|
l: $data.KPI_ICONS.stockCount,
|
|
m: common_vendor.t($data.KPI_LABELS.stockCount),
|
|
n: common_vendor.t($data.kpi.stockCount),
|
|
o: $data.consultDialogVisible
|
|
}, $data.consultDialogVisible ? {
|
|
p: $data.consultMessage,
|
|
q: common_vendor.o(($event) => $data.consultMessage = $event.detail.value),
|
|
r: common_vendor.o((...args) => $options.closeConsultDialog && $options.closeConsultDialog(...args)),
|
|
s: common_vendor.o((...args) => $options.submitConsult && $options.submitConsult(...args)),
|
|
t: common_vendor.o(() => {
|
|
}),
|
|
v: common_vendor.o(() => {
|
|
})
|
|
} : {}, {
|
|
w: $data.loadingNotices
|
|
}, $data.loadingNotices ? {} : $data.noticeError ? {
|
|
y: common_vendor.t($data.noticeError)
|
|
} : !$data.notices.length ? {} : {
|
|
A: 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
|
|
});
|
|
})
|
|
}, {
|
|
x: $data.noticeError,
|
|
z: !$data.notices.length,
|
|
B: common_assets._imports_0,
|
|
C: common_vendor.o((...args) => $options.onPartsSearchTap && $options.onPartsSearchTap(...args)),
|
|
D: 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
|