'use strict';
/**
* controller for User Profile Example
*/
app.controller('woketimeCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", "api_wechatfile", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data, api_wechatfile) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
var loginUser = $rootScope.user;
$scope.gridOptions = {};
$scope.gridOptions.data = 'myData';
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = true;
$scope.gridOptions.enableGridMenu = false;
$scope.gridOptions.enableRowSelection = true;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = false;
$scope.gridOptions.fastWatch = true;
$scope.gridOptions.useExternalFiltering = true;
$scope.gridOptions.useExternalPagination = true;
$scope.gridOptions.paginationPageSizes = [10];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = false;
//$scope.gridOptions.rowTemplate= "
";
$scope.gridOptions.rowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function(row) {
return row.id;
};
$scope.transfer = function(deleteFlag) {
if (deleteFlag == true) { return "是" } else { return "否" }
}
$scope.transferstatus = function(deleteFlag) {
if (deleteFlag == true) { return "停用" } else { return "使用" }
}
$scope.translate = function(item) {
return moment(item).format('HH:mm')
}
$scope.gridOptions.columnDefs = [
{ name: 'item', displayName: '序号', width: 50, enableFiltering: false },
{ name: 'name', displayName: '班次', width: '10%', enableFiltering: false },
{
name: 'startTime',
displayName: '开始时间',
width: '10%',
enableFiltering: false,
cellTemplate: '{{grid.appScope.translate(row.entity.startTime)}}
'
},
{
name: 'endTime',
displayName: '结束时间',
width: '10%',
enableFiltering: false,
cellTemplate: '{{grid.appScope.translate(row.entity.endTime)}}
'
},
{ name: 'person', displayName: '本班次人数', width: '10%', enableFiltering: false },
{ name: 'dictionaryDTO.name', displayName: '季节', width: '10%', enableFiltering: false },
{ name: 'description', displayName: '班次描述', width: '12%', enableFiltering: false },
{ name: 'deleteFlag', displayName: '使用状态', width: '10%', enableFiltering: false, cellTemplate: '{{grid.appScope.transferstatus(row.entity.deleteFlag)}}
' },
{ name: 'isTemplate', displayName: '是否为模版', width: '10%', enableFiltering: false, cellTemplate: '{{grid.appScope.transfer(row.entity.isTemplate)}}
' },
{
name: '编辑',
cellTemplate: '',
enableFiltering: false
},
];
$scope.saveData = function(selectdata) {
var modalInstance = $modal.open({
templateUrl: 'assets/views/system/tpl/systemworktime.html',
controller: function($scope, $modalInstance, api_bpm_data) {
$scope.title = "修改班次";
$scope.worktimedata = {};
$scope.worktimedata = selectdata;
$scope.dictionary = [];
api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
if (data) {
$scope.dictionary = data;
}
})
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
$scope.savercode = function(worktimedata) {
var fildata = {
"scheduleclass": {
"id": worktimedata.id,
// "code": worktimedata.code,
"name": worktimedata.name,
"person": worktimedata.person,
"description": worktimedata.description,
"startTime": moment(worktimedata.startTime).format('YYYY-MM-DD HH:mm:ss'),
"endTime": moment(worktimedata.endTime).format('YYYY-MM-DD HH:mm:ss'),
"shiftTime": worktimedata.shiftTime,
"succeedTime": worktimedata.succeedTime,
"dictionaryDTO": worktimedata.dictionaryDTO,
"isTemplate": worktimedata.isTemplate,
"deleteFlag": worktimedata.deleteFlag
}
}
// api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
// if (data.status == 200) {
// $scope.dictionary = data;
// }
// })
api_bpm_data.updData('scheduleclass', fildata).then(function(response) {
if (response) {
if (response.status == 200) {
SweetAlert.swal({
title: "修改成功!",
type: "success"
}, function() {
// $scope.refreshData('expand-right', defaultFilterData);
})
} else {
SweetAlert.swal({
title: "修改失败!",
type: "error"
})
}
}
})
$modalInstance.close();
}
}
});
}
$scope.addData = function() {
var modalInstance = $modal.open({
templateUrl: 'assets/views/system/tpl/systemworktime.html',
controller: function($scope, $modalInstance, api_bpm_data) {
$scope.title = "新增班次";
$scope.dictionary = [];
api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
if (data) {
$scope.dictionary = data;
}
})
$scope.worktimedata = { "startTime": new Date(), "endTime": new Date(), "isTemplate": false }
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
$scope.savercode = function(worktimedata) {
$modalInstance.close(worktimedata);
};
}
});
modalInstance.result.then(function(selectedItem) {
if (selectedItem) {
var fildata = {
"scheduleclass": {
// "code": selectedItem.code,
"name": selectedItem.name,
"person": selectedItem.person,
"description": selectedItem.description,
"startTime": moment(selectedItem.startTime).format('YYYY-MM-DD HH:mm:ss'),
"endTime": moment(selectedItem.endTime).format('YYYY-MM-DD HH:mm:ss'),
"shiftTime": selectedItem.shiftTime,
"succeedTime": selectedItem.succeedTime,
"dictionaryDTO": selectedItem.dictionaryDTO,
"isTemplate": selectedItem.isTemplate,
"deleteFlag": selectedItem.deleteFlag
}
}
if (!fildata.scheduleclass.name) {
SweetAlert.swal({
title: "新增失败!",
text: "班次未填",
type: "error"
})
} else if (!fildata.scheduleclass.startTime) {
SweetAlert.swal({
title: "新增失败!",
text: "班次开始时间未填",
type: "error"
})
} else if (!fildata.scheduleclass.endTime) {
SweetAlert.swal({
title: "新增失败!",
text: "班次结束时间未填",
type: "error"
})
} else if (!fildata.scheduleclass.person) {
SweetAlert.swal({
title: "新增失败!",
text: "本班次人数未填",
type: "error"
})
} else {
api_bpm_data.addData('scheduleclass', fildata).then(function(response) {
if (response.status == 200) {
SweetAlert.swal({
title: "新增成功!",
type: "success"
}, function() {
$scope.refreshData('expand-right', defaultFilterData);
})
} else {
SweetAlert.swal({
title: "新增失败!",
type: "error"
})
}
})
}
}
});
}
$scope.removeData = function() {
var modalInstance = $modal.open({
templateUrl: 'assets/views/incident/tpl/acceptTask.tpl.html',
controller: function($scope, scope, $modalInstance, api_user_data) {
var rmvList = [];
$scope.title = "删除";
$scope.connect = "确定要删除本班次?";
rmvList.push(scope.selected.items[0].id);
$scope.ok = function() {
$modalInstance.close(rmvList);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function() {
return $scope;
}
}
});
modalInstance.result.then(function(selectedItem) {
if (selectedItem) {
if (selectedItem.length > 0) {
api_bpm_data.rmvData('scheduleclass', selectedItem).then(function(response) {
if (response.status == 200) {
SweetAlert.swal({
title: "删除成功!",
type: "success",
confirmButtonColor: "#007AFF"
}, function() {
$scope.refreshData('expand-right', defaultFilterData);
// $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
// $scope.selected = {
// items: []
// };
// $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
$scope.gridApi.grid.selection.selectedCount = 0;
});
} else {
SweetAlert.swal({
title: "操作异常!",
text: "系统异常,请稍后重试,或者联系管理员!",
type: "error"
});
}
})
}
}
})
}
$scope.selected = {
items: []
}
$scope.editted = {
items: []
}
$scope.gridOptions.onRegisterApi = function(gridApi) {
$scope.gridApi = gridApi;
// gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
// console.log(rowEntity);
// });
gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
var filtersData = $scope.memoryfilterData;
filtersData.idx = newPage - 1;
filtersData.sum = pageSize;
defaultFilterData = filtersData;
$scope.refreshData('expand-right', filtersData);
});
// gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
// scope.grid.appScope.selected.items[0] = scope.entity
// });
gridApi.selection.on.rowSelectionChanged($scope, function(data) {
if (data.isSelected) {
data.grid.appScope.selected.items[0] = data.entity;
} else {
if (data.grid.appScope.selected.items[0].id == data.entity.id) {
data.grid.appScope.selected.items = [];
}
}
});
};
var defaultFilterData = {
"idx": 0,
"sum": 10
};
$scope.memoryfilterData = {
"idx": 0,
"sum": 10
}
$scope.ldloading = {};
$scope.refresh = function(style, filterData) {
$scope.selected = { items: [] };
if ($scope.gridApi) {
// $scope.gridApi.grid.options.paginationCurrentPage = 0;
$scope.gridApi.grid.selection.selectedCount = 0;
}
$scope.refreshData('expand-right', defaultFilterData);
}
$scope.refreshData = function(style, filterData) {
$scope.ldloading[style.replace('-', '_')] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
$scope.myData = [];
// $scope.selected = { items: [] };
// if ($scope.gridApi) {
// $scope.gridApi.grid.selection.selectedCount = 0;
// }
api_bpm_schedule.getScheduleClass().then(function(response) {
if (response.status == 200) {
$scope.ldloading[style.replace('-', '_')] = false;
var scheduleClassList = response.list;
$scope.gridOptions.totalItems = response.totalNum;
angular.forEach(scheduleClassList, function(item) {
var templateEvent = {
id: item.id,
name: item['name'],
// code: item['code'],
startTime: item.startTime,
person: item.person,
//starts_at:
endTime: item.endTime,
dictionaryDTO: item.dictionaryDTO,
succeedTime: item.succeedTime,
shiftTime: item.shiftTime,
description: item.description,
deleteFlag: item.deleteFlag,
isTemplate: item.isTemplate,
draggable: true
};
$scope.myData.push(templateEvent);
})
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
}
}
})
// $scope.myData = [];
// api_bpm_data.fetchDataList('closecode',filterData).then(function(data){
// var myData = Restangular.stripRestangular(data);
// $scope.gridOptions.totalItems = myData.totalNum;
// $scope.myData = myData.list;
// $scope.ldloading[style.replace('-', '_')] = false;
// },function(){
// $scope.ldloading[style.replace('-', '_')] = false;
// });
};
$scope.refreshData('expand-right', defaultFilterData);
}]);