scoreConfigurationPerformanceCtrl.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. 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) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. $scope.xinzeng = false;
  11. $scope.shanchu = false;
  12. $scope.bianji = false;
  13. $scope.zantingzhixing = false;
  14. for (var i = 0; i < loginUser.menu.length; i++) {
  15. if (loginUser.menu[i].link == "xunjianjihua_xinzeng") {
  16. $scope.xinzeng = true
  17. }
  18. if (loginUser.menu[i].link == "xunjianjihua_shanchu") {
  19. $scope.shanchu = true
  20. }
  21. if (loginUser.menu[i].link == "xunjianjihua_bianji") {
  22. $scope.bianji = true
  23. }
  24. if (loginUser.menu[i].link == "xunjianjihua_zantingzhixing") {
  25. $scope.zantingzhixing = true
  26. }
  27. }
  28. var defaultFilterData = {
  29. "idx": 0,
  30. "sum": 10
  31. };
  32. $scope.gridOptions = {};
  33. $scope.gridOptions.data = 'myData';
  34. $scope.gridOptions.enableColumnResizing = true;
  35. $scope.gridOptions.enableFiltering = false;
  36. $scope.gridOptions.enableGridMenu = true;
  37. $scope.gridOptions.enableRowSelection = true;
  38. $scope.gridOptions.showGridFooter = true;
  39. $scope.gridOptions.showColumnFooter = false;
  40. $scope.gridOptions.useExternalFiltering = false;
  41. $scope.gridOptions.useExternalPagination = true;
  42. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  43. $scope.gridOptions.paginationPageSize = 10;
  44. $scope.gridOptions.multiSelect = true;
  45. $scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
  46. //行鼠标悬浮变色功能
  47. // $scope.gridOptions.rowTemplate = '<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ng-mouseover="grid.appScope.hoveredIndex = rowRenderIndex" ng-mouseleave="grid.appScope.hoveredIndex = null" ui-grid-one-bind-id-grid="rowRenderIndex + \'-\' + col.uid + \'-cell\'" class="ui-grid-cell" ng-class="{\'ui-grid-row-header-cell\': col.isRowHeader, \'your-hover-class\': grid.appScope.hoveredIndex === rowRenderIndex}" role="{{col.isRowHeader ? \'rowheader\' : \'gridcell\'}}" ui-grid-cell></div>';
  48. $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>";
  49. $scope.gridOptions.rowIdentity = function (row) {
  50. return row.id;
  51. };
  52. $scope.gridOptions.getRowIdentity = function (row) {
  53. return row.id;
  54. };
  55. $scope.gridOptions.columnDefs = [{
  56. name: 'item',
  57. displayName: '序号',
  58. width: 50,
  59. enableFiltering: false
  60. },
  61. {
  62. name: 'parent.parent.category',
  63. displayName: '一级分类',
  64. width: '10%',
  65. enableFiltering: false
  66. },
  67. {
  68. name: 'parent.category',
  69. displayName: '二级分类',
  70. width: '10%',
  71. enableFiltering: false
  72. },
  73. {
  74. name: 'category',
  75. displayName: '三级分类',
  76. width: '10%',
  77. enableFiltering: false
  78. },
  79. {
  80. name: 'complexity.value',
  81. displayName: '默认积分',
  82. width: '5%',
  83. enableFiltering: false
  84. },
  85. {
  86. name: 'five',
  87. displayName: '积分规则',
  88. width: '50%',
  89. enableFiltering: false,
  90. cellTemplate: '<div class="ui-grid-cell-contents">' +
  91. '<span ng-repeat="item in row.entity.rules">【{{item.startCount}}-{{item.endCount}}单】获得积分{{item.score}};</span>' +
  92. '</div>'
  93. },
  94. {
  95. minWidth: '100',
  96. name: '操作',
  97. enableFiltering: false,
  98. cellTemplate: '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  99. '<a ng-click="grid.appScope.edit(row.entity)">编辑</a>' +
  100. '</div>'
  101. },
  102. ];
  103. $scope.gridOptions.onRegisterApi = function (gridApi) {
  104. //导入gridApi对象
  105. $scope.gridApi = gridApi;
  106. //分页选项
  107. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  108. var filtersData = {};
  109. filtersData.idx = newPage - 1;
  110. filtersData.sum = pageSize;
  111. $scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
  112. $scope.fileData.idx = newPage - 1;
  113. $scope.fileData.sum = pageSize;
  114. $scope.refreshData('expand-right', $scope.fileData);
  115. });
  116. //勾选行事件
  117. gridApi.selection.on.rowSelectionChanged($scope, function (data) {
  118. if (data.isSelected) {
  119. $scope.selected.items.push(data.entity);
  120. } else {
  121. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  122. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  123. //angular.forEach(objs, function(data,index,array)
  124. angular.forEach($scope.selected.items, function (ObjIndex, index, destObj) {
  125. // console.log(ObjIndex);
  126. // console.log(index);
  127. // console.log(destObj);
  128. if (ObjIndex.id == data.entity.id) {
  129. destObj.splice(index, 1)
  130. }
  131. })
  132. }
  133. });
  134. //批量全选
  135. gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows, event) {
  136. angular.forEach(rows, function (ObjIndex, index, destObj) {
  137. if (ObjIndex.isSelected) {
  138. $scope.selected.items.push(ObjIndex.entity);
  139. } else {
  140. $scope.selected.items = [];
  141. }
  142. });
  143. });
  144. };
  145. // 批量修改积分
  146. $scope.edits = function () {
  147. var modalInstance = $modal.open({
  148. templateUrl: 'assets/views/scoreConfigurationPerformance-edit.html',
  149. size: "sm",
  150. controller: function ($scope, scope, $modalInstance, SweetAlert) {
  151. console.log(scope.selected.items);
  152. $scope.incidentComplexity = scope.incidentComplexity;
  153. $scope.configs = {
  154. defaultScore:null,
  155. configs: [],
  156. selectedItems: scope.selected.items,
  157. refreshData: scope.refreshData,
  158. fileData: scope.fileData
  159. };
  160. // 增加配置
  161. $scope.addConfig = function(){
  162. $scope.configs.configs.push({startCount: 1, endCount: 1, score: 1});
  163. }
  164. // 移除配置
  165. $scope.removeConfig = function(index){
  166. $scope.configs.configs.splice(index, 1);
  167. }
  168. $scope.ok = function () {
  169. // 校验
  170. var flag = true;
  171. if($scope.configs.configs.length){
  172. //是否是大于1的正整数
  173. var isNumberReg = /^[1-9][0-9]*$/;
  174. $scope.configs.configs.forEach(v => {
  175. if(!isNumberReg.test(v.startCount) || !isNumberReg.test(v.endCount) || !isNumberReg.test(v.score)){
  176. flag = false;
  177. }
  178. })
  179. //是否起始 < 终值
  180. if(flag){
  181. $scope.configs.configs.forEach(v => {
  182. if(v.startCount > v.endCount){
  183. flag = false;
  184. }
  185. })
  186. }
  187. // 是否有区间交叉
  188. if(flag){
  189. let startArr = $scope.configs.configs.map(v => v.startCount);
  190. let endArr = $scope.configs.configs.map(v => v.endCount);
  191. for(let i=1;i<startArr.length;i++){
  192. if (startArr[i] <= endArr[i-1]){
  193. flag = false;
  194. break;
  195. }
  196. }
  197. }
  198. }
  199. if(!flag){
  200. SweetAlert.swal({
  201. title: "提示",
  202. text: "请正确填写选项!",
  203. type: "error"
  204. });
  205. return;
  206. }
  207. $modalInstance.close($scope.configs);
  208. };
  209. $scope.cancel = function () {
  210. $modalInstance.dismiss('cancel');
  211. };
  212. },
  213. resolve: {
  214. scope: function(){
  215. return $scope;
  216. }
  217. }
  218. })
  219. modalInstance.result.then(function (result) {
  220. console.log(result);
  221. var postData = {
  222. ids: result.selectedItems.map(v => v.id).toString(),
  223. complexity: result.defaultScore?result.defaultScore.id:undefined,
  224. rules: result.configs.length?result.configs:undefined
  225. }
  226. if (result) {
  227. $rootScope.isMask = true;
  228. api_bpm_data.setScoreRule(postData).then(function (response) {
  229. $rootScope.isMask = false;
  230. if(response.status == 200){
  231. SweetAlert.swal({
  232. title: "操作成功!",
  233. type: "success",
  234. });
  235. result.refreshData('expand-right', result.fileData);
  236. }else{
  237. SweetAlert.swal({
  238. title: "操作失败!",
  239. type: "error",
  240. });
  241. }
  242. })
  243. }
  244. });
  245. };
  246. //编辑
  247. $scope.edit = function (data) {
  248. console.log(data);
  249. var modalInstance = $modal.open({
  250. templateUrl: 'assets/views/scoreConfigurationPerformance-edit.html',
  251. size: "sm",
  252. controller: function ($scope, scope, $modalInstance, SweetAlert) {
  253. console.log(scope.selected.items);
  254. $scope.incidentComplexity = scope.incidentComplexity;
  255. $scope.configs = {
  256. defaultScore:data.complexity || null,
  257. configs: data.rules ? data.rules.map(v=>({startCount:v.startCount,endCount:v.endCount,score:v.score})) : [],
  258. selectedItems: [data],
  259. refreshData: scope.refreshData,
  260. fileData: scope.fileData
  261. };
  262. // 增加配置
  263. $scope.addConfig = function(){
  264. $scope.configs.configs.push({startCount: 1, endCount: 1, score: 1});
  265. }
  266. // 移除配置
  267. $scope.removeConfig = function(index){
  268. $scope.configs.configs.splice(index, 1);
  269. }
  270. $scope.ok = function () {
  271. // 校验
  272. var flag = true;
  273. if($scope.configs.configs.length){
  274. //是否是大于1的正整数
  275. var isNumberReg = /^[1-9][0-9]*$/;
  276. $scope.configs.configs.forEach(v => {
  277. if(!isNumberReg.test(v.startCount) || !isNumberReg.test(v.endCount) || !isNumberReg.test(v.score)){
  278. flag = false;
  279. }
  280. })
  281. //是否起始 < 终值
  282. if(flag){
  283. $scope.configs.configs.forEach(v => {
  284. if(v.startCount > v.endCount){
  285. flag = false;
  286. }
  287. })
  288. }
  289. // 是否有区间交叉
  290. if(flag){
  291. let startArr = $scope.configs.configs.map(v => v.startCount);
  292. let endArr = $scope.configs.configs.map(v => v.endCount);
  293. for(let i=1;i<startArr.length;i++){
  294. if (startArr[i] <= endArr[i-1]){
  295. flag = false;
  296. break;
  297. }
  298. }
  299. }
  300. }
  301. if(!flag){
  302. SweetAlert.swal({
  303. title: "提示",
  304. text: "请正确填写选项!",
  305. type: "error"
  306. });
  307. return;
  308. }
  309. $modalInstance.close($scope.configs);
  310. };
  311. $scope.cancel = function () {
  312. $modalInstance.dismiss('cancel');
  313. };
  314. },
  315. resolve: {
  316. scope: function(){
  317. return $scope;
  318. }
  319. }
  320. })
  321. modalInstance.result.then(function (result) {
  322. console.log(result);
  323. var postData = {
  324. ids: result.selectedItems.map(v => v.id).toString(),
  325. complexity: result.defaultScore?result.defaultScore.id:undefined,
  326. rules: result.configs.length?result.configs:undefined
  327. }
  328. if (result) {
  329. $rootScope.isMask = true;
  330. api_bpm_data.setScoreRule(postData).then(function (response) {
  331. $rootScope.isMask = false;
  332. if(response.status == 200){
  333. SweetAlert.swal({
  334. title: "操作成功!",
  335. type: "success",
  336. });
  337. result.refreshData('expand-right', result.fileData);
  338. }else{
  339. SweetAlert.swal({
  340. title: "操作失败!",
  341. type: "error",
  342. });
  343. }
  344. })
  345. }
  346. });
  347. };
  348. $scope.selected = {
  349. items: []
  350. }
  351. //重置按钮
  352. $scope.reload = function () {
  353. this.two_cates = [];
  354. delete $scope.fileData.incidentcategory.oneCate;
  355. delete $scope.fileData.incidentcategory.twoCate;
  356. $scope.refreshData('expand-right', $scope.fileData);
  357. }
  358. //数据刷新
  359. $scope.refreshData = function (style, filterData) {
  360. $scope.ldloading[style.replace('-', '_')] = true;
  361. if (angular.isUndefined(filterData)) {
  362. filterData = defaultFilterData;
  363. }
  364. $scope.myData = [];
  365. var postData = angular.copy(filterData);
  366. if(postData.incidentcategory.twoCate){
  367. postData.incidentcategory.id = postData.incidentcategory.twoCate.id;
  368. postData.incidentcategory.cascade = true;
  369. delete postData.incidentcategory.oneCate;
  370. delete postData.incidentcategory.twoCate;
  371. }else if(postData.incidentcategory.oneCate){
  372. postData.incidentcategory.id = postData.incidentcategory.oneCate.id;
  373. postData.incidentcategory.cascade = true;
  374. delete postData.incidentcategory.oneCate;
  375. }
  376. postData.incidentcategory.selectType = 'three';
  377. postData.incidentcategory.rules = [];
  378. api_bpm_data.fetchDataList('incidentcategory', postData).then(function (data) {
  379. var myData = Restangular.stripRestangular(data);
  380. $scope.gridOptions.totalItems = myData.totalNum;
  381. if (angular.isArray(myData.list)) {
  382. $scope.myData = myData.list;
  383. for (var i = 0; i < $scope.myData.length; i++) {
  384. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
  385. }
  386. console.log($scope.myData)
  387. } else {
  388. SweetAlert.swal({
  389. title: "数据为空",
  390. text: myData.data,
  391. type: "warning"
  392. });
  393. }
  394. $scope.ldloading[style.replace('-', '_')] = false;
  395. }, function () {
  396. $scope.ldloading[style.replace('-', '_')] = false;
  397. });
  398. };
  399. $scope.refreshData2 = function (style, filterData) {
  400. $scope.ldloading[style.replace('-', '_')] = true;
  401. if (angular.isUndefined(filterData)) {
  402. filterData = defaultFilterData;
  403. }
  404. var postData = angular.copy(filterData);
  405. if(postData.incidentcategory.twoCate){
  406. postData.incidentcategory.id = postData.incidentcategory.twoCate.id;
  407. postData.incidentcategory.cascade = true;
  408. delete postData.incidentcategory.oneCate;
  409. delete postData.incidentcategory.twoCate;
  410. }else if(postData.incidentcategory.oneCate){
  411. postData.incidentcategory.id = postData.incidentcategory.oneCate.id;
  412. postData.incidentcategory.cascade = true;
  413. delete postData.incidentcategory.oneCate;
  414. }
  415. postData.incidentcategory.selectType = 'three';
  416. postData.incidentcategory.rules = [];
  417. api_bpm_data.fetchDataList('incidentcategory', postData).then(function (data) {
  418. var myData = Restangular.stripRestangular(data);
  419. $scope.gridOptions.totalItems = myData.totalNum;
  420. if (angular.isArray(myData.list)) {
  421. $scope.myData = myData.list;
  422. for (var i = 0; i < $scope.myData.length; i++) {
  423. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  424. }
  425. console.log($scope.myData)
  426. } else {
  427. SweetAlert.swal({
  428. title: "数据为空",
  429. text: myData.data,
  430. type: "warning"
  431. });
  432. }
  433. $scope.ldloading[style.replace('-', '_')] = false;
  434. }, function () {
  435. $scope.ldloading[style.replace('-', '_')] = false;
  436. });
  437. };
  438. $scope.ldloading = {};
  439. $scope.fileData = {
  440. "idx": 0,
  441. "sum": 10,
  442. "incidentcategory": {}
  443. }
  444. $scope.searchinspe = function () {
  445. $scope.refreshData('expand-right', $scope.fileData);
  446. }
  447. // 获取默认积分
  448. $scope.incidentComplexity = [];
  449. $scope.getIncidentComplexity = function () {
  450. api_wechatfile.getDictionary({
  451. key: "incident_complexity",
  452. type: "list"
  453. }).then(function (res) {
  454. $scope.incidentComplexity = res;
  455. })
  456. }
  457. $scope.getIncidentComplexity();
  458. // 获取一级分类
  459. $scope.getOneCates = function (keyword='') {
  460. $scope.one_cates = [];
  461. api_configure_data.fetchDataList("incidentcategory", {
  462. "idx": 0,
  463. "sum": 1000,
  464. "incidentcategory": {
  465. category: keyword,
  466. selectType: 'one'
  467. }
  468. }).then(function (res) {
  469. $scope.one_cates = res.list;
  470. })
  471. }
  472. // 选择一级分类
  473. $scope.changeOneCate = function(oneCate){
  474. $scope.getTwoCates(oneCate);
  475. }
  476. // 获取二级分类
  477. $scope.getTwoCates = function (oneCate, keyword='') {
  478. $scope.two_cates = [];
  479. if(!oneCate){
  480. return;
  481. }
  482. api_configure_data.fetchDataList("incidentcategory", {
  483. "idx": 0,
  484. "sum": 1000,
  485. "incidentcategory": {
  486. category: keyword,
  487. parentCategory:{id:oneCate.id}
  488. }
  489. }).then(function (res) {
  490. $scope.two_cates = res.list
  491. })
  492. }
  493. $scope.refreshData('expand-right', $scope.fileData);
  494. $scope.timer = $interval(function () {
  495. $scope.refreshData2('expand-right', $scope.fileData);
  496. }, $rootScope.refreshTime);
  497. $scope.$on('$destroy', function () {
  498. $interval.cancel($scope.timer)
  499. })
  500. }]);