Jelajahi Sumber

2024.05.27 补充提交

zweiqin 1 tahun lalu
induk
melakukan
a8713e9590
1 mengubah file dengan 22 tambahan dan 17 penghapusan
  1. 22 17
      src/views/commodity/commodityList/components/EditModal.vue

+ 22 - 17
src/views/commodity/commodityList/components/EditModal.vue

@@ -25,7 +25,7 @@
               <el-button v-if="data.depth < 3" type="text" size="mini" @click="handleAppend(data)">
                 {{ { 1: '添加二级分组名称', 2: '添加三级分组名称' }[data.depth] }}
               </el-button>
-              <el-button type="text" size="mini" @click="handleDelete(data, node)">
+              <el-button v-if="data.depth > 1" type="text" size="mini" @click="handleDelete(data, node)">
                 删除
               </el-button>
             </div>
@@ -143,7 +143,6 @@ export default {
       visible: false,
       formData: {
         shopGroupId: '',
-        shopId: '',
         groupName: '',
         groupImage: '',
         groupDescribe: '',
@@ -187,7 +186,6 @@ export default {
       } else {
         this.formData = {
           shopGroupId: '',
-          shopId: '',
           groupName: '',
           groupImage: '',
           groupDescribe: '',
@@ -206,7 +204,6 @@ export default {
         const res = await commodityListGetById({ shopGroupId: id })
         this.formData = Object.assign(this.$options.data().formData, res.data, {
           shopGroupId: res.data.shopGroupId || '',
-          shopId: res.data.shopId || '',
           groupName: res.data.groupName || '',
           groupImage: res.data.groupImage || '',
           groupDescribe: res.data.groupDescribe || '',
@@ -228,30 +225,38 @@ export default {
       if (data.depth < 3) {
         data.childs.push({
           shopGroupId: '',
-          shopId: '',
           groupName: '',
           groupImage: '',
           groupDescribe: '',
           groupLevel: '',
           depth: data.depth + 1,
-          groupPid: 0,
+          groupPid: data.shopGroupId,
           childs: [],
-          ids: []
+          ids: [],
+          orderNumber: Date.now()
         })
       }
     },
     handleDelete(data, node) {
-      this.$confirm('选中数据将被永久删除, 是否继续?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      })
-        .then(async () => {
-          await commodityListDelete({ shopGroupId: data.shopGroupId })
-          this.$message({ message: '删除成功!', type: 'success' })
-          this.getInfo(this.formData.shopGroupId)
-          this.$emit('success')
+      if (data.shopGroupId) {
+        this.$confirm('选中数据将被永久删除, 是否继续?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
         })
+          .then(async () => {
+            await commodityListDelete({ shopGroupId: data.shopGroupId })
+            this.$message({ message: '删除成功!', type: 'success' })
+            this.getInfo(this.formData.shopGroupId)
+            this.$emit('success')
+          })
+      } else {
+        XeUtils.eachTree([ this.formData ], (item) => {
+          if (item.shopGroupId === data.groupPid) {
+            item.childs.splice(item.childs.findIndex((i) => i.orderNumber === data.orderNumber), 1)
+          }
+        }, { children: 'childs' })
+      }
     },
     handleAddProduct(data, node) {
       this.multipleSelection = []