diff --git a/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode.vue b/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode.vue new file mode 100644 index 0000000..e5dfa19 --- /dev/null +++ b/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode.vue @@ -0,0 +1,108 @@ + + + diff --git a/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode/form.vue b/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode/form.vue deleted file mode 100644 index 12f2ddb..0000000 --- a/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode/form.vue +++ /dev/null @@ -1,90 +0,0 @@ - - - diff --git a/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode/index.vue b/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode/index.vue deleted file mode 100644 index 2e79906..0000000 --- a/src/views/supermarketerp/supermarketSpu/components/supermarketAuxiliaryCode/index.vue +++ /dev/null @@ -1,176 +0,0 @@ - - - diff --git a/src/views/supermarketerp/supermarketSpu/components/supermarketInventory.vue b/src/views/supermarketerp/supermarketSpu/components/supermarketInventory.vue new file mode 100644 index 0000000..753886c --- /dev/null +++ b/src/views/supermarketerp/supermarketSpu/components/supermarketInventory.vue @@ -0,0 +1,5 @@ + + + diff --git a/src/views/supermarketerp/supermarketSpu/components/supermarketUnit.vue b/src/views/supermarketerp/supermarketSpu/components/supermarketUnit.vue new file mode 100644 index 0000000..2f7297c --- /dev/null +++ b/src/views/supermarketerp/supermarketSpu/components/supermarketUnit.vue @@ -0,0 +1,191 @@ + + + diff --git a/src/views/supermarketerp/supermarketSpu/components/supermarketUnit/form.vue b/src/views/supermarketerp/supermarketSpu/components/supermarketUnit/form.vue deleted file mode 100644 index ed25a08..0000000 --- a/src/views/supermarketerp/supermarketSpu/components/supermarketUnit/form.vue +++ /dev/null @@ -1,161 +0,0 @@ - - - diff --git a/src/views/supermarketerp/supermarketSpu/components/supermarketUnit/index.vue b/src/views/supermarketerp/supermarketSpu/components/supermarketUnit/index.vue deleted file mode 100644 index 7327a90..0000000 --- a/src/views/supermarketerp/supermarketSpu/components/supermarketUnit/index.vue +++ /dev/null @@ -1,226 +0,0 @@ - - - diff --git a/src/views/supermarketerp/supermarketSpu/form.vue b/src/views/supermarketerp/supermarketSpu/form.vue index 1fa265f..f41fbde 100644 --- a/src/views/supermarketerp/supermarketSpu/form.vue +++ b/src/views/supermarketerp/supermarketSpu/form.vue @@ -1,6 +1,6 @@ @@ -170,21 +175,25 @@ import { useMessage } from "/@/hooks/message" import { getObj, addObj, putObj, getSupermarketCategory, getSupermarketBrand } from "/@/api/supermarketerp/supermarketSpu" import { getSupplierTypeOptions } from "/@/api/supermarketerp/smErpSupplier" import { rule } from "/@/utils/validate" -import supermarketAuxiliaryCode from "./components/supermarketAuxiliaryCode/index.vue" -import supermarketUnit from "./components/supermarketUnit/index.vue" +import SupermarketUnit from "./components/supermarketUnit.vue" +import supermarketInventory from "./components/supermarketInventory.vue" +import SupermarketAuxiliaryCode from "./components/supermarketAuxiliaryCode.vue" import { TabPaneName } from "element-plus" import { displayPrice, storePrice } from "/@/utils/formatMoney" const emit = defineEmits(["refresh"]) -const tabPaneEnum = ["基础信息", "包装单位", "辅助条码"] +const supermarketUnitEntityListRef = ref() +const supermarketInventoryRef = ref() +const supermarketAuxiliaryCodeEntityList = ref() +const tabPaneEnum = ["基础信息", "包装单位", "库存", "辅助条码"] const dataFormRef = ref() const visible = ref(false) const loading = ref(false) const currentTabPaneIndex = ref(0) const tabPaneActiveName = computed(() => tabPaneEnum[currentTabPaneIndex.value]) // 提交表单数据 -const form = reactive({ +const form = reactive({ id: "", merchantId: "", productCode: "", @@ -248,19 +257,6 @@ const { supermarket_nature, status } = useDict("supermarket_nature", "status") const categoryOptions = ref([]) // 商品分类的下拉选项 const brandOptions = ref([]) // 超市品牌的下拉选项 const supplierOptions = ref([]) // 货商的下拉选项 -// 默认包装单位 -// const defaultSpuUnit = computed(() => ({ -// flag: "default", -// barCode: form.barcode, -// unit: form.unit, -// packageNum: form.packageNum, -// retailPrice: form.retailPrice, -// purchasePrice: form.purchasePrice, -// promotionPrice: form.promotionPrice, -// costPrice: form.costPrice, -// spec: form.spec, -// status: "0", -// })) // 打开弹窗 const openDialog = async (id: string) => { @@ -295,69 +291,69 @@ const openDialog = async (id: string) => { const getsupermarketSpuData = async (id: string) => { // 获取数据 loading.value = true - const res = await getObj(id).finally(() => (loading.value = false)) - if (res.code === 0) { - res.data.smErpUnitEntityList.map((item: any) => { - // 格式化数据 - item.retailPrice = displayPrice(item.retailPrice, "") - item.promotionPrice = displayPrice(item.promotionPrice, "") - item.purchasePrice = displayPrice(item.purchasePrice, "") - item.costPrice = displayPrice(item.costPrice, "") - }) + try { + const res = await getObj(id).finally(() => (loading.value = false)) + if (res.code === 0) { + res.data.smErpUnitEntityList = res.data.smErpUnitEntityList.map((item: any) => { + // 格式化数据 + item.retailPrice = displayPrice(item.retailPrice, "") + item.promotionPrice = displayPrice(item.promotionPrice, "") + item.purchasePrice = displayPrice(item.purchasePrice, "") + item.costPrice = displayPrice(item.costPrice, "") + return item + }) - Object.assign(form, res.data) - console.log(res.data) + Object.assign(form, res.data) + console.log("获取的商品详情:", res.data) + } + } catch (error: any) { + loading.value = false + useMessage().error(error.msg) } } // tab栏切换 -const handleTabChange = (name: TabPaneName) => { - currentTabPaneIndex.value = tabPaneEnum.findIndex((item) => item === name) -} +const handleTabChange = (name: TabPaneName) => (currentTabPaneIndex.value = tabPaneEnum.findIndex((item) => item === name)) + +// 整理包装单位列表 +const handleUnit = computed(() => { + return form.smErpUnitEntityList.map((item: any) => { + item.costPrice = storePrice(item.costPrice) + item.promotionPrice = storePrice(item.promotionPrice) + item.purchasePrice = storePrice(item.purchasePrice) + item.retailPrice = storePrice(item.retailPrice) + if (item.isNew) { + item.id = "" + delete item.isNew + } + }) +}) + +// 整理辅助条码列表 +const handleAuxiliaryCode = computed(() => { + return form.smErpAuxiliaryCodeEntityList.map((item: any) => { + if (item.isNew) { + item.id = "" + delete item.isNew + } + }) +}) // 提交 const onSubmit = async () => { - console.log(form) + console.log("提交的数据", form) const valid = await dataFormRef.value.validate().catch(() => {}) - if (!valid) useMessage().warning("基础信息必填项未填写完整") - if (!form.smErpUnitEntityList || form.smErpUnitEntityList.length <= 0) useMessage().warning("请添加包装单位") - if (!form.smErpAuxiliaryCodeEntityList || form.smErpAuxiliaryCodeEntityList.length <= 0) useMessage().warning("请添加辅助条码") - if (!valid) return false + if (!valid) return useMessage().warning("基础信息必填项未填写完整") + if (!form.smErpUnitEntityList || form.smErpUnitEntityList.length <= 0) return useMessage().warning("请添加包装单位") + if (!form.smErpAuxiliaryCodeEntityList || form.smErpAuxiliaryCodeEntityList.length <= 0) return useMessage().warning("请添加辅助条码") + if (!(await supermarketUnitEntityListRef.value.editableTableValidate())) return useMessage().warning("包装单位必填项未填写完整") + if (!(await supermarketAuxiliaryCodeEntityList.value.editableTableValidate())) return useMessage().warning("辅助条码必填项未填写完整") try { loading.value = true - if (form.id) { - form.smErpUnitEntityList.map((item: any) => { - item.costPrice = storePrice(item.costPrice) - item.promotionPrice = storePrice(item.promotionPrice) - item.purchasePrice = storePrice(item.purchasePrice) - item.retailPrice = storePrice(item.retailPrice) - if (item.isNew) { - item.id = "" - delete item.isNew - } - }) - form.smErpAuxiliaryCodeEntityList.map((item: any) => { - if (item.isNew) { - item.id = "" - delete item.isNew - } - }) - await putObj(form) - } else { - form.smErpUnitEntityList.map((item: any) => { - item.id = "" - item.costPrice = storePrice(item.costPrice) - item.promotionPrice = storePrice(item.promotionPrice) - item.purchasePrice = storePrice(item.purchasePrice) - item.retailPrice = storePrice(item.retailPrice) - }) - form.smErpAuxiliaryCodeEntityList.map((item: any) => { - item.id = "" - }) - await addObj(form) - } + const _pa = { ...form, smErpUnitEntityList: handleUnit.value, smErpAuxiliaryCodeEntityList: handleAuxiliaryCode.value } + form.id ? await putObj(_pa) : await addObj(_pa) useMessage().success(form.id ? "修改成功" : "添加成功") visible.value = false emit("refresh") @@ -368,7 +364,6 @@ const onSubmit = async () => { } } -// 暴露变量 defineExpose({ openDialog, })