163 lines
5.9 KiB
JavaScript
163 lines
5.9 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../../common/vendor.js");
|
|
const stores_price = require("../../../stores/price.js");
|
|
const utils_price = require("../../../utils/price.js");
|
|
if (!Array) {
|
|
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
|
_easycom_uni_icons2();
|
|
}
|
|
const _easycom_uni_icons = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-icons/uni-icons.js";
|
|
if (!Math) {
|
|
_easycom_uni_icons();
|
|
}
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
__name: "list",
|
|
setup(__props) {
|
|
const priceStore = stores_price.usePriceStore();
|
|
const searchKeyword = common_vendor.ref("");
|
|
const showAddModal = common_vendor.ref(false);
|
|
const editingItem = common_vendor.ref(null);
|
|
const originalCategory = common_vendor.ref("");
|
|
const formData = common_vendor.reactive({
|
|
category: "",
|
|
name: "",
|
|
price: "",
|
|
unit: "kg"
|
|
});
|
|
const filteredPrices = common_vendor.computed(() => {
|
|
let prices = priceStore.prices;
|
|
if (searchKeyword.value) {
|
|
const keyword = searchKeyword.value.toLowerCase();
|
|
prices = prices.filter(
|
|
(item) => item.name.toLowerCase().includes(keyword) || item.category.toLowerCase().includes(keyword)
|
|
);
|
|
}
|
|
return prices;
|
|
});
|
|
const editPrice = (item) => {
|
|
editingItem.value = item;
|
|
originalCategory.value = item.category;
|
|
formData.category = item.category;
|
|
formData.name = item.name;
|
|
formData.price = item.price.toString();
|
|
formData.unit = item.unit;
|
|
showAddModal.value = true;
|
|
};
|
|
const deletePrice = (category) => {
|
|
common_vendor.index.showModal({
|
|
title: "确认删除",
|
|
content: "确定要删除此品类吗?",
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
priceStore.deletePrice(category);
|
|
common_vendor.index.showToast({ title: "删除成功", icon: "success" });
|
|
}
|
|
}
|
|
});
|
|
};
|
|
const closeModal = () => {
|
|
showAddModal.value = false;
|
|
editingItem.value = null;
|
|
originalCategory.value = "";
|
|
formData.category = "";
|
|
formData.name = "";
|
|
formData.price = "";
|
|
formData.unit = "kg";
|
|
};
|
|
const savePrice = () => {
|
|
if (!formData.category) {
|
|
common_vendor.index.showToast({ title: "请输入品类代码", icon: "none" });
|
|
return;
|
|
}
|
|
if (!formData.name) {
|
|
common_vendor.index.showToast({ title: "请输入品类名称", icon: "none" });
|
|
return;
|
|
}
|
|
if (!formData.price || parseFloat(formData.price) <= 0) {
|
|
common_vendor.index.showToast({ title: "请输入有效单价", icon: "none" });
|
|
return;
|
|
}
|
|
if (editingItem.value) {
|
|
priceStore.updatePrice({
|
|
category: formData.category,
|
|
name: formData.name,
|
|
price: parseFloat(formData.price),
|
|
unit: formData.unit
|
|
});
|
|
common_vendor.index.showToast({ title: "修改成功", icon: "success" });
|
|
} else {
|
|
priceStore.addPrice({
|
|
category: formData.category,
|
|
name: formData.name,
|
|
price: parseFloat(formData.price),
|
|
unit: formData.unit
|
|
});
|
|
common_vendor.index.showToast({ title: "新增成功", icon: "success" });
|
|
}
|
|
closeModal();
|
|
};
|
|
const goToHome = () => {
|
|
common_vendor.index.redirectTo({ url: "/pages/admin/index" });
|
|
};
|
|
const goToOrderList = () => {
|
|
common_vendor.index.redirectTo({ url: "/pages/admin/order/list" });
|
|
};
|
|
const goToUserManager = () => {
|
|
common_vendor.index.redirectTo({ url: "/pages/admin/user/list" });
|
|
};
|
|
common_vendor.onMounted(() => {
|
|
priceStore.loadPrices();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: common_vendor.o(($event) => showAddModal.value = true),
|
|
b: searchKeyword.value,
|
|
c: common_vendor.o(($event) => searchKeyword.value = $event.detail.value),
|
|
d: common_vendor.f(filteredPrices.value, (item, k0, i0) => {
|
|
return {
|
|
a: "ce40c64c-0-" + i0,
|
|
b: common_vendor.p({
|
|
type: common_vendor.unref(utils_price.getCategoryIcon)(item.category),
|
|
size: 48,
|
|
color: "#3366ff"
|
|
}),
|
|
c: common_vendor.t(item.name),
|
|
d: common_vendor.t(item.category),
|
|
e: common_vendor.t(item.price),
|
|
f: common_vendor.t(item.unit === "kg" ? "kg" : "个"),
|
|
g: common_vendor.o(($event) => editPrice(item), item.category),
|
|
h: common_vendor.o(($event) => deletePrice(item.category), item.category),
|
|
i: item.category
|
|
};
|
|
}),
|
|
e: filteredPrices.value.length === 0
|
|
}, filteredPrices.value.length === 0 ? {} : {}, {
|
|
f: common_vendor.o(goToHome),
|
|
g: common_vendor.o(goToOrderList),
|
|
h: common_vendor.o(goToUserManager),
|
|
i: showAddModal.value
|
|
}, showAddModal.value ? {
|
|
j: common_vendor.t(editingItem.value ? "编辑品类" : "新增品类"),
|
|
k: common_vendor.o(closeModal),
|
|
l: formData.category,
|
|
m: common_vendor.o(($event) => formData.category = $event.detail.value),
|
|
n: formData.name,
|
|
o: common_vendor.o(($event) => formData.name = $event.detail.value),
|
|
p: formData.price,
|
|
q: common_vendor.o(($event) => formData.price = $event.detail.value),
|
|
r: formData.unit === "kg" ? 1 : "",
|
|
s: common_vendor.o(($event) => formData.unit = "kg"),
|
|
t: formData.unit === "piece" ? 1 : "",
|
|
v: common_vendor.o(($event) => formData.unit = "piece"),
|
|
w: common_vendor.o(closeModal),
|
|
x: common_vendor.o(savePrice),
|
|
y: common_vendor.o(() => {
|
|
}),
|
|
z: common_vendor.o(closeModal)
|
|
} : {});
|
|
};
|
|
}
|
|
});
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-ce40c64c"]]);
|
|
wx.createPage(MiniProgramPage);
|