123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- app.controller('incidentcateCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_bpm_data", "api_solution", "api_user_data","api_wechatfile", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_bpm_data, api_solution, api_user_data,api_wechatfile) {
- // $scope.langs=i18nService.getAllLangs();
- // $scope.lang = 'zh-cn';
- var loginUser = $rootScope.user;
- //组
- api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(data) {
- $scope.group = data.list;
- });
- //优先级
- // api_bpm_data.fetchDataList('priority', { "idx": 0, "sum": 10 }).then(function(data) {
- // $scope.priority = data.list;
- // });
- api_wechatfile.getDictionary({"key":"incident_priority","type":"list"}).then(function(data){
- $scope.priority=data
- })
- /* ----- tree----- */
- var apple_selected, tree, treedata_avm, treedata_geography;
- //$scope.selectedTreeNode = {};ssss
- var i = 0;
- $scope.out = [];
- $scope.outdata = [];
- var systemtype = [];
- $scope.subdata={};
- $scope.addcate = false;
- $scope.changecate = false;
- // $scope.refreshListData = function(){
- // var data ={"idx":0,"sum":1000};
- // api_bpm_data.fetchDataList('incidentcategory',data).then(function(response){
- // if(response){
- // if(response.status=200){
- // $scope.outdata = response.list;
- // }
- // }
- // })
- // }
- // $scope.refreshListData();
- var childdata = {};
- $scope.my_tree_handler = function(branch) {
- $scope.changecate = true;
- $scope.addcate = false;
- filterData.treeIds = branch.id;
- $scope.selectedTreeNode = branch;
- $scope.output = branch;
- console.log(branch);
- if(branch.hasPlace==1){
- $scope.subdata.hasPlace=true
- }else{
- $scope.subdata.hasPlace=false
- }
- convertchildToTree(branch);
- // console.log($scope.subdata)
- var eqflag = false;
- angular.forEach($scope.outdata, function(item) {
- if (item.id == $scope.output.id) eqflag = true;
- });
- if (eqflag) {
- } else {
- $scope.outdata.push({
- 'name': $scope.output.label,
- 'id': $scope.output.id
- });
- var postData = {
- typeList: []
- };
- if ($scope.outdata.length > 0) {
- angular.forEach($scope.outdata, function(data) {
- postData.typeList.push({ id: data.id });
- })
- }
- // api_solution.findSolutionTypesUser(postData).then(function(response){
- // //Restangular.
- // $scope.userdata = response.data;
- // });
- }
- };
- $scope.addType = function(element) {
- $scope.addcate = true
- $scope.changecate = false
- // var modalInstance = $modal.open({
- // templateUrl: 'assets/views/system/tpl/systemclose.html',
- // controller: function($scope, $modalInstance, api_bpm_data){
- // // api_bpm_data.fetchDataList('closecode',filterData).then(function(data){
- // // var myData = Restangular.stripRestangular(data);
- // // }
- // }
- // });
- }
- /* -----start remove incidet category----- */
- $scope.remove = function(element) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function($scope, scope, $modalInstance, api_bpm_data) {
- // $scope.title = '优先级删除';
- // $scope.connect = '确定要删除此优先级?';
- $scope.title = "故障现象删除?";
- $scope.connect = "确定要删除此故障现象?";
- $scope.ok = function() {
- $modalInstance.close(element);
- };
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- },
- size: 'sm',
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- var rmvList = [];
- rmvList.push(selectedItem.id);
- if (selectedItem.children.length > 0) {
- SweetAlert.swal({
- title: "删除失败!",
- text: "请先删除选中的分类的子级",
- type: "error"
- })
- } else {
- api_bpm_data.rmvData('incidentcategory', rmvList).then(function(response) {
- if (response.data) {
- SweetAlert.swal({
- title: "删除成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- $scope.try_async_load();
- $scope.$apply($scope.my_data);
- });
- } else {
- SweetAlert.swal({
- title: "操作异常!",
- text: "系统异常,请稍后重试,或者联系管理员!",
- type: "error"
- });
- }
- })
- }
- }
- })
- }
- /* -----end remove incidet category----- */
- function convertchildToTree(datum) {
- $scope.subdata = {};
- // console.log($scope.parentdata)
- if (datum.parent) {
- // angular.forEach($scope.parentdata, function(item, index) {
- // if (datum.id == item.id) return $scope.subdata = item;
- // });
- $scope.subdata = { 'id': datum.id, 'category': datum.label, 'parent': datum.parent, 'hasPlace': datum.hasPlace, 'hasSimple': datum.hasSimple, 'group': datum.group, 'priority': datum.priority }
- } else {
- $scope.subdata = { 'id': datum.id, 'category': datum.label, 'group': datum.group, 'hasSimple': datum.hasSimple, 'hasPlace': datum.hasPlace, 'priority': datum.priority }
- }
- // if(datum.children.length==0){
- // angular.forEach($scope.parentdata,function(item, index){
- // if(datum.id==item.id) return $scope.subdata=item;
- // });
- // }else{$scope.subdata={id:datum.id,category:datum.label}}
- }
- 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
- //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?
- // console.log("datum="+JSON.stringify(datum))
- if (typeof datum.parent === "undefined") {
- //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.id];
- //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.onFilterCallback = function(item){
- // $scope.addcategory.parent=item.label;
- // }
- $scope.parentdata = {};
- $scope.try_async_load = function() {
- $scope.my_data = [];
- $scope.doing_async = true;
- var data = { "idx": 0, "sum": 1000 };
- api_bpm_data.fetchDataList('incidentcategory', data).then(function(response) {
- var data = response.list;
- var objects = [];
- $scope.parentdata = data;
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (angular.isDefined(data[i].parent)) {
- object.parent = data[i].parent;
- }
- if (angular.isDefined(data[i].hasPlace)) {
- object.hasPlace = data[i].hasPlace;
- }
- if (angular.isDefined(data[i].hasSimple)) {
- object.hasSimple = data[i].hasSimple;
- }
- if (angular.isDefined(data[i].group)) {
- object.group = data[i].group;
- }
- if (angular.isDefined(data[i].priority)) {
- object.priority = data[i].priority;
- }
- object.label = data[i].category;
- // object.actions = data[i][3]; //权限部分
- // object.group = "1";
- // object.user = "2";
- object.state = {
- "opened": true
- };
- object.typeName = "type";
- // if()
- // if (object.actions.indexOf("2") >= 0) { //知识库类型 具有增加权限--系统管理员
- $scope.showAddSolutionType = true;
- // }
- // if (object.actions.indexOf("5") >= 0) { //知识库类型 具有授权权限--系统管理员
- $scope.showReviewKnowledgeType = true;
- // }
- 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;
- }
- });
- };
- $scope.closethis = function(formdata) {
- formdata.category = "";
- formdata.parent.category = "";
- };
- /* -----start submit incidet category----- */
- $scope.submitchange = function(formdata) {
- // if (formdata.hasArea) {
- // formdata.hasArea = 1;
- // formdata.hasPlace = 1;
- // } else {
- // formdata.hasArea = 0;
- // formdata.hasPlace = 0;
- // }
- if (formdata.hasPlace==true) {
- formdata.hasPlace = 1;
- } else {
- formdata.hasPlace = 0;
- }
- // }
- if (formdata.hasSimple == true) {
- formdata.hasSimple = 1;
- } else {
- formdata.hasSimple = 0;
- }
- if ($scope.selectedTreeNode.parent) {
- formdata.parent = { "id": $scope.selectedTreeNode.parent.id };
- }
- var filedata = { "incidentcategory": formdata }
- api_bpm_data.updData('incidentcategory', filedata).then(function(response) {
- if (response) {
- if (response.status == 200) {
- $scope.try_async_load()
- SweetAlert.swal({
- title: "修改成功!",
- type: "success"
- }, function() {
- $scope.$apply($scope.my_data);
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- type: "error"
- })
- }
- }
- });
- };
- $scope.adddata = {};
- $scope.addparent = false;
- $scope.submitadd = function(formdata) {
- // var paret = {};
- // var filedata = {};
- // filedata = angular.copy(formdata);
- // delete filedata.addp
- // if (angular.isDefined(formdata.parent) && addparent) {
- // angular.forEach($scope.parentdata, function(data) {
- // if (formdata.parent.category.id == data.id) {
- // filedata = { "incidentcategory": { "category": formdata.category, "parent": { "id": data.id } } }
- // }
- // })
- // } else {
- // filedata = { "incidentcategory": { "category": formdata.category } }
- // }
- // filedata = { "incidentcategory": { "category": formdata.category, "parent": { "id": formdata.parentNode.id } } }
- // if (formdata.hasArea && formdata.hasArea == true) {
- // if (formdata.hasArea) {
- // formdata.hasArea = 1;
- // formdata.hasPlace = 1;
- // } else {
- // formdata.hasArea = 0;
- // formdata.hasPlace = 0;
- // }
- if (formdata.hasPlace == true) {
- formdata.hasPlace = 1;
- } else {
- formdata.hasPlace = 0;
- }
- if (formdata.hasSimple == true) {
- formdata.hasSimple = 1;
- } else {
- formdata.hasSimple = 0;
- }
- if (formdata.parent) {
- formdata.parent = { "id": formdata.parent.id };
- }
- var filedata = { "incidentcategory": formdata }
- api_bpm_data.addData('incidentcategory', filedata).then(function(response) {
- if (response) {
- if (response.status == 200) {
- $scope.userdata = [];
- $scope.outdata = [];
- $scope.try_async_load();
- SweetAlert.swal({
- title: "增加成功!",
- type: "success"
- })
- } else if (response.status == 408) {
- SweetAlert.swal({
- title: "增加失败!",
- text: response.error,
- type: "error"
- })
- } else {
- SweetAlert.swal({
- title: "增加失败!",
- type: "error"
- })
- }
- }
- });
- };
- /* -----end submit incidet category----- */
- $scope.try_async_load();
- // $scope.ldloading={};
- var filterData = {
- key: 'null',
- status: 0,
- pageIndex: 0,
- pageSum: 10,
- //treeIds:'[]',
- userId: loginUser.id
- }
- }]);
|