'use strict';
app.controller('gdzc_historyCtrl', ["$scope", "$http", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_text", "api_bpm_data", "api_user_data", "api_cmdb", "api_cmdb2", "api_cmdb3", "api_cmdb4", function($scope, $http, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_text, api_bpm_data, api_user_data, api_cmdb, api_cmdb2, api_cmdb3, api_cmdb4) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
$scope.myData = [];
var loginUser = $rootScope.user;
var pdKey = $state.current.pdKey;
$scope.gridOptions = {};
$scope.gridOptions.data = 'myData';
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = false;
$scope.gridOptions.enableGridMenu = false;
$scope.gridOptions.enableSelectAll = true;
$scope.gridOptions.enableRowSelection = true;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = false;
$scope.gridOptions.fastWatch = true;
$scope.gridOptions.enableSorting = true;
$scope.gridOptions.useExternalSorting = true;
$scope.gridOptions.useExternalFiltering = false;
$scope.gridOptions.useExternalPagination = true;
$scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = true;
var mun = $scope.gridOptions.paginationPageSize;
$scope.gridOptions.rowTemplate = "
";
$scope.gridOptions.rowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function(row) {
return row.id;
};
$scope.transferColor = function(item) {
var color = "icon iconfont icon-zhengchang greenfont";
if (item.colourInfo) {
if (item.colourInfo.id == 1) {
color = "icon iconfont icon-yiyuqi redfont";
} else if (item.colourInfo.id == 2) {
color = "iconfont icon-yuqixinxiu yellofont";
}
} else {
// color = "white";
}
return color;
}
$scope.transfertip = function(item) {
var tip = "正常";
if (item.colourInfo) {
if (item.colourInfo.id == 1) {
tip = "逾期";
} else if (item.colourInfo.id == 2) {
tip = "即将逾期";
}
} else {
// color = "white";
}
return tip;
}
$scope.transferstatus = function(item) {
var statecolor = "#fc4c58";
if (item.id == 2) { //待处理
statecolor = "#fc4c58";
} else if (item.id == 7) { //待审核
statecolor = "#fcb44c";
} else if (item.id == 3) { //请求重新指派
statecolor = "#ebf902";
} else if (item.id == 4) { //处理中
statecolor = "#0aa5f5";
} else if (item.id == 5) { //已解决
statecolor = "#2edbb8";
} else if (item.id == 6) { //已关闭
statecolor = "#bbbbbb";
}
return statecolor;
}
$scope.gridOptions.columnDefs = [{
name: 'versionNumber',
displayName: '版本',
width: '14%',
cellTemplate: '' +
'
{{row.entity.versionNumber}}
' +
'
'
},
{
name: 'name',
displayName: '操作人',
width: '13%',
cellTemplate: '' +
'
{{row.entity.operator.name}}
' +
'
'
},
{
name: 'time',
displayName: '操作时间',
width: '20%',
cellTemplate: '' +
'
{{row.entity.time}}
' +
'
'
},
{
name: 'motion',
displayName: '操作动作',
width: '13%',
cellTemplate: '' +
'
{{row.entity.motion}}
' +
'
'
}, {
name: 'description',
displayName: '内容',
width: '40%',
cellTemplate: '' +
'
{{row.entity.description}}
{{row.entity.description}}
' +
'
'
}
];
$scope.value = 10;
$scope.decrement = function() {
$scope.value = $scope.value - 1;
};
$scope.record = function() {
api_text.record($rootScope.takes).then(function(data) {
if (data.errno == 0) {
$scope.busy = false;
}
})
};
$scope.parameters = null;
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = !$scope.opened;
};
$scope.endOpen = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.startOpened = false;
$scope.endOpened = !$scope.endOpened;
};
$scope.startOpen = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.endOpened = false;
$scope.startOpened = !$scope.startOpened;
};
$scope.othcode = {};
var items = [];
$scope.selected = {
items: []
};
var wt_data = {};
//列表排序
$scope.gridOptions.onRegisterApi = function(gridApi) {
$scope.gridApi = gridApi;
var index = 0;
var oldheader = {};
gridApi.grid.sortColumn = function(gridApi) {
if (oldheader.field) {
if (oldheader.field == gridApi.field) {
// index = 0;
} else {
index = 0;
}
}
index++;
oldheader = gridApi;
var fildata = $scope.memoryfilterData;
if (index % 3 == 0) {
delete $scope.memoryfilterData.incident;
fildata = $scope.memoryfilterData;
} else if (index % 3 == 1) {
if (fildata.incident) {
if (gridApi.field == "acceptDate") {
angular.extend(fildata.incident, { "sort": gridApi.field });
} else {
angular.extend(fildata.incident, { "sort": gridApi.field + " desc , _incident.acceptDate" });
}
} else {
if (gridApi.field == "acceptDate") {
angular.extend(fildata, { 'incident': { "sort": gridApi.field } });
} else {
angular.extend(fildata, { 'incident': { "sort": gridApi.field + " desc , _incident.acceptDate" } });
}
}
} else if (index % 3 == 2) {
if (fildata.incident) {
if (gridApi.field == "acceptDate") {
angular.extend(fildata.incident, { "sort": gridApi.field, "order": "asc" });
} else {
angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
}
} else {
if (gridApi.field == "acceptDate") {
angular.extend(fildata, { 'incident': { "sort": gridApi.field, "order": "asc" } });
} else {
angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
}
}
// angular.extend(fildata, { 'incident': { "sort": gridApi.field, "order": "asc" } });
}
$scope.refreshData('expand-right', fildata);
}
gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
var filtersData = $scope.memoryfilterData;
filtersData.idx = newPage - 1;
filtersData.sum = pageSize;
$scope.refreshData('expand-right', filtersData);
});
gridApi.core.on.filterChanged($scope, function() {
var grid = this.grid;
if ($rootScope.user.group) {
var filtersData = {
idx: 0,
sum: mun
};
} else {
var filtersData = {
idx: 0,
sum: mun
};
}
angular.forEach(grid.columns, function(item) {
if (item.enableFiltering) {
if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
filtersData = $scope.memoryfilterData
if (angular.isUndefined(filtersData['incident'])) {
filtersData['incident'] = {};
}
if (item.field == 'requester.name') {
filtersData['incident']['requester'] = {};
filtersData.incident.requester['accountName'] = item.filters[0].term;
} else if (item.field == 'handlingPersonnelUser.name') {
filtersData['incident']['handlingPersonnelUser'] = {};
filtersData.incident.handlingPersonnelUser['name'] = item.filters[0].term;
} else if (item.field == 'requester.account') {
filtersData['incident']['requester'] = {};
filtersData.incident.requester['account'] = item.filters[0].term;
} else if (item.field == 'acceptUser.name') {
filtersData['incident']['acceptUser'] = {};
filtersData.incident.acceptUser['name'] = item.filters[0].term;
} else {
filtersData['incident'][item.field] = item.filters[0].term;
}
}
}
});
filtersData.idx = 0;
$scope.memoryfilterData = filtersData;
$scope.refreshData('expand-right', filtersData);
});
};
//当前人是否分组
if ($rootScope.user.group) {
if ($rootScope.user.group.length == 0) {
SweetAlert.swal("访问失败!", "当前登录人未分配工作组,无权限访问,请添加工作组后重试。", "error");
} else {
$scope.memoryfilterData = defaultFilterData = {
"idx": 0,
"sum": mun
};
}
} else {
$scope.memoryfilterData = defaultFilterData = {
"idx": 0,
"sum": mun
};
};
var items = [];
if ($stateParams.model) {
if (JSON.parse($stateParams.model).searchType && JSON.parse($stateParams.model).searchType != null) {
$scope.searchTypes = JSON.parse($stateParams.model).searchType;
} else {
$scope.searchTypes = "todo";
}
} else {
$scope.searchTypes = "todo";
}
if ($rootScope.user.group) {
var defaultFilterData = {
"idx": 0,
"sum": mun
};
} else {
var defaultFilterData = {
"idx": 0,
"sum": mun
};
}
if (angular.isDefined($rootScope.search) && angular.isDefined($rootScope.search.incident)) {
defaultFilterData['searchType'] = $rootScope.search.incident;
$scope.searchTypes = $rootScope.search.incident;
}
if ($rootScope['cmdbs'] != 'incident') { $rootScope.idx = 1 }
if (angular.isDefined($rootScope.idx) && $rootScope.cmdbs != "false") {
$rootScope['cmdbs'] = 'incident';
defaultFilterData.idx = $rootScope.idx - 1;
} else { $rootScope.cmdbs = ""; }
$scope.ldloading = {};
// console.log($stateParams.idd)
//获取列表数据
$scope.refreshData = function(style, filterData) {
var pdKey = "assetConsumablesHistory";
$scope.myData = [];
$scope.gridOptions['sum'] = filterData.sum;
filterData['assetConsumablesHistory'] = { "assetConsumablesId": $stateParams.idd };
api_cmdb3.fetchDataList(pdKey, filterData).then(function(data) {
// console.log(data.list);
if (data.list) {
var myData = Restangular.stripRestangular(data);
var list = [];
$scope.gridOptions['totalItems'] = myData.totalNum;
$scope.myData = myData.list;
// console.log($scope.myData);
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
}
} else {
SweetAlert.swal({
title: "系统错误",
text: "请稍后再试!",
type: "error"
});
}
$scope.ldloading[style.replace('-', '_')] = false;
}, function() {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
$scope.refreshData('expand-right', defaultFilterData);
}])