Procházet zdrojové kódy

呵呵商城改版part10

Aslee před 3 roky
rodič
revize
318176490f

+ 18 - 0
src/main/java/com/caimei/modules/hehe/entity/CmHeheProduct.java

@@ -32,6 +32,8 @@ public class CmHeheProduct extends DataEntity<CmHeheProduct> {
     private String mainImage;       //商品图片
     private String shopName;        //供应商名称
     private List<Integer> ids;             //刚添加的活动id
+    private Integer bigTypeId;      // 一级分类id
+    private Integer smallTypeId;    // 二级分类id
 
     private Integer activityId;     //活动id
     private String floorIds;        //楼层id,以,隔开
@@ -184,4 +186,20 @@ public class CmHeheProduct extends DataEntity<CmHeheProduct> {
     public void setFloorIds(String floorIds) {
         this.floorIds = floorIds;
     }
+
+    public Integer getBigTypeId() {
+        return bigTypeId;
+    }
+
+    public void setBigTypeId(Integer bigTypeId) {
+        this.bigTypeId = bigTypeId;
+    }
+
+    public Integer getSmallTypeId() {
+        return smallTypeId;
+    }
+
+    public void setSmallTypeId(Integer smallTypeId) {
+        this.smallTypeId = smallTypeId;
+    }
 }

+ 7 - 0
src/main/java/com/caimei/modules/hehe/web/CmHeheProductController.java

@@ -8,6 +8,7 @@ import com.caimei.modules.hehe.entity.CmHeheFloor;
 import com.caimei.modules.hehe.service.CmHeheActivityService;
 import com.caimei.modules.hehe.service.CmHeheFloorService;
 import com.caimei.modules.product.entity.Product;
+import com.caimei.modules.product.service.ProductService;
 import com.google.common.collect.Maps;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,6 +51,9 @@ public class CmHeheProductController extends BaseController {
     @Autowired
     private CmHeheActivityService cmHeheActivityService;
 
+    @Autowired
+    private ProductService productService;
+
     @ModelAttribute
     public CmHeheProduct get(@RequestParam(required = false) String id) {
         CmHeheProduct entity = null;
@@ -98,6 +102,9 @@ public class CmHeheProductController extends BaseController {
             });
         }
         model.addAttribute("activityList", activityList);
+        // 查询分类列表
+        Map<String, Object> classify = productService.findClassify(2);
+        model.addAttribute("classify", classify);
         return "modules/hehe/cmHeheProductForm";
     }
 

+ 4 - 2
src/main/java/com/caimei/modules/product/service/ProductService.java

@@ -349,9 +349,11 @@ public class ProductService extends CrudService<ProductDao, Product> {
         return cmBrandDao.getList();
     }
 
