|
@@ -44,6 +44,36 @@ app.controller("summaryDetailCtrl", [
|
44
|
44
|
|
45
|
45
|
i18nService.setCurrentLang($scope.lang);
|
46
|
46
|
|
|
47
|
+ var loginUser = $rootScope.user;
|
|
48
|
+ $scope.summary_hc_add = false;
|
|
49
|
+ $scope.summary_hc_remove = false;
|
|
50
|
+ $scope.summary_hc_edit = false;
|
|
51
|
+
|
|
52
|
+ $scope.summary_gs_add = false;
|
|
53
|
+ $scope.summary_gs_remove = false;
|
|
54
|
+ $scope.summary_gs_edit = false;
|
|
55
|
+ for (var i = 0; i < loginUser.menu.length; i++) {
|
|
56
|
+ if (loginUser.menu[i].link == "summary_hc_add") {
|
|
57
|
+ $scope.summary_hc_add = true;
|
|
58
|
+ }
|
|
59
|
+ if (loginUser.menu[i].link == "summary_hc_remove") {
|
|
60
|
+ $scope.summary_hc_remove = true;
|
|
61
|
+ }
|
|
62
|
+ if (loginUser.menu[i].link == "summary_hc_edit") {
|
|
63
|
+ $scope.summary_hc_edit = true;
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ if (loginUser.menu[i].link == "summary_gs_add") {
|
|
67
|
+ $scope.summary_gs_add = true;
|
|
68
|
+ }
|
|
69
|
+ if (loginUser.menu[i].link == "summary_gs_remove") {
|
|
70
|
+ $scope.summary_gs_remove = true;
|
|
71
|
+ }
|
|
72
|
+ if (loginUser.menu[i].link == "summary_gs_edit") {
|
|
73
|
+ $scope.summary_gs_edit = true;
|
|
74
|
+ }
|
|
75
|
+ }
|
|
76
|
+
|
47
|
77
|
// 获取信息
|
48
|
78
|
$scope.consumableList = [];
|
49
|
79
|
$scope.incidentDTO = {};
|
|
@@ -120,9 +150,356 @@ app.controller("summaryDetailCtrl", [
|
120
|
150
|
}
|
121
|
151
|
]
|
122
|
152
|
}).then(
|
123
|
|
- function (data) {
|
|
153
|
+ function (response) {
|
|
154
|
+ $rootScope.isMask = false;
|
|
155
|
+ if(response.status == 200){
|
|
156
|
+ SweetAlert.swal({
|
|
157
|
+ title: "撤销成功!",
|
|
158
|
+ type: "success"
|
|
159
|
+ }, function() {
|
|
160
|
+ $scope.getInfo()
|
|
161
|
+ })
|
|
162
|
+ } else {
|
|
163
|
+ SweetAlert.swal({
|
|
164
|
+ title: "撤销失败!",
|
|
165
|
+ text: response.msg || '请求数据失败!',
|
|
166
|
+ type: "error"
|
|
167
|
+ }, function() {
|
|
168
|
+ $scope.getInfo()
|
|
169
|
+ })
|
|
170
|
+ }
|
|
171
|
+ },
|
|
172
|
+ function () {
|
|
173
|
+ $rootScope.isMask = false;
|
|
174
|
+ }
|
|
175
|
+ );
|
|
176
|
+ }
|
|
177
|
+ },
|
|
178
|
+ function () {}
|
|
179
|
+ );
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ const uniqBy = (arr, predicate) => {
|
|
183
|
+ const cb = typeof predicate === 'function' ? predicate : (o) => o[predicate];
|
|
184
|
+
|
|
185
|
+ return [...arr.reduce((map, item) => {
|
|
186
|
+ const key = (item === null || item === undefined) ?
|
|
187
|
+ item : cb(item);
|
|
188
|
+
|
|
189
|
+ map.has(key) || map.set(key, item);
|
|
190
|
+
|
|
191
|
+ return map;
|
|
192
|
+ }, new Map()).values()];
|
|
193
|
+ };
|
|
194
|
+
|
|
195
|
+ // 修改耗材
|
|
196
|
+ $scope.updateHc = function(consumable){
|
|
197
|
+ console.log(consumable)
|
|
198
|
+ var modalInstance = $modal.open({
|
|
199
|
+ templateUrl: 'assets/views/system/tpl/hcChange.html',
|
|
200
|
+ controller: function($scope, scope, $modalInstance, api_user_data, api_bpm) {
|
|
201
|
+ $scope.title = '耗材修改';
|
|
202
|
+ $scope.isAdd = false;
|
|
203
|
+ $scope.dataInfo = {
|
|
204
|
+ num: consumable.consumablesNum,
|
|
205
|
+ consumable: {id: consumable.consumableId, name: consumable.consumableName},
|
|
206
|
+ }
|
|
207
|
+
|
|
208
|
+ $scope.getHcList=function(keyword = ''){
|
|
209
|
+ // 查询故障耗材列表
|
|
210
|
+ var postData = {
|
|
211
|
+ "idx": 0,
|
|
212
|
+ "sum": 20,
|
|
213
|
+ incidentCategoryConsumable: {
|
|
214
|
+ duty: $stateParams.dutyId,
|
|
215
|
+ category: { id: $stateParams.categoryId },
|
|
216
|
+ }
|
|
217
|
+ };
|
|
218
|
+ api_user_data.fetchDataList('incidentCategoryConsumable',postData).then(function(res){
|
|
219
|
+ if(res.status == 200){
|
|
220
|
+ let list = res.list || [];
|
|
221
|
+ if(list.length){
|
|
222
|
+ let arr = list.map(v => v.consumableDTOS).flat();
|
|
223
|
+ $scope.hcList = uniqBy(arr, 'id');
|
|
224
|
+ }else{
|
|
225
|
+ // 查询耗材列表
|
|
226
|
+ var postData = {
|
|
227
|
+ "idx": 0,
|
|
228
|
+ "sum": 20,
|
|
229
|
+ consumable: {
|
|
230
|
+ keyWord: keyword,
|
|
231
|
+ dutyDTO: { id: $stateParams.dutyId },
|
|
232
|
+ showZero: true,
|
|
233
|
+ }
|
|
234
|
+ };
|
|
235
|
+
|
|
236
|
+ api_user_data.fetchDataList('consumable',postData).then(function(res){
|
|
237
|
+ if(res.status == 200){
|
|
238
|
+ $scope.hcList = res.list || [];
|
|
239
|
+ }else{
|
|
240
|
+ uni.showToast({
|
|
241
|
+ icon: 'none',
|
|
242
|
+ title: res.msg || '请求数据失败!'
|
|
243
|
+ });
|
|
244
|
+ }
|
|
245
|
+ })
|
|
246
|
+ }
|
|
247
|
+ }else{
|
|
248
|
+ uni.showToast({
|
|
249
|
+ icon: 'none',
|
|
250
|
+ title: res.msg || '请求数据失败!'
|
|
251
|
+ });
|
|
252
|
+ }
|
|
253
|
+ })
|
|
254
|
+ }
|
|
255
|
+ $scope.getHcList();
|
|
256
|
+ $scope.changeNum = function(val){
|
|
257
|
+ $scope.dataInfo.num = val?Math.abs(parseFloat(val.toFixed(2), 10)):val;
|
|
258
|
+ }
|
|
259
|
+ $scope.cancel = function() {
|
|
260
|
+ $modalInstance.dismiss('cancel');
|
|
261
|
+ };
|
|
262
|
+ $scope.savercode = function() {
|
|
263
|
+ if ($scope.dataInfo.num && $scope.dataInfo.consumable && $scope.dataInfo.consumable.id){
|
|
264
|
+ $rootScope.isMask = true;
|
|
265
|
+ let postData = {
|
|
266
|
+ "consumableList": [
|
|
267
|
+ {
|
|
268
|
+ "consumablesId": $scope.dataInfo.consumable ? $scope.dataInfo.consumable.id : undefined,
|
|
269
|
+ "consumablesNum": $scope.dataInfo.num
|
|
270
|
+ }
|
|
271
|
+ ],
|
|
272
|
+ modifyNum: "edit",
|
|
273
|
+ "summaryId": $stateParams.id,
|
|
274
|
+ };
|
|
275
|
+ api_bpm.addSummaryDoc(postData).then(function(response) {
|
|
276
|
+ if (response) {
|
|
277
|
+ if (response.status == 200) {
|
|
278
|
+ SweetAlert.swal({
|
|
279
|
+ title: "修改成功!",
|
|
280
|
+ type: "success"
|
|
281
|
+ }, function() {
|
|
282
|
+ scope.getInfo()
|
|
283
|
+ })
|
|
284
|
+ } else {
|
|
285
|
+ SweetAlert.swal({
|
|
286
|
+ title: "修改失败!",
|
|
287
|
+ text: response.msg || '请求数据失败!',
|
|
288
|
+ type: "error"
|
|
289
|
+ }, function() {
|
|
290
|
+ scope.getInfo()
|
|
291
|
+ })
|
|
292
|
+ }
|
|
293
|
+ $modalInstance.close();
|
|
294
|
+ }else{
|
|
295
|
+ SweetAlert.swal({
|
|
296
|
+ title: "修改失败!",
|
|
297
|
+ text: response.msg || '请求数据失败!',
|
|
298
|
+ type: "error"
|
|
299
|
+ }, function() {
|
|
300
|
+ scope.getInfo()
|
|
301
|
+ })
|
|
302
|
+ }
|
|
303
|
+ })
|
|
304
|
+
|
|
305
|
+ }else{
|
|
306
|
+ SweetAlert.swal({
|
|
307
|
+ title: "新增失败!",
|
|
308
|
+ text: "请填写必填项!",
|
|
309
|
+ type: "error",
|
|
310
|
+ confirmButtonColor: "#DD6B55"
|
|
311
|
+ }, function () {
|
|
312
|
+
|
|
313
|
+ });
|
|
314
|
+ }
|
|
315
|
+ }
|
|
316
|
+ },
|
|
317
|
+ resolve: {
|
|
318
|
+ scope: function() {
|
|
319
|
+ return $scope;
|
|
320
|
+ }
|
|
321
|
+ }
|
|
322
|
+ });
|
|
323
|
+ }
|
|
324
|
+
|
|
325
|
+ // 新增耗材
|
|
326
|
+ $scope.addHc = function(){
|
|
327
|
+ var modalInstance = $modal.open({
|
|
328
|
+ templateUrl: 'assets/views/system/tpl/hcChange.html',
|
|
329
|
+ controller: function($scope, scope, $modalInstance, api_user_data, api_bpm) {
|
|
330
|
+ $scope.title = '耗材新增';
|
|
331
|
+ $scope.isAdd = true;
|
|
332
|
+ $scope.dataInfo = {
|
|
333
|
+ num: 1,
|
|
334
|
+ consumable: null,
|
|
335
|
+ }
|
|
336
|
+
|
|
337
|
+ $scope.getHcList=function(keyword = ''){
|
|
338
|
+ // 查询故障耗材列表
|
|
339
|
+ var postData = {
|
|
340
|
+ "idx": 0,
|
|
341
|
+ "sum": 20,
|
|
342
|
+ incidentCategoryConsumable: {
|
|
343
|
+ duty: $stateParams.dutyId,
|
|
344
|
+ category: { id: $stateParams.categoryId },
|
|
345
|
+ }
|
|
346
|
+ };
|
|
347
|
+ api_user_data.fetchDataList('incidentCategoryConsumable',postData).then(function(res){
|
|
348
|
+ if(res.status == 200){
|
|
349
|
+ let list = res.list || [];
|
|
350
|
+ if(list.length){
|
|
351
|
+ let arr = list.map(v => v.consumableDTOS).flat();
|
|
352
|
+ $scope.hcList = uniqBy(arr, 'id');
|
|
353
|
+ }else{
|
|
354
|
+ // 查询耗材列表
|
|
355
|
+ var postData = {
|
|
356
|
+ "idx": 0,
|
|
357
|
+ "sum": 20,
|
|
358
|
+ consumable: {
|
|
359
|
+ keyWord: keyword,
|
|
360
|
+ dutyDTO: { id: $stateParams.dutyId },
|
|
361
|
+ showZero: true,
|
|
362
|
+ }
|
|
363
|
+ };
|
|
364
|
+
|
|
365
|
+ api_user_data.fetchDataList('consumable',postData).then(function(res){
|
|
366
|
+ if(res.status == 200){
|
|
367
|
+ $scope.hcList = res.list || [];
|
|
368
|
+ }else{
|
|
369
|
+ uni.showToast({
|
|
370
|
+ icon: 'none',
|
|
371
|
+ title: res.msg || '请求数据失败!'
|
|
372
|
+ });
|
|
373
|
+ }
|
|
374
|
+ })
|
|
375
|
+ }
|
|
376
|
+ }else{
|
|
377
|
+ uni.showToast({
|
|
378
|
+ icon: 'none',
|
|
379
|
+ title: res.msg || '请求数据失败!'
|
|
380
|
+ });
|
|
381
|
+ }
|
|
382
|
+ })
|
|
383
|
+ }
|
|
384
|
+ $scope.getHcList();
|
|
385
|
+ $scope.changeNum = function(val){
|
|
386
|
+ $scope.dataInfo.num = val?Math.abs(parseFloat(val.toFixed(2), 10)):val;
|
|
387
|
+ }
|
|
388
|
+ $scope.cancel = function() {
|
|
389
|
+ $modalInstance.dismiss('cancel');
|
|
390
|
+ };
|
|
391
|
+ $scope.savercode = function() {
|
|
392
|
+ if ($scope.dataInfo.num && $scope.dataInfo.consumable && $scope.dataInfo.consumable.id){
|
|
393
|
+ $rootScope.isMask = true;
|
|
394
|
+ let postData = {
|
|
395
|
+ "consumableList": [
|
|
396
|
+ {
|
|
397
|
+ "consumablesId": $scope.dataInfo.consumable ? $scope.dataInfo.consumable.id : undefined,
|
|
398
|
+ "consumablesNum": $scope.dataInfo.num
|
|
399
|
+ }
|
|
400
|
+ ],
|
|
401
|
+ "summaryId": $stateParams.id,
|
|
402
|
+ };
|
|
403
|
+ api_bpm.addSummaryDoc(postData).then(function(response) {
|
|
404
|
+ if (response) {
|
|
405
|
+ if (response.status == 200) {
|
|
406
|
+ SweetAlert.swal({
|
|
407
|
+ title: "新增成功!",
|
|
408
|
+ type: "success"
|
|
409
|
+ }, function() {
|
|
410
|
+ scope.getInfo()
|
|
411
|
+ })
|
|
412
|
+ } else {
|
|
413
|
+ SweetAlert.swal({
|
|
414
|
+ title: "新增失败!",
|
|
415
|
+ text: response.msg || '请求数据失败!',
|
|
416
|
+ type: "error"
|
|
417
|
+ }, function() {
|
|
418
|
+ scope.getInfo()
|
|
419
|
+ })
|
|
420
|
+ }
|
|
421
|
+ $modalInstance.close();
|
|
422
|
+ }else{
|
|
423
|
+ SweetAlert.swal({
|
|
424
|
+ title: "新增失败!",
|
|
425
|
+ text: response.msg || '请求数据失败!',
|
|
426
|
+ type: "error"
|
|
427
|
+ }, function() {
|
|
428
|
+ scope.getInfo()
|
|
429
|
+ })
|
|
430
|
+ }
|
|
431
|
+ })
|
|
432
|
+
|
|
433
|
+ }else{
|
|
434
|
+ SweetAlert.swal({
|
|
435
|
+ title: "新增失败!",
|
|
436
|
+ text: "请填写必填项!",
|
|
437
|
+ type: "error",
|
|
438
|
+ confirmButtonColor: "#DD6B55"
|
|
439
|
+ }, function () {
|
|
440
|
+
|
|
441
|
+ });
|
|
442
|
+ }
|
|
443
|
+ }
|
|
444
|
+ },
|
|
445
|
+ resolve: {
|
|
446
|
+ scope: function() {
|
|
447
|
+ return $scope;
|
|
448
|
+ }
|
|
449
|
+ }
|
|
450
|
+ });
|
|
451
|
+ }
|
|
452
|
+
|
|
453
|
+ // 撤销工时
|
|
454
|
+ $scope.removeGs = function(workHourManagement){
|
|
455
|
+ var modalInstance = $modal.open({
|
|
456
|
+ templateUrl: "assets/views/delete.html",
|
|
457
|
+ controller: function ($scope, $modalInstance) {
|
|
458
|
+ $scope.title = "撤销";
|
|
459
|
+ $scope.connect = "您确认要撤销此条工时("+ workHourManagement.workName + "【"+ workHourManagement.workHourNum2 +"】" +")的使用吗?";
|
|
460
|
+ $scope.ok = function () {
|
|
461
|
+ $modalInstance.close("start");
|
|
462
|
+ };
|
|
463
|
+
|
|
464
|
+ $scope.cancel = function () {
|
|
465
|
+ $modalInstance.dismiss("cancel");
|
|
466
|
+ };
|
|
467
|
+ },
|
|
468
|
+ size: "sm",
|
|
469
|
+ });
|
|
470
|
+
|
|
471
|
+ modalInstance.result.then(
|
|
472
|
+ function (result) {
|
|
473
|
+ if(result == 'start'){
|
|
474
|
+ $rootScope.isMask = true;
|
|
475
|
+ api_bpm_data.removeHc({
|
|
476
|
+ summaryId: +$stateParams.id,
|
|
477
|
+ remove: 'remove',
|
|
478
|
+ workHourManagementList: [
|
|
479
|
+ {
|
|
480
|
+ workHourId: workHourManagement.id,
|
|
481
|
+ workHourNum: workHourManagement.workHourNum,
|
|
482
|
+ }
|
|
483
|
+ ]
|
|
484
|
+ }).then(
|
|
485
|
+ function (response) {
|
124
|
486
|
$rootScope.isMask = false;
|
125
|
|
- $scope.getInfo();
|
|
487
|
+ if(response.status == 200){
|
|
488
|
+ SweetAlert.swal({
|
|
489
|
+ title: "撤销成功!",
|
|
490
|
+ type: "success"
|
|
491
|
+ }, function() {
|
|
492
|
+ $scope.getInfo()
|
|
493
|
+ })
|
|
494
|
+ } else {
|
|
495
|
+ SweetAlert.swal({
|
|
496
|
+ title: "撤销失败!",
|
|
497
|
+ text: response.msg || '请求数据失败!',
|
|
498
|
+ type: "error"
|
|
499
|
+ }, function() {
|
|
500
|
+ $scope.getInfo()
|
|
501
|
+ })
|
|
502
|
+ }
|
126
|
503
|
},
|
127
|
504
|
function () {
|
128
|
505
|
$rootScope.isMask = false;
|
|
@@ -133,5 +510,399 @@ app.controller("summaryDetailCtrl", [
|
133
|
510
|
function () {}
|
134
|
511
|
);
|
135
|
512
|
}
|
|
513
|
+
|
|
514
|
+ // 修改工时
|
|
515
|
+ $scope.updateGs = function(workHourManagement){
|
|
516
|
+ console.log(workHourManagement)
|
|
517
|
+ var modalInstance = $modal.open({
|
|
518
|
+ templateUrl: 'assets/views/system/tpl/gsChange.html',
|
|
519
|
+ controller: function($scope, scope, $modalInstance, api_user_data, api_bpm) {
|
|
520
|
+ $scope.title = '工时修改';
|
|
521
|
+ $scope.isAdd = false;
|
|
522
|
+ $scope.dataInfo = {
|
|
523
|
+ num: workHourManagement.workHourNum2,
|
|
524
|
+ workHourManagement: [{id: workHourManagement.id, name: workHourManagement.workName}],
|
|
525
|
+ }
|
|
526
|
+
|
|
527
|
+ // --------------------
|
|
528
|
+ $scope.select_treedata = [];
|
|
529
|
+ $rootScope.bala1 = $scope.getGsList = function (s, fn) {
|
|
530
|
+ if (s) {
|
|
531
|
+ var filterKeyword = s.filterKeyword;
|
|
532
|
+ }
|
|
533
|
+ var postData = {
|
|
534
|
+ idx: 0,
|
|
535
|
+ sum: 9999,
|
|
536
|
+ };
|
|
537
|
+ $scope.my_data = [];
|
|
538
|
+ $scope.doing_async = true;
|
|
539
|
+ api_bpm_data
|
|
540
|
+ .fetchDataList("workHourManagement", postData)
|
|
541
|
+ .then(function (response) {
|
|
542
|
+ if (response.status == 200) {
|
|
543
|
+ var data = response.list;
|
|
544
|
+ if (filterKeyword) {
|
|
545
|
+ data.forEach((e) => {
|
|
546
|
+ e.isExpanded = true;
|
|
547
|
+ });
|
|
548
|
+ var li = transform(data).children;
|
|
549
|
+ console.log(li);
|
|
550
|
+ fn(li);
|
|
551
|
+ return;
|
|
552
|
+ } else {
|
|
553
|
+ var objects = [];
|
|
554
|
+ for (var i = 0; i < data.length; i++) {
|
|
555
|
+ var object = {};
|
|
556
|
+ object.id = data[i].id;
|
|
557
|
+ object.parent = data[i].parent;
|
|
558
|
+ object.workName = data[i].workName;
|
|
559
|
+ object.isExpanded = true;
|
|
560
|
+ objects.push(object);
|
|
561
|
+ }
|
|
562
|
+ $scope.my_data = convertParentToChildList(objects);
|
|
563
|
+ $scope.select_treedata = angular.copy($scope.my_data);
|
|
564
|
+ console.log($scope.select_treedata)
|
|
565
|
+ }
|
|
566
|
+ if ($scope.my_data.length > 0) {
|
|
567
|
+ $scope.doing_async = false;
|
|
568
|
+ }
|
|
569
|
+ selectItem(workHourManagement,$scope.select_treedata);
|
|
570
|
+ $scope.dataInfo.workHourManagement = workHourManagement;
|
|
571
|
+ } else {
|
|
572
|
+ SweetAlert.swal({
|
|
573
|
+ title: "系统错误!",
|
|
574
|
+ text: "请刷新重试!",
|
|
575
|
+ type: "error",
|
|
576
|
+ });
|
|
577
|
+ }
|
|
578
|
+ });
|
|
579
|
+ };
|
|
580
|
+ $scope.getGsList();
|
|
581
|
+ // --------------------
|
|
582
|
+ $scope.changeNum = function(val){
|
|
583
|
+ $scope.dataInfo.num = val?Math.abs(parseFloat(val.toFixed(2), 10)):val;
|
|
584
|
+ }
|
|
585
|
+ $scope.cancel = function() {
|
|
586
|
+ $modalInstance.dismiss('cancel');
|
|
587
|
+ };
|
|
588
|
+ $scope.savercode = function() {
|
|
589
|
+ if ($scope.dataInfo.num && $scope.dataInfo.workHourManagement.length){
|
|
590
|
+ $rootScope.isMask = true;
|
|
591
|
+ let postData = {
|
|
592
|
+ "workHourManagementList": $scope.dataInfo.workHourManagement.map(v => ({ workHourId: v.id, workHourNum: $scope.dataInfo.num })),
|
|
593
|
+ "summaryId": $stateParams.id,
|
|
594
|
+ modifyNum: "edit"
|
|
595
|
+ };
|
|
596
|
+ api_bpm.addSummaryDoc(postData).then(function(response) {
|
|
597
|
+ if (response) {
|
|
598
|
+ if (response.status == 200) {
|
|
599
|
+ SweetAlert.swal({
|
|
600
|
+ title: "修改成功!",
|
|
601
|
+ type: "success"
|
|
602
|
+ }, function() {
|
|
603
|
+ scope.getInfo()
|
|
604
|
+ })
|
|
605
|
+ } else {
|
|
606
|
+ SweetAlert.swal({
|
|
607
|
+ title: "修改失败!",
|
|
608
|
+ text: response.msg || '请求数据失败!',
|
|
609
|
+ type: "error"
|
|
610
|
+ }, function() {
|
|
611
|
+ scope.getInfo()
|
|
612
|
+ })
|
|
613
|
+ }
|
|
614
|
+ $modalInstance.close();
|
|
615
|
+ }else{
|
|
616
|
+ SweetAlert.swal({
|
|
617
|
+ title: "修改失败!",
|
|
618
|
+ text: response.msg || '请求数据失败!',
|
|
619
|
+ type: "error"
|
|
620
|
+ }, function() {
|
|
621
|
+ scope.getInfo()
|
|
622
|
+ })
|
|
623
|
+ }
|
|
624
|
+ })
|
|
625
|
+
|
|
626
|
+ }else{
|
|
627
|
+ SweetAlert.swal({
|
|
628
|
+ title: "新增失败!",
|
|
629
|
+ text: "请填写必填项!",
|
|
630
|
+ type: "error",
|
|
631
|
+ confirmButtonColor: "#DD6B55"
|
|
632
|
+ }, function () {
|
|
633
|
+
|
|
634
|
+ });
|
|
635
|
+ }
|
|
636
|
+ }
|
|
637
|
+ },
|
|
638
|
+ resolve: {
|
|
639
|
+ scope: function() {
|
|
640
|
+ return $scope;
|
|
641
|
+ }
|
|
642
|
+ }
|
|
643
|
+ });
|
|
644
|
+ }
|
|
645
|
+
|
|
646
|
+ // 新增工时
|
|
647
|
+ $scope.addGs = function(){
|
|
648
|
+ var modalInstance = $modal.open({
|
|
649
|
+ templateUrl: 'assets/views/system/tpl/gsChange.html',
|
|
650
|
+ controller: function($scope, scope, $modalInstance, api_user_data, api_bpm) {
|
|
651
|
+ $scope.title = '工时新增';
|
|
652
|
+ $scope.isAdd = true;
|
|
653
|
+ $scope.dataInfo = {
|
|
654
|
+ // num: 1,
|
|
655
|
+ workHourManagement: [],
|
|
656
|
+ }
|
|
657
|
+ // --------------------
|
|
658
|
+ $scope.select_treedata = [];
|
|
659
|
+ $rootScope.bala1 = $scope.getGsList = function (s, fn) {
|
|
660
|
+ if (s) {
|
|
661
|
+ var filterKeyword = s.filterKeyword;
|
|
662
|
+ }
|
|
663
|
+ var postData = {
|
|
664
|
+ idx: 0,
|
|
665
|
+ sum: 9999,
|
|
666
|
+ };
|
|
667
|
+ $scope.my_data = [];
|
|
668
|
+ $scope.doing_async = true;
|
|
669
|
+ api_bpm_data
|
|
670
|
+ .fetchDataList("workHourManagement", postData)
|
|
671
|
+ .then(function (response) {
|
|
672
|
+ if (response.status == 200) {
|
|
673
|
+ var data = response.list;
|
|
674
|
+ if (filterKeyword) {
|
|
675
|
+ data.forEach((e) => {
|
|
676
|
+ e.isExpanded = true;
|
|
677
|
+ });
|
|
678
|
+ var li = transform(data).children;
|
|
679
|
+ console.log(li);
|
|
680
|
+ fn(li);
|
|
681
|
+ return;
|
|
682
|
+ } else {
|
|
683
|
+ var objects = [];
|
|
684
|
+ for (var i = 0; i < data.length; i++) {
|
|
685
|
+ var object = {};
|
|
686
|
+ object.id = data[i].id;
|
|
687
|
+ object.parent = data[i].parent;
|
|
688
|
+ object.workName = data[i].workName;
|
|
689
|
+ object.isExpanded = true;
|
|
690
|
+ objects.push(object);
|
|
691
|
+ }
|
|
692
|
+ $scope.my_data = convertParentToChildList(objects);
|
|
693
|
+ $scope.select_treedata = angular.copy($scope.my_data);
|
|
694
|
+ console.log($scope.select_treedata)
|
|
695
|
+ }
|
|
696
|
+ if ($scope.my_data.length > 0) {
|
|
697
|
+ $scope.doing_async = false;
|
|
698
|
+ }
|
|
699
|
+ // selectItem(selectdata.workName,$scope.select_treedata);
|
|
700
|
+ // $scope.deptdata.workName = selectdata.workName;
|
|
701
|
+ } else {
|
|
702
|
+ SweetAlert.swal({
|
|
703
|
+ title: "系统错误!",
|
|
704
|
+ text: "请刷新重试!",
|
|
705
|
+ type: "error",
|
|
706
|
+ });
|
|
707
|
+ }
|
|
708
|
+ });
|
|
709
|
+ };
|
|
710
|
+ $scope.getGsList();
|
|
711
|
+ // --------------------
|
|
712
|
+ $scope.changeNum = function(val){
|
|
713
|
+ $scope.dataInfo.num = val?Math.abs(parseFloat(val.toFixed(2), 10)):val;
|
|
714
|
+ }
|
|
715
|
+ $scope.cancel = function() {
|
|
716
|
+ $modalInstance.dismiss('cancel');
|
|
717
|
+ };
|
|
718
|
+ $scope.savercode = function() {
|
|
719
|
+ console.log($scope.dataInfo);
|
|
720
|
+ // if ($scope.dataInfo.num && $scope.dataInfo.workHourManagement.length){
|
|
721
|
+ if ($scope.dataInfo.workHourManagement.length){
|
|
722
|
+ $rootScope.isMask = true;
|
|
723
|
+ let workHourManagementList = scope.workHourManagementList || []
|
|
724
|
+ let postData = {
|
|
725
|
+ "workHourManagementList": $scope.dataInfo.workHourManagement.concat(workHourManagementList).map(v => ({ workHourId: v.id, workHourNum: v.workHourNum2 || 1 })),
|
|
726
|
+ "summaryId": $stateParams.id,
|
|
727
|
+ };
|
|
728
|
+ api_bpm.addSummaryDoc(postData).then(function(response) {
|
|
729
|
+ if (response) {
|
|
730
|
+ if (response.status == 200) {
|
|
731
|
+ SweetAlert.swal({
|
|
732
|
+ title: "新增成功!",
|
|
733
|
+ type: "success"
|
|
734
|
+ }, function() {
|
|
735
|
+ scope.getInfo()
|
|
736
|
+ })
|
|
737
|
+ } else {
|
|
738
|
+ SweetAlert.swal({
|
|
739
|
+ title: "新增失败!",
|
|
740
|
+ text: response.msg || '请求数据失败!',
|
|
741
|
+ type: "error"
|
|
742
|
+ }, function() {
|
|
743
|
+ scope.getInfo()
|
|
744
|
+ })
|
|
745
|
+ }
|
|
746
|
+ $modalInstance.close();
|
|
747
|
+ }else{
|
|
748
|
+ SweetAlert.swal({
|
|
749
|
+ title: "新增失败!",
|
|
750
|
+ text: response.msg || '请求数据失败!',
|
|
751
|
+ type: "error"
|
|
752
|
+ }, function() {
|
|
753
|
+ scope.getInfo()
|
|
754
|
+ })
|
|
755
|
+ }
|
|
756
|
+ })
|
|
757
|
+
|
|
758
|
+ }else{
|
|
759
|
+ SweetAlert.swal({
|
|
760
|
+ title: "新增失败!",
|
|
761
|
+ text: "请填写必填项!",
|
|
762
|
+ type: "error",
|
|
763
|
+ confirmButtonColor: "#DD6B55"
|
|
764
|
+ }, function () {
|
|
765
|
+
|
|
766
|
+ });
|
|
767
|
+ }
|
|
768
|
+ }
|
|
769
|
+ },
|
|
770
|
+ resolve: {
|
|
771
|
+ scope: function() {
|
|
772
|
+ return $scope;
|
|
773
|
+ }
|
|
774
|
+ }
|
|
775
|
+ });
|
|
776
|
+ }
|
|
777
|
+
|
|
778
|
+ function selectItem(pmodel, childrens) {
|
|
779
|
+ if (angular.isArray(pmodel)) {
|
|
780
|
+ angular.forEach(pmodel, function (index) {
|
|
781
|
+ if (index && index.id) {
|
|
782
|
+ angular.forEach(childrens, function (item) {
|
|
783
|
+ if (item.id == index.id) {
|
|
784
|
+ item.selected = true;
|
|
785
|
+ }
|
|
786
|
+ if (item && item.children) {
|
|
787
|
+ selectItem(pmodel, item.children);
|
|
788
|
+ }
|
|
789
|
+ });
|
|
790
|
+ }
|
|
791
|
+ });
|
|
792
|
+ } else {
|
|
793
|
+ if (pmodel && pmodel.id) {
|
|
794
|
+ angular.forEach(childrens, function (item, index) {
|
|
795
|
+ if (item.id == pmodel.id) {
|
|
796
|
+ item.selected = true;
|
|
797
|
+ }
|
|
798
|
+ if (item && item.children) {
|
|
799
|
+ selectItem(pmodel, item.children);
|
|
800
|
+ }
|
|
801
|
+ });
|
|
802
|
+ }
|
|
803
|
+ }
|
|
804
|
+ }
|
|
805
|
+
|
|
806
|
+ function convertParentToChildList(data) {
|
|
807
|
+ var treeMap = {};
|
|
808
|
+ var list = [];
|
|
809
|
+ convertListToTree(data, treeMap);
|
|
810
|
+ angular.forEach(treeMap, function (item) {
|
|
811
|
+ list.push(item);
|
|
812
|
+ });
|
|
813
|
+ return list;
|
|
814
|
+ }
|
|
815
|
+
|
|
816
|
+ function convertListToTree(data, treeMap) {
|
|
817
|
+ var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
|
|
818
|
+ var root = null; //Initially set our loop to null
|
|
819
|
+ var parentNode = null;
|
|
820
|
+ //loop over data
|
|
821
|
+ for (var i = 0; i < data.length; i++) {
|
|
822
|
+ var datum = data[i];
|
|
823
|
+ //each node will have children, so let's give it a "children" poperty
|
|
824
|
+ datum.children = [];
|
|
825
|
+
|
|
826
|
+ //add an entry for this node to the map so that any future children can
|
|
827
|
+ //lookup the parent
|
|
828
|
+ idToNodeMap[datum.id] = datum;
|
|
829
|
+
|
|
830
|
+ //Does this node have a parent?
|
|
831
|
+ if (typeof datum.parent === "undefined" || datum.parent == null) {
|
|
832
|
+ //Doesn't look like it, so this node is the root of the tree
|
|
833
|
+ root = datum;
|
|
834
|
+ treeMap[datum.id] = root;
|
|
835
|
+ } else {
|
|
836
|
+ //This node has a parent, so let's look it up using the id
|
|
837
|
+ parentNode = idToNodeMap[datum.parent.id];
|
|
838
|
+
|
|
839
|
+ //We don't need this property, so let's delete it.
|
|
840
|
+ delete datum.parent;
|
|
841
|
+
|
|
842
|
+ //Let's add the current node as a child of the parent node.
|
|
843
|
+ parentNode.children.push(datum);
|
|
844
|
+ }
|
|
845
|
+ }
|
|
846
|
+ return root;
|
|
847
|
+ }
|
|
848
|
+
|
|
849
|
+ //树形图
|
|
850
|
+ // 将故障现象搜索结果返回的数据整理成children模式
|
|
851
|
+ function transform(nodes) {
|
|
852
|
+ var treeConverter = {
|
|
853
|
+ result: null, //转化后的结果,是根节点,所有节点都是从根节点长出来的
|
|
854
|
+ attributeName: 'id', //节点唯一标识符
|
|
855
|
+ needFind: true, //是否查询节点在result中已经存在,为了优化效率
|
|
856
|
+ transform: function (node) { //转化递归函数,参数:一个待插入节点
|
|
857
|
+
|
|
858
|
+ if (node.parent != null) { //该节点有父节点
|
|
859
|
+ var newNode = this.transform(node.parent); //递归进入,返回值为一个节点,用作父节点,该父节点必然存在于result中,这点由下面的算法可以控制
|
|
860
|
+ if (this.needFind) {
|
|
861
|
+ for (var i = 0; i < newNode.children.length; i++) { //查找要插入的node子节点是否在newNode这个父节点中存在
|
|
862
|
+ if (newNode.children[i][this.attributeName] === node[this.attributeName]) {
|
|
863
|
+ return newNode.children[i]; //存在的话直接返回newNode父节点内的该子节点,该子节点必然存在于result中,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
|
|
864
|
+ }
|
|
865
|
+ }
|
|
866
|
+ }
|
|
867
|
+ this.needFind = false; //不存在的话,关闭之后递归的循环判断,因为待插入node节点不存在于result中,故而它的子节点一定不存在于result中,不用再循环判断
|
|
868
|
+ // delete node.parent; //删除该节点的parent属性,如果有的话
|
|
869
|
+ node.children = []; //因为确定是要新插入的节点,没有children:[]属性,故给该节点增加children:[]属性
|
|
870
|
+
|
|
871
|
+ newNode.children.push(node); //将该node节点push进newNode的子节点数组中
|
|
872
|
+ return node; //return该新插入节点,作为递归返回值给上层,用作newNode父节点,node存在于result中故newNode存在于result中
|
|
873
|
+ } else if (node.parent == null) { //该叶节点没有父节点,即为根节点
|
|
874
|
+ // delete node.parent; //删除该节点的parent属性,如果有的话
|
|
875
|
+ if (this.result == null) { //根节点不存在
|
|
876
|
+ node.children = []; //给该节点增加children:[]属性
|
|
877
|
+ return this.result = node; //该节点赋给result,并return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
|
|
878
|
+ } else {
|
|
879
|
+ node.children = [];
|
|
880
|
+ // 顶级去重
|
|
881
|
+ for (var i = 0; i < this.result.children.length; i++) {
|
|
882
|
+ if (this.result.children[i][this.attributeName] === node[this.attributeName]) {
|
|
883
|
+ return this.result.children[i];
|
|
884
|
+ }
|
|
885
|
+ }
|
|
886
|
+ this.result.children.push(node)
|
|
887
|
+ return node // 直接return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
|
|
888
|
+ }
|
|
889
|
+ }
|
|
890
|
+ },
|
|
891
|
+ getWhole: function (nodes, attributeName) { //传入整个叶子节点数组,attributeName作为节点唯一标识符属性,返回整个转化结果
|
|
892
|
+ var _node = {};
|
|
893
|
+ _node.children = [];
|
|
894
|
+ this.result = _node; //重置根节点
|
|
895
|
+ this.attributeName = attributeName == null ? 'id' : attributeName; //唯一标识符默认为“id”
|
|
896
|
+ nodes = JSON.parse(JSON.stringify(nodes)); //复制出一个新的节点对象作为参数,保证不改变原有数据
|
|
897
|
+ nodes.forEach(item => { //循环调用转化方法
|
|
898
|
+ this.needFind = true; //重置开启节点是否已存在判断,保证不插入重复节点
|
|
899
|
+ this.transform(item);
|
|
900
|
+ })
|
|
901
|
+ return this.result; //返回根节点
|
|
902
|
+ }
|
|
903
|
+ }
|
|
904
|
+ var result = treeConverter.getWhole(nodes); //调用
|
|
905
|
+ return result;
|
|
906
|
+ }
|
136
|
907
|
},
|
137
|
908
|
]);
|