app.controller('workHourManagement', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_bpm_data", "api_solution", "api_user_data","api_wechatfile","api_sysinfo","api_statistic","api_bpm","jry_api_bpm", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_bpm_data, api_solution, api_user_data,api_wechatfile,api_sysinfo,api_statistic,api_bpm,jry_api_bpm) { var loginUser = $rootScope.user; $scope.xinzeng=false; $scope.shanchu=false; $scope.bianji=false; for(var i=0;i x.id !== id) newTree.forEach(x => x.children && (x.children = $scope.filterTree(x.children,id))) return newTree } $scope.thisParent={};//当前点击节点的父节点 $scope.dataSave = [];//储存$scope.tree_data $scope.my_tree_handler = function(branch) { $scope.selectedChangeCategory = null; console.log($scope.dataSave) if($scope.dataSave.length === 0){ $scope.dataSave = angular.copy($scope.tree_data); } console.log(branch) if(branch.parent){ $scope.tree_data = $scope.filterTree($scope.dataSave,branch.id); console.log($scope.tree_data,'过滤后'); } $scope.changecate = true; $scope.addcate = false; filterData.treeIds = branch.id; $scope.output = branch; $scope.thisParent=branch.parent||null; if($scope.thisParent){ $scope.thisParent.label=$scope.thisParent.workName; $scope.thisParent.isExpanded=true; $scope.thisParent.selected=true; $scope.subdata['parent']=$scope.thisParent }; convertchildToTree(branch,'工时管理'); console.log(branch) $scope.subdata.workName=branch.label; $scope.subdata.wage=branch.wage; $scope.subdata.workUnit=branch.workUnit; $scope.subdata.workHourNum=branch.workHourNum; $scope.subdata.duty=branch.duty; 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 }); } }; $scope.thisParent={};//当前点击节点的父节点 $scope.addType = function(element) { $scope.adddata = {}; $scope.tree_data = $scope.dataSave.length?angular.copy($scope.dataSave):$scope.tree_data; $scope.addcate = true $scope.changecate = false } /* -----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.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('workHourManagement', rmvList).then(function(response) { if (response.data) { SweetAlert.swal({ title: "删除成功!", type: "success", confirmButtonColor: "#007AFF" }, function() { $scope.try_async_load(); $scope.$apply($scope.my_data); $scope.changecate = false; }); } else { SweetAlert.swal({ title: "操作异常!", text: "系统异常,请稍后重试,或者联系管理员!", type: "error" }); } }) } } }) } /* -----end remove incidet category----- */ function convertchildToTree(datum,type) { if(type === '工时管理'){ $scope.subdata = {}; if (datum.parent) { $scope.subdata = { 'id': datum.id, 'workName': datum.label, 'duty': datum.duty, 'wage': datum.wage, 'workUnit': datum.workUnit, 'workHourNum': datum.workHourNum, 'parent': datum.parent } } else { $scope.subdata = { 'id': datum.id, 'workName': datum.label, 'duty': datum.duty, 'wage': datum.wage, 'workUnit': datum.workUnit, 'workHourNum': datum.workHourNum } } } } 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.selectedChangeCategory=item; console.log(item) } $scope.try_async_load = function() { $scope.my_data = []; $scope.doing_async = true; api_bpm_data.fetchDataList('workHourManagement', { "idx": 0, "sum": 1000 }).then(function(response) { var data = response.list; var objects = []; 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].duty)) { object.duty = data[i].duty; } if (angular.isDefined(data[i].wage)) { object.wage = data[i].wage; } if (angular.isDefined(data[i].workUnit)) { object.workUnit = data[i].workUnit; } if (angular.isDefined(data[i].workHourNum)) { object.workHourNum = data[i].workHourNum; } if (angular.isDefined(data[i].workName)) { object.workName = data[i].workName; } object.label = data[i].workName; object.state = { "opened": true }; object.typeName = "type"; objects.push(object); } $scope.my_data = convertParentToChildList(objects); $scope.tree_data = angular.copy($scope.my_data); $scope.dataSave = $scope.tree_data; $scope.doing_async = false; }); }; $scope.closethis = function(formdata) { formdata.workName = ""; formdata.parent.workName = ""; }; /* -----start submit incidet category----- */ // 修改 $scope.submitchange = function(formdata1) { var formdata = angular.copy(formdata1); if(formdata.duty === undefined || formdata.wage === undefined|| formdata.workUnit === undefined || formdata.workHourNum === undefined || formdata.workName === undefined){ SweetAlert.swal({ title: "请填写必填项!", type: "warning" }) return; } if($scope.selectedChangeCategory){ formdata['parent'] ={'id':$scope.selectedChangeCategory.id}; }else if($scope.thisParent){ formdata['parent'] ={'id':$scope.thisParent.id}; } var filedata = { "workHourManagement": formdata } console.log(filedata); // return; api_bpm_data.updData('workHourManagement', 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(formdata1) { var formdata = angular.copy(formdata1); console.log(formdata); if(formdata.duty === undefined || formdata.wage === undefined || formdata.workUnit === undefined || formdata.workHourNum === undefined || formdata.workName === undefined){ SweetAlert.swal({ title: "请填写必填项!", type: "warning" }) return; } var filedata = { "workHourManagement": formdata } // return; api_bpm_data.addData('workHourManagement', filedata).then(function(response) { if (response) { if (response.status == 200) { $scope.userdata = []; $scope.outdata = []; $scope.addcate = false; $scope.changecate = false; $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(); var filterData = { key: 'null', status: 0, pageIndex: 0, pageSum: 10, userId: loginUser.id } // 工时管理结束 // 获取责任科室列表 $scope.getDutyList=function(dept){ var postData={ idx: 0, sum: 10, dutyDepartment: { dept: dept||'', selectType: "pinyin_qs", } } api_user_data.fetchDataList('dutyDepartment',postData).then(res=>{ $scope.dutyList=res.list; }) } $scope.getDutyList() // 修改消耗工时数量 $scope.changeNum = function(value, type){ var reg = /(^[0-9]*\.([0-9]{1}\d*)$)|(^[0-9]*$)/; if(reg.test(value)){ $scope.adddata[type] = parseFloat(value); }else{ $scope.adddata[type] = ''; } } }]);