'use strict'; /** * controller for User Profile Example */ app.controller('jry_incidentSetCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_bpm_data", "api_solution", "api_user_data","jry_api_bpm","api_wechatfile", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_bpm_data, api_solution, api_user_data,jry_api_bpm,api_wechatfile) { $scope.ceshi="哈哈"; $scope.addShow=false; $scope.editShow=false; $scope.editData=""; $scope.editToweightData={}; $scope.editToYXData={}; $scope.editDscrip=""; $scope.addNewDescribeOpen=function(){ // console.log('ok') if($scope.treeId==""){ SweetAlert.swal({ title: "新增失败", text: "请先选择属性图一类!", type: "error" }); }else{ $scope.addShow=true; $(".addBox").animate({"top":"50%"},800,"linear") } } $scope.addNewDescribeClose=function(){ $scope.addShow=false; $(".addBox").css({"top":"-169px"}); $scope.addDscrip=""; $scope.toweightData={}; $scope.toYXData={}; } //获取优先级 $scope.getYXData=function(){ jry_api_bpm.jry_getFetchDataList({"idx":0,"sum":1000},"priority").then(function(res){ $scope.YXData=res.list // console.log(res) }) } //获取权重 $scope.getWeightData=function(){ api_wechatfile.getDictionary({"key":"incident_complexity","type":"list"}).then(function(res){ $scope.weightData=res // console.log(res) }) } $scope.addDscrip=""; // 新增提交 $scope.addSave=function(){ if($scope.addDscrip==""||$scope.toweightData.weightData==undefined||$scope.toYXData.YXData==undefined){ SweetAlert.swal({ title: "新增失败!", text: "必填项不能为空!", type: "error" }); }else{ var filedata={ "incidentdescribe":{ "describes":$scope.addDscrip, "weight":{id:$scope.toweightData.weightData.id}, "categoryid":{id:$scope.treeId}, "priority":{id:$scope.toYXData.YXData.id} } } jry_api_bpm.jry_addFn(filedata,"incidentdescribe").then(function(res1){ // console.log(res1); if(res1.status==200){ $scope.addShow=false; $scope.addDscrip=""; $scope.toweightData={}; $scope.toYXData={}; $(".addBox").css({"top":"-169px"}); jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){ $scope.jry_scricData=res.list; }) SweetAlert.swal({ title: "修改成功!", confirmButtonColor: "#007AFF", type: "success" }); }else{ SweetAlert.swal({ title: "新增失败!", text: "请重新再试!", type: "error" }); } }) } } // 编辑弹框显示 $scope.jry_editShow=function(res){ $scope.editData=$scope.jry_scricData[res]; $scope.editDscrip=$scope.editData.describes; $scope.editToweightData.weightData=$scope.editData.weight; $scope.editToYXData.YXData=$scope.editData.priority; $scope.editId=$scope.editData.id; $scope.version=$scope.editData.version; $scope.editShow=true; $(".editBox").animate({"top":"50%"},800,"linear") } // 关闭编辑框 $scope.editDescribeClose=function(){ $scope.editShow=false; $(".editBox").css({"top":"-169px"}) } // 删除 $scope.jry_move=function(res){ var moveId=[]; moveId.push($scope.jry_scricData[res].id); // console.log($scope.moveId) SweetAlert.swal({ title: "确认删除?", text: "删除的数据不可恢复,请确认继续操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "继续删除", cancelButtonText: "取消操作", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { jry_api_bpm.jry_movFn(moveId,"incidentdescribe").then(function (response) { if (response.status == 200) { jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){ $scope.jry_scricData=res.list; }) SweetAlert.swal("操作成功!", "数据已经被删除.", "success"); } else { SweetAlert.swal("操作失败!", "数据暂时无法被删除,请稍候重试", "error"); } }); } else { SweetAlert.swal("操作取消", "数据安全", "error"); } }); } // 编辑确认 $scope.editSave=function(){ if($scope.editDscrip==""){ SweetAlert.swal({ title: "修改失败!", text: "必填项不能为空!", type: "error" }); }else{ var filedata={ "incidentdescribe":{ "describes":$scope.editDscrip, "weight":{id:$scope.editToweightData.weightData.id}, "id":$scope.editId, "priority":{id:$scope.editToYXData.YXData.id}, "version":$scope.version } } jry_api_bpm.jry_editFn(filedata,"incidentdescribe").then(function(res1){ if(res1.status==200){ $scope.editShow=false; $(".editBox").css({"top":"-169px"}); jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){ $scope.jry_scricData=res.list; }) SweetAlert.swal({ title: "修改成功!", confirmButtonColor: "#007AFF", type: "success" }); }else{ SweetAlert.swal({ title: "修改失败!", text: "请重新再试!", type: "error" }); } }) } } $scope.getYXData(); $scope.getWeightData(); $scope.toYXData={}; $scope.toweightData={}; // $scope.langs=i18nService.getAllLangs(); // $scope.lang = 'zh-cn'; var loginUser = $rootScope.user; // $scope.gridOptions = {}; // $scope.gridOptions.data = 'myData'; // $scope.gridOptions.enableColumnResizing = true; // $scope.gridOptions.enableFiltering = false; // $scope.gridOptions.enableGridMenu = false; // $scope.gridOptions.enableRowSelection = true; // $scope.gridOptions.showGridFooter = true; // $scope.gridOptions.showColumnFooter = false; // $scope.gridOptions.fastWatch = true; // $scope.gridOptions.useExternalPagination = true; // $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100]; // $scope.gridOptions.paginationPageSize = 10; // $scope.gridOptions.multiSelect = true; //组 api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(data) { $scope.group = data.list; }); /* ----- tree----- */ var apple_selected, tree, treedata_avm, treedata_geography; //$scope.selectedTreeNode = {};ssss var i = 0; $scope.out = []; $scope.outdata = []; var systemtype = []; $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.jry_scricData=[]; $scope.toGetData={ "idx":0, "sum":1000 } $scope.treeId=""; $scope.my_tree_handler = function(branch) { console.log(branch); $scope.treeId=branch.id; $scope.toGetData["incidentdescribe"]={"categoryid":{id:$scope.treeId}}; jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){ $scope.jry_scricData=res.list }) // $scope.changecate = true; // $scope.addcate = false; // filterData.treeIds = branch.id; // $scope.selectedTreeNode = branch; // $scope.output = branch; // 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----- */ // $scope.remove = function(element){ // if(element.children.length>0){ // SweetAlert.swal({ // title:"删除失败!", // text:"请先删除选中的分类的子级", // type:"error" // }) // }else{ // var filedata=[element.id] // api_bpm_data.rmvData('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" // }) // } // } // }); // } // } 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, 'hasArea': datum.hasArea, 'hasSimple': datum.hasSimple, 'group': datum.group } } else { $scope.subdata = { 'id': datum.id, 'category': datum.label, 'group': datum.group, 'hasSimple': datum.hasSimple, 'hasArea': datum.hasArea } } // 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 var parentNode; 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].hasArea)) { object.hasArea = data[i].hasArea; } if (angular.isDefined(data[i].hasSimple)) { object.hasSimple = data[i].hasSimple; } if (angular.isDefined(data[i].group)) { object.group = data[i].group; } 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.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.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.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 } }])