This commit is contained in:
2025-09-20 12:05:53 +08:00
parent bff3d0414d
commit 9b107d665a
73 changed files with 2903 additions and 140 deletions

View File

@@ -28,6 +28,7 @@ const _sfc_main = {
supplierName: "",
items: [],
activeCategory: "sale_income",
counterpartyType: "customer",
trxAmount: 0,
selectedAccountId: null,
selectedAccountName: "",
@@ -50,16 +51,16 @@ const _sfc_main = {
return this.supplierName || "零散供应商";
},
incomeCategories() {
return common_constants.INCOME_CATEGORIES;
return this._incomeCategories || common_constants.INCOME_CATEGORIES;
},
expenseCategories() {
return common_constants.EXPENSE_CATEGORIES;
return this._expenseCategories || common_constants.EXPENSE_CATEGORIES;
},
accountLabel() {
return this.selectedAccountName || "现金";
},
counterpartyLabel() {
return this.customerName || this.supplierName || "—";
return this.counterpartyType === "customer" ? this.customerName || "—" : this.supplierName || "—";
},
// 收款/付款合计
payTotal() {
@@ -67,6 +68,9 @@ const _sfc_main = {
return Number(p.cash || 0) + Number(p.bank || 0) + Number(p.wechat || 0);
}
},
onLoad() {
this.fetchCategories();
},
onShow() {
if (this.biz === "sale") {
if (this.order.customerId && this.order.customerId !== this._lastCustomerId) {
@@ -85,6 +89,26 @@ const _sfc_main = {
}
},
methods: {
async fetchCategories() {
try {
const res = await common_http.get("/api/finance/categories");
if (res && Array.isArray(res.incomeCategories))
this._incomeCategories = res.incomeCategories;
if (res && Array.isArray(res.expenseCategories))
this._expenseCategories = res.expenseCategories;
this.ensureActiveCategory();
} catch (_) {
this.ensureActiveCategory();
}
},
ensureActiveCategory() {
const list = this.biz === "income" ? this.incomeCategories || [] : this.expenseCategories || [];
if (!list.length)
return;
const exists = list.some((it) => it && it.key === this.activeCategory);
if (!exists)
this.activeCategory = list[0].key;
},
async loadCustomerLevel(customerId) {
try {
const d = await common_http.get(`/api/customers/${customerId}`);
@@ -133,6 +157,7 @@ const _sfc_main = {
},
switchBiz(type) {
this.biz = type;
this.ensureActiveCategory();
},
onDateChange(e) {
this.order.orderTime = e.detail.value;
@@ -147,13 +172,21 @@ const _sfc_main = {
common_vendor.index.navigateTo({ url: "/pages/product/select" });
},
chooseAccount() {
common_vendor.index.navigateTo({ url: "/pages/account/select" });
common_vendor.index.navigateTo({ url: "/pages/account/select?mode=pick" });
},
chooseCounterparty() {
if (this.biz === "income" || this.biz === "expense") {
if (!(this.biz === "income" || this.biz === "expense"))
return;
if (this.counterpartyType === "customer") {
common_vendor.index.navigateTo({ url: "/pages/customer/select" });
} else {
common_vendor.index.navigateTo({ url: "/pages/supplier/select" });
}
},
setCounterparty(t) {
this.counterpartyType = t;
this.ensureActiveCategory();
},
recalc() {
this.$forceUpdate();
},
@@ -189,7 +222,8 @@ const _sfc_main = {
} : {
type: this.biz,
category: this.activeCategory,
counterpartyId: this.order.customerId || null,
counterpartyType: this.counterpartyType,
counterpartyId: this.counterpartyType === "customer" ? this.order.customerId || null : this.order.supplierId || null,
accountId: this.selectedAccountId || null,
amount: Number(this.trxAmount || 0),
txTime: this.order.orderTime,
@@ -288,7 +322,11 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
ac: common_vendor.t($options.totalAmount.toFixed(2)),
ad: common_vendor.o((...args) => $options.chooseProduct && $options.chooseProduct(...args))
} : {
ae: common_vendor.f($data.biz === "income" ? $options.incomeCategories : $options.expenseCategories, (c, k0, i0) => {
ae: $data.counterpartyType === "customer" ? 1 : "",
af: common_vendor.o(($event) => $options.setCounterparty("customer")),
ag: $data.counterpartyType === "supplier" ? 1 : "",
ah: common_vendor.o(($event) => $options.setCounterparty("supplier")),
ai: common_vendor.f($data.biz === "income" ? $options.incomeCategories : $options.expenseCategories, (c, k0, i0) => {
return {
a: common_vendor.t(c.label),
b: c.key,
@@ -296,23 +334,23 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
d: common_vendor.o(($event) => $data.activeCategory = c.key, c.key)
};
}),
af: common_vendor.t($options.counterpartyLabel),
ag: common_vendor.o((...args) => $options.chooseCounterparty && $options.chooseCounterparty(...args)),
ah: common_vendor.t($options.accountLabel),
ai: common_vendor.o((...args) => $options.chooseAccount && $options.chooseAccount(...args)),
aj: $data.trxAmount,
ak: common_vendor.o(common_vendor.m(($event) => $data.trxAmount = $event.detail.value, {
aj: common_vendor.t($options.counterpartyLabel),
ak: common_vendor.o((...args) => $options.chooseCounterparty && $options.chooseCounterparty(...args)),
al: common_vendor.t($options.accountLabel),
am: common_vendor.o((...args) => $options.chooseAccount && $options.chooseAccount(...args)),
an: $data.trxAmount,
ao: common_vendor.o(common_vendor.m(($event) => $data.trxAmount = $event.detail.value, {
number: true
})),
al: $data.order.remark,
am: common_vendor.o(($event) => $data.order.remark = $event.detail.value)
ap: $data.order.remark,
aq: common_vendor.o(($event) => $data.order.remark = $event.detail.value)
}, {
aa: $data.biz === "sale" || $data.biz === "purchase",
an: !$data.items.length
ar: !$data.items.length
}, !$data.items.length ? {
ao: common_assets._imports_0$1
as: common_assets._imports_0$1
} : {
ap: common_vendor.f($data.items, (it, idx, i0) => {
at: common_vendor.f($data.items, (it, idx, i0) => {
return {
a: common_vendor.t(it.productName),
b: common_vendor.o([common_vendor.m(($event) => it.quantity = $event.detail.value, {
@@ -328,8 +366,8 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
};
})
}, {
aq: common_vendor.o((...args) => $options.saveAndReset && $options.saveAndReset(...args)),
ar: common_vendor.o((...args) => $options.submit && $options.submit(...args))
av: common_vendor.o((...args) => $options.saveAndReset && $options.saveAndReset(...args)),
aw: common_vendor.o((...args) => $options.submit && $options.submit(...args))
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);