|
@@ -0,0 +1,374 @@
|
|
1
|
+'use strict';
|
|
2
|
+/**
|
|
3
|
+ * controller for User Profile Example
|
|
4
|
+ */
|
|
5
|
+app.controller('thirdPartyCompanyCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_login",'api_wechatfile', function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login,api_wechatfile) {
|
|
6
|
+ $scope.langs = i18nService.getAllLangs();
|
|
7
|
+ $scope.lang = 'zh-cn';
|
|
8
|
+
|
|
9
|
+ i18nService.setCurrentLang($scope.lang);
|
|
10
|
+
|
|
11
|
+ var loginUser = $rootScope.user;
|
|
12
|
+ $scope.xinzeng = false;
|
|
13
|
+ $scope.shanchu = false;
|
|
14
|
+ $scope.bianji = false;
|
|
15
|
+ $scope.chongzhimima = false;
|
|
16
|
+ for (var i = 0; i < loginUser.menu.length; i++) {
|
|
17
|
+ if (loginUser.menu[i].link == "renyuanguanli_xinzeng") {
|
|
18
|
+ $scope.xinzeng = true
|
|
19
|
+ }
|
|
20
|
+ if (loginUser.menu[i].link == "renyuanguanli_shanchu") {
|
|
21
|
+ $scope.shanchu = true
|
|
22
|
+ }
|
|
23
|
+ if (loginUser.menu[i].link == "renyuanguanli_bianji") {
|
|
24
|
+ $scope.bianji = true
|
|
25
|
+ }
|
|
26
|
+ if (loginUser.menu[i].link == "renyuanguanli_chongzhimima") {
|
|
27
|
+ $scope.chongzhimima = true
|
|
28
|
+ }
|
|
29
|
+ }
|
|
30
|
+ $scope.gridOptions = {};
|
|
31
|
+ $scope.gridOptions.data = 'myData';
|
|
32
|
+ $scope.gridOptions.enableColumnResizing = true;
|
|
33
|
+ $scope.gridOptions.enableFiltering = true;
|
|
34
|
+ $scope.gridOptions.enableGridMenu = true;
|
|
35
|
+ $scope.gridOptions.enableRowSelection = true;
|
|
36
|
+ $scope.gridOptions.showGridFooter = true;
|
|
37
|
+ $scope.gridOptions.showColumnFooter = false;
|
|
38
|
+ $scope.gridOptions.fastWatch = true;
|
|
39
|
+ $scope.gridOptions.useExternalFiltering = true;
|
|
40
|
+ $scope.gridOptions.useExternalPagination = true;
|
|
41
|
+ $scope.gridOptions.paginationPageSizes = [10];
|
|
42
|
+ $scope.gridOptions.paginationPageSize = 10;
|
|
43
|
+ $scope.gridOptions.multiSelect = false;
|
|
44
|
+
|
|
45
|
+ $scope.gridOptions.rowIdentity = function (row) {
|
|
46
|
+ return row.id;
|
|
47
|
+ };
|
|
48
|
+ $scope.gridOptions.getRowIdentity = function (row) {
|
|
49
|
+ return row.id;
|
|
50
|
+ };
|
|
51
|
+ //remote data
|
|
52
|
+
|
|
53
|
+ $scope.gridOptions.columnDefs = [{
|
|
54
|
+ name: 'item',
|
|
55
|
+ displayName: '序号',
|
|
56
|
+ width: '5%',
|
|
57
|
+ minWidth: '70',
|
|
58
|
+ enableFiltering: false,
|
|
59
|
+ cellTemplate: '<div>' +
|
|
60
|
+ '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
|
|
61
|
+ '</div>'
|
|
62
|
+ },
|
|
63
|
+ {
|
|
64
|
+ name: 'name',
|
|
65
|
+ displayName: '公司名称',
|
|
66
|
+ width: '20%',
|
|
67
|
+ minWidth: '100',
|
|
68
|
+ enableFiltering: false
|
|
69
|
+ },
|
|
70
|
+ {
|
|
71
|
+ name: 'contacts',
|
|
72
|
+ displayName: '公司联系人',
|
|
73
|
+ width: '20%',
|
|
74
|
+ minWidth: '100',
|
|
75
|
+ enableFiltering: false
|
|
76
|
+ },
|
|
77
|
+ {
|
|
78
|
+ name: 'mphone',
|
|
79
|
+ displayName: '联系人电话',
|
|
80
|
+ width: '20%',
|
|
81
|
+ minWidth: '120',
|
|
82
|
+ enableFiltering: false
|
|
83
|
+ },
|
|
84
|
+ {
|
|
85
|
+ name: 'serviceTypeNames',
|
|
86
|
+ displayName: '公司服务种类',
|
|
87
|
+ width: '20%',
|
|
88
|
+ minWidth: '120',
|
|
89
|
+ enableFiltering: false,
|
|
90
|
+ // cellTemplate: '<div>' +
|
|
91
|
+ // '<div class="ui-grid-cell-contents">{{row.entity.userType.value == 2 ?row.entity.company.name:row.entity.userType.name}}</div>' +
|
|
92
|
+ // '</div>'
|
|
93
|
+ },
|
|
94
|
+ {
|
|
95
|
+ name: '操作',
|
|
96
|
+ width: '10%',
|
|
97
|
+ minWidth: '100',
|
|
98
|
+ cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
|
|
99
|
+ '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
|
|
100
|
+ '</div></div>',
|
|
101
|
+ enableFiltering: false
|
|
102
|
+ }
|
|
103
|
+ ];
|
|
104
|
+ $scope.groupdata = {};
|
|
105
|
+ $scope.my_data = [];
|
|
106
|
+
|
|
107
|
+ $scope.select_treedata = [];
|
|
108
|
+ $scope.propTypeOptions = [];
|
|
109
|
+
|
|
110
|
+ $scope.saveData = function (data) {
|
|
111
|
+ var modelData = {
|
|
112
|
+ model: {
|
|
113
|
+ company: data
|
|
114
|
+ }
|
|
115
|
+ };
|
|
116
|
+ modelData.model.company = {
|
|
117
|
+ categoryTypeIds: data.categoryTypeIds,//事件分类
|
|
118
|
+ contacts: data.contacts,//联系人
|
|
119
|
+ id: data.id,//id
|
|
120
|
+ mphone: data.mphone,//联系电话
|
|
121
|
+ name: data.name,//公司名称
|
|
122
|
+ startTime: data.startTime,//开始时间
|
|
123
|
+ endTime: data.endTime,//结束时间
|
|
124
|
+ serviceTypeIds: data.serviceTypeIds,//服务分类ids
|
|
125
|
+ serviceTypeNames: data.serviceTypeNames//服务分类名称s
|
|
126
|
+ }
|
|
127
|
+ console.log(modelData)
|
|
128
|
+ $state.go('app.system.form', {
|
|
129
|
+ formKey: 'company_edit',
|
|
130
|
+ service: 'api_user_data',
|
|
131
|
+ model: JSON.stringify(modelData)
|
|
132
|
+ });
|
|
133
|
+ };
|
|
134
|
+ $scope.addData = function () {
|
|
135
|
+ var modelData = {
|
|
136
|
+ model: {
|
|
137
|
+ user: {}
|
|
138
|
+ }
|
|
139
|
+ };
|
|
140
|
+ $state.go('app.system.form', {
|
|
141
|
+ formKey: 'company_edit',
|
|
142
|
+ service: 'api_user_data',
|
|
143
|
+ model: JSON.stringify(modelData)
|
|
144
|
+ });
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+ $scope.removeData = function () {
|
|
150
|
+ var modalInstance = $modal.open({
|
|
151
|
+ templateUrl: 'assets/views/delete.html',
|
|
152
|
+ controller: function ($scope, scope, $modalInstance, api_bpm_data) {
|
|
153
|
+ var rmvList = [];
|
|
154
|
+ $scope.title = '第三方公司删除';
|
|
155
|
+ $scope.connect = '确定要删除此第三方公司?';
|
|
156
|
+ angular.forEach(scope.selected.items, function (item) {
|
|
157
|
+ rmvList.push(item.id);
|
|
158
|
+ });
|
|
159
|
+ $scope.ok = function () {
|
|
160
|
+ $modalInstance.close(rmvList);
|
|
161
|
+ };
|
|
162
|
+ $scope.cancel = function () {
|
|
163
|
+ $modalInstance.dismiss('cancel');
|
|
164
|
+ };
|
|
165
|
+ },
|
|
166
|
+ size: 'sm',
|
|
167
|
+ resolve: {
|
|
168
|
+ scope: function () {
|
|
169
|
+ return $scope;
|
|
170
|
+ }
|
|
171
|
+ }
|
|
172
|
+ });
|
|
173
|
+ modalInstance.result.then(function (selectedItem) {
|
|
174
|
+ if (selectedItem) {
|
|
175
|
+ if (selectedItem.length > 0) {
|
|
176
|
+ api_user_data.rmvData('company', selectedItem).then(function (response) {
|
|
177
|
+ if (response.data[0].deleteFlag != 0) {
|
|
178
|
+ SweetAlert.swal({
|
|
179
|
+ title: "删除成功!",
|
|
180
|
+ type: "success",
|
|
181
|
+ confirmButtonColor: "#007AFF"
|
|
182
|
+ }, function () {
|
|
183
|
+ $scope.myData = _.reject($scope.myData, function (o) {
|
|
184
|
+ return _.includes(selectedItem, o.id);
|
|
185
|
+ });
|
|
186
|
+ $scope.selected = {
|
|
187
|
+ items: []
|
|
188
|
+ };
|
|
189
|
+ $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
|
|
190
|
+ $scope.gridApi.grid.selection.selectedCount = 0;
|
|
191
|
+ });
|
|
192
|
+
|
|
193
|
+ } else {
|
|
194
|
+ SweetAlert.swal({
|
|
195
|
+ title: "无法删除!",
|
|
196
|
+ text: "【"+response.data[0].name+"】已经绑定了用户!",
|
|
197
|
+ type: "error"
|
|
198
|
+ });
|
|
199
|
+ }
|
|
200
|
+ })
|
|
201
|
+ }
|
|
202
|
+ }
|
|
203
|
+ })
|
|
204
|
+ }
|
|
205
|
+ //获取公司服务种类
|
|
206
|
+ $scope.company_service_type = [];
|
|
207
|
+ $scope.getCompanyServiceTypes = function(){
|
|
208
|
+ api_wechatfile.getDictionary({
|
|
209
|
+ key: "company_service_type",
|
|
210
|
+ type: "list"
|
|
211
|
+ }).then(function (res) {
|
|
212
|
+ $scope.company_service_type = res;
|
|
213
|
+ $scope.refreshData('expand-right', $scope.fileData);
|
|
214
|
+ $scope.timer = $interval(function () {
|
|
215
|
+ $scope.refreshData('expand-right', $scope.fileData);
|
|
216
|
+ }, $rootScope.refreshTime);
|
|
217
|
+ })
|
|
218
|
+ }
|
|
219
|
+ $scope.getCompanyServiceTypes();
|
|
220
|
+
|
|
221
|
+ $scope.selected = {
|
|
222
|
+ items: []
|
|
223
|
+ }
|
|
224
|
+
|
|
225
|
+ $scope.editted = {
|
|
226
|
+ items: []
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ $scope.gridOptions.onRegisterApi = function (gridApi) {
|
|
230
|
+ $scope.gridApi = gridApi;
|
|
231
|
+ gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
|
|
232
|
+ var filtersData = $scope.memoryfilterData;
|
|
233
|
+ filtersData.idx = newPage - 1;
|
|
234
|
+ filtersData.sum = pageSize;
|
|
235
|
+ $scope.fileData.idx = newPage - 1;
|
|
236
|
+ $scope.fileData.sum = pageSize;
|
|
237
|
+ defaultFilterData = filtersData;
|
|
238
|
+ $scope.refreshData('expand-right', $scope.fileData);
|
|
239
|
+ });
|
|
240
|
+
|
|
241
|
+ gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
|
|
242
|
+ var j = 0;
|
|
243
|
+ for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
|
|
244
|
+ if (scope.grid.appScope.selected.items[i] == scope.entity) {
|
|
245
|
+ j++;
|
|
246
|
+ break;
|
|
247
|
+ }
|
|
248
|
+ }
|
|
249
|
+ if (j == 1) {
|
|
250
|
+ scope.grid.appScope.selected.items.splice(i, 1);
|
|
251
|
+ } else {
|
|
252
|
+ scope.grid.appScope.selected.items.push(scope.entity)
|
|
253
|
+ }
|
|
254
|
+ });
|
|
255
|
+ gridApi.core.on.filterChanged($scope, function () {
|
|
256
|
+ var grid = this.grid;
|
|
257
|
+ var filtersData = $scope.memoryfilterData;
|
|
258
|
+ angular.forEach(grid.columns, function (item) {
|
|
259
|
+ if (item.enableFiltering) {
|
|
260
|
+ if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
|
|
261
|
+ if (angular.isUndefined(filtersData['company'])) {
|
|
262
|
+ filtersData['company'] = {};
|
|
263
|
+ filtersData['company']['flag'] = -1;
|
|
264
|
+ filtersData['company'][item.field] = item.filters[0].term;
|
|
265
|
+ } else {
|
|
266
|
+ filtersData.company.flag = -1;
|
|
267
|
+ filtersData.company[item.field] = item.filters[0].term;
|
|
268
|
+ }
|
|
269
|
+ }
|
|
270
|
+ }
|
|
271
|
+ });
|
|
272
|
+ $scope.memoryfilterData = filtersData;
|
|
273
|
+ $scope.refreshData('expand-right', $scope.fileData);
|
|
274
|
+ });
|
|
275
|
+ };
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+ var defaultFilterData = {
|
|
279
|
+ "idx": 0,
|
|
280
|
+ "sum": 10
|
|
281
|
+ };
|
|
282
|
+
|
|
283
|
+ $scope.memoryfilterData = {
|
|
284
|
+ "idx": 0,
|
|
285
|
+ "sum": 10
|
|
286
|
+ }
|
|
287
|
+
|
|
288
|
+ $scope.ldloading = {};
|
|
289
|
+ $scope.fileData = {
|
|
290
|
+ "idx": 0,
|
|
291
|
+ "sum": 10,
|
|
292
|
+ "company": {}
|
|
293
|
+ }
|
|
294
|
+ $scope.treeItem = "";
|
|
295
|
+ $scope.onFilterCallback = function (item) {
|
|
296
|
+ $scope.treeItem = item
|
|
297
|
+ }
|
|
298
|
+ // 搜索
|
|
299
|
+ $scope.searchData = function () {
|
|
300
|
+ if ($scope.treeItem) {
|
|
301
|
+ $scope.fileData.company.groupdata = $scope.treeItem
|
|
302
|
+ }
|
|
303
|
+ if($scope.fileData.company.name){
|
|
304
|
+ $scope.fileData.company.selectType= "pinyin_qs"
|
|
305
|
+ }
|
|
306
|
+ $scope.refreshData('expand-right', $scope.fileData);
|
|
307
|
+ }
|
|
308
|
+ // 清空
|
|
309
|
+ $scope.clean = function () {
|
|
310
|
+ delete $scope.fileData.company.account;
|
|
311
|
+ delete $scope.fileData.company.name;
|
|
312
|
+ delete $scope.fileData.company.groupdata;
|
|
313
|
+ $scope.treeItem = "";
|
|
314
|
+ $scope.refreshData('expand-right', $scope.fileData);
|
|
315
|
+ }
|
|
316
|
+ //刷新
|
|
317
|
+ $scope.refresh = function (style, filterData) {
|
|
318
|
+ $scope.selected = {
|
|
319
|
+ items: []
|
|
320
|
+ };
|
|
321
|
+ if ($scope.gridApi) {
|
|
322
|
+ $scope.gridApi.grid.selection.selectedCount = 0;
|
|
323
|
+ }
|
|
324
|
+ $scope.refreshData('expand-right', $scope.fileData);
|
|
325
|
+ }
|
|
326
|
+ //获取列表数据
|
|
327
|
+ $scope.refreshData = function (style, filterData) {
|
|
328
|
+ console.log(filterData)
|
|
329
|
+ $scope.ldloading[style.replace('-', '_')] = true;
|
|
330
|
+ if (angular.isUndefined(filterData)) {
|
|
331
|
+ filterData = defaultFilterData;
|
|
332
|
+ }
|
|
333
|
+ if (angular.isDefined($scope.searchTypes)) {
|
|
334
|
+ filterData['searchType'] = $scope.searchTypes;
|
|
335
|
+ }
|
|
336
|
+ $scope.myData = [];
|
|
337
|
+ filterData['flag'] = -1;
|
|
338
|
+ console.log("filterData=" + JSON.stringify(filterData))
|
|
339
|
+ api_user_data.fetchDataList('company', filterData).then(function (data) {
|
|
340
|
+ var myData = Restangular.stripRestangular(data);
|
|
341
|
+ $scope.gridOptions.totalItems = myData.totalNum;
|
|
342
|
+ //数据转换start
|
|
343
|
+ myData.list.forEach(function(v){
|
|
344
|
+ if(v.serviceTypeIds){
|
|
345
|
+ var sArr = v.serviceTypeIds.split(',');
|
|
346
|
+ var sNameArr = [];
|
|
347
|
+ $scope.company_service_type.forEach(function(v1){
|
|
348
|
+ sArr.forEach(function(v2){
|
|
349
|
+ if(v1.id == v2){
|
|
350
|
+ sNameArr.push(v1.name);
|
|
351
|
+ }
|
|
352
|
+ })
|
|
353
|
+ })
|
|
354
|
+ v.serviceTypeNames = sNameArr.join(',');//公司服务种类名称
|
|
355
|
+ }
|
|
356
|
+ })
|
|
357
|
+ console.log(myData.list);
|
|
358
|
+ //数据转换end
|
|
359
|
+ $scope.myData = myData.list;
|
|
360
|
+ for (var i = 0; i < $scope.myData.length; i++) {
|
|
361
|
+ $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
|
|
362
|
+ }
|
|
363
|
+ $scope.ldloading[style.replace('-', '_')] = false;
|
|
364
|
+ }, function () {
|
|
365
|
+ $scope.ldloading[style.replace('-', '_')] = false;
|
|
366
|
+ });
|
|
367
|
+
|
|
368
|
+ };
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+ $scope.$on('$destroy', function () {
|
|
372
|
+ $interval.cancel($scope.timer)
|
|
373
|
+ });
|
|
374
|
+}]);
|