Browse Source

增加批量移除我的产品数据方法

hejq 8 years ago
parent
commit
817c4e6b97

+ 23 - 2
src/main/java/com/uas/platform/b2b/controller/ProductUsersController.java

@@ -143,9 +143,30 @@ public class ProductUsersController {
         ModelMap map = new ModelMap();
         try {
             productUsersService.deleteById(id);
-            logger.log("删除物料", "[" + SystemSession.getUser().getUserName() + "]删除了id为 [" + id + "]的物料");
+            logger.log("删除个人产品",  "删除了id为 [" + id + "]个人产品");
         } catch (Exception e) {
-            map.put("error", "该物料可能已经被其他单据引用,无法删除");
+            map.put("error", "删除个人产品失败");
+        }
+        return map;
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     * @return
+     * @throws Exception
+     */
+    @RequestMapping(value = "/edit/deleteByBatch", method = RequestMethod.POST)
+    public ModelMap deleteByBatch(String ids) throws Exception {
+        List<Long> idList = JSONObject.parseArray(ids, Long.class);
+        ModelMap map = new ModelMap();
+        try {
+            productUsersService.deleteByBatch(idList);
+            logger.log("删除个人产品",  "数量:" + idList.size());
+        } catch (Exception e) {
+            map.put("error", "删除个人产品失败");
         }
         return map;
     }

+ 6 - 0
src/main/java/com/uas/platform/b2b/service/ProductUsersService.java

@@ -59,4 +59,10 @@ public interface ProductUsersService {
      * @param id
      */
     void coverToUserProd(Long id);
+
+    /**
+     * 批量删除我的产品
+     * @param idList
+     */
+    void deleteByBatch(List<Long> idList);
 }

+ 6 - 0
src/main/java/com/uas/platform/b2b/service/impl/ProductUsersServiceImpl.java

@@ -323,4 +323,10 @@ public class ProductUsersServiceImpl implements ProductUsersService {
             logger.log("我的产品库", "新增了我产品信息", "id:" + prod.getId());
         }
     }
+
+    @Override
+    public void deleteByBatch(List<Long> idList) {
+        List<ProductUsers> prods = productUsersDao.findAll(idList);
+        productUsersDao.delete(prods);
+    }
 }

+ 91 - 28
src/main/webapp/resources/js/index/app.js

@@ -20834,7 +20834,7 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
             var ids = angular.toJson($rootScope.ids);
             ids = ids.replace(/\[|]/g,'');
             prodUser.coverToUserByIds({ids: ids}, {}, function(data) {
-                toaster.pop('success', '成功转入' + data.count);
+                toaster.pop('success', '成功转入' + data.count + '个物料');
             }, function(res) {
                 toaster.pop('error', '转入失败');
             });
@@ -20919,19 +20919,6 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
                                 product.checked = $scope.checks.checked;
                             }
                         });
-//						$scope.total = page.totalElement;
-//						Products.matchsize({type: 'all'}, {}, function(data) {
-//							$scope.size = data.size;
-//							if($scope.total < $scope.size) {
-//								$timeout(function() {
-//									$scope.tableParams.reload();
-//								}, 500);
-//							} else {
-//								$scope.loading = false;
-//							}
-//						}, function(response) {
-//							toaster.pop('error', '提示', response.data);
-//						});
                     }
                 }, function (response) {
                     $scope.loading = false;
@@ -21317,18 +21304,6 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
                             }
                         });
                         $scope.total = page.totalElement;
