|
|
@@ -2505,15 +2505,15 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
|
|
|
]
|
|
|
$scope.setReplies = function (type, index) {
|
|
|
if (type === 'add' && $scope.replaceMaterialList.length < 10) {
|
|
|
- for (var index = 0 ;index < $scope.replaceMaterialList.length ; index ++) {
|
|
|
- $scope.errorObj[index] = {code : 0, brand : 0};
|
|
|
- if (!$scope.replaceMaterialList[index].ptrCmpcode) {
|
|
|
- $scope.errorObj[index].code = 1;
|
|
|
+ for (var i = 0; i < $scope.replaceMaterialList.length; i ++) {
|
|
|
+ $scope.errorObj[i] = {code : 0, brand : 0};
|
|
|
+ if (!$scope.replaceMaterialList[i].ptrCmpcode) {
|
|
|
+ $scope.errorObj[i].code = 1;
|
|
|
}
|
|
|
- if (!$scope.replaceMaterialList[index].ptrBranden) {
|
|
|
- $scope.errorObj[index].brand = 1;
|
|
|
+ if (!$scope.replaceMaterialList[i].ptrBranden) {
|
|
|
+ $scope.errorObj[i].brand = 1;
|
|
|
}
|
|
|
- if ($scope.replaceMaterialList[index].ptrBranden && $scope.replaceMaterialList[index].ptrCmpcode) {
|
|
|
+ if ($scope.replaceMaterialList[i].ptrBranden && $scope.replaceMaterialList[i].ptrCmpcode) {
|
|
|
$scope.canAdd = true;
|
|
|
} else {
|
|
|
$scope.canAdd = false;
|
|
|
@@ -2536,6 +2536,28 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var getRealLen = function (str) {
|
|
|
+ var len = 0;
|
|
|
+ for (var i = 0; i < str.length; i++) {
|
|
|
+ if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
|
+ len += 2;
|
|
|
+ } else {
|
|
|
+ len++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return len;
|
|
|
+ };
|
|
|
+
|
|
|
+ var cutOutString = function (str, length) {
|
|
|
+ for (var i = 1; i <= str.length; i++) {
|
|
|
+ if (getRealLen(str.substr(0, i)) > length){
|
|
|
+ str = str.substr(0, i-1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+ };
|
|
|
+
|
|
|
// $scope.showSimilarCodeList = false;
|
|
|
$scope.isInCodeList = true;
|
|
|
// $scope.showSimilarBrandList = false;
|
|
|
@@ -2582,17 +2604,45 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
|
|
|
$scope.isInBrandList = flag;
|
|
|
}
|
|
|
$scope.onCodeChange = function (code, index) {
|
|
|
- if (!code) {
|
|
|
- $scope.setShowSimilarCodeList(false, index);
|
|
|
+ if ((/[^\x00-\xff]/g).test(code)) {
|
|
|
+ var chineseIndex = -1;
|
|
|
+ for (var i = 0; i < code.length; i++) {
|
|
|
+ if ((/[^\x00-\xff]/g).test(code.charAt(i))) {
|
|
|
+ chineseIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $scope.replaceMaterialList[index].ptrCmpcode = cutOutString(code, chineseIndex);
|
|
|
+ } else if (code && getRealLen(code) > 100) {
|
|
|
+ $scope.replaceMaterialList[index].ptrCmpcode = cutOutString(code, 100);
|
|
|
} else {
|
|
|
- $scope.getSimilarCode(code, index);
|
|
|
+ if (!code) {
|
|
|
+ $scope.setShowSimilarCodeList(false, index);
|
|
|
+ } else {
|
|
|
+ $scope.getSimilarCode(code, index);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
$scope.onBrandChange = function (brand, index) {
|
|
|
- if (!brand) {
|
|
|
- $scope.setShowSimilarBrandList(false, index);
|
|
|
+ if ((/[^\x00-\xff]/g).test(brand)) {
|
|
|
+ var chineseIndex = -1;
|
|
|
+ for (var i = 0; i < brand.length; i++) {
|
|
|
+ if ((/[^\x00-\xff]/g).test(brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(brand.charAt(i))) {
|
|
|
+ chineseIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (chineseIndex > -1) {
|
|
|
+ $scope.replaceMaterialList[index].ptrBranden = brand.substring(0, chineseIndex);
|
|
|
+ }
|
|
|
+ } else if (brand && getRealLen(brand) > 50) {
|
|
|
+ $scope.replaceMaterialList[index].ptrBranden = cutOutString(brand, 50);
|
|
|
} else {
|
|
|
- $scope.getSimilarBrand(brand, index);
|
|
|
+ if (!brand) {
|
|
|
+ $scope.setShowSimilarBrandList(false, index);
|
|
|
+ } else {
|
|
|
+ $scope.getSimilarBrand(brand, index);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
$scope.onCodeBlur = function (index) {
|
|
|
@@ -2722,6 +2772,17 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
|
|
|
};
|
|
|
$modalInstance.close(a);
|
|
|
};
|
|
|
+ var getRealLen = function (str) {
|
|
|
+ var len = 0;
|
|
|
+ for (var i = 0; i < str.length; i++) {
|
|
|
+ if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
|
+ len += 2;
|
|
|
+ } else {
|
|
|
+ len++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return len;
|
|
|
+ }
|
|
|
}]);
|
|
|
|
|
|
|