Files
PartsInquiry/frontend/unpackage/dist/dev/mp-weixin/pages/detail/index.js
2025-09-24 20:35:15 +08:00

211 lines
7.0 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const API_OF = {
sale: "/api/orders",
purchase: "/api/purchase-orders",
collect: "/api/payments",
fund: "/api/other-transactions",
stock: "/api/inventories/logs"
};
const _sfc_main = {
data() {
return {
biz: "sale",
bizList: [
{ key: "sale", name: "出货" },
{ key: "purchase", name: "进货" },
{ key: "collect", name: "收款" },
{ key: "fund", name: "资金" },
{ key: "stock", name: "盘点" }
],
range: "month",
query: { kw: "" },
items: [],
page: 1,
size: 20,
finished: false,
loading: false,
startDate: "",
endDate: ""
};
},
computed: {
placeholder() {
return "单据号/客户名称/品名规格/备注";
},
periodLabel() {
return this.startDate && this.endDate ? `${this.startDate}~${this.endDate}` : "";
},
totalAmount() {
return this.items.reduce((s, it) => s + Number(it.amount || 0), 0);
}
},
onLoad() {
const hasToken = (() => {
try {
return !!common_vendor.index.getStorageSync("TOKEN");
} catch (e) {
return false;
}
})();
if (!hasToken) {
this.items = [];
this.total = 0;
common_vendor.index.showToast({ title: "请登录使用该功能", icon: "none" });
return;
}
try {
common_vendor.index.__f__("log", "at pages/detail/index.vue:102", "[detail] onLoad route = pages/detail/index");
} catch (e) {
}
this.computeRange();
this.reload();
},
methods: {
switchBiz(k) {
if (this.biz === k)
return;
this.biz = k;
this.reload();
},
switchRange(r) {
this.range = r;
this.computeRange();
this.reload();
},
computeRange() {
const now = /* @__PURE__ */ new Date();
const pad = (n) => String(n).padStart(2, "0");
const fmt = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
let start = now, end = now;
if (this.range === "today") {
start = end = now;
} else if (this.range === "week") {
const day = now.getDay() || 7;
start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - day + 1);
end = now;
} else if (this.range === "month") {
start = new Date(now.getFullYear(), now.getMonth(), 1);
end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
} else if (this.range === "year") {
start = new Date(now.getFullYear(), 0, 1);
end = new Date(now.getFullYear(), 11, 31);
} else {
start = new Date(now.getFullYear(), now.getMonth(), 1);
end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
}
this.startDate = fmt(start);
this.endDate = fmt(end);
},
reload() {
this.items = [];
this.page = 1;
this.finished = false;
this.loadMore();
},
onStartChange(e) {
var _a;
this.startDate = ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.value) || this.startDate;
if (this.endDate && this.startDate > this.endDate)
this.endDate = this.startDate;
this.reload();
},
onEndChange(e) {
var _a;
this.endDate = ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.value) || this.endDate;
if (this.startDate && this.endDate < this.startDate)
this.startDate = this.endDate;
this.reload();
},
async loadMore() {
if (this.loading || this.finished)
return;
this.loading = true;
try {
const path = API_OF[this.biz] || "/api/orders";
const params = { kw: this.query.kw, page: this.page, size: this.size, startDate: this.startDate, endDate: this.endDate, biz: this.biz };
if (this.biz === "sale")
params.type = "out";
const res = await common_http.get(path, params);
const list = Array.isArray(res == null ? void 0 : res.list) ? res.list : Array.isArray(res) ? res : [];
this.items = this.items.concat(list);
if (list.length < this.size)
this.finished = true;
this.page += 1;
} catch (e) {
common_vendor.index.showToast({ title: "加载失败", icon: "none" });
} finally {
this.loading = false;
}
},
formatDate(s) {
if (!s)
return "";
try {
const d = new Date(s);
const pad = (n) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
} catch (_) {
return String(s).slice(0, 10);
}
},
onCreate() {
if (this.biz === "sale") {
common_vendor.index.switchTab({ url: "/pages/order/create" });
return;
}
common_vendor.index.showToast({ title: "该类型创建页待实现", icon: "none" });
},
openDetail(it) {
common_vendor.index.showToast({ title: "详情开发中", icon: "none" });
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.f($data.bizList, (b, k0, i0) => {
return {
a: common_vendor.t(b.name),
b: b.key,
c: common_vendor.n($data.biz === b.key && "active"),
d: common_vendor.o(($event) => $options.switchBiz(b.key), b.key)
};
}),
b: common_vendor.t($data.startDate),
c: $data.startDate,
d: common_vendor.o((...args) => $options.onStartChange && $options.onStartChange(...args)),
e: common_vendor.t($data.endDate),
f: $data.endDate,
g: common_vendor.o((...args) => $options.onEndChange && $options.onEndChange(...args)),
h: $options.placeholder,
i: common_vendor.o((...args) => $options.reload && $options.reload(...args)),
j: $data.query.kw,
k: common_vendor.o(common_vendor.m(($event) => $data.query.kw = $event.detail.value, {
trim: true
})),
l: common_vendor.o((...args) => $options.reload && $options.reload(...args)),
m: common_vendor.t($options.totalAmount.toFixed(2)),
n: $data.items.length
}, $data.items.length ? {
o: common_vendor.f($data.items, (it, k0, i0) => {
return {
a: common_vendor.t($options.formatDate(it.orderTime || it.txTime || it.createdAt)),
b: common_vendor.t(it.customerName || it.supplierName || it.accountName || it.remark || "-"),
c: common_vendor.t(it.orderNo || it.code || it.id),
d: common_vendor.t((it.amount || 0).toFixed(2)),
e: Number(it.amount || 0) >= 0 ? 1 : "",
f: Number(it.amount || 0) < 0 ? 1 : "",
g: it.id,
h: common_vendor.o(($event) => $options.openDetail(it), it.id)
};
})
} : {}, {
p: common_vendor.o((...args) => $options.loadMore && $options.loadMore(...args)),
q: common_vendor.o((...args) => $options.onCreate && $options.onCreate(...args))
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/detail/index.js.map