yuhaitao14 7 years ago
parent
commit
1f82bd0e4c

+ 11 - 0
shop/src/main/java/com/zskk/shop/controller/admin/GoodsManagerController.java

@@ -149,6 +149,17 @@ public class GoodsManagerController extends AbstractController{
 		return new ControllerResult(sysLabelService.getGoodLabels(gid));
 		return new ControllerResult(sysLabelService.getGoodLabels(gid));
 	}
 	}
 	
 	
+	@RequestMapping("setGoodLabels")
+	@ResponseBody
+	public ControllerResult setGoodLabels(@RequestParam("gid") Integer gid, @RequestParam("lids") String lids){
+		GoodBase base = goodService.queryOneGoodBase(gid);
+		if (base == null){
+			throw new ZSKKException(ErrorConstant.PARAM_ERROR);
+		}
+		sysLabelService.saveGoodLabels(base, JSON.parseArray(lids, Integer.class));
+		return new ControllerResult(Boolean.TRUE);
+	}
+	
 	@RequestMapping("getPackages")
 	@RequestMapping("getPackages")
 	@ResponseBody
 	@ResponseBody
 	public ControllerResult getPackages(@RequestParam("search") String search){
 	public ControllerResult getPackages(@RequestParam("search") String search){

+ 2 - 0
shop/src/main/java/com/zskk/shop/dao/SysLabelMapper.java

@@ -32,4 +32,6 @@ public interface SysLabelMapper {
 	public void addLabelGood(GoodLabel bean);
 	public void addLabelGood(GoodLabel bean);
 	
 	
 	public void delLabelGoods(Integer lid);
 	public void delLabelGoods(Integer lid);
+	
+	public void delGoodLabels(Integer gid);
 }
 }

+ 17 - 0
shop/src/main/java/com/zskk/shop/service/SysLabelService.java

@@ -10,12 +10,16 @@ package com.zskk.shop.service;
 
 
 import java.util.List;
 import java.util.List;
 
 
+import org.codehaus.groovy.transform.trait.Traits.TraitBridge;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 
 import com.zskk.shop.dao.SysLabelMapper;
 import com.zskk.shop.dao.SysLabelMapper;
+import com.zskk.shop.dao.entry.GoodBase;
 import com.zskk.shop.dao.entry.GoodLabel;
 import com.zskk.shop.dao.entry.GoodLabel;
 import com.zskk.shop.dao.entry.SysLabel;
 import com.zskk.shop.dao.entry.SysLabel;
+import com.zskk.shop.utils.ToolsUtil;
 
 
 @Service
 @Service
 public class SysLabelService {
 public class SysLabelService {
@@ -76,4 +80,17 @@ public class SysLabelService {
 		label.setStatus(status);
 		label.setStatus(status);
 		return sysLabelMapper.updateLabel(label);
 		return sysLabelMapper.updateLabel(label);
 	}
 	}
+	
+	@Transactional
+	public void saveGoodLabels(GoodBase base, List<Integer> lids){
+		sysLabelMapper.delGoodLabels(base.getGid());
+		Integer now = ToolsUtil.getNow();
+		for (Integer lid: lids){
+			GoodLabel bean = new GoodLabel();
+			bean.setCtime(now);
+			bean.setGid(base.getGid());
+			bean.setLid(lid);
+			sysLabelMapper.addLabelGood(bean);
+		}
+	}
 }
 }

+ 3 - 0
shop/src/main/resource/mapper/SysLabelMapper.xml

@@ -44,4 +44,7 @@
 	<delete id="delLabelGoods" >
 	<delete id="delLabelGoods" >
 		delete from good_label where lid=#{lid}
 		delete from good_label where lid=#{lid}
 	</delete>
 	</delete>
+	<delete id="delGoodLabels">
+		delete from good_label where gid=#{gid}
+	</delete>
 </mapper>
 </mapper>

+ 2 - 1
shop/static/manager/src/api/index.js

