'use strict';
/**
* controller for User Profile Example
*/
app.controller('inspectListMobileCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
var loginUser = $rootScope.user;
var defaultFilterData = {
"assignee": loginUser.id,
// "assignee": "1",
"idx": 0,
"sum": 10,
"status": '',
// "searchType": "all"
};
var inspectListParameter = {
"assignee": loginUser.id,
// "assignee": "1",
"idx": 0,
"sum": 10,
"status": ''
};
// $scope.memoryfilterData = {
// "idx": 0,
// "sum": 10
// }
//ui-grid设置
$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 = true;
// $scope.gridOptions.rowTemplate = '
";
$scope.gridOptions.rowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.columnDefs = [
// { name: 'itemId', displayName: '序号', width: 50, enableFiltering: false },
{
name: '操作',
width: 100,
enableFiltering: false,
cellTemplate: ''
},
// {
// name: '修改',
// cellTemplate: '',
// width: 50,
// enableFiltering: false
// },
{
name: 'inspection.inspectionTypeDTO.type',
displayName: '巡检分类',
width: 120,
enableFiltering: false,
cellTemplate: '{{row.entity.inspection.inspectionTypeDTO.type}}
'
},
{
name: 'inspection.title',
displayName: '计划主题',
width: 120,
enableFiltering: false,
cellTemplate: '{{row.entity.inspection.title}}
'
},
{
name: 'inspection.createUser.name',
displayName: '创建人',
width: 80,
enableFiltering: false,
cellTemplate: '{{row.entity.inspection.createUser.name}}
'
},
{
name: 'stateName',
displayName: '状态',
width: 80,
enableFiltering: false,
cellTemplate: '{{row.entity.stateName}}
'
},
{
name: 'processUser.name',
displayName: '处理人',
width: 80,
enableFiltering: false,
cellTemplate: '{{row.entity.processUser.name}}
'
},
{
name: 'startDate',
displayName: '开始时间',
width: 160,
enableFiltering: false,
cellTemplate: '{{row.entity.startDate}}
'
},
{
name: 'overdueTime',
displayName: '逾期时间',
width: 160,
enableFiltering: false,
cellTemplate: '{{row.entity.overdueTime}}
'
}
];
// $scope.addData = function() {
// $state.go('app.inspection.inspectList.editor', {
// formKey: 'inspectionform',
// service: 'api_bpm_data'
// });
// }
$scope.selectRowFunction = function(data) {
$state.go('app.inspection.inspectListEditor', {
"taskId": data.taskId,
"processInstanceId": data.processInstanceId,
"pdKey": data.processKey,
"formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
// "formUiName": data.inspection.inspectionTypeDTO.formUiName,
});
};
$scope.lookFunction = function(data) {
$state.go('app.inspection.inspectListdetail', {
"formKey": data.inspection.inspectionTypeDTO.formUiName,
"dataId": data.id,
"taskId": data.taskId,
"processInstanceId": data.processInstanceId,
"pdKey": data.processKey,
// "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
"formUiName": data.inspection.inspectionTypeDTO.formUiName,
});
};
// $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.gridOptions.onRegisterApi = function(gridApi) {
gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
var filterData = JSON.parse(sessionStorage.inspectListParameter);
filterData.idx = newPage - 1;
filterData.sum = pageSize;
$scope.refreshData('expand-right', filterData);
});
gridApi.selection.on.rowSelectionChanged($scope, function(data) {
data.grid.appScope.selected.items = data.entity
console.log(data);
});
}
//本地存储
sessionStorage.inspectListParameter = JSON.stringify(inspectListParameter);
// var data = JSON.parse(sessionStorage.inspectListParameter);
// sessionStorage.inspectListParameter = JSON.stringify(data);
$scope.ldloading = {};
//树形控件点击事件
$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.onChange = function(searchType) {
var filterData = JSON.parse(sessionStorage.inspectListParameter);
filterData.searchType = searchType;
// if (searchType == "") {
// filterData = defaultFilterData;
// } else if (searchType == "createUserId") {
// if (filterData.inspectionProcessActual && filterData.inspectionProcessActual.inspectionTypeId) {
// var inspectionTypeId = filterData.inspectionProcessActual.inspectionTypeId;
// filterData.inspectionProcessActual = {};
// filterData.inspectionProcessActual.inspectionTypeId = inspectionTypeId;
// filterData.inspectionProcessActual.createUserId = loginUser.id;
// } else {
// filterData.inspectionProcessActual = {};
// filterData.inspectionProcessActual.createUserId = loginUser.id;
// }
// } else if (searchType == "excuteUserId") {
// if (filterData.inspectionProcessActual && filterData.inspectionProcessActual.inspectionTypeId) {
// var inspectionTypeId = filterData.inspectionProcessActual.inspectionTypeId;
// filterData.inspectionProcessActual = {};
// filterData.inspectionProcessActual.inspectionTypeId = inspectionTypeId;
// filterData.inspectionProcessActual.excuteUserId = loginUser.id;
// } else {
// filterData.inspectionProcessActual = {};
// filterData.inspectionProcessActual.excuteUserId = loginUser.id;
// }
// }
// filterData.inspectionProcessActual.createUserId = loginUser.id;
sessionStorage.inspectListParameter = JSON.stringify(filterData);
$scope.refreshData('expand-right', filterData);
}
$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 = [];
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 {
SweetAlert.swal({
title: "数据为空",
text: myData.data,
type: "warning"
});
}
}, function() {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
//树形控件加载
$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();
}]);