1 |
- app.controller("incidentcateCtrl",["$rootScope","$scope","$state","$timeout","$interval","SweetAlert","$modal","Restangular","api_bpm_data","api_solution",function(t,a,e,n,r,i,o,d,c,u){function l(t){a.subdata={},t.parent_uid?angular.forEach(a.parentdata,function(e,n){if(t.id==e.id)return a.subdata=e}):a.subdata={id:t.id,category:t.label}}function s(t,a){for(var e={},n=null,r=0;r<t.length;r++){var i=t[r];i.children=[],e[i.id]=i,"undefined"==typeof i.parent?(n=i,a[i.id]=n):(parentNode=e[i.parent.id],delete i.parent,parentNode.children.push(i))}return n}function p(t){var a={},e=[];return s(t,a),angular.forEach(a,function(t){e.push(t)}),e}var y=t.user;a.out=[],a.outdata=[];a.addcate=!1,a.changecate=!1;a.my_tree_handler=function(t){a.changecate=!0,a.addcate=!1,f.treeIds=t.id,a.selectedTreeNode=t,a.output=t,l(t);var e=!1;if(angular.forEach(a.outdata,function(t){t.id==a.output.id&&(e=!0)}),e);else{a.outdata.push({name:a.output.label,id:a.output.id});var n={typeList:[]};a.outdata.length>0&&angular.forEach(a.outdata,function(t){n.typeList.push({id:t.id})})}},a.addType=function(t){a.addcate=!0,a.changecate=!1},a.remove=function(t){var e=o.open({templateUrl:"assets/views/delete.html",controller:["$scope","scope","$modalInstance","api_bpm_data",function(a,e,n,r){a.ok=function(){n.close(t)},a.cancel=function(){n.dismiss("cancel")}}],size:"sm",resolve:{scope:function(){return a}}});e.result.then(function(t){if(t){var e=[];e.push(t.id),t.children.length>0?i.swal({title:"删除失败!",text:"请先删除选中的分类的子级",type:"error"}):c.rmvData("incidentcategory",e).then(function(t){t.data?i.swal({title:"删除成功!",type:"success",confirmButtonColor:"#007AFF"},function(){a.try_async_load(),a.$apply(a.my_data)}):i.swal({title:"操作异常!",text:"系统异常,请稍后重试,或者联系管理员!",type:"error"})})}})},a.parentdata={},a.try_async_load=function(){a.my_data=[],a.doing_async=!0;var t={idx:0,sum:1e3};c.fetchDataList("incidentcategory",t).then(function(t){var e=t.list,n=[];a.parentdata=e;for(var r=0;r<e.length;r++){var i={};i.id=e[r].id,angular.isDefined(e[r].parent)&&(i.parent=e[r].parent),i.label=e[r].category,i.state={opened:!0},i.typeName="type",a.showAddSolutionType=!0,a.showReviewKnowledgeType=!0,n.push(i)}a.my_data=p(n),a.tree_data=angular.copy(a.my_data),a.my_data.length>0&&(a.doing_async=!1)})},a.closethis=function(t){t.category="",t.parent.category=""},a.submitchange=function(t){angular.forEach(a.my_data,function(a){t.id==a.id&&(a.category=t.category)});var e="";angular.isDefined(t.parent)?(e=t.parent.id,filedata={incidentcategory:{id:t.id,category:t.category,parent:{id:e}}}):filedata={incidentcategory:{id:t.id,category:t.category}},c.updData("incidentcategory",filedata).then(function(t){t&&(200==t.status?(a.try_async_load(),i.swal({title:"修改成功!",type:"success"},function(){a.$apply(a.my_data)})):i.swal({title:"修改失败!",type:"error"}))})},a.submitadd=function(t,e){var n={};angular.isDefined(t.parent)&&e?angular.forEach(a.parentdata,function(a){t.parent.category.id==a.id&&(n={incidentcategory:{category:t.category,parent:{id:a.id}}})}):n={incidentcategory:{category:t.category}},c.addData("incidentcategory",n).then(function(t){t&&(200==t.status?(a.userdata=[],a.outdata=[],a.try_async_load(),i.swal({title:"增加成功!",type:"success"})):408==t.status?i.swal({title:"增加失败!",text:t.error,type:"error"}):i.swal({title:"增加失败!",type:"error"}))})},a.try_async_load();var f={key:"null",status:0,pageIndex:0,pageSum:10,userId:y.id}}]);
|