-//						Products.matchsize({type: 'purc'}, {}, function(data) {
-//							$scope.size = data.size;
-//							if($scope.total < $scope.size) {
-//								$timeout(function() {
-//									$scope.tableParams.reload();
-//								}, 500);
-//							} else {
-//								$scope.loading = false;
-//							}
-//						}, function(response) {
-//							toaster.pop('error', '提示', response.data);
-//						});
                     }
                 }, function (response) {
                     $scope.loading = false;
@@ -22295,10 +22270,11 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 
 
     /**
-     * 个人产库
+     * 个人产
      */
-    app.controller('UserProductCtrl', ['$scope', 'prodUser', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$modal', function ($scope, prodUser, ngTableParams, $filter, BaseService, toaster, $timeout, $modal) {
+    app.controller('UserProductCtrl', ['$scope', 'prodUser', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$modal', '$rootScope', function ($scope, prodUser, ngTableParams, $filter, BaseService, toaster, $timeout, $modal, $rootScope) {
         BaseService.scrollBackToTop();
+        $rootScope.ids = [];// 每次加载先清空数据
         $scope.searchMethod = false;
         var getService = function () {
             return $scope.searchMethod ? prodUser.getInfo : prodUser.info;
@@ -22324,6 +22300,17 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
                     if (page) {
                         params.total(page.totalElement);
                         $defer.resolve(page.content);
+                        $scope.checkall = true;
+                        angular.forEach(page.content, function (prod) {
+                            if ($rootScope.ids.indexOf(prod.id) > -1) {
+                                prod.$selected = true;
+                            } else {
+                                $scope.checkall = false;
+                            }
+                        });
+                        $scope.checkboxes = {
+                            checked: $scope.checkall
+                        };
                     }
                 }, function (response) {
                     $scope.loading = false;
@@ -22387,6 +22374,82 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
             });
         }
 
+        $scope.checkboxes = {
+            checked: false
+        };
+        angular.forEach($scope.tableParams.data, function (item) {
+            $scope.checkboxes.checked = false;
+            if($rootScope.ids.in_array(item.id)) {
+                $rootScope.ids.remove(item.id);
+                $scope.checkboxes.checked = true;
+            }
+        });
+
+        // 点击勾选全部的复选框
+        $scope.checkAll = function () {
+            angular.forEach($scope.tableParams.data, function (item) {
+                item.$selected = $scope.checkboxes.checked;
+                if(item.$selected) {
+                    if(!$rootScope.ids.in_array(item.id)) {
+                        $rootScope.ids.push(item.id);
+                    }
+                } else {
+                    if($rootScope.ids.in_array(item.id)) {
+                        $rootScope.ids.remove(item.id);
+                    }
+                }
+            });
+        };
+
+        // 判断数组中是否存在某个对象
+        Array.prototype.S = String.fromCharCode(2);
+        Array.prototype.in_array = function(e) {
+            var r = new RegExp(this.S + e + this.S);
+            return (r.test(this.S + this.join(this.S) + this.S));
+        }
+
+        // 从数组中移除某个对象
+        Array.prototype.remove = function(val) {
+            var index = this.indexOf(val);
+            if (index > -1) {
+                this.splice(index, 1);
+            }
+        };
+
+        // 点击其中一个明细的复选框
+        $scope.checkOne = function (product) {
+            var result = true;
+            angular.forEach($scope.tableParams.data, function (item) {
+                if (item.$selected != true) {
+                    result = false;
+                    return;
+                }
+            });
+            if(product.$selected) {
+                if(!$rootScope.ids.in_array(product.id)) {
+                    $rootScope.ids.push(product.id);
+                }
+            } else {
+                if($rootScope.ids.in_array(product.id)) {
+                    $rootScope.ids.remove(product.id);
+                }
+            }
+            $scope.checkboxes = {
+                checked: result
+            };
+        };
+
+        // 批量删除
+        $scope.deleteByBatch = function() {
+            var ids = angular.toJson($rootScope.ids);
+            prodUser.deleteByBatch({ids: ids}, {}, function(data) {
+                toaster.pop('success', '成功删除' + $rootScope.ids.length + '个物料');
+                $scope.tableParams.page(1);
+                $scope.tableParams.reload();
+            }, function(res) {
+                toaster.pop('error', '删除失败');
+            });
+        }
     }]);
 
     /**

+ 7 - 0
src/main/webapp/resources/js/index/services/ProductUsers.js

@@ -32,6 +32,13 @@ define([ 'ngResource'], function() {
                 url: 'productuser/edit/delete',
                 method: 'POST'
             },
+            /**
+             * 批量删除个人产品(不删除产品数据)
+             */
+            deleteByBatch: {
+                url: 'productuser/edit/deleteByBatch',
+                method: 'POST'
+            },
             /**
              * 批量转入我的产品库
              */

+ 8 - 0
src/main/webapp/resources/tpl/index/approvalFlow/userProduct.html

@@ -188,6 +188,7 @@
         <div class="p-right">
             <a ng-click="addProduct()">新增</a>
             <a ng-click="uploadByBatch()" title="批量导入">批量导入</a>
+            <a ng-click="deleteByBatch()">批量删除</a>
         </div>
     </div>
     <div class="condition block" style="padding: 10px 15px;">
@@ -212,6 +213,10 @@
         <table class="order-table block " ng-table="tableParams">
             <thead>
             <tr class="header">
+                <th width="50px">
+                    <input type="checkbox" class="selector select_all"
+                           ng-model="checkboxes.checked" ng-click="checkAll()" title="点击选择后可以批量删除">
+                </th>
                 <th width="140">产品编号</th>
                 <th>产品名称(类目)</th>
                 <th width="160">产品型号</th>
@@ -222,6 +227,9 @@
             </thead>
             <tbody ng-repeat="user in $data">
             <tr class="order-hd">
+                <td class="text-center">
+                    <input type="checkbox" class="selector"
+                          ng-model="user.$selected" ng-click="checkOne(user)"></td>
                 <td class="text-center" title="{{user.product.code}}" ng-bind="::user.product.code"></td>
                 <td class="line-h20 first text-center">
                     <div class="order-main">