workHourManagementCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. 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) {
  2. var loginUser = $rootScope.user;
  3. $scope.xinzeng=false;
  4. $scope.shanchu=false;
  5. $scope.bianji=false;
  6. for(var i=0;i<loginUser.menu.length;i++){
  7. if(loginUser.menu[i].link=="workHourManagement_add"){
  8. $scope.xinzeng=true
  9. }
  10. if(loginUser.menu[i].link=="workHourManagement_del"){
  11. $scope.shanchu=true
  12. }
  13. if(loginUser.menu[i].link=="workHourManagement_edit"){
  14. $scope.bianji=true
  15. }
  16. }
  17. $scope.listData=[
  18. {"name":"工时管理"},
  19. ]
  20. // 工时管理开始
  21. /* ----- tree----- */
  22. var i = 0;
  23. $scope.out = [];
  24. $scope.outdata = [];
  25. $scope.subdata={};
  26. $scope.addcate = false;
  27. $scope.changecate = false;
  28. $scope.filterTree = function (data,id) {
  29. data = angular.copy(data);
  30. var newTree = data.filter(x => x.id !== id)
  31. newTree.forEach(x => x.children && (x.children = $scope.filterTree(x.children,id)))
  32. return newTree
  33. }
  34. $scope.thisParent={};//当前点击节点的父节点
  35. $scope.dataSave = [];//储存$scope.tree_data
  36. $scope.my_tree_handler = function(branch) {
  37. $scope.selectedChangeCategory = null;
  38. console.log($scope.dataSave)
  39. if($scope.dataSave.length === 0){
  40. $scope.dataSave = angular.copy($scope.tree_data);
  41. }
  42. console.log(branch)
  43. if(branch.parent){
  44. $scope.tree_data = $scope.filterTree($scope.dataSave,branch.id);
  45. console.log($scope.tree_data,'过滤后');
  46. }
  47. $scope.changecate = true;
  48. $scope.addcate = false;
  49. filterData.treeIds = branch.id;
  50. $scope.output = branch;
  51. $scope.thisParent=branch.parent||null;
  52. if($scope.thisParent){
  53. $scope.thisParent.label=$scope.thisParent.workName;
  54. $scope.thisParent.isExpanded=true;
  55. $scope.thisParent.selected=true;
  56. $scope.subdata['parent']=$scope.thisParent
  57. };
  58. convertchildToTree(branch,'工时管理');
  59. console.log(branch)
  60. $scope.subdata.workName=branch.label;
  61. $scope.subdata.wage=branch.wage;
  62. $scope.subdata.workUnit=branch.workUnit;
  63. $scope.subdata.workHourNum=branch.workHourNum;
  64. $scope.subdata.duty=branch.duty;
  65. var eqflag = false;
  66. angular.forEach($scope.outdata, function(item) {
  67. if (item.id == $scope.output.id) eqflag = true;
  68. });
  69. if (eqflag) {
  70. } else {
  71. $scope.outdata.push({
  72. 'name': $scope.output.label,
  73. 'id': $scope.output.id
  74. });
  75. }
  76. };
  77. $scope.thisParent={};//当前点击节点的父节点
  78. $scope.addType = function(element) {
  79. $scope.adddata = {};
  80. $scope.tree_data = $scope.dataSave.length?angular.copy($scope.dataSave):$scope.tree_data;
  81. $scope.addcate = true
  82. $scope.changecate = false
  83. }
  84. /* -----start remove incidet category----- */
  85. $scope.remove = function(element) {
  86. var modalInstance = $modal.open({
  87. templateUrl: 'assets/views/delete.html',
  88. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  89. $scope.title = "工时删除?";
  90. $scope.connect = "确定要删除此工时?";
  91. $scope.ok = function() {
  92. $modalInstance.close(element);
  93. };
  94. $scope.cancel = function() {
  95. $modalInstance.dismiss('cancel');
  96. };
  97. },
  98. size: 'sm',
  99. resolve: {
  100. scope: function() {
  101. return $scope;
  102. }
  103. }
  104. });
  105. modalInstance.result.then(function(selectedItem) {
  106. if (selectedItem) {
  107. var rmvList = [];
  108. rmvList.push(selectedItem.id);
  109. if (selectedItem.children.length > 0) {
  110. SweetAlert.swal({
  111. title: "删除失败!",
  112. text: "请先删除选中的分类的子级",
  113. type: "error"
  114. })
  115. } else {
  116. api_bpm_data.rmvData('workHourManagement', rmvList).then(function(response) {
  117. if (response.data) {
  118. SweetAlert.swal({
  119. title: "删除成功!",
  120. type: "success",
  121. confirmButtonColor: "#007AFF"
  122. }, function() {
  123. $scope.try_async_load();
  124. $scope.$apply($scope.my_data);
  125. $scope.changecate = false;
  126. });
  127. } else {
  128. SweetAlert.swal({
  129. title: "操作异常!",
  130. text: "系统异常,请稍后重试,或者联系管理员!",
  131. type: "error"
  132. });
  133. }
  134. })
  135. }
  136. }
  137. })
  138. }
  139. /* -----end remove incidet category----- */
  140. function convertchildToTree(datum,type) {
  141. if(type === '工时管理'){
  142. $scope.subdata = {};
  143. if (datum.parent) {
  144. $scope.subdata = { 'id': datum.id, 'workName': datum.label, 'duty': datum.duty, 'wage': datum.wage, 'workUnit': datum.workUnit, 'workHourNum': datum.workHourNum, 'parent': datum.parent }
  145. } else {
  146. $scope.subdata = { 'id': datum.id, 'workName': datum.label, 'duty': datum.duty, 'wage': datum.wage, 'workUnit': datum.workUnit, 'workHourNum': datum.workHourNum }
  147. }
  148. }
  149. }
  150. function convertListToTree(data, treeMap) {
  151. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  152. var root = null; //Initially set our loop to null
  153. //loop over data
  154. for (var i = 0; i < data.length; i++) {
  155. var datum = data[i];
  156. //each node will have children, so let's give it a "children" poperty
  157. datum.children = [];
  158. //add an entry for this node to the map so that any future children can
  159. //lookup the parent
  160. idToNodeMap[datum.id] = datum;
  161. //Does this node have a parent?
  162. // console.log("datum="+JSON.stringify(datum))
  163. if (typeof datum.parent === "undefined") {
  164. //Doesn't look like it, so this node is the root of the tree
  165. root = datum;
  166. treeMap[datum.id] = root;
  167. } else {
  168. //This node has a parent, so let's look it up using the id
  169. parentNode = idToNodeMap[datum.parent.id];
  170. //We don't need this property, so let's delete it.
  171. // delete datum.parent;
  172. //Let's add the current node as a child of the parent node.
  173. parentNode.children.push(datum);
  174. }
  175. }
  176. return root;
  177. }
  178. function convertParentToChildList(data) {
  179. var treeMap = {};
  180. var list = [];
  181. convertListToTree(data, treeMap);
  182. angular.forEach(treeMap, function(item) {
  183. list.push(item);
  184. });
  185. return list;
  186. }
  187. $scope.onFilterCallback = function(item){
  188. $scope.selectedChangeCategory=item;
  189. console.log(item)
  190. }
  191. $scope.try_async_load = function() {
  192. $scope.my_data = [];
  193. $scope.doing_async = true;
  194. api_bpm_data.fetchDataList('workHourManagement', { "idx": 0, "sum": 1000 }).then(function(response) {
  195. var data = response.list;
  196. var objects = [];
  197. for (var i = 0; i < data.length; i++) {
  198. var object = {};
  199. object.id = data[i].id;
  200. if (angular.isDefined(data[i].parent)) {
  201. object.parent = data[i].parent;
  202. }
  203. if (angular.isDefined(data[i].duty)) {
  204. object.duty = data[i].duty;
  205. }
  206. if (angular.isDefined(data[i].wage)) {
  207. object.wage = data[i].wage;
  208. }
  209. if (angular.isDefined(data[i].workUnit)) {
  210. object.workUnit = data[i].workUnit;
  211. }
  212. if (angular.isDefined(data[i].workHourNum)) {
  213. object.workHourNum = data[i].workHourNum;
  214. }
  215. if (angular.isDefined(data[i].workName)) {
  216. object.workName = data[i].workName;
  217. }
  218. object.label = data[i].workName;
  219. object.state = {
  220. "opened": true
  221. };
  222. object.typeName = "type";
  223. objects.push(object);
  224. }
  225. $scope.my_data = convertParentToChildList(objects);
  226. $scope.tree_data = angular.copy($scope.my_data);
  227. $scope.dataSave = $scope.tree_data;
  228. $scope.doing_async = false;
  229. });
  230. };
  231. $scope.closethis = function(formdata) {
  232. formdata.workName = "";
  233. formdata.parent.workName = "";
  234. };
  235. /* -----start submit incidet category----- */
  236. // 修改
  237. $scope.submitchange = function(formdata1) {
  238. var formdata = angular.copy(formdata1);
  239. if(formdata.duty === undefined || formdata.wage === undefined|| formdata.workUnit === undefined || formdata.workHourNum === undefined || formdata.workName === undefined){
  240. SweetAlert.swal({
  241. title: "请填写必填项!",
  242. type: "warning"
  243. })
  244. return;
  245. }
  246. if($scope.selectedChangeCategory){
  247. formdata['parent'] ={'id':$scope.selectedChangeCategory.id};
  248. }else if($scope.thisParent){
  249. formdata['parent'] ={'id':$scope.thisParent.id};
  250. }
  251. var filedata = { "workHourManagement": formdata }
  252. console.log(filedata);
  253. // return;
  254. api_bpm_data.updData('workHourManagement', filedata).then(function(response) {
  255. if (response) {
  256. if (response.status == 200) {
  257. $scope.try_async_load();
  258. SweetAlert.swal({
  259. title: "修改成功!",
  260. type: "success"
  261. }, function() {
  262. $scope.$apply($scope.my_data);
  263. })
  264. } else {
  265. SweetAlert.swal({
  266. title: "修改失败!",
  267. type: "error"
  268. })
  269. }
  270. }
  271. });
  272. };
  273. $scope.adddata = {};
  274. $scope.addparent = false;
  275. // 新增保存提交
  276. $scope.submitadd = function(formdata1) {
  277. var formdata = angular.copy(formdata1);
  278. console.log(formdata);
  279. if(formdata.duty === undefined || formdata.wage === undefined || formdata.workUnit === undefined || formdata.workHourNum === undefined || formdata.workName === undefined){
  280. SweetAlert.swal({
  281. title: "请填写必填项!",
  282. type: "warning"
  283. })
  284. return;
  285. }
  286. var filedata = { "workHourManagement": formdata }
  287. // return;
  288. api_bpm_data.addData('workHourManagement', filedata).then(function(response) {
  289. if (response) {
  290. if (response.status == 200) {
  291. $scope.userdata = [];
  292. $scope.outdata = [];
  293. $scope.addcate = false;
  294. $scope.changecate = false;
  295. $scope.try_async_load();
  296. SweetAlert.swal({
  297. title: "增加成功!",
  298. type: "success"
  299. })
  300. } else if (response.status == 408) {
  301. SweetAlert.swal({
  302. title: "增加失败!",
  303. text: response.error,
  304. type: "error"
  305. })
  306. } else {
  307. SweetAlert.swal({
  308. title: "增加失败!",
  309. type: "error"
  310. })
  311. }
  312. }
  313. });
  314. };
  315. /* -----end submit incidet category----- */
  316. $scope.try_async_load();
  317. var filterData = {
  318. key: 'null',
  319. status: 0,
  320. pageIndex: 0,
  321. pageSum: 10,
  322. userId: loginUser.id
  323. }
  324. // 工时管理结束
  325. // 获取责任科室列表
  326. $scope.getDutyList=function(dept){
  327. var postData={
  328. idx: 0,
  329. sum: 10,
  330. dutyDepartment: {
  331. dept: dept||'',
  332. selectType: "pinyin_qs",
  333. }
  334. }
  335. api_user_data.fetchDataList('dutyDepartment',postData).then(res=>{
  336. $scope.dutyList=res.list;
  337. })
  338. }
  339. $scope.getDutyList()
  340. // 修改消耗工时数量
  341. $scope.changeNum = function(value, type){
  342. var reg = /(^[0-9]*\.([0-9]{1}\d*)$)|(^[0-9]*$)/;
  343. if(reg.test(value)){
  344. $scope.adddata[type] = parseFloat(value);
  345. }else{
  346. $scope.adddata[type] = '';
  347. }
  348. }
  349. }]);