Browse Source

优化用户体验

shenjj 7 years ago
parent
commit
834ab2ecec

+ 68 - 36
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_materialCtrl.js

@@ -2901,23 +2901,37 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
           code: 0,
           brand: 0
         };
-        if (!productReplaceList[i].ptrCmpcode) {
-          $scope.errorObj[i].code = 1;
-        }
-        if (!productReplaceList[i].ptrBranden) {
-          $scope.errorObj[i].brand = 1;
+
+        if (!productReplaceList[i].ptrCmpcode && !productReplaceList[i].ptrBranden) {
+        	// 都为空的情况下
+          $scope.errorObj[i].code = 0;
+          $scope.errorObj[i].brand = 0;
+          productReplaceList[i]['index'] = 1
+
+				} else {
+          if (!productReplaceList[i].ptrCmpcode) {
+            $scope.errorObj[i].code = 1;
+          }
+					else if (!productReplaceList[i].ptrBranden) {
+            $scope.errorObj[i].brand = 1;
+          }
+          productReplaceList[i].detno = i + 1;
         }
-        productReplaceList[i].detno = i + 1;
+
+
         if ($scope.errorObj[i].code == 1 || $scope.errorObj[i].brand == 1) {
           toaster.pop('error', '请填完整信息');
           return;
         }
       }
