123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- 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<loginUser.menu.length;i++){
- if(loginUser.menu[i].link=="workHourManagement_add"){
- $scope.xinzeng=true
- }
- if(loginUser.menu[i].link=="workHourManagement_del"){
- $scope.shanchu=true
- }
- if(loginUser.menu[i].link=="workHourManagement_edit"){
- $scope.bianji=true
- }
- }
- $scope.listData=[
- {"name":"工时管理"},
- ]
- // 工时管理开始
- /* ----- tree----- */
- var i = 0;
- $scope.out = [];
- $scope.outdata = [];
- $scope.subdata={};
- $scope.addcate = false;
- $scope.changecate = false;
- $scope.filterTree = function (data,id) {
- data = angular.copy(data);
- var newTree = data.filter(x => 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] = '';
- }
- }
- }]);
|