'use strict';
app.controller('cmdbauditeditorCtrl', ["$scope", "$http", "$filter", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_text", "api_bpm_data", "api_user_data", "api_bpm", function($scope, $http, $filter, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_text, api_bpm_data, api_user_data, api_bpm) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
$scope.myData = [];
$scope.model = {};
var loginUser = $rootScope.user;
var pdKey = $state.current.pdKey;
$scope.lookright = false;
//时间
if ($stateParams.model) {
$scope.model = JSON.parse($stateParams.model);
$scope.lookright = $scope.model.look;
}
// $scope.model.time = moment(new Date()).format('YYYY-MM-DD');
$scope.mindata = new Date();
$scope.endOpen = true;
$scope.datepicker = {};
$scope.datepicker.opened = false;
$scope.datepicker.open = function($event) {
$scope.datepicker.opened = true;
};
$scope.options = { 'key': "time" }
$scope.datepickerPopup = "yyyy-MM-dd HH:mm:ss";
$scope.width = { 'width': document.getElementById("formtow").scrollWidth };
window.onresize = function() {
if (document.getElementById("form")) {
$scope.width = { 'width': document.getElementById("formtow").scrollWidth };
}
}
$scope.transferdifferenceStatus = function(item) {
var statecolor = "有差异";
if (item == 1) {
statecolor = "有差异";
} else if (item == 2) {
statecolor = "无差异";
}
return statecolor;
}
$scope.transferstatus = function(item) {
var statecolor = "未处理";
if (item == 1) { //待处理
statecolor = "发起变更";
} else if (item == 2) { //已处理
statecolor = "忽略";
} else if (item == 3) { //已处理
statecolor = "无需处理";
} else if (item == 4) { //已处理
statecolor = "未处理";
}
return statecolor;
}
$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 = [1000];
$scope.gridOptions.paginationPageSize = 1000;
$scope.gridOptions.multiSelect = true;
// $scope.gridOptions.rowTemplate = "
";
$scope.gridOptions.columnDefs = [
{ name: 'item', displayName: '序号', width: 50 },
{ name: 'assetId', displayName: '配置项ID', width: 150, enableFiltering: false },
{ name: 'assetName', displayName: '配置项名称', width: 100, enableFiltering: false },
{
name: 'differenceStatus',
displayName: '是否有差异',
enableFiltering: false,
width: 100,
cellTemplate: '' +
'
{{grid.appScope.transferdifferenceStatus(row.entity.differenceStatus)}}
' +
'
'
},
{ name: 'changeOrder', width: 150, displayName: '变更单号', enableFiltering: false },
{
name: 'status',
displayName: '处理方式',
enableFiltering: false,
width: 100,
cellTemplate: '' +
'
{{grid.appScope.transferstatus(row.entity.status)}}
' +
'
'
},
{
name: '操作',
enableSorting: false,
cellTemplate: ''
}
];
$scope.myDatalingbeiall = [];
$scope.memoryfilterDatashe = {
}
$scope.gridOptions.onRegisterApi = function(gridApi) {
$scope.gridApi = gridApi;
gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
// var filtersData = $scope.memoryfilterData;
// filtersData.idx = newPage - 1;
// filtersData.sum = pageSize;
// $scope.loadData(filtersData);
$scope.memoryfilterDatashe.idx = newPage - 1;
$scope.memoryfilterDatashe.sum = pageSize;
$scope.myDatalingbei = $scope.interceptMydata($scope.myDatalingbeiall, $scope.memoryfilterDatashe.idx, 10)
});
// gridApi.selection.on.rowSelectionChanged($scope, function(data) {
// $scope.selected.items = data.entity;
// //console.log(data);
// });
// gridApi.selection.on.rowSelectionChangedBatch($scope, function(data) {
// $scope.selected.items = data.entity;
// //console.log(data);
// });
// gridApi.core.on.filterChanged($scope, function() {
// var grid = this.grid;
// var filtersData = {
// idx: 0,
// sum: 20,
// "user": { "roledata": { "rolecode": "roleset" }, "selectType": "1" }
// };
// angular.forEach(grid.columns, function(item) {
// if (item.enableFiltering) {
// // console.log("item.filters[0]=" + JSON.stringify(item.filters));
// if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
// if (angular.isUndefined(filtersData['user'])) {
// filtersData['user'] = {};
// }
// filtersData['user'][item.field] = item.filters[0].term;
// }
// }
// });
// $scope.memoryfilterDatashe = filtersData;
// // $scope.loadData(filtersData);
// });
};
//管理员
$scope.audituser = [];
var fieldatas = { "idx": 0, "sum": 1000, "user": { "roledata": { "rolecode": "3ff5dd43-0a0b-44d9-a36e-2b5417f41242" }, "selectType": "1",engineer: 1, } }
api_user_data.fetchDataList('user', fieldatas).then(function(data) {
if (data.status == 200) {
$scope.audituser = data.list;
}
});
//单号
// var fieldatas = { "idx": 0, "sum": 1000, "user": { "roledata": { "rolecode": "change petitor" }, "selectType": "1" } }
// api_bpm_domain.workernumber('PZSJ').then(function(data) {
// if (data.status == 200) {
// $scope.model.orderId = data.data;
// }
// });
$scope.interceptMydata = function(mydate, idx, sum) {
return mydate.slice(idx * sum, (idx + 1) * sum)
}
$scope.removeshebei = function(item) {
event.preventDefault();
var modalInstance = $modal.open({
templateUrl: 'assets/views/delete.html',
controller: function($scope, $modalInstance, scope) {
$scope.title = '设备移除';
$scope.connect = '确定要移除此设备?';
$scope.consumptive = scope.selected.items;
$scope.ok = function() {
$modalInstance.close($scope.consumptive);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function() {
return $scope;
},
}
});
modalInstance.result.then(function(selectedItem) {
angular.forEach($scope.myDatalingbeiall, function(items, index) {
if (items.id == selectedItem.id) {
$scope.myDatalingbeiall.splice(index, 1);
}
})
// $scope.myData3.push(selectedItem);
$scope.model.comptrollerAssets = $scope.myDatalingbeiall;
$scope.gridOptions['totalItems'] = $scope.myDatalingbeiall.length;
for (var i = 0; i < $scope.myDatalingbeiall.length; i++) {
$scope.myDatalingbeiall[i]['item'] = i + 1 + $scope.memoryfilterDatashe.idx * $scope.memoryfilterDatashe.sum
}
$scope.myDatalingbei = $scope.interceptMydata($scope.myDatalingbeiall, 0, 10)
})
}
// $scope.onDblClick = function(data, event) {
// $scope.selectButtonClick(data, event);
// };
//对比
$scope.lookFunction = function(data) {
// $state.go('app.means.cmdbcontrast', { model: JSON.stringify(data) });
var url = $state.href('cmdbcontrast', { model: JSON.stringify(data) });
window.open(url, '_blank');
// if ($scope.lookright) {
// $state.go('app.means.cmdbcontrast', { key: 1, model: JSON.stringify(data) });
// } else {
// $state.go('app.means.cmdbcontrast', { key: 2, model: JSON.stringify(data) });
// }
};
//发起变更
$scope.selectRowFunction = function(item) {
var data = {
"model": { change: { source: { id: 88 }, title: item.assetName, description: item.assetName }, cmdbId: item.id }
}
$state.go('app.change.incident', { 'key': 1, 'model': JSON.stringify(data) });
}
//关闭
$scope.closeModel = function() {
$state.go('app.means.auditlist', {});
}
//忽略
$scope.ignore = function(data) {
var modalInstance = $modal.open({
templateUrl: 'assets/views/delete.html',
controller: function($scope, $modalInstance, scope) {
$scope.title = '提示';
$scope.connect = '忽略后,将不再显示,是否确定忽略?';
$scope.ok = function() {
$modalInstance.close(data);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function() {
return $scope;
},
}
});
modalInstance.result.then(function(selectedItem) {
angular.forEach($scope.myData, function(items, index) {
if (items.id == selectedItem.id) {
$scope.myData[index].status = 2;
}
})
})
};
var defaultdata = {
"comptroller": {
"id": $scope.model.id
}
}
var defaultdatatwo = {
"comptroller": {
"orderId": $scope.model.orderId
}
}
$scope.ldloading = {};
$scope.refreshData = function(filterData) {
$scope.ldloading.zoom_in = true;
defaultdatatwo.idx = 0; //idx: 0
defaultdatatwo.sum = 100; //sum: 10
if ($scope.lookright) {
api_bpm.fetchDataList('comptroller', defaultdatatwo).then(function(data) {
$scope.model = Restangular.stripRestangular(data).list[0];
$scope.myData = $scope.model.comptrollerAssets;
$scope.gridOptions['totalItems'] = $scope.myData.length;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1
}
$scope.ldloading.zoom_in = false;
}, function() {});
} else {
api_bpm.updData('comptroller', filterData).then(function(data) {
// var filterData = $scope.memoryfilterDatashe;
$scope.model = Restangular.stripRestangular(data).data;
$scope.myData = $scope.model.comptrollerAssets;
$scope.gridOptions['totalItems'] = $scope.myData.length;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1;
}
$scope.ldloading.zoom_in = false;
}, function() {});
}
};
$scope.refreshData(defaultdata);
$scope.tworeash = function() {
$scope.ldloading.zoom_in = true;
$scope.refreshData(defaultdata);
}
//提交
$scope.isvailu = true;
$scope.changesubmit = function(data) {
$scope.isvailu = true;
angular.forEach(data.comptrollerAssets, function(item) {
if (item.status == 4 && item.differenceStatus == 1) {
$scope.isvailu = false;
}
})
if ($scope.isvailu) {
$rootScope.loading = true;
if (!data.user || data.user == "") {
$rootScope.loading = false;
SweetAlert.swal({
title: "提交失败",
text: "审计管理员!",
type: "error"
});
} else {
if (!data.time || data.time == "") {
$rootScope.loading = false;
SweetAlert.swal({
title: "提交失败",
text: "审计日期!",
type: "error"
});
} else {
if (!data.comptrollerAssets || data.comptrollerAssets == "") {
$rootScope.loading = false;
SweetAlert.swal({
title: "提交失败",
text: "配置项未填!",
type: "error"
});
} else {
var filterData = { 'comptroller': data };
// moment(filterData.time).format('YYYY-MM-DD hh:mm:ss');
filterData.comptroller.status = 2;
// api_bpm.addData('comptroller', filterData).then(function(data) {
api_bpm.updData('comptroller', filterData).then(function(data) {
if (data.status == 200) {
SweetAlert.swal({
title: "保存成功!",
type: "success",
confirmButtonColor: "#007AFF"
}, function() {
$rootScope.loading = false;
$state.go("app.means.auditlist");
});
} else {
$rootScope.loading = false;
SweetAlert.swal({
title: "系统错误",
text: "请稍后再试!",
type: "error"
});
}
// $scope.ldloading[style.replace('-', '_')] = false;
}, function() {
// $scope.ldloading[style.replace('-', '_')] = false;
});
}
}
}
} else {
SweetAlert.swal({
title: "提交失败",
text: "请处理完全部数据!",
type: "error"
});
}
}
}])
//操作按钮权限控制
app.controller('CmdbauditOperCtrl', ['$rootScope', '$http', '$scope', '$modal', function($rootScope, $http, $scope, $modal) {
if ($scope.item.status != null) {
if ($scope.item.status == 4) {
$scope.item.chaozuoPower = true;
}
}
$scope.$watch($scope.item.status, function() {
console.log($scope.myData)
})
$scope.look = function() {
//$state.go('app.detail', { formKey:'incident_back', pdKey:'incident', dataId: $scope.item.id});
$scope.colobject.grid.appScope.lookFunction($scope.item);
}
$scope.edit = function() {
$scope.colobject.grid.appScope.selectRowFunction($scope.item);
}
$scope.handler = function() {
$scope.colobject.grid.appScope.ignore($scope.item);
$scope.doEdit($scope.item.status);
}
}]);
//操作按钮
app.directive('cmdbauditoperator', function() {
return {
restrict: 'E',
scope: {
item: '=',
colobject: '='
},
controller: 'CmdbauditOperCtrl',
template: ''
};
});