"use strict";
/**
* controller for User Profile Example
*/
app.controller("summaryCtrl", [
"$rootScope",
"$scope",
"$state",
"$timeout",
"$interval",
"$modal",
"SweetAlert",
"i18nService",
"uiGridConstants",
"uiGridGroupingConstants",
"Restangular",
"api_bpm_schedule",
"api_bpm_data",
"api_wechatfile",
"api_configure_data",
"moment",
function (
$rootScope,
$scope,
$state,
$timeout,
$interval,
$modal,
SweetAlert,
i18nService,
uiGridConstants,
uiGridGroupingConstants,
Restangular,
api_bpm_schedule,
api_bpm_data,
api_wechatfile,
api_configure_data,
moment
) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = "zh-cn";
i18nService.setCurrentLang($scope.lang);
var loginUser = $rootScope.user;
$scope.chakan = false;
$scope.shanchu = false;
$scope.shenhe = false;
for (var i = 0; i < loginUser.menu.length; i++) {
if (loginUser.menu[i].link == "summary_chakan") {
$scope.chakan = true;
}
if (loginUser.menu[i].link == "summary_shanchu") {
$scope.shanchu = true;
}
if (loginUser.menu[i].link == "summary_shenhe") {
$scope.shenhe = true;
}
}
var defaultFilterData = {
idx: 0,
sum: 10,
};
var repairSummaryParameter = {
idx: 0,
sum: 10,
operation: "",
status: "",
repairSummary: {},
};
//本地存储
sessionStorage.repairSummaryParameter = JSON.stringify(repairSummaryParameter);
$scope.memoryfilterData = {
idx: 0,
sum: 10,
};
// $scope.isMask = false;
$scope.gridOptions = {};
$scope.gridOptions.data = "myData";
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = false;
$scope.gridOptions.enableGridMenu = true;
$scope.gridOptions.enableRowSelection = true;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = false;
$scope.gridOptions.useExternalFiltering = false;
$scope.gridOptions.useExternalPagination = true;
$scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = true;
$scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
//行鼠标悬浮变色功能
// $scope.gridOptions.rowTemplate = '
';
$scope.gridOptions.rowTemplate =
'';
$scope.gridOptions.rowIdentity = function (row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function (row) {
return row.id;
};
$scope.transfer = function (status) {
if (status === "正常") {
return "执行中";
} else if (status === "停止") {
return "暂停中";
}
};
$scope.gridOptions.columnDefs = [
{
name: "item",
displayName: "序号",
width: 50,
enableFiltering: false,
},
{
name: "incidentSign",
displayName: "事件单号",
width: "10%",
enableFiltering: false,
},
{
name: "description",
displayName: "故障描述",
width: "400",
enableFiltering: false,
// cellTemplate: '{{row.entity.planStartTime.length>16?grid.appScope.transferTime(row.entity.planStartTime):row.entity.planStartTime}}
'
},
{
name: "maintainer",
displayName: "维修人",
width: "10%",
enableFiltering: false,
cellTemplate: '{{row.entity.maintainer ? row.entity.maintainer.name : ""}}
'
},
{
name: "totalMaintenancePrice",
displayName: "维修总价",
width: "10%",
enableFiltering: false,
cellTemplate: '{{row.entity.totalMaintenancePrice || 0}}元
'
},
{
name: "createTime",
displayName: "生成时间",
width: "11%",
enableFiltering: false,
cellTemplate: '{{ grid.appScope.transferTime(row.entity.createTime) }}
'
},
{
name: "state",
displayName: "状态",
width: "6%",
enableFiltering: false,
cellTemplate:
'暂存未审核审核通过
',
},
{
minWidth: "230",
name: "操作",
enableFiltering: false,
cellTemplate:
'' +
'
查看' +
'
删除' +
'
审核通过' +
"
",
},
// { name: 'planTime2', displayName: '截止时间', width: 160, enableFiltering: false },
];
$scope.transferTime = function (time) {
if(time){
return moment(time).format("YYYY-MM-DD HH:mm");
}else{
return '';
}
};
$scope.inspectdata = {};
//跳转到查看列表
$scope.seeFunction = function (data) {
console.log(data)
$state.go("app.incident.summaryDetail", {
incidentId: data.incidentId,
id: data.id,
});
};
//审核通过
$scope.runFunction = function (data) {
var modalInstance = $modal.open({
// templateUrl: 'assets/views/inspect/changRun.html',
templateUrl: "assets/views/delete.html",
// size: "sm",
controller: function ($scope, $modalInstance) {
$scope.isRunFunction = true;
var status = "";
$scope.title = "审核通过";
$scope.connect = "确定要审核通过?";
$scope.ok = function () {
$modalInstance.close(data);
};
$scope.cancel = function () {
$modalInstance.dismiss("cancel");
};
},
size: "sm",
});
modalInstance.result.then(function (result) {
if (result) {
var toData = {
summaryId: result.id,
};
api_bpm_data.approved(toData).then(
function (response) {
var myData = Restangular.stripRestangular(response);
if (myData.status == 200) {
$scope.refreshData("expand-right", $scope.fileData);
}
},
function () {
// $scope.ldloading[style.replace('-', '_')] = false;
}
);
}
});
};
//行删除
$scope.removeData = function (item) {
console.log($scope.selected.items);
var rmDatas = [item] || $scope.selected.items;
var modalInstance = $modal.open({
templateUrl: "assets/views/delete.html",
controller: function ($scope, $modalInstance) {
$scope.title = "删除";
$scope.connect = "确定要删除?";
$scope.ok = function () {
$modalInstance.close("start");
};
$scope.cancel = function () {
$modalInstance.dismiss("cancel");
};
},
size: "sm",
});
modalInstance.result.then(
function (result) {
if (result) {
if (rmDatas.length != 0) {
$rootScope.isMask = true;
}
var rmvList = [];
angular.forEach(rmDatas, function (item) {
rmvList.push(item.id);
});
if (rmvList.length > 0) {
api_bpm_data
.rmvData("repairSummary", rmvList)
.then(function (response) {
if (response.status == 200) {
$rootScope.isMask = false;
SweetAlert.swal(
{
title: "删除成功!",
type: "success",
confirmButtonColor: "#007AFF",
},
function () {
$scope.myData = _.reject($scope.myData, function (o) {
return _.includes(rmvList, o.id);
});
$scope.selected = {
items: [],
};
}
);
$scope.gridApi.selection.clearSelectedRows();
$scope.refreshData("expand-right", $scope.fileData);
//取消遮罩层
// $scope.isMask = false;
} else {
$rootScope.isMask = false;
SweetAlert.swal({
title: "操作异常!",
text: "系统异常,请稍后重试,或者联系管理员!",
type: "error",
});
}
});
}
}
},
function () {
// $scope.ldloading[style.replace('-', '_')] = false;
}
);
};
$scope.selected = {
items: [],
};
$scope.editted = {
items: [],
};
$scope.testRow = [];
$scope.gridOptions.onRegisterApi = function (gridApi) {
//导入gridApi对象
$scope.gridApi = gridApi;
//分页选项
gridApi.pagination.on.paginationChanged(
$scope,
function (newPage, pageSize) {
var filterData = JSON.parse(sessionStorage.repairSummaryParameter);
var filtersData = {};
filtersData.idx = newPage - 1;
filtersData.sum = pageSize;
$scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
// console.log(pp);
filterData.idx = $scope.pageNum;
$scope.fileData.idx = newPage - 1;
$scope.fileData.sum = pageSize;
sessionStorage.repairSummaryParameter = JSON.stringify(filterData);
$scope.refreshData("expand-right", $scope.fileData);
}
);
//勾选行事件
gridApi.selection.on.rowSelectionChanged($scope, function (data) {
if (data.isSelected) {
$scope.selected.items.push(data.entity);
} else {
//objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
//array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
//angular.forEach(objs, function(data,index,array)
angular.forEach(
$scope.selected.items,
function (ObjIndex, index, destObj) {
// console.log(ObjIndex);
// console.log(index);
// console.log(destObj);
if (ObjIndex.id == data.entity.id) {
destObj.splice(index, 1);
}
}
);
}
});
//批量全选
gridApi.selection.on.rowSelectionChangedBatch(
$scope,
function (rows, event) {
// if ($scope.selected.items.length != 0) {
// $scope.selected.items = [];
angular.forEach(rows, function (ObjIndex, index, destObj) {
if (ObjIndex.isSelected) {
$scope.selected.items.push(ObjIndex.entity);
} else {
$scope.selected.items = [];
// $scope.selected.items.splice(index, 1);
}
});
// } else {
// }
// $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
// if ($scope.selected.items.length == 0) {
// $scope.selected.items = $scope.mySelectedRows;
// } else if ($scope.mySelectedRows.length == 0) {
// for (var i = 0; i < $scope.selected.items.length; i++) {
// for (var j = 0; j < rows.length; j++) {
// if ($scope.selected.items[i].id == rows[j].entity.id) {
// $scope.selected.items.splice(i, 1);
// }
// }
// }
// } else {
// angular.forEach($scope.mySelectedRows, function(item) {
// $scope.selected.items.push(item);
// });
// }
}
);
//列过滤事件
gridApi.core.on.filterChanged($scope, function () {
var grid = this.grid;
var filterData = JSON.parse(sessionStorage.repairSummaryParameter);
angular.forEach(grid.columns, function (item) {
if (item.enableFiltering) {
if (
angular.isDefined(item.filters[0].term) &&
item.filters[0].term != ""
) {
if (angular.isUndefined(filterData["repairSummary"])) {
filterData["repairSummary"] = {};
}
filterData["repairSummary"]["title"] = item.filters[0].term;
}
}
});
sessionStorage.repairSummaryParameter = JSON.stringify(filterData);
$scope.refreshData("expand-right", filterData);
});
};
//数据刷新
$scope.refreshData = function (style, filterData) {
$scope.ldloading[style.replace("-", "_")] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
$scope.myData = [];
if($rootScope.user.duty){
filterData.repairSummary.dutyId = $rootScope.user.duty.id;
}else if($rootScope.user.branch){
filterData.repairSummary.branch = $rootScope.user.branch.id;
}
api_bpm_data.fetchDataList("repairSummary", filterData).then(
function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
if (angular.isArray(myData.list)) {
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]["item"] =
i + 1 + filterData.idx * filterData.sum;
if ($scope.myData[i].doing + $scope.myData[i].completed != 0) {
$scope.myData[i].percent = (
($scope.myData[i].completed * 100) /
($scope.myData[i].doing + $scope.myData[i].completed)
).toFixed(1);
} else if ($scope.myData[i].completed == 0) {
$scope.myData[i].percent = "0.0";
} else {
$scope.myData[i].percent = "0.0";
}
}
console.log($scope.myData);
for (var i = 0; i < $scope.myData.length; i++) {
if ($scope.myData[i].status == "正常") {
$scope.myData[i].style = "fa fa-play";
} else if ($scope.myData[i].status == "停止") {
$scope.myData[i].style = "fa fa-pause";
}
$scope.myData[i].runStatus = $scope.transfer(
$scope.myData[i].status
);
}
} else {
SweetAlert.swal({
title: "数据为空",
text: myData.data,
type: "warning",
});
}
$scope.ldloading[style.replace("-", "_")] = false;
},
function () {
$scope.ldloading[style.replace("-", "_")] = false;
}
);
};
$scope.refreshData2 = function (style, filterData) {
$scope.ldloading[style.replace("-", "_")] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
// $scope.myData = [];
if($rootScope.user.duty){
filterData.repairSummary.dutyId = $rootScope.user.duty.id;
}else if($rootScope.user.branch){
filterData.repairSummary.branch = $rootScope.user.branch.id;
}
api_bpm_data.fetchDataList("repairSummary", filterData).then(
function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
if (angular.isArray(myData.list)) {
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]["item"] =
i + 1 + filterData.idx * filterData.sum;
if ($scope.myData[i].doing + $scope.myData[i].completed != 0) {
$scope.myData[i].percent = (
($scope.myData[i].completed * 100) /
($scope.myData[i].doing + $scope.myData[i].completed)
).toFixed(1);
} else if ($scope.myData[i].completed == 0) {
$scope.myData[i].percent = "0.0";
} else {
$scope.myData[i].percent = "0.0";
}
}
console.log($scope.myData);
for (var i = 0; i < $scope.myData.length; i++) {
if ($scope.myData[i].status == "正常") {
$scope.myData[i].style = "fa fa-play";
} else if ($scope.myData[i].status == "停止") {
$scope.myData[i].style = "fa fa-pause";
}
$scope.myData[i].runStatus = $scope.transfer(
$scope.myData[i].status
);
}
} else {
SweetAlert.swal({
title: "数据为空",
text: myData.data,
type: "warning",
});
}
$scope.ldloading[style.replace("-", "_")] = false;
},
function () {
$scope.ldloading[style.replace("-", "_")] = false;
}
);
};
$scope.ldloading = {};
$scope.fileData = {
idx: 0,
sum: 10,
repairSummary: {},
};
$scope.inspecttype = {};
$scope.searchinspe = function (item) {
$scope.refreshData("expand-right", $scope.fileData);
};
$scope.refresh = function () {
var jry_filterData = JSON.parse(sessionStorage.repairSummaryParameter);
var intervalData = {};
intervalData.idx = jry_filterData.idx;
intervalData.sum = jry_filterData.sum;
intervalData.repairSummary = $scope.inspectdata;
$scope.refreshData("expand-right", intervalData);
};
$scope.refreshData("expand-right", $scope.fileData);
$scope.timer = $interval(function () {
$scope.refreshData2("expand-right", $scope.fileData);
}, $rootScope.refreshTime);
$scope.$on("$destroy", function () {
$interval.cancel($scope.timer);
});
},
]);