diff --git a/src/views/supermarketerp/supermarketSpu/components/package-unit.vue b/src/views/supermarketerp/supermarketSpu/components/package-unit.vue
index 29479f6..eed0c61 100644
--- a/src/views/supermarketerp/supermarketSpu/components/package-unit.vue
+++ b/src/views/supermarketerp/supermarketSpu/components/package-unit.vue
@@ -144,6 +144,7 @@ export interface rowVU {
isBase?: boolean | null
flag?: string
taste?: string
+ tasteId: string
}
export interface TasteItem {
id: string
@@ -218,6 +219,7 @@ const pushEvent = (row?: rowVU | undefined) => {
promotionPrice: 0,
costPrice: 0,
taste: "",
+ tasteId: "",
}
Object.assign(newRow, row)
}
diff --git a/src/views/supermarketerp/supermarketSpu/components/taste-form.vue b/src/views/supermarketerp/supermarketSpu/components/taste-form.vue
index 26e66dd..7d8add1 100644
--- a/src/views/supermarketerp/supermarketSpu/components/taste-form.vue
+++ b/src/views/supermarketerp/supermarketSpu/components/taste-form.vue
@@ -13,7 +13,7 @@
:column-config="{ resizable: true }"
:row-config="{ isHover: true }"
:resizable-config="{ dragMode: 'fixed' }"
- :data="tasteList || []"
+ :data="tableTasteList"
:edit-config="{
trigger: 'click',
mode: 'cell',
@@ -30,8 +30,8 @@
>
-
-
+
+
@@ -50,6 +50,7 @@
取消
+ 确认
@@ -64,15 +65,36 @@ type Row = {
}
const tasteList = defineModel("modelValue", { default: [] })
-
+const tableTasteList = ref([])
const tableRef = ref()
const visible = ref(false)
const validRules = {
- tasteName: [{ required: true, message: "口味单位不能为空", trigger: "blur" }],
+ tasteName: [
+ { required: true, message: "口味单位不能为空", trigger: "blur" },
+ {
+ validator({ cellValue, row, rowIndex }: any) {
+ if (
+ cellValue &&
+ tableTasteList.value
+ .filter((item: Row, index: number) => rowIndex != index && item.tasteName == row.tasteName)
+ .some((v: Row) => v.tasteName == row.tasteName)
+ )
+ return new Error("该口味已存在")
+ },
+ },
+ ],
stock: [{ required: true, message: "库存不能为空", trigger: "blur" }],
}
+// 自定义编辑模板的input校验
+const slotInputChange = (slotParams: any) => {
+ const $table = tableRef.value
+ if ($table) {
+ $table.updateStatus(slotParams)
+ }
+}
+
// 底部新增行
const pushEvent = () => {
const newRow: Row = {
@@ -80,7 +102,7 @@ const pushEvent = () => {
tasteName: "",
stock: 0,
}
- tasteList.value.push(newRow)
+ tableTasteList.value.push(newRow)
nextTick(() => {
const $table = tableRef.value
if ($table) {
@@ -91,11 +113,28 @@ const pushEvent = () => {
// 删除行
const removeRow = (rowIndex: number) => {
- tasteList.value.splice(rowIndex, 1)
+ tableTasteList.value.splice(rowIndex, 1)
}
-const openDialog = (id: string) => {
+const openDialog = () => {
visible.value = true
+ tableTasteList.value = tasteList.value ? [...tasteList.value] : []
+}
+
+// 提交
+const onConfirm = async () => {
+ const $table = tableRef.value
+ if ($table) {
+ const errMap = await $table.validate(true)
+ if (errMap) {
+ console.log("全量校验失败!", errMap)
+ return
+ } else {
+ console.log("全量校验成功!")
+ visible.value = false
+ tasteList.value = [...tableTasteList.value]
+ }
+ }
}
defineExpose({
diff --git a/src/views/supermarketerp/supermarketSpu/components/taste-stock.vue b/src/views/supermarketerp/supermarketSpu/components/taste-stock.vue
deleted file mode 100644
index 8b5a7ba..0000000
--- a/src/views/supermarketerp/supermarketSpu/components/taste-stock.vue
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
- 新增
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 删除
-
-
-
-
-
-
-
diff --git a/src/views/supermarketerp/supermarketSpu/form.vue b/src/views/supermarketerp/supermarketSpu/form.vue
index 2e0d703..03abb2d 100644
--- a/src/views/supermarketerp/supermarketSpu/form.vue
+++ b/src/views/supermarketerp/supermarketSpu/form.vue
@@ -248,6 +248,7 @@ const settlePackageUnitList = () => {
item.isBase = false
}
if (item.id.startsWith("tmp_")) item.id = ""
+ if (item.tasteId.startsWith("tmp_")) item.tasteId = ""
// 转换金额单位
item.costPrice = storePrice(item.costPrice)
item.promotionPrice = storePrice(item.promotionPrice)