@@ -77,5 +77,6 @@ export default {
     getGoodLabels: (params, vue) => post(`${serverPath}manage/getGoodLabels`, params, vue),
     getGoodLabels: (params, vue) => post(`${serverPath}manage/getGoodLabels`, params, vue),
     okLabels: (params, vue) => post(`${serverPath}manage/label/okLabels`, params, vue),
     okLabels: (params, vue) => post(`${serverPath}manage/label/okLabels`, params, vue),
     getPackages: (params, vue) => post(`${serverPath}manage/getPackages`, params, vue),
     getPackages: (params, vue) => post(`${serverPath}manage/getPackages`, params, vue),
-    bindPackage: (params, vue) => post(`${serverPath}manage/bindPackage`, params, vue)
+    bindPackage: (params, vue) => post(`${serverPath}manage/bindPackage`, params, vue),
+    setGoodLabels: (params, vue) => post(`${serverPath}manage/setGoodLabels`, params, vue)
 }
 }

+ 67 - 12
shop/static/manager/src/components/page/GoodLabelManage.vue

@@ -1,16 +1,17 @@
 <template>
 <template>
     <div>
     <div>
         <div class="old">
         <div class="old">
-            <el-tag v-for="(it, index) in oldLabels" :key="it.id" closable type="success" @close="removeOldLabel(index)">
-                {{it.name}}
+            <el-tag class="tag" v-for="(oit, oindex) in oldLabels" :key="oit.id" closable type="success" @close="removeOldLabel(oindex)">
+                {{oit.name}}
             </el-tag>
             </el-tag>
         </div>
         </div>
         <div class="new">
         <div class="new">
-            <el-tag v-for="(it, index) in newLabels" :key="it.id"  type="success">
-                {{it.name}}
-            </el-tag>
+            <el-button type="danger" plain v-for="(nit, nindex) in newLabels" :key="nit.id" v-on:click="add(nindex)" size="mini">{{nit.name}}</el-button>
+        </div>
+        <div class="option">
+            <el-button type="primary" @click="save">保存</el-button>
+            <el-button @click="goBack">取消</el-button>
         </div>
         </div>
-        <div class="option"></div>
     </div>
     </div>
 </template>
 </template>
 <script>
 <script>
@@ -30,13 +31,47 @@ export default {
         }
         }
       })
       })
     },
     },
-    getNewGoodLabels: function(){
-        this.$http.okLabels({}, this).then(res => {
-            this.newLabels = res.obj
-        });
+    getNewGoodLabels: function() {
+      this.$http.okLabels({}, this).then(res => {
+        this.newLabels = res.obj
+      })
+    },
+    removeOldLabel: function(index) {
+      this.oldLabels.splice(index, 1)
     },
     },
-    removeOldLabel: function(index){
-        this.oldLabels.splice(index, 1)
+    goBack: function() {
+      this.$router.back()
+    },
+    add: function(index) {
+      var item = this.newLabels[index]
+      var have = false
+      this.oldLabels.forEach(it => {
+        if (it.id === item.id) {
+          have = true
+        }
+      })
+      if (!have) {
+        this.oldLabels.push({ id: item.id, name: item.name })
+      }
+    },
+    save: function() {
+      var lids = []
+      this.oldLabels.forEach(it => {
+        lids.push(it.id)
+      })
+      var that = this
+      this.$http
+        .setGoodLabels({ gid: this.gid, lids: lids }, this)
+        .then(res => {
+          this.$message({
+            message: '操作成功',
+            type: 'success',
+            duration: 1000,
+            onClose: function() {
+              that.goBack()
+            }
+          })
+        })
     }
     }
   },
   },
   mounted() {
   mounted() {
@@ -47,3 +82,23 @@ export default {
   }
   }
 }
 }
 </script>
 </script>
+
+<style>
+.old {
+  height: 150px;
+}
+.new {
+  border-top: 1px solid #666;
+  padding-top: 20px;
+  height: 150px;
+}
+.tag {
+  margin-left: 10px;
+  margin-right: 10px;
+}
+.option {
+  border-top: 1px solid #666;
+  padding-top: 20px;
+}
+</style>
+