Browse Source

商品增加复制功能

wzy 7 months ago
parent
commit
758103c928

+ 38 - 0
src/api/commodity.js

@@ -248,4 +248,42 @@ export function addProductFixed(data) {
     method: 'post',
     data
   })
+}
+
+
+// 商品分类
+// export function getClassify(data) {
+//   return request({
+//     url: '/product/getClassify',
+//     method: 'post',
+//     data
+//   })
+// }
+
+export function getClassifyList(data) {
+  return request({
+    url: '/classify/getAll',
+    method: 'post',
+    data
+  })
+}
+
+
+// 编辑商品类别
+export function commdityClassgetById(data) {
+  return request({
+    url: '/classify/getById',
+    method: 'post',
+    data
+  })
+}
+
+
+// 复制商品
+export function copyGoods(params) {
+  return request({
+    url: '/canvas/copyProduct',
+    method: 'get',
+    params
+  })
 }

+ 1 - 0
src/permission.js

@@ -57,6 +57,7 @@ router.beforeEach(async (to, from, next) => {
         try {
           next()
         } catch (error) {
+          console.log(error);
           // remove token and go to login page to re-login
           await store.dispatch('user/resetToken')
           Message.error(error || 'Has Error')

+ 4 - 1
src/views/business/businessList/index.vue

@@ -44,7 +44,10 @@
         v-loading="listLoading" height="100%" element-loading-text="正在查询中。。。" :data="list"
         v-bind="{ stripe: true, size: 'small', border: true, fit: true, highlightCurrentRow: true }"
       >
-        <el-table-column label="店铺名称" width="220">
+        <el-table-column label="店铺ID" align="center">
+          <template slot-scope="scope">{{ scope.row.shopId }}</template>
+        </el-table-column>
+        <el-table-column label="店铺名称" width="200" align="center">
           <template slot-scope="scope">{{ scope.row.shopName }}</template>
         </el-table-column>
         <el-table-column prop="shopCode" label="店铺编码" />

+ 1 - 1
src/views/dashboard/components/Counter.vue

@@ -58,7 +58,7 @@ export default {
         // vue-countup-v2什么傻逼组件
         this.$nextTick(() => {
           if (this.$refs.countUpRef) {
-            this.$refs.countUpRef.instance.options.suffix = this.countUpOptions.suffix
+            this.$refs.countUpRef.instance.options.suffix = this.countUpOptions.suffix || ''
             this.$refs.countUpRef.instance.options.decimalPlaces = this.countUpOptions.decimalPlaces
           }
         })

+ 97 - 14
src/views/renovation/commoditySystem/components/AddSelection.vue

@@ -23,16 +23,18 @@
           v-model="formData.productIdproductId" maxlength="20" placeholder="请输入商家id"
         />
       </el-form-item>
-      <!-- <el-form-item label="平台分类" prop="classifyId">
-        <el-select v-model="formData.classifyId" placeholder="请选择平台分类">
+      
+      <el-form-item label="平台分类" prop="classifyId" v-if="isCopy">
+        <el-cascader v-model="classifyId" placeholder="请选择官方分类" clearable :props="props" />
+        <!-- <el-select v-model="formData.classifyId" placeholder="请选择平台分类">
         <el-option
         v-for="item in classOptions" :key="item.classifyId" :label="item.classifyName"
         :value="item.classifyId"
         >
         </el-option>
-        </el-select>
-        </el-form-item> -->
-      <el-form-item label="商家分组" prop="shopGroupId">
+        </el-select> -->
+        </el-form-item>
+      <el-form-item label="商家分组" prop="shopGroupId" v-if="!isCopy">
         <el-cascader
           v-model="formData.shopGroupArr" placeholder="请选择商家分组" :options="shopGroupList"
           :props="{ checkStrictly: true, expandTrigger: 'hover', label: 'groupName', value: 'shopGroupId', children: 'childs' }"
@@ -44,7 +46,7 @@
           </el-option>
           </el-select> -->
       </el-form-item>
-      <el-form-item label="是否加入选品" prop="shelveState">
+      <el-form-item label="是否加入选品" prop="shelveState" v-if="!isCopy">
         <el-radio-group v-model="formData.shelveState">
           <el-radio :label="1">是</el-radio>
           <el-radio :label="0">不是</el-radio>
@@ -53,18 +55,34 @@
     </el-form>
     <template #footer>
       <span class="dialog-footer">
-        <el-button size="mini" @click="handleClose">取 消</el-button>
-        <el-button type="primary" size="mini" @click="handleSubmit">确 定</el-button>
+        <!-- 是复制还是加入选品 -->
+        <template v-if="!isCopy">
+          <el-button size="mini" @click="handleClose">取 消</el-button>
+          <el-button type="primary" size="mini" @click="handleSubmit">确 定</el-button>
+        </template>
+        <template v-else>
+          <el-button size="mini" @click="handleClose(1)">取 消</el-button>
+          <el-button type="primary" size="mini" @click="handleCopy">复 制</el-button>
+        </template>
+        
       </span>
     </template>
   </el-dialog>
 </template>
 
 <script>
-import { commdityClassGetAll, commdityClassGetGroup, getProductById, addProductFixed } from '@/api/commodity'
+import { commdityClassGetAll, commdityClassGetGroup, getProductById, addProductFixed,commdityClassgetById, getClassifyList,copyGoods } from '@/api/commodity'
 
+let arrList = [];
 export default {
   name: 'AddSelection',
+  props:{
+    // 控制是否是复制商品
+    isCopy:{
+      type: Boolean,
+      default: false
+    }
+  },
   components: {
   },
   data() {
@@ -81,7 +99,7 @@ export default {
         shopParentId: '',
         shopGroupId: '',
         shopGroupArr: [], // 非后端参数
-        shelveState: ''
+        shelveState: '',
       },
       formRules: {
         productId: [
@@ -95,10 +113,52 @@ export default {
         ],
         shelveState: [
           { required: true, message: '请选择是否加入选品' }
+        ],
+        classifyId:[
+          { required: true, message: '请选择商品分类' }
         ]
       },
-      classOptions: [],
-      shopGroupList: []
+      // classOptions: [],
+      shopGroupList: [],
+      //  异步加载
+      props: {
+                lazy: true,
+                checkStrictly: true,
+                label: 'classifyName',
+                value: 'classifyId',
+                lazyLoad(node, resolve) {
+                    const { level, value } = node;
+                    if (level === 0) {
+                        getClassifyList({ page: 1, pageSize: 15 }).then(res => {
+                            resolve(res.data.list)
+                        })
+                    } else if (level === 1) {
+                        commdityClassgetById({ oneClassifyId: value }).then(res => {
+                            // 将里面所有的childs.categoryName 换为classifyName
+                            let arr = res.data.childs.map(item => {
+                                item.classifyName = item.categoryName
+                                item.classifyId = item.id
+                                return item
+                            })
+                            arrList = arr
+                            resolve(arr)
+                        })
+                    } else {
+                        //  过滤出对应id
+                        let arrItem = arrList.filter(item => {
+                            return item.classifyId == value
+                        })
+                        if (arrItem.length <= 0) return
+                        let arr = arrItem[0].childs.map(item => {
+                            item.classifyName = item.categoryName
+                            item.classifyId = item.id
+                            return item
+                        })
+                        resolve(arr)
+                    }
+                }
+            },
+            classifyId:""
     }
   },
   created() {
@@ -106,8 +166,11 @@ export default {
     this.getGroupSelect()
   },
   methods: {
-    handleClose() {
+    handleClose(val) {
       this.visible = false
+      if(val == 1){
+        this.$emit("changeIsCopy")
+      }
     },
     //  获取商品类别
     async getAllClass() {
@@ -122,7 +185,7 @@ export default {
     initList() {
     },
     handleOpen(params = {}) {
-      this.modalOptions.title = '加入选品'
+      this.modalOptions.title = this.isCopy?'复制商品':'加入选品'
       this.formData.productId = params.productId
       this.formData.shopGroupArr = []
       // this.formData = Object.assign(this.$options.data().formData, params)
@@ -174,6 +237,26 @@ export default {
           return false
         }
       })
+    },
+    //  复制商品
+    async handleCopy(){
+      let { productIdproductId, productId, shopGroupArr } = this.formData
+      let obj = Object.assign({},{
+        shopId:productIdproductId,
+        productId:productId,
+        shopGroupArr:0,
+        classifyId:this.classifyId[this.classifyId.length - 1]
+      })
+      let res = await copyGoods(obj)
+      if(res.code == 200 || res.code == ''){
+        this.$message({
+          message: '复制成功',
+          type: 'success'
+        })
+        this.visible = false
+        this.classifyId = ""
+        this.$emit("changeIsCopy")
+      }
     }
   }
 }

+ 12 - 2
src/views/renovation/commoditySystem/index.vue

@@ -102,6 +102,9 @@
             >
               加入选品
             </el-button>
+            <el-button type="text" @click="copyShelf(row)">
+              复制商品
+            </el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -121,7 +124,7 @@
     <!-- 设置虚拟销量 -->
     <VirtualSales ref="VirtualSales" @success="getList" />
     <!-- 加入选品 -->
-    <AddSelection ref="AddSelection" @success="getList" />
+    <AddSelection ref="AddSelection" @success="getList" :isCopy="isCopy" @changeIsCopy="isCopy=false" />
     <!-- 查看详情 -->
     <DetailModal ref="DetailModal" />
   </div>
@@ -158,7 +161,9 @@ export default {
         shopName: '', // 商户名称
         page: 1, // 当前页
         pageSize: 20
-      }
+      },
+      //   控制是否是复制商品
+      isCopy:false,
     }
   },
   created() {
@@ -195,6 +200,11 @@ export default {
         })
         .catch(() => { })
     },
+    //  复制商品
+    copyShelf(row){
+      this.$refs.AddSelection && this.$refs.AddSelection.handleOpen(row)
+      this.isCopy = true
+    },
     // 导出商品
     async handleProductDataExport() {
       this.$message({