123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572 |
- '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 = '<div style="background: red"><a>123</a></div';
- // $scope.gridOptions.rowTemplate = "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
- $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: '<div>' +
- '<div class="ui-grid-cell-contents" tooltip={{grid.appScope.transfertip(row.entity.ruleColour)}} tooltip-placement="right"><i style="font-size: 18px !important;" class="{{grid.appScope.transferColor(row.entity.ruleColour)}}"></i></div></div>'
- },
- {
- 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: '<div>' +
- '<div class="ui-grid-cell-contents">{{grid.appScope.transferTime(row.entity.startDate)}}</div>' +
- '</div>'
- },
- {
- name: 'overdueTime',
- displayName: '逾期时间',
- width: '15%',
- width: 160,
- enableFiltering: false,
- cellTemplate: '<div>' +
- '<div class="ui-grid-cell-contents">{{grid.appScope.transferTime(row.entity.overdueTime)}}</div>' +
- '</div>'
- },
- {
- name: '操作',
- minWidth: '150',
- enableFiltering: false,
- cellTemplate: '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
- '<a ng-click="grid.appScope.lookFunction(row.entity)" tooltip="查看" tooltip-placement="right" class="bianjifont">查看</a>' +
- '<a ng-show="{{grid.appScope.showChuli(row.entity)&&grid.appScope.chuli}}" ng-click="grid.appScope.selectRowFunction(row.entity)" class="bianjifont">处理</a>' +
- // '<a ng-show="{{!row.entity.state==1}}" ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"/></a>' +
- '</div>'
- },
- ];
- // $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)
- })
- }]);
|