selectBrandModel.js
6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
(function (angular) {
function selectBrandModel($scope, $rootScope, merchant, $uibModalInstance, aiNicheService, $filter) {
$scope.isSuper = $rootScope.loginUser.isSuper
$scope.merchant = merchant
//主营品牌操作
$scope.searchCar = '';
$scope.carBrandOptions_copy = []
$scope.$watch('searchCar', function (newValue) {
$scope.carBrandOptions = [];
$scope.carBrandOptions_copy.forEach(function (el) {
if (el.name.indexOf(newValue) !== -1) {
$scope.carBrandOptions.push(el)
}
})
})
$scope.toggleCarBrand = function (index, type) {
// console.log("传入的参数:" + "index : " + index + " type : " + type);
if (type == 2) {
$scope.carBrandOptions[index].toggle = !$scope.carBrandOptions[index].toggle;
}
// console.log($scope.carBrandOptions[index].carSeresList_copy)
if (!$scope.carBrandOptions[index].carSeresList_copy) {
$scope.carBrandOptions[index].childs1 = $scope.carBrandOptions[index].childs;
$scope.carBrandOptions[index].carSeresList_copy = $scope.carBrandOptions[index].childs;
angular.element(`#search-${index}`)[0].addEventListener('input', function (val) {
var value = val.target.value;
$scope.carBrandOptions[index].childs1 = [];
$scope.carBrandOptions[index].carSeresList_copy.forEach(function (el) {
if (el.name.indexOf(value) !== -1) {
$scope.carBrandOptions[index].childs1.push(el)
}
$scope.$apply();
})
})
if (type == 1) {
angular.forEach($scope.carBrandOptions[index].childs1, function (k) {
k.checked = $scope.carBrandOptions[index].checked;
angular.forEach(k.childs, function (e) {
e.checked = k.checked;
});
});
}
} else {
if (type == 1) {
angular.forEach($scope.carBrandOptions[index].childs1, function (k) {
k.checked = $scope.carBrandOptions[index].checked;
angular.forEach(k.childs, function (e) {
e.checked = k.checked;
});
});
}
if (type == 3) {
var ifOneChecked = false;
for (var i = 0; i < $scope.carBrandOptions[index].childs1.length; i++) {
if ($scope.carBrandOptions[index].childs1[i].checked) {
ifOneChecked = true;
angular.forEach($scope.carBrandOptions[index].childs1[i].childs, function (k) {
k.checked = $scope.carBrandOptions[index].childs1[i].checked;
});
break;
} else {
angular.forEach($scope.carBrandOptions[index].childs1[i].childs, function (k) {
k.checked = $scope.carBrandOptions[index].childs1[i].checked;
});
}
}
if (ifOneChecked) {
$scope.carBrandOptions[index].checked = true;
} else {
$scope.carBrandOptions[index].checked = false;
}
}
}
};
$scope.selectCarSmallBrandArr = [];
$scope.getCheckedCarBrand = function () {
var selectCarSmallBrandArr = [];
var carBrandSelectItems = $filter('filter')($scope.carBrandOptions, {
checked: true
}, true);
angular.forEach(carBrandSelectItems, function (k) {
var carSmallBrandSelectItems = $filter('filter')(k.childs1, {
checked: true
}, true);
angular.forEach(carSmallBrandSelectItems, function (e) {
if (!e.disabled) {
selectCarSmallBrandArr.push({
'brandId': k.id,
'brandName': k.name,
'brandLogo': k.logoUrl,
'childsBrandId': e.id,
'childsBrandName': e.name
});
}
});
});
$scope.selectCarSmallBrandArr = selectCarSmallBrandArr;
};
/**
* 关闭弹框方法
* */
$scope.handleClose = function () {
$uibModalInstance.dismiss(0);
};
$scope.handleConfirm = function () {
//主营品牌数据
$scope.getCheckedCarBrand();
// if ($scope.selectCarSmallBrandArr.length > 0) {
// params.carBrandList = $scope.selectCarSmallBrandArr;
// }
// console.log($scope.selectCarSmallBrandArr)
aiNicheService.addCarRules($scope.selectCarSmallBrandArr, function (res) {
swal({
type: res.returnCode == 0 ? 'success' : 'error',
title: '',
html: true,
text: res.returnCode == 0 ? '添加成功' : res.message,
showConfirmButton: false,
timer: 1000
});
if (res.returnCode == 0) {
$uibModalInstance.close(true);
}
})
}
$scope.selectedBrandList = []
$scope.init = function () {
apiName = $scope.isSuper ? 'getAllCarBrandList' : 'getMerchantCarBrand'
aiNicheService.getAllVehicleBrand(function (res) {
if(res.data){
res.data.forEach(function (item, index) {
item.childs.forEach(function (subItem, subIndex) {
$scope.selectedBrandList.push({
brandId: item.id,
childsBrandId: subItem.id
})
})
})
}
//获取车品牌
aiNicheService[apiName](function (subRes) {
$scope.carBrandOptions = subRes.data;
$scope.carBrandOptions_copy = subRes.data
angular.forEach($scope.selectedBrandList, function (i) {
angular.forEach($scope.carBrandOptions, function (j, index) {
if (i.brandId == j.id) {
j.checked = true;
j.disabled = true;
$scope.carBrandOptions[index].childs1 = $scope.carBrandOptions[index].childs;
$scope.carBrandOptions[index].carSeresList_copy = $scope.carBrandOptions[index].childs;
angular.forEach($scope.carBrandOptions[index].childs1, function (k, index1) {
if (!i.childsBrandId || i.childsBrandId == k.id) {
k.checked = true;
k.disabled = true;
}
});
}
});
});
});
});
}
$scope.init();
}
angular.module('AIniche').controller('selectBrandModel', selectBrandModel);
})(angular);