-    public Map<String, Object> findClassify() {
+    public Map<String, Object> findClassify(Integer mallType) {
         Map<String, Object> classifyMap = new HashMap<>();
-        List<CmBigtype> bigTypeList = cmBigtypeDao.findList(new CmBigtype());
+        CmBigtype bigtype = new CmBigtype();
+        bigtype.setMallType(mallType);
+        List<CmBigtype> bigTypeList = cmBigtypeDao.findList(bigtype);
         List<CmSmalltype> smalltypeList = cmSmalltypeDao.findList(new CmSmalltype());
         List<CmTinytype> tinytypeList = cmTinytypeDao.findList(new CmTinytype());
         classifyMap.put("bigTypeList", bigTypeList);

+ 1 - 1
src/main/java/com/caimei/modules/product/web/ProductController.java

@@ -336,7 +336,7 @@ public class ProductController extends BaseController{
             product.setLadderPriceList(ladderPriceList);
         }
         List<CmBrand> brandList = productService.findBrandList();
-        Map<String, Object> classify = productService.findClassify();
+        Map<String, Object> classify = productService.findClassify(1);
         List<Province> provinceList = areaService.loadProvince();
         model.addAttribute("brandList", brandList);
         model.addAttribute("classify", classify);

+ 5 - 5
src/main/java/com/caimei/modules/product/web/ProductNewController.java

@@ -215,7 +215,7 @@ public class ProductNewController extends BaseController {
             }
         }
         List<CmBrand> brandList = productService.findBrandList();
-        Map<String, Object> classify = productService.findClassify();
+        Map<String, Object> classify = productService.findClassify(1);
         model.addAttribute("brandList", brandList);
         model.addAttribute("classify", classify);
         model.addAttribute("page", page);
@@ -262,7 +262,7 @@ public class ProductNewController extends BaseController {
         }
         product.setCommodityType(StringUtils.isEmpty(product.getCommodityType()) ? "0" : product.getCommodityType());
         List<CmBrand> brandList = productService.findBrandList();
-        Map<String, Object> classify = productService.findClassify();
+        Map<String, Object> classify = productService.findClassify(1);
         List<Province> provinceList = areaService.loadProvince();
         List<CmProductCombination> combinationList = cmProductCombinationService.findProductCombinationList();
 
@@ -417,7 +417,7 @@ public class ProductNewController extends BaseController {
             return "redirect:" + Global.getAdminPath() + "/product/new/list/";
         }
         product.setCommodityType(StringUtils.isEmpty(product.getCommodityType()) ? "0" : product.getCommodityType());
-        Map<String, Object> classify = productService.findClassify();
+        Map<String, Object> classify = productService.findClassify(1);
         model.addAttribute("classify", classify);
         model.addAttribute("product", product);
         return "modules/product-new/fastEdit";
@@ -434,7 +434,7 @@ public class ProductNewController extends BaseController {
         }
         model.addAttribute("product", product);
 
-        Map<String, Object> classify = productService.findClassify();
+        Map<String, Object> classify = productService.findClassify(1);
         model.addAttribute("classify", classify);
 
         List<ProductCustomClassification> customClassify = productService.getProductTypes(product.getProductID());
@@ -849,7 +849,7 @@ public class ProductNewController extends BaseController {
         } else {
             model.addAttribute("recommendType", recommendType);
         }
-        Map<String, Object> classify = productService.findClassify();
+        Map<String, Object> classify = productService.findClassify(1);
         model.addAttribute("classify", classify);
         model.addAttribute("product", product);
         model.addAttribute("recommendList", recommendList);

+ 8 - 0
src/main/resources/mappings/modules/hehe/CmHeheProductMapper.xml

@@ -5,6 +5,8 @@
 	<sql id="cmHeheProductColumns">
 		a.id AS "id",
 		a.productId AS "productId",
+		ifnull(a.bigTypeId,0) AS "bigTypeId",
+		ifnull(a.smallTypeId,0) AS "smallTypeId",
 		a.validFlag AS "validFlag",
 		a.price AS "price",
 		a.includedTax AS "includedTax",
@@ -97,6 +99,8 @@
 	<insert id="insert" parameterType="CmHeheProduct"  keyProperty="id" useGeneratedKeys="true">
 		INSERT INTO cm_hehe_product(
 			productId,
+			bigTypeId,
+			smallTypeId,
 			validFlag,
 			price,
 			includedTax,
@@ -106,6 +110,8 @@
 			addTime
 		) VALUES (
 			#{productId},
+			#{bigTypeId},
+			#{smallTypeId},
 			#{validFlag},
 			#{price},
 			#{includedTax},
@@ -127,6 +133,8 @@
 	<update id="update">
 		UPDATE cm_hehe_product SET 	
 			productId = #{productId},
+		    bigTypeId = #{bigTypeId},
+			smallTypeId = #{smallTypeId},
 			validFlag = #{validFlag},
 			price = #{price},
 			includedTax = #{includedTax},

+ 109 - 0
src/main/webapp/WEB-INF/views/modules/hehe/cmHeheProductForm.jsp

@@ -348,6 +348,23 @@
 				</div>
 			</div>
 		</div>
+		<div class="control-group">
+			<label class="control-label"><font color="red">*</font>商品分类:</label>
+			<div class="controls">
+				<form:select path="bigTypeId" class="input-small required" id="bigType" onchange="loadSmallType()">
+					<form:option value="" label="请选择"/>
+					<form:options items="${classify.bigTypeList}" itemLabel="name" itemValue="bigTypeID"
+								  htmlEscape="false"/>
+				</form:select>
+				<form:select path="smallTypeId" class="input-small required" id="smallType">
+					<form:option value="" label="请选择"/>
+					<c:forEach items="${classify.smalltypeList}" var="smallType">
+						<form:option value="${smallType.smallTypeID}" label="${smallType.name}"
+									 bigTypeId="${smallType.bigTypeID}"/>
+					</c:forEach>
+				</form:select>
+			</div>
+		</div>
 		<div class="control-group">
 			<label class="control-label"><font color="red">*</font>商品状态:</label>
 			<div class="controls">
@@ -537,6 +554,98 @@
 			obj.value = '';
 		}
 	}
