|
|
@@ -1,6 +1,6 @@
|
|
|
define([ 'app/app' ], function(app) {
|
|
|
'use strict';
|
|
|
- app.register.controller('vendorDeliveryRuleCtrl', ['$scope', '$rootScope', 'ngTableParams', 'DistributionRule', 'BaseService', 'toaster', '$state', '$http', 'Enterprise', 'TreeData', function ($scope, $rootScope, ngTableParams, DistributionRule, BaseService, toaster, $state, $http, Enterprise, TreeData) {
|
|
|
+ app.register.controller('vendorDeliveryRuleCtrl', ['$scope', '$rootScope', 'ngTableParams', 'DistributionRule', 'BaseService', 'toaster', '$state', '$http', 'Enterprise', 'TreeData','$q', function ($scope, $rootScope, ngTableParams, DistributionRule, BaseService, toaster, $state, $http, Enterprise, TreeData,$q) {
|
|
|
$rootScope.active = 'vendor_logistics';
|
|
|
$scope.tab = 'deliverRule';
|
|
|
$scope.title = '配送规则';
|
|
|
@@ -53,7 +53,9 @@ define([ 'app/app' ], function(app) {
|
|
|
$scope.modifyRule = data;
|
|
|
$scope.isModify = true;
|
|
|
$scope.isActive = $scope.modifyRule.active == 1;
|
|
|
- $scope.fareArray = angular.fromJson($scope.modifyRule.fares);
|
|
|
+ if ($scope.modifyRule.fareType == 2){
|
|
|
+ $scope.fareArray = angular.fromJson($scope.modifyRule.fares);
|
|
|
+ }
|
|
|
if (!$scope.fareArray){
|
|
|
$scope.fareArray = [];
|
|
|
var firstFare = {
|
|
|
@@ -91,9 +93,6 @@ define([ 'app/app' ], function(app) {
|
|
|
var data = angular.fromJson($scope.modifyRule.areas);
|
|
|
$scope.mapArray = data;
|
|
|
}
|
|
|
- if ($scope.mapArray.length == 0){
|
|
|
-
|
|
|
- }
|
|
|
}else {
|
|
|
$scope.isModify = false;
|
|
|
$scope.modifyRule = {};
|
|
|
@@ -177,21 +176,7 @@ define([ 'app/app' ], function(app) {
|
|
|
$scope.loadCityData();
|
|
|
|
|
|
$scope.repeatError = false;
|
|
|
- $scope.checkRuleName = function () {
|
|
|
- console.log($scope.nameArray);
|
|
|
- var k = 1;
|
|
|
- angular.forEach($scope.nameArray, function (item) {
|
|
|
- if (item == $scope.modifyRule.ruleName){
|
|
|
- k = 0;
|
|
|
- return;
|
|
|
- }
|
|
|
- });
|
|
|
- if (k == 1){
|
|
|
- $scope.repeatError = false;
|
|
|
- }else {
|
|
|
- $scope.repeatError = true;
|
|
|
- }
|
|
|
-
|
|
|
+ $scope.checkRuleNameSize = function () {
|
|
|
if ($scope.modifyRule.ruleName){
|
|
|
var size = $scope.modifyRule.ruleName.replace(/[^x00-xFF]/g,'**').length;
|
|
|
if (size > 20) {
|
|
|
@@ -317,47 +302,63 @@ define([ 'app/app' ], function(app) {
|
|
|
$scope.fareArray[index+1].start = Number(data.end);
|
|
|
};
|
|
|
|
|
|
- $scope.saveDistributionRule = function (isAdd) {
|
|
|
- if (!isAdd){
|
|
|
- $scope.checkRuleName();
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 后台检查规则名是否重复
|
|
|
+ * @param newSave
|
|
|
+ * @returns {*|{url, method}}
|
|
|
+ */
|
|
|
+ var checkRepeatName = function (newSave) {
|
|
|
+ return DistributionRule.checkRuleName({id:$scope.modifyRule.id,ruleName:$scope.modifyRule.ruleName,newSave:newSave}, {}, function (data) {
|
|
|
+
|
|
|
+ })
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查配送规则字段
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+ var checkRuleError = function () {
|
|
|
if (!$scope.modifyRule.shippingMethod){
|
|
|
toaster.pop('error', "请选择配送方式");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
if(!$scope.modifyRule.ruleName){
|
|
|
toaster.pop('error', "请填写规则名称");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
if($scope.nameError){
|
|
|
toaster.pop('error', "最多可输入10个文字");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
if($scope.repeatError){
|
|
|
toaster.pop('error', "该规则名称已存在,请修改");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
/**
|
|
|
* TODO 暂时注释,以后在放出来
|
|
|
*/
|
|
|
// if(!$scope.orderType.normal && !$scope.orderType.preSale && !$scope.orderType.bill){
|
|
|
// toaster.pop('error', "请选择适用类型");
|
|
|
- // return;
|
|
|
+ // return false;
|
|
|
// }
|
|
|
// if(!$scope.modifyRule.userType){
|
|
|
// toaster.pop('error', "请选择适用类型");
|
|
|
- // return;
|
|
|
+ // return false;
|
|
|
// }
|
|
|
if ($scope.mapArray.length > 0){
|
|
|
$scope.modifyRule.qtyArea = angular.toJson($scope.mapArray);
|
|
|
}else {
|
|
|
toaster.pop('error', "您还没有选择任何地区");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!$scope.modifyRule.qtyArea){
|
|
|
+ toaster.pop('error', "您还没有选择任何地区");
|
|
|
+ return false;
|
|
|
}
|
|
|
if ($scope.modifyRule.fareType == 1){
|
|
|
if (!$scope.modifyRule.uniformPrice){
|
|
|
toaster.pop('error', "请输入统一规定运费");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
if ($scope.modifyRule.fareType == 2){
|
|
|
@@ -370,38 +371,57 @@ define([ 'app/app' ], function(app) {
|
|
|
});
|
|
|
if (lackData){
|
|
|
toaster.pop('error', "请完善计费方式");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
$scope.modifyRule.qtyFare = angular.toJson($scope.fareArray);
|
|
|
}
|
|
|
+ return true;
|
|
|
+ };
|
|
|
|
|
|
+ /**
|
|
|
+ * isAdd false-另存为
|
|
|
+ * @param isAdd
|
|
|
+ */
|
|
|
+ $scope.saveDistributionRule = function (isAdd) {
|
|
|
+ $q.all([checkRepeatName(!isAdd).$promise]).then(function(data) {
|
|
|
+ console.log(data[0]);
|
|
|
+ if (data){
|
|
|
+ $scope.repeatError = data[0].data;
|
|
|
+ }
|
|
|
+ var valid = checkRuleError();
|
|
|
+ console.log(valid);
|
|
|
+ if (!valid){
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- //拼接适用类型
|
|
|
- var typeArray = [];
|
|
|
- if ($scope.orderType.normal){
|
|
|
- typeArray.push(1201);
|
|
|
- }
|
|
|
- if ($scope.orderType.preSale){
|
|
|
- typeArray.push(1202);
|
|
|
- }
|
|
|
- if ($scope.orderType.bill){
|
|
|
- typeArray.push(1203);
|
|
|
- }
|
|
|
- $scope.modifyRule.orderType = typeArray.join("-");
|
|
|
+ //拼接适用类型
|
|
|
+ var typeArray = [];
|
|
|
+ if ($scope.orderType.normal){
|
|
|
+ typeArray.push(1201);
|
|
|
+ }
|
|
|
+ if ($scope.orderType.preSale){
|
|
|
+ typeArray.push(1202);
|
|
|
+ }
|
|
|
+ if ($scope.orderType.bill){
|
|
|
+ typeArray.push(1203);
|
|
|
+ }
|
|
|
+ $scope.modifyRule.orderType = typeArray.join("-");
|
|
|
|
|
|
- DistributionRule.saveRule({isAdd:isAdd, isActive:$scope.isActive}, $scope.modifyRule , function (data) {
|
|
|
- if (data){
|
|
|
- $scope.editFrame = false;
|
|
|
- $scope.tab = 'deliverRule';
|
|
|
- if (isAdd){
|
|
|
- toaster.pop('info', "保存成功");
|
|
|
- }else{
|
|
|
- toaster.pop('info', "新增规则成功");
|
|
|
+ DistributionRule.saveRule({isAdd:isAdd, isActive:$scope.isActive}, $scope.modifyRule , function (data) {
|
|
|
+ if (data){
|
|
|
+ $scope.editFrame = false;
|
|
|
+ $scope.tab = 'deliverRule';
|
|
|
+ if (isAdd){
|
|
|
+ toaster.pop('info', "保存成功");
|
|
|
+ }else{
|
|
|
+ toaster.pop('info', "新增规则成功");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- },function (error) {
|
|
|
- toaster.pop('error', "保存配送规则失败");
|
|
|
- })
|
|
|
+ },function (error) {
|
|
|
+ toaster.pop('error', "保存配送规则失败");
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
};
|
|
|
|
|
|
// 切换计费类型
|
|
|
@@ -638,7 +658,6 @@ define([ 'app/app' ], function(app) {
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
- console.log(me.$data);
|
|
|
me._updateParentsCheck(me.$data);
|
|
|
}
|
|
|
};
|