'use strict';
/**
* controller for User Profile Example
*/
app.controller('inspectListCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", "api_configure_data", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data, api_configure_data) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
var loginUser = $rootScope.user;
$scope.chuli = false;
for (var i = 0; i < loginUser.menu.length; i++) {
if (loginUser.menu[i].link == "xunjianliebiao_chuli") {
$scope.chuli = true
}
}
var defaultFilterData = {
"assignee": loginUser.id,
// "assignee": "1",
"idx": 0,
"sum": 10,
"status": '',
"searchType": "todo"
};
var inspectListParameter = {
"assignee": loginUser.id,
// "assignee": "1",
"idx": 0,
"sum": 10,
"status": ''
};
// $scope.memoryfilterData = {
// "idx": 0,
// "sum": 10
// }
//本地存储
sessionStorage.inspectListParameter = JSON.stringify(inspectListParameter);
//ui-grid设置
$scope.gridOptions = {};
$scope.gridOptions.data = 'myData';
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = true;
$scope.gridOptions.enableGridMenu = true;
$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, 20, 50, 100];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = true;
// $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 && 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 && item.colourInfo) {
if (item.colourInfo.id == 1) {
tip = "逾期";
} else if (item.colourInfo.id == 2) {
tip = "即将逾期";
}
} else {
// color = "white";
}
return tip;
}
$scope.gridOptions.columnDefs = [{
name: 'id',
displayName: '',
width: 40,
enableFiltering: false,
cellTemplate: ''
},
{
name: 'sign',
displayName: '单号',
width: '12%',
minWidth: 120,
enableFiltering: false
},
{
name: 'inspection.inspectionType.type',
displayName: '巡检分类',
width: '12%',
minWidth: 120,
enableFiltering: false
},
{
name: 'inspection.title',
displayName: '计划主题',
width: '12%',
minWidth: 120,
enableFiltering: false
},
{
name: 'inspection.createUser.name',
displayName: '创建人',
width: '8%',
minWidth: 80,
enableFiltering: false
},
{
name: 'stateName',
displayName: '状态',
width: '8%',
minWidth: 80,
enableFiltering: false
},
{
name: 'inspection.executeUser.name',
displayName: '处理人',
width: '8%',
minWidth: 80,
enableFiltering: false
},
{
name: 'startDate',
displayName: '开始时间',
width: '15%',
minWidth: 160,
enableFiltering: false,
cellTemplate: '' +
'
{{grid.appScope.transferTime(row.entity.startDate)}}
' +
'
'
},
{
name: 'overdueTime',
displayName: '逾期时间',
width: '15%',
width: 160,
enableFiltering: false,
cellTemplate: '' +
'
{{grid.appScope.transferTime(row.entity.overdueTime)}}
' +
'
'
},
{
name: '操作',
minWidth: '150',
enableFiltering: false,
cellTemplate: '' +
'
查看' +
'
处理' +
// '
' +
'
'
},
];
// $scope.addData = function() {
// $state.go('app.inspection.inspectList.editor', {
// formKey: 'inspectionform',
// service: 'api_bpm_data'
// });
// }
$scope.transferTime = function (time) {
return moment(time).format('YYYY-MM-DD HH:mm');
}
$scope.showChuli=function(data){
if(data.processUser.id==loginUser.id&&data.stateName=="执行中"){
return true
} else {
return false
}
}
$scope.selectRowFunction = function (data) {
var filedata = {
model: {
inspectionProcessActual: data
}
}
$state.go('app.inspection.inspectListEditor', {
"taskId": data.taskId,
'dataId': data.id,
"processInstanceId": data.processInstanceId,
"pdKey": data.processKey,
"formUiEdit": data.inspection.inspectionType.formUiEdit,
// "formUiName": data.inspection.inspectionTypeDTO.formUiName,
"model": JSON.stringify(filedata)
});
};
$scope.lookFunction = function (data) {
var filedata = {
model: {
inspectionProcessActual: data
}
// model:data
}
$state.go('app.inspection.inspectListdetail', {
"formKey": data.inspection.inspectionType.formUiName,
"dataId": data.id,
"taskId": data.taskId,
"processInstanceId": data.processInstanceId,
"pdKey": data.processKey,
// "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
"formUiName": data.inspection.inspectionType.formUiName,
"model": JSON.stringify(filedata)
});
};
$scope.model = {
"assignee": JSON.parse(sessionStorage.inspectListParameter).assignee,
"idx": 0,
"sum": 10,
"searchType": "todo",
"inspectionProcessActual": {
"inspection": {}
}
};
// $scope.removeData = function() {
// // var rmvList = [$scope.selected.items.id]
// var rmvList = [];
// angular.forEach($scope.selected.items, function(item) {
// rmvList.push(item.id);
// });
// if (rmvList.length > 0) {
// api_bpm_data.rmvData('inspection', rmvList).then(function(response) {
// if (response.status == 200) {
// SweetAlert.swal({
// title: "删除成功!",
// type: "success",
// confirmButtonColor: "#007AFF"
// }, function() {
// $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
// $scope.selected = {
// items: []
// };
// });
// } else {
// SweetAlert.swal({
// title: "操作异常!",
// text: "系统异常,请稍后重试,或者联系管理员!",
// type: "error"
// });
// }
// })
// }
// }
$scope.selected = {
items: []
}
$scope.editted = {
items: []
}
$scope.jry_idx = 0;
$scope.jry_sum = 10;
//分页控制
$scope.gridOptions.onRegisterApi = function (gridApi) {
gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
console.log("ok");
var filterData = JSON.parse(sessionStorage.inspectListParameter);
filterData.idx = newPage - 1;
filterData.sum = pageSize;
$scope.jry_idx = newPage - 1;
$scope.jry_sum = pageSize;
$scope.model.idx = newPage - 1;
$scope.model.sum = pageSize;
$scope.refreshData('expand-right', $scope.model);
});
// gridApi.selection.on.rowSelectionChanged($scope, function(data) {
// data.grid.appScope.selected.items = data.entity
// console.log(data);
// });
}
// var data = JSON.parse(sessionStorage.inspectListParameter);
// sessionStorage.inspectListParameter = JSON.stringify(data);
$scope.ldloading = {};
$scope.statusData = {};
//搜索事件
$scope.searchinspectlist = function (item) {
var filterData = JSON.parse(sessionStorage.inspectListParameter);
// console.log(filterData);
// if (item.type) {
// filterData.inspection = { 'inspectionTypeDTO': { 'id':item.type.id}};
// }
// if (item.title) {
// filterData.inspection = { 'title': item.title};
// }
$scope.model.idx = $scope.jry_idx;
$scope.model.sum = $scope.jry_sum;
if ($scope.model.inspectionProcessActual.inspectionType) {
$scope.model.inspectionTypeId = $scope.model.inspectionProcessActual.inspectionType.id;
delete $scope.model.inspectionProcessActual.inspectionType
}
if ($scope.statusData.state) {
$scope.model.inspectionProcessActual.state = $scope.statusData.state.state
}
// filterData.status = item;
sessionStorage.inspectListParameter = JSON.stringify(filterData);
$scope.refreshData('expand-right', $scope.model);
};
$scope.clean = function () {
delete $scope.model.inspectionProcessActual.inspection.title;
delete $scope.model.inspectionProcessActual.inspectionType;
delete $scope.model.inspectionTypeId;
delete $scope.model.inspectionProcessActual.inspection.executeUser;
delete $scope.model.inspectionProcessActual.inspection.createUser;
delete $scope.model.inspectionProcessActual.state;
$scope.statusData = {};
$scope.try_async_load();
$scope.refreshData('expand-right', $scope.model);
}
//树形控件点击事件
$scope.my_tree_handler = function (branch) {
var filterData = JSON.parse(sessionStorage.inspectListParameter);
filterData.status = branch.id;
// if (filterData.inspectionProcessActual) {
// filterData.inspectionProcessActual.inspectionTypeId = branch.id;
// } else {
// filterData = angular.extend(filterData, {
// "inspectionProcessActual": {
// "inspectionTypeId": branch.id
// }
// })
// }
sessionStorage.inspectListParameter = JSON.stringify(filterData);
$scope.refreshData('expand-right', filterData);
};
//搜索栏点击事件
$scope.searchstate = 'todo';
$scope.onChange = function (searchType) {
$scope.searchstate = searchType;
var filterData = JSON.parse(sessionStorage.inspectListParameter);
filterData.searchType = searchType;
$scope.model.searchType = searchType;
sessionStorage.inspectListParameter = JSON.stringify(filterData);
$scope.refreshData('expand-right', $scope.model);
}
$scope.reload = function () {
var filterData = JSON.parse(sessionStorage.inspectListParameter);
$scope.refreshData('expand-right', filterData);
}
$scope.refreshData = function (style, filterData) {
$scope.ldloading[style.replace('-', '_')] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
$scope.myData = [];
$scope.memoryfilterData = filterData;
api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.resultCount;
if (angular.isArray(myData.data)) {
$scope.myData = myData.data;
for (var i = 0; i < $scope.myData.length; i++) {
//添加序号
$scope.myData[i]['itemId'] = i + 1 + filterData.idx * filterData.sum;
}
$scope.ldloading[style.replace('-', '_')] = false;
} else {
$scope.ldloading[style.replace('-', '_')] = false;
SweetAlert.swal({
title: "数据为空",
text: myData.data,
type: "warning"
});
}
}, function () {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
$scope.refreshData2 = function (style, filterData) {
$scope.ldloading[style.replace('-', '_')] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
// $scope.myData = [];
$scope.memoryfilterData = filterData;
api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.resultCount;
if (angular.isArray(myData.data)) {
$scope.myData = myData.data;
for (var i = 0; i < $scope.myData.length; i++) {
//添加序号
$scope.myData[i]['itemId'] = i + 1 + filterData.idx * filterData.sum;
}
$scope.ldloading[style.replace('-', '_')] = false;
} else {
$scope.ldloading[style.replace('-', '_')] = false;
SweetAlert.swal({
title: "数据为空",
text: myData.data,
type: "warning"
});
}
}, function () {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
$scope.inspecttype = {};
// 获取处理人
$scope.getExecuteUser = function () {
api_configure_data.fetchDataList("user", {
"idx": 0,
"sum": 1000,
"user": {
"roledata": {
"rolecode": "inspectman"
},
"simple": true
}
}).then(function (res) {
$scope.executeUserData = res.list
})
}
$scope.getExecuteUser()
$scope.statusData = [{
"name": "执行中",
"state": 0
},
{
"name": "已完成",
"state": 1
}
]
// 获取创建人
$scope.getCreateUser = function () {
api_configure_data.fetchDataList("user", {
"idx": 0,
"sum": 1000,
"user":{
"simple": true
}
}).then(function (res) {
$scope.createUserData = res.list
})
}
$scope.getCreateUser()
$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.my_tree = {};
$scope.try_async_load = function () {
$scope.my_data = [];
$scope.doing_async = true;
api_bpm_data.fetchDataList('inspectionType', {
"idx": 0,
"sum": 1000
}).then(function (response) {
if (response.status == 200) {
var data = response.list;
var objects = [];
for (var i = 0; i < data.length; i++) {
var object = {};
object.id = data[i].id;
if (data[i].parent && data[i].parent.id != 0) {
object.parent = data[i].parent.id;
}
object.label = data[i].type;
objects.push(object);
}
$scope.my_data = convertParentToChildList(objects);
$scope.tree_data = angular.copy($scope.my_data);
if ($scope.my_data.length > 0) {
$scope.doing_async = false;
}
// return $scope.my_tree.expand_all()
} else {
SweetAlert.swal({
title: "系统错误!",
text: "请刷新重试!",
type: "error"
});
}
});
};
function convertListToTree(data, treeMap) {
var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
var root = null; //Initially set our loop to null
var parentNode = null;
//loop over data
for (var i = 0; i < data.length; i++) {
var datum = data[i];
//each node will have children, so let's give it a "children" poperty
datum.children = [];
//add an entry for this node to the map so that any future children can
//lookup the parent
idToNodeMap[datum.id] = datum;
//Does this node have a parent?
if (typeof datum.parent === "undefined" || datum.parent == null) {
//Doesn't look like it, so this node is the root of the tree
root = datum;
treeMap[datum.id] = root;
} else {
//This node has a parent, so let's look it up using the id
parentNode = idToNodeMap[datum.parent];
//We don't need this property, so let's delete it.
delete datum.parent;
//Let's add the current node as a child of the parent node.
parentNode.children.push(datum);
}
}
return root;
}
function convertParentToChildList(data) {
var treeMap = {};
var list = [];
convertListToTree(data, treeMap);
angular.forEach(treeMap, function (item) {
list.push(item);
});
return list;
}
$scope.refreshData('expand-right', defaultFilterData);
$scope.try_async_load();
$scope.timer = $interval(function () {
$scope.refreshData2('expand-right', $scope.model);
}, $rootScope.refreshTime);
$scope.$on('$destroy', function () {
$interval.cancel($scope.timer)
})
}]);