+
+	$(window).load(function () {
+		loadInitType();
+	});
+
+	// 网站分类
+	var currentBigtype = ${cmHeheProduct.bigTypeId};
+	var currentSmalltype = ${cmHeheProduct.smallTypeId};
+	var bigTypeList = [
+		<c:forEach items="${classify.bigTypeList}" var="bigType" varStatus="index">
+		<c:if test="${index.index > 0}">, </c:if>
+		{
+			bigTypeId: ${bigType.bigTypeID},
+			name: "${bigType.name}",
+			typeSort: ${bigType.typeSort}
+		}
+		</c:forEach>
+	];
+	var smalltypeList = [
+		<c:forEach items="${classify.smalltypeList}" var="smalltype" varStatus="index">
+		<c:if test="${index.index > 0}">, </c:if>
+		{
+			smallTypeId: ${smalltype.smallTypeID},
+			name: "${smalltype.name}",
+			bigTypeId: ${smalltype.bigTypeID},
+		}
+		</c:forEach>
+	];
+	
+	
+	// 初始分类
+	function loadInitType() {
+		if (currentBigtype != null && typeof (currentBigtype) != "undefined") {
+			setTimeout(function () {
+				loadBigType();
+			}, 0);
+		}
+	}
+
+	// 分类联动
+	function loadBigType() {
+		$("#bigType").html("");
+		$("#bigType").prev().find(".select2-chosen").text("请选择");
+		$("#bigType").append("<option value=''>请选择</option>");
+		$("#smallType").html("");
+		$("#smallType").prev().find(".select2-chosen").text("请选择");
+		$("#smallType").append("<option value=''>请选择</option>");
+		$("#tinyType").html("");
+		$("#tinyType").prev().find(".select2-chosen").text("请选择");
+		$("#tinyType").append("<option value=''>请选择</option>");
+		for (var i = 0; i < bigTypeList.length; i++) {
+			if (currentBigtype != null && typeof (currentBigtype) != "undefined" && currentBigtype == bigTypeList[i].bigTypeId) {
+				$("#bigType").append("<option selected value='" + bigTypeList[i].bigTypeId + "'>" + bigTypeList[i].name + "</option>");
+				$("#bigType").prev().find(".select2-chosen").text(bigTypeList[i].name);
+				setTimeout(function () {
+					loadSmallType();
+				}, 500);
+			} else {
+				$("#bigType").append("<option value='" + bigTypeList[i].bigTypeId + "'>" + bigTypeList[i].name + "</option>");
+			}
+		}
+		loadSmallType();
+	}
+
+	function loadSmallType(id) {
+		if (id) {
+			$("#bigType").val(id);
+			$("#bigType").prev().find(".select2-chosen").text($("#bigType option:selected").text());
+		}
+		var bigType = $("#bigType").val();
+		$("#smallType").html("");
+		$("#smallType").prev().find(".select2-chosen").text("请选择");
+		$("#smallType").append("<option value=''>请选择</option>");
+		$("#tinyType").html("");
+		$("#tinyType").prev().find(".select2-chosen").text("请选择");
+		$("#tinyType").append("<option value=''>请选择</option>");
+		if (typeof (bigType) != "undefined" && bigType != "") {
+			var smallTypeNum = 0;
+			for (var i = 0; i < smalltypeList.length; i++) {
+				if (bigType == smalltypeList[i].bigTypeId) {
+					smallTypeNum = smallTypeNum + 1;
+					if (currentSmalltype != null && typeof (currentSmalltype) != "undefined" && currentSmalltype == smalltypeList[i].smallTypeId) {
+						$("#smallType").append("<option selected value='" + smalltypeList[i].smallTypeId + "'>" + smalltypeList[i].name + "</option>");
+						$("#smallType").prev().find(".select2-chosen").text(smalltypeList[i].name);
+					} else {
+						$("#smallType").append("<option value='" + smalltypeList[i].smallTypeId + "'>" + smalltypeList[i].name + "</option>");
+					}
+				}
+			}
+			document.getElementById("s2id_smallType").style.cssText = "display: inline-block";
+		}
+	}
 </script>
 </body>
 </html>