'use strict'; /** * controller for User Profile Example */ app.controller('scoreConfigurationPerformanceCtrl', ["$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.xinzeng = false; $scope.shanchu = false; $scope.bianji = false; $scope.zantingzhixing = false; for (var i = 0; i < loginUser.menu.length; i++) { if (loginUser.menu[i].link == "xunjianjihua_xinzeng") { $scope.xinzeng = true } if (loginUser.menu[i].link == "xunjianjihua_shanchu") { $scope.shanchu = true } if (loginUser.menu[i].link == "xunjianjihua_bianji") { $scope.bianji = true } if (loginUser.menu[i].link == "xunjianjihua_zantingzhixing") { $scope.zantingzhixing = true } } var defaultFilterData = { "idx": 0, "sum": 10 }; $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.gridOptions.columnDefs = [{ name: 'item', displayName: '序号', width: 50, enableFiltering: false }, { name: 'parent.parent.category', displayName: '一级分类', width: '10%', enableFiltering: false }, { name: 'parent.category', displayName: '二级分类', width: '10%', enableFiltering: false }, { name: 'category', displayName: '三级分类', width: '10%', enableFiltering: false }, { name: 'complexity.value', displayName: '默认积分', width: '5%', enableFiltering: false }, { name: 'five', displayName: '积分规则', width: '50%', enableFiltering: false, cellTemplate: '
' + '【{{item.startCount}}-{{item.endCount}}单】获得积分{{item.score}};' + '
' }, { minWidth: '100', name: '操作', enableFiltering: false, cellTemplate: '
' + '编辑' + '
' }, ]; $scope.gridOptions.onRegisterApi = function (gridApi) { //导入gridApi对象 $scope.gridApi = gridApi; //分页选项 gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) { var filtersData = {}; filtersData.idx = newPage - 1; filtersData.sum = pageSize; $scope.pageNum = $scope.gridApi.pagination.getPage() - 1; $scope.fileData.idx = newPage - 1; $scope.fileData.sum = pageSize; $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) { angular.forEach(rows, function (ObjIndex, index, destObj) { if (ObjIndex.isSelected) { $scope.selected.items.push(ObjIndex.entity); } else { $scope.selected.items = []; } }); }); }; // 批量修改积分 $scope.edits = function () { var modalInstance = $modal.open({ templateUrl: 'assets/views/scoreConfigurationPerformance-edit.html', size: "sm", controller: function ($scope, scope, $modalInstance, SweetAlert) { console.log(scope.selected.items); $scope.incidentComplexity = scope.incidentComplexity; $scope.configs = { defaultScore:null, configs: [], selectedItems: scope.selected.items, refreshData: scope.refreshData, fileData: scope.fileData }; // 增加配置 $scope.addConfig = function(){ $scope.configs.configs.push({startCount: 1, endCount: 1, score: 1}); } // 移除配置 $scope.removeConfig = function(index){ $scope.configs.configs.splice(index, 1); } $scope.ok = function () { // 校验 var flag = true; if($scope.configs.configs.length){ //是否是大于1的正整数 var isNumberReg = /^[1-9][0-9]*$/; $scope.configs.configs.forEach(v => { if(!isNumberReg.test(v.startCount) || !isNumberReg.test(v.endCount) || !isNumberReg.test(v.score)){ flag = false; } }) //是否起始 < 终值 if(flag){ $scope.configs.configs.forEach(v => { if(v.startCount > v.endCount){ flag = false; } }) } // 是否有区间交叉 if(flag){ let startArr = $scope.configs.configs.map(v => v.startCount); let endArr = $scope.configs.configs.map(v => v.endCount); for(let i=1;i v.id).toString(), removeComplexity: 1, removeRules: 1 } if (result) { $rootScope.isMask = true; api_bpm_data.setScoreRule(postData).then(function (response) { $rootScope.isMask = false; if(response.status == 200){ var postData = { ids: result.selectedItems.map(v => v.id).toString(), complexity: result.defaultScore?result.defaultScore.id:undefined, rules: result.configs.length?result.configs:undefined } api_bpm_data.setScoreRule(postData).then(function (response) { if(response.status == 200){ SweetAlert.swal({ title: "操作成功!", type: "success", }); result.refreshData('expand-right', result.fileData); }else{ SweetAlert.swal({ title: "操作失败!", type: "error", }); } }) }else{ SweetAlert.swal({ title: "操作失败!", type: "error", }); } }) } }); }; //编辑 $scope.edit = function (data) { console.log(data); var modalInstance = $modal.open({ templateUrl: 'assets/views/scoreConfigurationPerformance-edit.html', size: "sm", controller: function ($scope, scope, $modalInstance, SweetAlert) { console.log(scope.selected.items); $scope.incidentComplexity = scope.incidentComplexity; $scope.configs = { defaultScore:data.complexity || null, configs: data.rules ? data.rules.map(v=>({startCount:v.startCount,endCount:v.endCount,score:v.score})) : [], selectedItems: [data], refreshData: scope.refreshData, fileData: scope.fileData }; // 增加配置 $scope.addConfig = function(){ $scope.configs.configs.push({startCount: 1, endCount: 1, score: 1}); } // 移除配置 $scope.removeConfig = function(index){ $scope.configs.configs.splice(index, 1); } $scope.ok = function () { // 校验 var flag = true; if($scope.configs.configs.length){ //是否是大于1的正整数 var isNumberReg = /^[1-9][0-9]*$/; $scope.configs.configs.forEach(v => { if(!isNumberReg.test(v.startCount) || !isNumberReg.test(v.endCount) || !isNumberReg.test(v.score)){ flag = false; } }) //是否起始 < 终值 if(flag){ $scope.configs.configs.forEach(v => { if(v.startCount > v.endCount){ flag = false; } }) } // 是否有区间交叉 if(flag){ let startArr = $scope.configs.configs.map(v => v.startCount); let endArr = $scope.configs.configs.map(v => v.endCount); for(let i=1;i v.id).toString(), removeComplexity: 1, removeRules: 1 } if (result) { $rootScope.isMask = true; api_bpm_data.setScoreRule(postData).then(function (response) { $rootScope.isMask = false; if(response.status == 200){ var postData = { ids: result.selectedItems.map(v => v.id).toString(), complexity: result.defaultScore?result.defaultScore.id:undefined, rules: result.configs.length?result.configs:undefined } api_bpm_data.setScoreRule(postData).then(function (response) { if(response.status == 200){ SweetAlert.swal({ title: "操作成功!", type: "success", }); result.refreshData('expand-right', result.fileData); }else{ SweetAlert.swal({ title: "操作失败!", type: "error", }); } }) }else{ SweetAlert.swal({ title: "操作失败!", type: "error", }); } }) } }); }; $scope.selected = { items: [] } //重置按钮 $scope.reload = function () { this.two_cates = []; delete $scope.fileData.incidentcategory.oneCate; delete $scope.fileData.incidentcategory.twoCate; $scope.refreshData('expand-right', $scope.fileData); } //数据刷新 $scope.refreshData = function (style, filterData) { $scope.ldloading[style.replace('-', '_')] = true; if (angular.isUndefined(filterData)) { filterData = defaultFilterData; } $scope.myData = []; var postData = angular.copy(filterData); if(postData.incidentcategory.twoCate){ postData.incidentcategory.id = postData.incidentcategory.twoCate.id; postData.incidentcategory.cascade = true; delete postData.incidentcategory.oneCate; delete postData.incidentcategory.twoCate; }else if(postData.incidentcategory.oneCate){ postData.incidentcategory.id = postData.incidentcategory.oneCate.id; postData.incidentcategory.cascade = true; delete postData.incidentcategory.oneCate; } postData.incidentcategory.selectType = 'three'; postData.incidentcategory.rules = []; api_bpm_data.fetchDataList('incidentcategory', postData).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; } console.log($scope.myData) } 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; } var postData = angular.copy(filterData); if(postData.incidentcategory.twoCate){ postData.incidentcategory.id = postData.incidentcategory.twoCate.id; postData.incidentcategory.cascade = true; delete postData.incidentcategory.oneCate; delete postData.incidentcategory.twoCate; }else if(postData.incidentcategory.oneCate){ postData.incidentcategory.id = postData.incidentcategory.oneCate.id; postData.incidentcategory.cascade = true; delete postData.incidentcategory.oneCate; } postData.incidentcategory.selectType = 'three'; postData.incidentcategory.rules = []; api_bpm_data.fetchDataList('incidentcategory', postData).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 } console.log($scope.myData) } 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, "incidentcategory": {} } $scope.searchinspe = function () { $scope.refreshData('expand-right', $scope.fileData); } // 获取默认积分 $scope.incidentComplexity = []; $scope.getIncidentComplexity = function () { api_wechatfile.getDictionary({ key: "incident_complexity", type: "list" }).then(function (res) { $scope.incidentComplexity = res; }) } $scope.getIncidentComplexity(); // 获取一级分类 $scope.getOneCates = function (keyword='') { $scope.one_cates = []; api_configure_data.fetchDataList("incidentcategory", { "idx": 0, "sum": 1000, "incidentcategory": { category: keyword, selectType: 'one' } }).then(function (res) { $scope.one_cates = res.list; }) } // 选择一级分类 $scope.changeOneCate = function(oneCate){ $scope.getTwoCates(oneCate); } // 获取二级分类 $scope.getTwoCates = function (oneCate, keyword='') { $scope.two_cates = []; if(!oneCate){ return; } api_configure_data.fetchDataList("incidentcategory", { "idx": 0, "sum": 1000, "incidentcategory": { category: keyword, parentCategory:{id:oneCate.id} } }).then(function (res) { $scope.two_cates = res.list }) } $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) }) }]);