'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", 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": "todo" }; 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, 20, 50, 100]; $scope.gridOptions.paginationPageSize = 10; $scope.gridOptions.multiSelect = true; // $scope.gridOptions.rowTemplate = '
123
"; $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: 'inspection.inspectionType.type', displayName: '巡检分类', width: 120, enableFiltering: false }, { name: 'inspection.title', displayName: '计划主题', width: 120, enableFiltering: false }, { name: 'inspection.createUser.name', displayName: '创建人', width: 80, enableFiltering: false }, { name: 'stateName', displayName: '状态', width: 80, enableFiltering: false }, { name: 'processUser.name', displayName: '处理人', width: 80, enableFiltering: false }, { name: 'startDate', displayName: '开始时间', width: 160, enableFiltering: false }, { name: 'overdueTime', displayName: '逾期时间', width: 160, enableFiltering: false }, { name: '操作', // width: 100, enableFiltering: false, cellTemplate: '
' + '查看' + '处理' + // '' + '
' }, ]; // $scope.addData = function() { // $state.go('app.inspection.inspectList.editor', { // formKey: 'inspectionform', // service: 'api_bpm_data' // }); // } $scope.selectRowFunction = function(data) { var filedata={ model:{inspectionProcessActual:data} } $state.go('app.inspection.inspectListEditor', { "taskId": data.taskId, "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.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.searchinspectlist = function(item) { var filterData = JSON.parse(sessionStorage.inspectListParameter); if (item.type) { filterData.status = item.type.id; } if (item.title) { filterData.title = item.title; } // filterData.status = item; sessionStorage.inspectListParameter = JSON.stringify(filterData); $scope.refreshData('expand-right', filterData); }; //树形控件点击事件 $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; 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 = []; $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.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(); }]);