9.16/1
This commit is contained in:
212
frontend/unpackage/dist/dev/mp-weixin/pages/order/create.js
vendored
Normal file
212
frontend/unpackage/dist/dev/mp-weixin/pages/order/create.js
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
"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_assets = require("../../common/assets.js");
|
||||
function todayString() {
|
||||
const d = /* @__PURE__ */ new Date();
|
||||
const m = (d.getMonth() + 1).toString().padStart(2, "0");
|
||||
const day = d.getDate().toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${m}-${day}`;
|
||||
}
|
||||
const _sfc_main = {
|
||||
data() {
|
||||
return {
|
||||
biz: "sale",
|
||||
saleType: "out",
|
||||
purchaseType: "in",
|
||||
order: {
|
||||
orderTime: todayString(),
|
||||
customerId: null,
|
||||
supplierId: null,
|
||||
remark: ""
|
||||
},
|
||||
customerName: "",
|
||||
supplierName: "",
|
||||
items: [],
|
||||
activeCategory: "sale_income",
|
||||
trxAmount: 0,
|
||||
selectedAccountId: null,
|
||||
selectedAccountName: ""
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
totalQuantity() {
|
||||
return this.items.reduce((s, it) => s + Number(it.quantity || 0), 0);
|
||||
},
|
||||
totalAmount() {
|
||||
return this.items.reduce((s, it) => s + Number(it.quantity || 0) * Number(it.unitPrice || 0), 0);
|
||||
},
|
||||
customerLabel() {
|
||||
return this.customerName || "零售客户";
|
||||
},
|
||||
supplierLabel() {
|
||||
return this.supplierName || "零散供应商";
|
||||
},
|
||||
incomeCategories() {
|
||||
return common_constants.INCOME_CATEGORIES;
|
||||
},
|
||||
expenseCategories() {
|
||||
return common_constants.EXPENSE_CATEGORIES;
|
||||
},
|
||||
accountLabel() {
|
||||
return this.selectedAccountName || "现金";
|
||||
},
|
||||
counterpartyLabel() {
|
||||
return this.customerName || this.supplierName || "—";
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
switchBiz(type) {
|
||||
this.biz = type;
|
||||
},
|
||||
onDateChange(e) {
|
||||
this.order.orderTime = e.detail.value;
|
||||
},
|
||||
chooseCustomer() {
|
||||
common_vendor.index.navigateTo({ url: "/pages/customer/select" });
|
||||
},
|
||||
chooseSupplier() {
|
||||
common_vendor.index.navigateTo({ url: "/pages/supplier/select" });
|
||||
},
|
||||
chooseProduct() {
|
||||
common_vendor.index.navigateTo({ url: "/pages/product/select" });
|
||||
},
|
||||
chooseAccount() {
|
||||
common_vendor.index.navigateTo({ url: "/pages/account/select" });
|
||||
},
|
||||
chooseCounterparty() {
|
||||
if (this.biz === "income" || this.biz === "expense") {
|
||||
common_vendor.index.navigateTo({ url: "/pages/customer/select" });
|
||||
}
|
||||
},
|
||||
recalc() {
|
||||
this.$forceUpdate();
|
||||
},
|
||||
async submit() {
|
||||
const isSaleOrPurchase = this.biz === "sale" || this.biz === "purchase";
|
||||
const payload = isSaleOrPurchase ? {
|
||||
type: this.biz === "sale" ? this.saleType : "purchase." + this.purchaseType,
|
||||
orderTime: this.order.orderTime,
|
||||
customerId: this.order.customerId,
|
||||
supplierId: this.order.supplierId,
|
||||
items: this.items.map((it) => ({ productId: it.productId, quantity: Number(it.quantity || 0), unitPrice: Number(it.unitPrice || 0) })),
|
||||
amount: this.totalAmount
|
||||
} : {
|
||||
type: this.biz,
|
||||
category: this.activeCategory,
|
||||
counterpartyId: this.order.customerId || null,
|
||||
accountId: this.selectedAccountId || null,
|
||||
amount: Number(this.trxAmount || 0),
|
||||
txTime: this.order.orderTime,
|
||||
remark: this.order.remark
|
||||
};
|
||||
try {
|
||||
const url = isSaleOrPurchase ? "/api/orders" : "/api/other-transactions";
|
||||
await common_http.post(url, payload);
|
||||
common_vendor.index.showToast({ title: "已保存", icon: "success" });
|
||||
setTimeout(() => {
|
||||
common_vendor.index.navigateBack();
|
||||
}, 600);
|
||||
} catch (e) {
|
||||
common_vendor.index.showToast({ title: e && e.message || "保存失败", icon: "none" });
|
||||
}
|
||||
},
|
||||
saveAndReset() {
|
||||
this.items = [];
|
||||
this.trxAmount = 0;
|
||||
this.order.remark = "";
|
||||
}
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return common_vendor.e({
|
||||
a: $data.biz === "sale" ? 1 : "",
|
||||
b: common_vendor.o(($event) => $options.switchBiz("sale")),
|
||||
c: $data.biz === "purchase" ? 1 : "",
|
||||
d: common_vendor.o(($event) => $options.switchBiz("purchase")),
|
||||
e: $data.biz === "income" ? 1 : "",
|
||||
f: common_vendor.o(($event) => $options.switchBiz("income")),
|
||||
g: $data.biz === "expense" ? 1 : "",
|
||||
h: common_vendor.o(($event) => $options.switchBiz("expense")),
|
||||
i: $data.biz === "sale"
|
||||
}, $data.biz === "sale" ? {
|
||||
j: $data.saleType === "out" ? 1 : "",
|
||||
k: common_vendor.o(($event) => $data.saleType = "out"),
|
||||
l: $data.saleType === "return" ? 1 : "",
|
||||
m: common_vendor.o(($event) => $data.saleType = "return"),
|
||||
n: $data.saleType === "collect" ? 1 : "",
|
||||
o: common_vendor.o(($event) => $data.saleType = "collect")
|
||||
} : $data.biz === "purchase" ? {
|
||||
q: $data.purchaseType === "in" ? 1 : "",
|
||||
r: common_vendor.o(($event) => $data.purchaseType = "in"),
|
||||
s: $data.purchaseType === "return" ? 1 : "",
|
||||
t: common_vendor.o(($event) => $data.purchaseType = "return"),
|
||||
v: $data.purchaseType === "pay" ? 1 : "",
|
||||
w: common_vendor.o(($event) => $data.purchaseType = "pay")
|
||||
} : {}, {
|
||||
p: $data.biz === "purchase",
|
||||
x: common_vendor.t($data.order.orderTime),
|
||||
y: $data.order.orderTime,
|
||||
z: common_vendor.o((...args) => $options.onDateChange && $options.onDateChange(...args)),
|
||||
A: $data.biz === "sale"
|
||||
}, $data.biz === "sale" ? {
|
||||
B: common_vendor.t($options.customerLabel),
|
||||
C: common_vendor.o((...args) => $options.chooseCustomer && $options.chooseCustomer(...args))
|
||||
} : $data.biz === "purchase" ? {
|
||||
E: common_vendor.t($options.supplierLabel),
|
||||
F: common_vendor.o((...args) => $options.chooseSupplier && $options.chooseSupplier(...args))
|
||||
} : {}, {
|
||||
D: $data.biz === "purchase",
|
||||
G: $data.biz === "sale" || $data.biz === "purchase"
|
||||
}, $data.biz === "sale" || $data.biz === "purchase" ? {
|
||||
H: common_vendor.t($options.totalQuantity),
|
||||
I: common_vendor.t($options.totalAmount.toFixed(2)),
|
||||
J: common_vendor.o((...args) => $options.chooseProduct && $options.chooseProduct(...args))
|
||||
} : {
|
||||
K: common_vendor.f($data.biz === "income" ? $options.incomeCategories : $options.expenseCategories, (c, k0, i0) => {
|
||||
return {
|
||||
a: common_vendor.t(c.label),
|
||||
b: c.key,
|
||||
c: $data.activeCategory === c.key ? 1 : "",
|
||||
d: common_vendor.o(($event) => $data.activeCategory = c.key, c.key)
|
||||
};
|
||||
}),
|
||||
L: common_vendor.t($options.counterpartyLabel),
|
||||
M: common_vendor.o((...args) => $options.chooseCounterparty && $options.chooseCounterparty(...args)),
|
||||
N: common_vendor.t($options.accountLabel),
|
||||
O: common_vendor.o((...args) => $options.chooseAccount && $options.chooseAccount(...args)),
|
||||
P: $data.trxAmount,
|
||||
Q: common_vendor.o(common_vendor.m(($event) => $data.trxAmount = $event.detail.value, {
|
||||
number: true
|
||||
})),
|
||||
R: $data.order.remark,
|
||||
S: common_vendor.o(($event) => $data.order.remark = $event.detail.value)
|
||||
}, {
|
||||
T: !$data.items.length
|
||||
}, !$data.items.length ? {
|
||||
U: common_assets._imports_0$1
|
||||
} : {
|
||||
V: 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, {
|
||||
number: true
|
||||
}), ($event) => $options.recalc()], idx),
|
||||
c: it.quantity,
|
||||
d: common_vendor.o([common_vendor.m(($event) => it.unitPrice = $event.detail.value, {
|
||||
number: true
|
||||
}), ($event) => $options.recalc()], idx),
|
||||
e: it.unitPrice,
|
||||
f: common_vendor.t((Number(it.quantity) * Number(it.unitPrice)).toFixed(2)),
|
||||
g: idx
|
||||
};
|
||||
})
|
||||
}, {
|
||||
W: common_vendor.o((...args) => $options.saveAndReset && $options.saveAndReset(...args)),
|
||||
X: common_vendor.o((...args) => $options.submit && $options.submit(...args))
|
||||
});
|
||||
}
|
||||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
wx.createPage(MiniProgramPage);
|
||||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/create.js.map
|
||||
Reference in New Issue
Block a user