pageEditCtrl.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. angular.module('app.business').controller("pageEditCtrl", function ($scope, $http, $stateParams, $state, $rootScope, APP_CONFIG, $uibModal, pageListService, warehouseService) {
  2. $scope.title = $stateParams.title;
  3. $scope.sealedStorage = {};
  4. // console.log("userInfoAllData", $rootScope.userInfoAllData)
  5. // 根据id查询数据
  6. $scope.getDataById = function (id) {
  7. pageListService.getDataById(id).then(function (data) {
  8. $scope.sealedStorage = data.data;
  9. $scope.auditList = data.data.processList;
  10. if ($scope.sealedStorage.auditState === 1 || $scope.sealedStorage.auditState === 3) {
  11. $scope.isNotEdit = false; // 审批状态
  12. } else {
  13. $scope.isNotEdit = true; // 审批状态
  14. }
  15. $scope.loadWare();
  16. }, function (data) {
  17. console.log(data);
  18. });
  19. };
  20. if ($stateParams.editType === 'add' && $stateParams.auditState === '1') {
  21. // 下拉编辑
  22. $scope.isNotEdit = false;
  23. $scope.showNotCommit = false; // 通过,驳回
  24. $scope.showCommit = true; // 保存,提交
  25. $scope.isNotEdit = false; // 审批信息
  26. } else if ($stateParams.editType === 'update') {
  27. console.log("$stateParams.editType-->", $stateParams.editType)
  28. // 下拉编辑
  29. $scope.isNotEdit = false;
  30. $scope.showNotCommit = false; // 通过,驳回
  31. $scope.showCommit = true; // 保存,提交
  32. $scope.isNotEdit = false; // 审批信息
  33. $scope.getDataById($stateParams.id);
  34. } else if ($stateParams.editType === 'audit') {
  35. // 下拉编辑
  36. $scope.isNotEdit = true;
  37. $scope.showNotCommit = true; // 通过,驳回
  38. $scope.showCommit = false; // 保存,提交
  39. $scope.isNotEdit = true; // 审批信息
  40. $scope.getDataById($stateParams.id);
  41. } else {
  42. // 下拉编辑
  43. $scope.isNotEdit = true;
  44. // 显示提交按钮
  45. $scope.showCommit = true;
  46. $scope.showNotCommit = false; // 通过,驳回
  47. $scope.showCommit = false; // 保存,提交
  48. $scope.isNotEdit = true; // 审批信息
  49. $scope.getDataById($stateParams.id);
  50. }
  51. // 新增,修改按钮判断
  52. $scope.editData = function (audit, auditType) {
  53. $scope.sealedStorage.saveProcess = {};
  54. $scope.sealedStorage.saveProcess.auditState = auditType;
  55. $scope.sealedStorage.saveProcess.taskType = 'storage_sealed_confirmation';
  56. $scope.sealedStorage.saveProcess.applyNameId = $rootScope.userInfo.userId;
  57. $scope.sealedStorage.saveProcess.applyName = $rootScope.userInfo.realName;
  58. if (auditType === '2' && $scope.sealedStorage.auditState === 1) {
  59. $scope.sealedStorage.saveProcess.taskName = '员工提交';
  60. $scope.sealedStorage.saveProcess.applyResult = '待审批';
  61. $scope.sealedStorage.saveProcess.applyContent = $rootScope.userInfo.realName + '提交';
  62. $scope.sealedStorage.auditState = auditType;
  63. } else if (auditType === '3') {
  64. $scope.sealedStorage.saveProcess.taskName = '驳回';
  65. $scope.sealedStorage.saveProcess.applyResult = '审批结束';
  66. $scope.sealedStorage.saveProcess.applyContent = audit.applyContent;
  67. $scope.sealedStorage.auditState = 3;
  68. } else if (auditType === '4' && $scope.sealedStorage.auditState === 2) {
  69. $scope.sealedStorage.saveProcess.taskName = '部门审核';
  70. $scope.sealedStorage.saveProcess.applyResult = '已审批';
  71. $scope.sealedStorage.auditState = auditType;
  72. } else if (auditType === '4' && $scope.sealedStorage.auditState === 4) {
  73. $scope.sealedStorage.saveProcess.taskName = '单位领导审核';
  74. $scope.sealedStorage.saveProcess.applyResult = '审批结束';
  75. $scope.sealedStorage.saveProcess.applyContent = audit.applyContent;
  76. $scope.sealedStorage.auditState = 5;
  77. } else {
  78. $scope.sealedStorage.auditState = auditType;
  79. }
  80. if ($stateParams.id === '0') {
  81. // 新增
  82. $scope.save(audit);
  83. } else {
  84. $scope.update(audit);
  85. }
  86. };
  87. // 获取入库中的仓房油罐
  88. $scope.selectNotSealedStorageList = function () {
  89. pageListService.selectNotSealedStorage($rootScope.userInfo.orgId).then(function (data) {
  90. $scope.sealedStorageList = data.data;
  91. }, function (data) {
  92. console.log(data);
  93. });
  94. };
  95. $scope.selectNotSealedStorageList();
  96. // 货位列表
  97. $scope.loadWare = function () {
  98. // datatype 0:仓房,1:油罐
  99. // console.log($rootScope.storehouseObj[$scope.sealedStorage.houseId].datatype)
  100. if ($rootScope.storehouseObj[$scope.sealedStorage.houseId].datatype == 1) {
  101. // 油罐,没有货位
  102. $scope.warelist = [];
  103. $scope.checkGrainAttribute();
  104. } else {
  105. // 仓房获取货位
  106. warehouseService.getStorehouse($rootScope.orgInfo.orgId, $scope.sealedStorage.houseId).then(function (data) {
  107. $scope.warelist = data.wareList;
  108. }, function (data) {
  109. console.log(data);
  110. });
  111. }
  112. };
  113. // 获取封仓数据
  114. $scope.checkGrainAttribute = function () {
  115. pageListService.checkGrainAttribute($rootScope.orgInfo.orgId, $scope.sealedStorage.houseId, $scope.sealedStorage.warehouseId).then(function (data) {
  116. let sealedStorage = data.data;
  117. if (sealedStorage === null) {
  118. alert("未查询到关联数据");
  119. } else {
  120. $scope.sealedStorage = data.data;
  121. console.log("sealedStorage:", $scope.sealedStorage)
  122. for (let i = 0; i < $scope.warelist.length; i++) {
  123. if ($scope.sealedStorage.warehouseId === $scope.warelist[i].warehouseId) {
  124. // 存放粮油类型(0:原粮/油,1:成品粮/油)
  125. if ('0' === $scope.warelist[i].lylx) {// 效验性质转变单审批状态
  126. pageListService.checkAuditState($scope.sealedStorage.houseId, $scope.sealedStorage.harvestYear, $scope.sealedStorage.warehouseId).then(function (data) {
  127. // 审批状态(0:仓储部经理审批,1:质检部经理审批,2:统计经理审批,3:会计审批,4:库领导审批,5:审批结束)
  128. let auditState = data.data;
  129. if (auditState !== '5') {
  130. alert("性质转变单审批未通过");
  131. $scope.sealedStorage = {};
  132. }
  133. }, function (data) {
  134. console.log(data);
  135. });
  136. }
  137. }
  138. }
  139. }
  140. console.log($scope.sealedStorage)
  141. }, function (data) {
  142. console.log(data);
  143. });
  144. };
  145. // 表单效验
  146. var validator = $("#storageSealed-form").validate();
  147. // 保存
  148. $scope.save = function () {
  149. if (validator.form()) {
  150. pageListService.saveData($scope.sealedStorage).then(function (data) {
  151. if (data.retCode === '200') {
  152. alert('保存成功');
  153. $state.go('app.business.grainReservesManage.storageSealedConfirmation.getPageList');
  154. } else {
  155. alert(data.message);
  156. }
  157. }, function (data) {
  158. console.log(data);
  159. });
  160. }
  161. };
  162. // 修改
  163. $scope.update = function () {
  164. if (validator.form()) {
  165. pageListService.updateData($scope.sealedStorage).then(function (data) {
  166. if (data.retCode === '200') {
  167. alert('修改成功');
  168. if ($stateParams.auditState === '1') {
  169. $state.go('app.business.grainReservesManage.storageSealedConfirmation.getPageList');
  170. }
  171. if ($stateParams.auditState === '2') {
  172. $state.go('app.business.grainReservesManage.storageSealedConfirmation.getPageList-audit');
  173. }
  174. if ($stateParams.auditState === '3') {
  175. $state.go('app.business.grainReservesManage.storageSealedConfirmation.getPageList-auditEnd');
  176. }
  177. } else {
  178. alert(data.message);
  179. }
  180. }, function (data) {
  181. console.log(data);
  182. });
  183. }
  184. };
  185. // 返回
  186. $scope.retList = function () {
  187. if ($rootScope.previousState_name !== '') {
  188. $rootScope.back();
  189. } else {
  190. $state.go('app.business.grainReservesManage.storageSealedConfirmation.getPageList');
  191. }
  192. }
  193. });