-      if ($scope.resultDatalistArray[$scope.replaceMaterialId]) {
-        $scope.resultDatalistArray[$scope.replaceMaterialId].arr = productReplaceList
-        $scope.resultDatalistArray[$scope.replaceMaterialId].headlength = productReplaceList.length
-      }
-      var _productReplaceList = $scope.resultDatalistArray[$scope.replaceMaterialId].arr
+
+      var _productReplaceList = productReplaceList.filter(function(item, index) {
+        return !item['index']
+			})
+
+			console.log(_productReplaceList)
+
+
       //提交
       Material.setProductReplacesByPerson({
         productId: $scope.replaceMaterialId
@@ -2940,15 +2954,15 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
         $scope.editCmp = material.pcmpcode;
         $scope.editBrand = material.pbranden;
         $scope._material = material;
-        if ($scope.resultDatalistArray[material.id]) {
-          getChangeList($scope.resultDatalistArray[material.id].arr, material)
-        } else {
-          Material.getGoodsListByProductId({
-            id: material.id
-          }, function(data) {
-            getChangeList(data, material)
-          })
-        }
+        // if ($scope.resultDatalistArray[material.id]) {
+        //   getChangeList($scope.resultDatalistArray[material.id].arr, material)
+        // } else {
+				Material.getGoodsListByProductId({
+					id: material.id
+				}, function(data) {
+					getChangeList(data, material)
+				})
+        // }
       } else {
         $scope.errorObj = [{
           code: 0,
@@ -3067,15 +3081,33 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
           toaster.pop('error', '请填完整信息');
           return
         }
-      } else if (type === 'sub' && $scope.replaceMaterialList.length > 1 && $scope.linearLength > 1) {
+      } else if (type === 'sub' && $scope.replaceMaterialList.length > 0 && $scope.linearLength > 0) {
+        var _productId = $scope.replaceMaterialList[0].productId
         $scope.linearLength--;
         $scope.replaceMaterialList.splice(index, 1);
         $scope.errorObj.splice(index, 1);
         $scope.isInCodeList.splice(index, 1);
         $scope.isInBrandList.splice(index, 1);
+
+        if($scope.linearLength === 0) {
+          $scope.replaceMaterialList.splice(0, 0, {
+            ptrCmpcode: '',
+            ptrBranden: '',
+            showSimilarCodeList: false,
+            showSimilarBrandList: false,
+            editable: true,
+            productId: _productId
+          })
+          $scope.errorObj.splice(0, 0, {
+            code: 0,
+            brand: 0
+          });
+          $scope.linearLength++
+          console.log($scope.replaceMaterialList)
+        }
       }
-      $scope.resultDatalistArray[$scope._material.id].arr = $scope.replaceMaterialList
-      $scope.resultDatalistArray[$scope._material.id].headlength = $scope.linearLength
+      // $scope.resultDatalistArray[$scope._material.id].arr = $scope.replaceMaterialList
+      // $scope.resultDatalistArray[$scope._material.id].headlength = $scope.linearLength
     }
 
     $scope.onCodeChange = function(code, index) {
@@ -3199,19 +3231,19 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
       $scope.lookCmp = material.pcmpcode;
       $scope.lookBrand = material.pbranden;
 
-      if ($scope.resultDatalistArray[material.id]) {
-        $scope.resultDatalist = $scope.resultDatalistArray[material.id].arr
-        console.log($scope.resultDatalist)
-        $scope.linearLength = $scope.resultDatalistArray[material.id].headlength
-      } else {
-        Material.getGoodsListByProductId({
-          id: material.id
-        }, function(data) {
-          $scope.resultDatalistArray[material.id] = normalChangeArr(data)
-          $scope.resultDatalist = $scope.resultDatalistArray[material.id].arr
-          $scope.linearLength = $scope.resultDatalistArray[material.id].headlength
-        })
-      }
+      // if ($scope.resultDatalistArray[material.id]) {
+      //   $scope.resultDatalist = $scope.resultDatalistArray[material.id].arr
+      //   console.log($scope.resultDatalist)
+      //   $scope.linearLength = $scope.resultDatalistArray[material.id].headlength
+      // } else {
+			Material.getGoodsListByProductId({
+				id: material.id
+			}, function(data) {
+				$scope.resultDatalistArray[material.id] = normalChangeArr(data)
+				$scope.resultDatalist = $scope.resultDatalistArray[material.id].arr
+				$scope.linearLength = $scope.resultDatalistArray[material.id].headlength
+			})
+      // }
     }
     //编辑按钮
     $scope.updateIndex = function() {

+ 41 - 11
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_materialPersonCtrl.js

@@ -1026,22 +1026,33 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
     $scope.setProductReplacesByPerson = function (productReplaceList) {
       for (var i = 0; i < productReplaceList.length; i++) {
         $scope.errorObj[i] = {code : 0, brand : 0};
-        if (!productReplaceList[i].ptrCmpcode) {
-          $scope.errorObj[i].code = 1;
-        }
-        if (!productReplaceList[i].ptrBranden) {
-          $scope.errorObj[i].brand = 1;
+
+        if (!productReplaceList[i].ptrCmpcode && !productReplaceList[i].ptrBranden) {
+          // 都为空的情况下
+          $scope.errorObj[i].code = 0;
+          $scope.errorObj[i].brand = 0;
+          productReplaceList[i]['index'] = 1
+
+        } else {
+          if (!productReplaceList[i].ptrCmpcode) {
+            $scope.errorObj[i].code = 1;
+          }
+          if (!productReplaceList[i].ptrBranden) {
+            $scope.errorObj[i].brand = 1;
+          }
+          productReplaceList[i].detno = i + 1;
         }
-        productReplaceList[i].detno = i + 1;
         if ($scope.errorObj[i].code == 1 || $scope.errorObj[i].brand == 1) {
           toaster.pop('error', '请填完整信息');
           return;
         }
       }
-      // for (var i = 0; i < productReplaceList.length; i++) {
-      //
-      // }
-      Material.setProductReplacesByPerson({productId:$scope.replaceMaterialId}, productReplaceList , function (data) {
+       var _productReplaceList = productReplaceList.filter(function(item, index) {
+        return !item['index']
+      })
+
+      console.log(_productReplaceList)
+      Material.setProductReplacesByPerson({productId:$scope.replaceMaterialId}, _productReplaceList , function (data) {
         $scope.setActiveIndex(-1);
         loadDataReload();
         toaster.pop('success', '保存成功');
@@ -2595,12 +2606,31 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
         } else {
           toaster.pop('error', '请填完整信息');
         }
-      } else if (type === 'sub' && $scope.replaceMaterialList.length > 1 && $scope.linearLength > 1) {
+      } else if (type === 'sub' && $scope.replaceMaterialList.length > 0 && $scope.linearLength > 0) {
+        var _productId = $scope.replaceMaterialList[0].productId
         $scope.linearLength--;
         $scope.replaceMaterialList.splice(index, 1);
         $scope.errorObj.splice(index, 1);
         $scope.isInCodeList.splice(index, 1);
         $scope.isInBrandList.splice(index, 1);
+
+        if($scope.linearLength === 0) {
+          $scope.replaceMaterialList.splice(0, 0, {
+            ptrCmpcode: '',
+            ptrBranden: '',
+            showSimilarCodeList: false,
+            showSimilarBrandList: false,
+            editable: true,
+            productId: _productId
+          })
+          $scope.errorObj.splice(0, 0, {
+            code: 0,
+            brand: 0
+          });
+          $scope.linearLength++
+          console.log($scope.replaceMaterialList)
+        }
+
       }
     }