scoreConfigurationPerformanceCtrl.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. removeComplexity: 1,
  224. removeRules: 1
  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. var postData = {
  232. ids: result.selectedItems.map(v => v.id).toString(),
  233. complexity: result.defaultScore?result.defaultScore.id:undefined,
  234. rules: result.configs.length?result.configs:undefined
  235. }
  236. api_bpm_data.setScoreRule(postData).then(function (response) {
  237. if(response.status == 200){
  238. SweetAlert.swal({
  239. title: "操作成功!",
  240. type: "success",
  241. });
  242. result.refreshData('expand-right', result.fileData);
  243. }else{
  244. SweetAlert.swal({
  245. title: "操作失败!",
  246. type: "error",
  247. });
  248. }
  249. })
  250. }else{
  251. SweetAlert.swal({
  252. title: "操作失败!",
  253. type: "error",
  254. });
  255. }
  256. })
  257. }
  258. });
  259. };
  260. //编辑
  261. $scope.edit = function (data) {
  262. console.log(data);
  263. var modalInstance = $modal.open({
  264. templateUrl: 'assets/views/scoreConfigurationPerformance-edit.html',
  265. size: "sm",
  266. controller: function ($scope, scope, $modalInstance, SweetAlert) {
  267. console.log(scope.selected.items);
  268. $scope.incidentComplexity = scope.incidentComplexity;
  269. $scope.configs = {
  270. defaultScore:data.complexity || null,
  271. configs: data.rules ? data.rules.map(v=>({startCount:v.startCount,endCount:v.endCount,score:v.score})) : [],
  272. selectedItems: [data],
  273. refreshData: scope.refreshData,
  274. fileData: scope.fileData
  275. };
  276. // 增加配置
  277. $scope.addConfig = function(){
  278. $scope.configs.configs.push({startCount: 1, endCount: 1, score: 1});
  279. }
  280. // 移除配置
  281. $scope.removeConfig = function(index){
  282. $scope.configs.configs.splice(index, 1);
  283. }
  284. $scope.ok = function () {
  285. // 校验
  286. var flag = true;
  287. if($scope.configs.configs.length){
  288. //是否是大于1的正整数
  289. var isNumberReg = /^[1-9][0-9]*$/;
  290. $scope.configs.configs.forEach(v => {
  291. if(!isNumberReg.test(v.startCount) || !isNumberReg.test(v.endCount) || !isNumberReg.test(v.score)){
  292. flag = false;
  293. }
  294. })
  295. //是否起始 < 终值
  296. if(flag){
  297. $scope.configs.configs.forEach(v => {
  298. if(v.startCount > v.endCount){
  299. flag = false;
  300. }
  301. })
  302. }
  303. // 是否有区间交叉
  304. if(flag){
  305. let startArr = $scope.configs.configs.map(v => v.startCount);
  306. let endArr = $scope.configs.configs.map(v => v.endCount);
  307. for(let i=1;i<startArr.length;i++){
  308. if (startArr[i] <= endArr[i-1]){
  309. flag = false;
  310. break;
  311. }
  312. }
  313. }
  314. }
  315. if(!flag){
  316. SweetAlert.swal({
  317. title: "提示",
  318. text: "请正确填写选项!",
  319. type: "error"
  320. });
  321. return;
  322. }
  323. $modalInstance.close($scope.configs);
  324. };
  325. $scope.cancel = function () {
  326. $modalInstance.dismiss('cancel');
  327. };
  328. },
  329. resolve: {
  330. scope: function(){
  331. return $scope;
  332. }
  333. }
  334. })
  335. modalInstance.result.then(function (result) {
  336. console.log(result);
  337. var postData = {
  338. ids: result.selectedItems.map(v => v.id).toString(),
  339. removeComplexity: 1,
  340. removeRules: 1
  341. }
  342. if (result) {
  343. $rootScope.isMask = true;
  344. api_bpm_data.setScoreRule(postData).then(function (response) {
  345. $rootScope.isMask = false;
  346. if(response.status == 200){
  347. var postData = {
  348. ids: result.selectedItems.map(v => v.id).toString(),
  349. complexity: result.defaultScore?result.defaultScore.id:undefined,
  350. rules: result.configs.length?result.configs:undefined
  351. }
  352. api_bpm_data.setScoreRule(postData).then(function (response) {
  353. if(response.status == 200){
  354. SweetAlert.swal({
  355. title: "操作成功!",
  356. type: "success",
  357. });
  358. result.refreshData('expand-right', result.fileData);
  359. }else{
  360. SweetAlert.swal({
  361. title: "操作失败!",
  362. type: "error",
  363. });
  364. }
  365. })
  366. }else{
  367. SweetAlert.swal({
  368. title: "操作失败!",
  369. type: "error",
  370. });
  371. }
  372. })
  373. }
  374. });
  375. };
  376. $scope.selected = {
  377. items: []
  378. }
  379. //重置按钮
  380. $scope.reload = function () {
  381. this.two_cates = [];
  382. delete $scope.fileData.incidentcategory.oneCate;
  383. delete $scope.fileData.incidentcategory.twoCate;
  384. $scope.refreshData('expand-right', $scope.fileData);
  385. }
  386. //数据刷新
  387. $scope.refreshData = function (style, filterData) {
  388. $scope.ldloading[style.replace('-', '_')] = true;
  389. if (angular.isUndefined(filterData)) {
  390. filterData = defaultFilterData;
  391. }
  392. $scope.myData = [];
  393. var postData = angular.copy(filterData);
  394. if(postData.incidentcategory.twoCate){
  395. postData.incidentcategory.id = postData.incidentcategory.twoCate.id;
  396. postData.incidentcategory.cascade = true;
  397. delete postData.incidentcategory.oneCate;
  398. delete postData.incidentcategory.twoCate;
  399. }else if(postData.incidentcategory.oneCate){
  400. postData.incidentcategory.id = postData.incidentcategory.oneCate.id;
  401. postData.incidentcategory.cascade = true;
  402. delete postData.incidentcategory.oneCate;
  403. }
  404. postData.incidentcategory.selectType = 'three';
  405. postData.incidentcategory.rules = [];
  406. api_bpm_data.fetchDataList('incidentcategory', postData).then(function (data) {
  407. var myData = Restangular.stripRestangular(data);
  408. $scope.gridOptions.totalItems = myData.totalNum;
  409. if (angular.isArray(myData.list)) {
  410. $scope.myData = myData.list;
  411. for (var i = 0; i < $scope.myData.length; i++) {
  412. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
  413. }
  414. console.log($scope.myData)
  415. } else {
  416. SweetAlert.swal({
  417. title: "数据为空",
  418. text: myData.data,
  419. type: "warning"
  420. });
  421. }
  422. $scope.ldloading[style.replace('-', '_')] = false;
  423. }, function () {
  424. $scope.ldloading[style.replace('-', '_')] = false;
  425. });
  426. };
  427. $scope.refreshData2 = function (style, filterData) {
  428. $scope.ldloading[style.replace('-', '_')] = true;
  429. if (angular.isUndefined(filterData)) {
  430. filterData = defaultFilterData;
  431. }
  432. var postData = angular.copy(filterData);
  433. if(postData.incidentcategory.twoCate){
  434. postData.incidentcategory.id = postData.incidentcategory.twoCate.id;
  435. postData.incidentcategory.cascade = true;
  436. delete postData.incidentcategory.oneCate;
  437. delete postData.incidentcategory.twoCate;
  438. }else if(postData.incidentcategory.oneCate){
  439. postData.incidentcategory.id = postData.incidentcategory.oneCate.id;
  440. postData.incidentcategory.cascade = true;
  441. delete postData.incidentcategory.oneCate;
  442. }
  443. postData.incidentcategory.selectType = 'three';
  444. postData.incidentcategory.rules = [];
  445. api_bpm_data.fetchDataList('incidentcategory', postData).then(function (data) {
  446. var myData = Restangular.stripRestangular(data);
  447. $scope.gridOptions.totalItems = myData.totalNum;
  448. if (angular.isArray(myData.list)) {
  449. $scope.myData = myData.list;
  450. for (var i = 0; i < $scope.myData.length; i++) {
  451. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  452. }
  453. console.log($scope.myData)
  454. } else {
  455. SweetAlert.swal({
  456. title: "数据为空",
  457. text: myData.data,
  458. type: "warning"
  459. });
  460. }
  461. $scope.ldloading[style.replace('-', '_')] = false;
  462. }, function () {
  463. $scope.ldloading[style.replace('-', '_')] = false;
  464. });
  465. };
  466. $scope.ldloading = {};
  467. $scope.fileData = {
  468. "idx": 0,
  469. "sum": 10,
  470. "incidentcategory": {}
  471. }
  472. $scope.searchinspe = function () {
  473. $scope.refreshData('expand-right', $scope.fileData);
  474. }
  475. // 获取默认积分
  476. $scope.incidentComplexity = [];
  477. $scope.getIncidentComplexity = function () {
  478. api_wechatfile.getDictionary({
  479. key: "incident_complexity",
  480. type: "list"
  481. }).then(function (res) {
  482. $scope.incidentComplexity = res;
  483. })
  484. }
  485. $scope.getIncidentComplexity();
  486. // 获取一级分类
  487. $scope.getOneCates = function (keyword='') {
  488. $scope.one_cates = [];
  489. api_configure_data.fetchDataList("incidentcategory", {
  490. "idx": 0,
  491. "sum": 1000,
  492. "incidentcategory": {
  493. category: keyword,
  494. selectType: 'one'
  495. }
  496. }).then(function (res) {
  497. $scope.one_cates = res.list;
  498. })
  499. }
  500. // 选择一级分类
  501. $scope.changeOneCate = function(oneCate){
  502. $scope.getTwoCates(oneCate);
  503. }
  504. // 获取二级分类
  505. $scope.getTwoCates = function (oneCate, keyword='') {
  506. $scope.two_cates = [];
  507. if(!oneCate){
  508. return;
  509. }
  510. api_configure_data.fetchDataList("incidentcategory", {
  511. "idx": 0,
  512. "sum": 1000,
  513. "incidentcategory": {
  514. category: keyword,
  515. parentCategory:{id:oneCate.id}
  516. }
  517. }).then(function (res) {
  518. $scope.two_cates = res.list
  519. })
  520. }
  521. $scope.refreshData('expand-right', $scope.fileData);
  522. $scope.timer = $interval(function () {
  523. $scope.refreshData2('expand-right', $scope.fileData);
  524. }, $rootScope.refreshTime);
  525. $scope.$on('$destroy', function () {
  526. $interval.cancel($scope.timer)
  527. })
  528. }]);