Browse Source

侧边栏购物车数量不会实时刷新问题

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@9604 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
dongbw 8 years ago
parent
commit
cf4ee8beda

+ 19 - 12
src/main/java/com/uas/platform/b2b/controller/CartController.java

@@ -1,16 +1,5 @@
 package com.uas.platform.b2b.controller;
 package com.uas.platform.b2b.controller;
 
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.uas.platform.b2b.model.Cart;
 import com.uas.platform.b2b.model.Cart;
 import com.uas.platform.b2b.model.Vendor;
 import com.uas.platform.b2b.model.Vendor;
 import com.uas.platform.b2b.search.SearchService;
 import com.uas.platform.b2b.search.SearchService;
@@ -22,6 +11,12 @@ import com.uas.search.b2b.model.SPage;
 import com.uas.search.b2b.model.Sort;
 import com.uas.search.b2b.model.Sort;
 import com.uas.search.b2b.model.Sort.Type;
 import com.uas.search.b2b.model.Sort.Type;
 import com.uas.search.b2b.util.SearchConstants;
 import com.uas.search.b2b.util.SearchConstants;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
 
 
 /**
 /**
  * 购物车
  * 购物车
@@ -53,7 +48,7 @@ public class CartController {
 
 
 	/**
 	/**
 	 * 购物车信息(搜索)
 	 * 购物车信息(搜索)
-	 * 
+	 *
 	 * @param params
 	 * @param params
 	 * @param keyword
 	 * @param keyword
 	 * @return
 	 * @return
@@ -137,4 +132,16 @@ public class CartController {
 	private List<Vendor> getVendorInfo() {
 	private List<Vendor> getVendorInfo() {
 		return cartService.getVendorInfo();
 		return cartService.getVendorInfo();
 	}
 	}
+
+	/**
+	 * 获取购物车数量
+	 * @return
+	 */
+	@RequestMapping(value = "/countTodo", method = RequestMethod.GET)
+	@ResponseBody
+	public ModelMap getCartTodoCount () {
+		ModelMap map = new ModelMap();
+		map.put("cartTodo", cartService.getCartTodoCount());
+		return map;
+	}
 }
 }

+ 3 - 4
src/main/java/com/uas/platform/b2b/service/CartService.java

@@ -1,13 +1,12 @@
 package com.uas.platform.b2b.service;
 package com.uas.platform.b2b.service;
 
 
-import java.util.List;
-
-import org.springframework.ui.ModelMap;
-
 import com.uas.platform.b2b.model.Cart;
 import com.uas.platform.b2b.model.Cart;
 import com.uas.platform.b2b.model.Vendor;
 import com.uas.platform.b2b.model.Vendor;
 import com.uas.platform.core.model.PageParams;
 import com.uas.platform.core.model.PageParams;
 import com.uas.search.b2b.model.SPage;
 import com.uas.search.b2b.model.SPage;
+import org.springframework.ui.ModelMap;
+
+import java.util.List;
 
 
 public interface CartService {
 public interface CartService {
 
 

+ 8 - 2
src/main/webapp/resources/js/index/app.js

@@ -11388,7 +11388,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 	/**
 	/**
 	 * 新增采购单
 	 * 新增采购单
 	 */
 	 */
-	app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http) {
+	app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window) {
 		BaseService.scrollBackToTop();
 		BaseService.scrollBackToTop();
 		// 每次进入时先清除掉rootScope下的venuu
 		// 每次进入时先清除掉rootScope下的venuu
 		$rootScope.venduu = null;
 		$rootScope.venduu = null;
@@ -11679,6 +11679,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 				$scope.loading = false;
 				$scope.loading = false;
 				toaster.pop('success', '成功', '保存成功');
 				toaster.pop('success', '成功', '保存成功');
 				window.location.hash = '#/purc/cart/'+data.id;
 				window.location.hash = '#/purc/cart/'+data.id;
+				$window.location.reload();
 			}, function(response){
 			}, function(response){
 				$scope.loading = false;
 				$scope.loading = false;
 				toaster.pop('error', '保存失败', response.data);
 				toaster.pop('error', '保存失败', response.data);
@@ -12743,7 +12744,12 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 				return getCartList;
 				return getCartList;
 			}
 			}
 		};
 		};
-		
+		var getTodoCartCount = function() {
+            cartOperation.getTodoCartCount({}, function(data) {
+		        $scope.countTodo = data.cartTodo;
+            });
+        };
+        getTodoCartCount();
 		$scope.tableParams = new ngTableParams({
 		$scope.tableParams = new ngTableParams({
 			page : 1, 
 			page : 1, 
 			count : 20,
 			count : 20,

+ 5 - 1
src/main/webapp/resources/js/index/services/Cart.js

@@ -25,7 +25,11 @@ define(['ngResource'], function() {
 				url: 'cart/vendorInfo',
 				url: 'cart/vendorInfo',
 				method: 'GET',
 				method: 'GET',
 				isArray: true
 				isArray: true
-			}
+			},
+            getTodoCartCount: {
+                url: 'cart/countTodo',
+                method: 'GET'
+            }
 		})
 		})
 	}]).factory('getCartList', ['$resource', function($resource) {
 	}]).factory('getCartList', ['$resource', function($resource) {
 		return $resource('cart/getCartList', {}, {
 		return $resource('cart/getCartList', {}, {

+ 9 - 1
src/main/webapp/resources/tpl/index/purc/right.html

@@ -168,11 +168,19 @@
 				<span class="text-inverse" ng-bind="todo.purcTodo > 99 ? '99+' : todo.purcTodo"></span>
 				<span class="text-inverse" ng-bind="todo.purcTodo > 99 ? '99+' : todo.purcTodo"></span>
 			</a>
 			</a>
 		</div>
 		</div>
-		<div class="item-wrap">
+		<!--<div class="item-wrap">
 			<a class="item-inner" ui-sref="purc.cart">
 			<a class="item-inner" ui-sref="purc.cart">
 				<span class="inner-text">购物车</span>
 				<span class="inner-text">购物车</span>
 				<span class="text-inverse" ng-bind="todo.cartTodo > 99 ? '99+' : todo.cartTodo"></span>
 				<span class="text-inverse" ng-bind="todo.cartTodo > 99 ? '99+' : todo.cartTodo"></span>
 			</a>
 			</a>
+		</div>-->
+	</div>
+	<div class="bar-center" ng-controller="CartController">
+		<div class="item-wrap">
+			<a class="item-inner" ui-sref="purc.cart">
+				<span class="inner-text">购物车</span>
+				<span class="text-inverse" ng-bind="countTodo > 99 ? '99+' : countTodo"></span>
+			</a>
 		</div>
 		</div>
 	</div>
 	</div>
 <!-- 	<div class="bar-bottom">
 <!-- 	<div class="bar-bottom">