qualitycheckCtrl.js 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. "use strict";
  2. angular.module('app.storage')
  3. .controller("qualitycheckCtrl", function($scope,$state,$rootScope,$uibModal, $http,$filter,StorehouseService,warehouseService, $stateParams,qualitycheckService, archiveService) {
  4. $scope.dicDataList = $rootScope.dicDataList;
  5. // 获取列表数据
  6. $scope.pageInfo = {pageNum : 1, pageSize : 10};
  7. $scope.search = {storehouseId:"", warehouseId:"",checkResult:null};
  8. if($stateParams.checkResult != null){
  9. $scope.search.checkResult = $stateParams.checkResult;
  10. }
  11. $scope.isArchive = false;
  12. $scope.isArchiveHouse = 0;
  13. // 仓房列表
  14. $scope.loadStore = function() {
  15. StorehouseService.getStorehouseList($rootScope.orgInfo.orgId).then(function(data){
  16. $scope.storelist = data.houseList;
  17. },function(data){
  18. console.log(data);
  19. });
  20. }
  21. $scope.loadData = function() {
  22. //归档用
  23. if($stateParams.dataState == "archive"){
  24. $scope.isArchive = true;
  25. //查询归档仓房下拉
  26. archiveService.getArchiveDataList().then(function (data) {
  27. if($scope.isArchiveHouse == 0){
  28. $scope.store_tank_list = data;
  29. }
  30. $scope.isArchiveHouse++;
  31. //如果不是下拉的则可能是点查看则按照这种方式跳转
  32. if($scope.search.storehouseId == undefined || $scope.search.storehouseId == ""){
  33. $scope.search.storehouseId = $rootScope.archiveState.storehouseId;
  34. $scope.search.createTime = $rootScope.archiveState.createTime;
  35. $scope.loadWare();
  36. }else{
  37. $scope.search.createTime = $scope.store_tank_list[$scope.search.storehouseId].createTime;
  38. }
  39. if($scope.search.createTime == "" || $scope.search.createTime == undefined){
  40. $scope.pageInfo.pageNum = 0;
  41. $scope.pageInfo.pageSize = 0;
  42. $scope.search.storehouseId = '000';
  43. }
  44. $scope.search.createTime = $filter('date')($scope.search.createTime, "yyyy-MM-dd HH:mm:ss");
  45. //原来代码
  46. qualitycheckService.getPageInfo($scope.pageInfo.pageNum, $scope.pageInfo.pageSize, $stateParams.type,
  47. $scope.search.checkResult, $scope.search.storehouseId, $scope.search.warehouseId, $stateParams.depotType,$scope.search.createTime).then(function (data) {
  48. $scope.pageInfo = data;
  49. }, function (data) {
  50. console.log(data);
  51. });
  52. }, function (data) {
  53. console.log(data);
  54. });
  55. }else{
  56. qualitycheckService.getPageInfo($scope.pageInfo.pageNum, $scope.pageInfo.pageSize, $stateParams.type,
  57. $scope.search.checkResult, $scope.search.storehouseId, $scope.search.warehouseId, $stateParams.depotType).then(function (data) {
  58. $scope.pageInfo = data;
  59. }, function (data) {
  60. console.log(data);
  61. });
  62. $scope.loadStore();
  63. }
  64. }
  65. $scope.loadData();
  66. // 货位列表
  67. $scope.loadWare = function() {
  68. warehouseService.getStorehouse($rootScope.orgInfo.orgId, $scope.search.storehouseId).then(function(data){
  69. $scope.warelist = data.wareList;
  70. },function(data){
  71. console.log(data);
  72. });
  73. }
  74. $scope.loadWare();
  75. // 翻页
  76. $scope.goPage = function (pageNum) {
  77. if ($scope.pageInfo.pageNum != pageNum && pageNum > 0) {
  78. $scope.pageInfo.pageNum = pageNum;
  79. $scope.loadData();
  80. }
  81. };
  82. // 接收广播,切换仓房
  83. $scope.$on("storeChangeed", function(event, storehouseId) {
  84. $scope.search.storehouseId = storehouseId;
  85. $scope.loadData();
  86. $scope.loadWare();
  87. })
  88. //------------------粮食初检信息开始--------------------//
  89. // 显示增加页面,checkType:0代表初检
  90. $scope.showAddFck = function () {
  91. if($stateParams.depotType == '1'){
  92. $state.go('app.business.agent.qualitycheck.fckadd', {id:0,checkType:0,isNotEdit:false});
  93. }else{
  94. $state.go('app.storage.qualitycheck.fckadd', {id:0,checkType:0,isNotEdit:false});
  95. }
  96. }
  97. //修改编辑页面
  98. $scope.showEditFck = function (id) {
  99. if($stateParams.depotType == '1'){
  100. $state.go('app.business.agent.qualitycheck.fckedit',{id:id,isNotEdit:false});
  101. }else{
  102. $state.go('app.storage.qualitycheck.fckedit',{id:id,isNotEdit:false});
  103. }
  104. }
  105. // 查看页面
  106. $scope.showViewFck = function(id) {
  107. if($stateParams.depotType == '1'){
  108. $state.go('app.business.agent.qualitycheck.fckedit',{id:id,isNotEdit:true});
  109. }else{
  110. $state.go('app.storage.qualitycheck.fckedit',{id:id,isNotEdit:true});
  111. }
  112. }
  113. //------------------粮食初检信息结束--------------------//
  114. //------------------粮食验收信息开始--------------------//
  115. // 显示增加页面
  116. $scope.showAddAck = function (id,houseId,warehouseId) {
  117. if($stateParams.depotType == '1'){
  118. $state.go('app.business.agent.qualitycheck.ackadd', {id:0,houseId:houseId,warehouseId:warehouseId,isNotEdit:false});
  119. }else{
  120. $state.go('app.storage.qualitycheck.ackadd', {id:0,houseId:houseId,warehouseId:warehouseId,isNotEdit:false});
  121. }
  122. }
  123. //修改编辑页面
  124. $scope.showEditAck = function (id) {
  125. if($stateParams.depotType == '1'){
  126. $state.go('app.business.agent.qualitycheck.ackedit',{id:id,isNotEdit:false});
  127. }else{
  128. $state.go('app.storage.qualitycheck.ackedit',{id:id,isNotEdit:false});
  129. }
  130. }
  131. // 查看页面
  132. $scope.showViewAck = function(id) {
  133. if($stateParams.depotType == '1'){
  134. $state.go('app.business.agent.qualitycheck.ackedit',{id:id,isNotEdit:true});
  135. }else{
  136. $state.go('app.storage.qualitycheck.ackedit',{id:id,isNotEdit:true});
  137. }
  138. }
  139. //从验收页面点击新增按钮弹出初检的列表 让选择验收那条记录
  140. $scope.showFirstCheckPage = function () {
  141. /* var isActFlag = false;
  142. $state.go('app.storage.qualitycheck.fck.fcklist',{type:0,isActFlag:false});*/
  143. var params = [];
  144. params.type = 0;//查询初检的列表
  145. var uibModalInstance = $uibModal.open({
  146. size:'lg',
  147. templateUrl: 'app/storage/views/qualitycheck/accept-first-list.html',
  148. controller: 'actSprModalCtrl',
  149. resolve: {
  150. // items是一个回调函数
  151. items: function () {
  152. // 这个值会被模态框的控制器获取到
  153. return params;
  154. }
  155. }
  156. });
  157. uibModalInstance.result.then(function (result) {
  158. if (result != null) {
  159. // $scope.loadData_check(foodbasicinfoId);//用于刷新列表页面
  160. }
  161. // 关闭模态框时刷新页面数据
  162. }, function (reason) {
  163. console.log(reason);
  164. });
  165. }
  166. //------------------粮食验收信息结束--------------------//
  167. //------------------春秋普查信息开始--------------------//
  168. //修改编辑页面
  169. $scope.showEditSpr = function (id) {
  170. if($stateParams.depotType == '1'){
  171. $state.go('app.business.agent.qualitycheck.spredit',{id:id,isNotEdit:false});
  172. }else{
  173. $state.go('app.storage.qualitycheck.spredit',{id:id,isNotEdit:false});
  174. }
  175. }
  176. // 查看页面
  177. $scope.showViewSpr = function(id) {
  178. if($stateParams.depotType == '1'){
  179. $state.go('app.business.agent.qualitycheck.spredit',{id:id,isNotEdit:true});
  180. }else{
  181. $state.go('app.storage.qualitycheck.spredit',{id:id,isNotEdit:true});
  182. }
  183. }
  184. $scope.showAcctCheckPage = function () {
  185. if($stateParams.depotType == '1'){
  186. $state.go('app.business.agent.qualitycheck.spradd', {id:0,isNotEdit:false});
  187. }else{
  188. $state.go('app.storage.qualitycheck.spradd', {id:0,isNotEdit:false});
  189. }
  190. }
  191. //------------------春秋普查信息结束--------------------//
  192. //------------------第三方检查开始--------------------//
  193. $scope.showAddTrk = function () {
  194. if($stateParams.depotType == '1'){
  195. $state.go('app.business.agent.qualitycheck.trkadd', {id:0,isNotEdit:false});
  196. }else{
  197. $state.go('app.storage.qualitycheck.trkadd', {id:0,isNotEdit:false});
  198. }
  199. }
  200. //修改编辑页面
  201. $scope.showEditTrk = function (id) {
  202. if($stateParams.depotType == '1'){
  203. $state.go('app.business.agent.qualitycheck.trkedit',{id:id,isNotEdit:false});
  204. }else{
  205. $state.go('app.storage.qualitycheck.trkedit',{id:id,isNotEdit:false});
  206. }
  207. }
  208. // 查看页面
  209. $scope.showViewTrk = function(id) {
  210. if($stateParams.depotType == '1'){
  211. $state.go('app.business.agent.qualitycheck.trkedit',{id:id,isNotEdit:true});
  212. }else{
  213. $state.go('app.storage.qualitycheck.trkedit',{id:id,isNotEdit:true});
  214. }
  215. }
  216. //------------------第三方检查结束--------------------//
  217. //------------------粮食出库信息开始--------------------//
  218. $scope.showAddOut = function () {
  219. if($stateParams.depotType == '1'){
  220. $state.go('app.business.agent.qualitycheck.outadd', {id:0,checkType:3,isNotEdit:false});
  221. }else{
  222. $state.go('app.storage.qualitycheck.outadd', {id:0,checkType:3,isNotEdit:false});
  223. }
  224. }
  225. //修改编辑页面
  226. $scope.showEditOut = function (id) {
  227. if($stateParams.depotType == '1'){
  228. $state.go('app.business.agent.qualitycheck.outedit',{id:id,isNotEdit:false});
  229. }else{
  230. $state.go('app.storage.qualitycheck.outedit',{id:id,isNotEdit:false});
  231. }
  232. }
  233. // 查看页面
  234. $scope.showViewOut = function(id) {
  235. if($stateParams.depotType == '1'){
  236. $state.go('app.business.agent.qualitycheck.outedit',{id:id,isNotEdit:true});
  237. }else{
  238. $state.go('app.storage.qualitycheck.outedit',{id:id,isNotEdit:true});
  239. }
  240. }
  241. //------------------粮食出库信息结束--------------------//
  242. // 根据id删除信息
  243. $scope.remove = function(id) {
  244. qualitycheckService.removeById(id).then(function (data) {
  245. if(data.msg == "success"){
  246. alert("删除成功");
  247. $scope.loadData();
  248. }else{
  249. alert("删除失败");
  250. }
  251. });
  252. }
  253. })
  254. .controller("qualitycheckSaveCtrl", function($scope,$state, $http, $stateParams, FileUploader, StorehouseService, warehouseService, keeperService, businessFileService,
  255. agentStorehouseService, $rootScope, $filter, enumService, qualitycheckService,keepAccountService, kcswService , productService,APP_CONFIG,agentDepotService) {
  256. $scope.isShow = true;
  257. $scope.isDepotShow = false;
  258. $scope.loadDataById = function(id) {
  259. qualitycheckService.loadDataById(id).then(function(data){
  260. if(data.qualitycheckInspection!=null) {
  261. $scope.qualitycheckInspection = data.qualitycheckInspection;
  262. }
  263. $scope.qualitycheck = data.qualitycheck;
  264. $scope.qualitycheck.houseId = data.qualitycheck.houseId.toString();
  265. $scope.qualitycheck.wareHouseName = data.wareHouseName;//用于验收,春秋的回显
  266. $scope.qualitycheck.inspectionStandardBasis = parseInt($scope.qualitycheck.inspectionStandardBasis);
  267. $scope.qualitycheck.inputTime = $scope.qualitycheck.inputTime.substr(0,10);
  268. $scope.qualitycheck.zhycsj = $scope.qualitycheck.zhycsj.substr(0,10);
  269. $scope.qualitycheck.chooseTime = $filter('date')($scope.qualitycheck.chooseTime, "yyyy-MM-dd HH:mm:ss");
  270. $scope.qualitycheck.checkTime = $filter('date')($scope.qualitycheck.checkTime, "yyyy-MM-dd HH:mm:ss");
  271. $scope.qualitycheck.applyCheckTime = $filter('date')($scope.qualitycheck.applyCheckTime, "yyyy-MM-dd");
  272. $scope.qualitycheck.keeperAdvicesTime = $filter('date')($scope.qualitycheck.keeperAdvicesTime, "yyyy-MM-dd");
  273. $scope.qualitycheck.chiefAdvicesTime = $filter('date')($scope.qualitycheck.chiefAdvicesTime, "yyyy-MM-dd");
  274. $scope.qualitycheck.viceManagerAdvicesTime = $filter('date')($scope.qualitycheck.viceManagerAdvicesTime, "yyyy-MM-dd");
  275. $scope.qualitycheck.managerAdvicesTime = $filter('date')($scope.qualitycheck.managerAdvicesTime, "yyyy-MM-dd");
  276. $scope.qualitycheck.improveTime = $filter('date')($scope.qualitycheck.improveTime, "yyyy-MM-dd");
  277. $scope.qualitycheck.checkResultTime = $filter('date')($scope.qualitycheck.checkResultTime, "yyyy-MM-dd HH:mm:ss");
  278. $scope.qualitycheck.qfrq = $filter('date')($scope.qualitycheck.qfrq, "yyyy-MM-dd");//签发日期
  279. $scope.change(0);//点击仓房切换货位
  280. if ($scope.qualitycheck.id == null) {
  281. $scope.qualitycheck.checker = $rootScope.userInfo.realName; //检验人,只有在新增和修改的时候才展示为当前登录人
  282. }
  283. if($stateParams.depotType == "1"){
  284. $scope.isDepotShow = true;
  285. $scope.getAgentDepotData();
  286. $scope.getBasicData($scope.qualitycheck.depotId);
  287. $scope.qualitycheck.houseId = parseInt(data.qualitycheck.houseId);
  288. if ($stateParams.isNotEdit == "false") {
  289. //加载明细品种
  290. $scope.getGrainDetailKind();
  291. }
  292. }
  293. $scope.getzblbData1(data);
  294. $scope.getstoreQualityData1(data);
  295. //获取对应的文件信息
  296. $scope.getFileList(id);
  297. },function(data){
  298. });
  299. };
  300. //获取对应的文件信息
  301. $scope.getFileList = function (id){
  302. businessFileService.getList(id, "qualityCj", $rootScope.orgInfo.orgId, "id asc").then(function(data) {
  303. $scope.fileList = data;
  304. },function(data) {
  305. console.log(data);
  306. });
  307. }
  308. //代储点的粮库名称
  309. $scope.getAgentDepotData = function(agentId) {
  310. agentDepotService.getPageInfo("1", "100", "", "").then(function (data) {
  311. $scope.depotList = data.list.map(function (item) {
  312. return {
  313. depotId: item.id,
  314. depotName: item.agentDepotName
  315. }
  316. });
  317. }, function (data) {
  318. console.log(data);
  319. });
  320. };
  321. // 树形下拉框(明细品种)
  322. $scope.getGrainDetailKind = function() {
  323. enumService.getTreeListByTypeId($scope.qualitycheck.subTypeDetailed, $scope.qualitycheck.subType).then(function(data) {
  324. $scope.grainDetailKindTreeData = data;
  325. },function(data) {
  326. console.log(data);
  327. });
  328. };
  329. $scope.selectOnlyzbl = function(item, selectedItems) {
  330. $scope.getzblbData(item.id);
  331. if (selectedItems !== undefined && selectedItems.length >= 4) {
  332. return false;
  333. } else {
  334. return true;
  335. }
  336. };
  337. $scope.selectOnly1Or2zbl = function(item, selectedItems) {
  338. if (selectedItems !== undefined && selectedItems.length >= 4) {
  339. return false;
  340. } else {
  341. return true;
  342. }
  343. };
  344. //树形下拉框(指标类别)
  345. $scope.datazbl3 = [];
  346. $scope.getzblbData=function(type) {
  347. $scope.zblblist = [{name: '质量指标检验',id: 1},{name: '储存品质检验',id: 2},{name: '食品安全检验',id: 3}];//质量指标检验,储存品质检验,食品安全检验
  348. //console.log($scope.zblblist);
  349. for (var i = 0; i < $scope.zblblist.length; i++) {
  350. // 当前为根.
  351. var obj = {
  352. id: $scope.zblblist[i].id,
  353. name: $scope.zblblist[i].name
  354. };
  355. if($scope.qualitycheck!=undefined){
  356. } else {
  357. for (var s = 0; s < $scope.zblblist.length; s++) {
  358. // obj.selected=true;
  359. }
  360. }
  361. $scope.datazbl3.push(obj);
  362. //console.log($scope.datazbl3);
  363. }
  364. $scope.data4 = angular.copy($scope.datazbl3);
  365. }
  366. $scope.getzblbData1=function(type) {
  367. $scope.zblblist = [{name: '质量指标检验',id: 1},{name: '储存品质检验',id: 2},{name: '食品安全检验',id: 3}];//质量指标检验,储存品质检验,食品安全检验
  368. //console.log($scope.zblblist);
  369. for (var i = 0; i < $scope.zblblist.length; i++) {
  370. // 当前为根.
  371. var obj = {
  372. id: $scope.zblblist[i].id,
  373. name: $scope.zblblist[i].name
  374. };
  375. if($scope.qualitycheck.zblb!=null){
  376. for (var s = 0; s < $scope.qualitycheck.zblb.length; s++) {
  377. var strsv = $scope.qualitycheck.zblb;
  378. var strsa = strsv.substring(0, strsv.length - 1);
  379. var strs = strsa.split("#")
  380. for (var w=0;w<strs.length ;w++ ) {
  381. if($scope.zblblist[i].id==strs[w]){
  382. obj.selected=true;
  383. }
  384. }
  385. }
  386. }
  387. $scope.datazbl3.push(obj);
  388. //console.log($scope.datazbl3);
  389. }
  390. $scope.data4 = angular.copy($scope.datazbl3);
  391. }
  392. $scope.selectOnlystoreQuality = function(item, selectedItems) {
  393. $scope.getstoreQualityData(item.id);
  394. if (selectedItems !== undefined && selectedItems.length >= 8) {
  395. return false;
  396. } else {
  397. return true;
  398. }
  399. };
  400. $scope.selectOnly1Or2storeQuality = function(item, selectedItems) {
  401. if (selectedItems !== undefined && selectedItems.length >= 8) {
  402. return false;
  403. } else {
  404. return true;
  405. }
  406. };
  407. //树形下拉框(指标结果判定)
  408. $scope.datastoreQuality3 = [];
  409. $scope.getstoreQualityData=function(type) {
  410. $scope.storeQualitylist = [{name: '宜存',id: 0},{name: '轻度不宜存',id: 1},{name: '重度不宜存',id: 2}
  411. ,{name: '达标',id: 3},{name: '不达标',id: 4},{name: '合格',id: 5},{name: '不合格',id: 6}];
  412. //console.log($scope.storeQualitylist);
  413. for (var i = 0; i < $scope.storeQualitylist.length; i++) {
  414. // 当前为根.
  415. var obj = {
  416. id: $scope.storeQualitylist[i].id,
  417. name: $scope.storeQualitylist[i].name
  418. };
  419. if($scope.qualitycheck!=undefined){
  420. }else {
  421. for (var s = 0; s < $scope.storeQualitylist.length; s++) {
  422. // obj.selected=true;
  423. }
  424. }
  425. $scope.datastoreQuality3.push(obj);
  426. //console.log($scope.datastoreQuality3);
  427. }
  428. $scope.data4storeQuality = angular.copy($scope.datastoreQuality3);
  429. }
  430. $scope.getstoreQualityData1=function(type) {
  431. $scope.storeQualitylist = [{name: '宜存',id: 0},{name: '轻度不宜存',id: 1},{name: '重度不宜存',id: 2}
  432. ,{name: '达标',id: 3},{name: '不达标',id: 4},{name: '合格',id: 5},{name: '不合格',id: 6}];
  433. //console.log($scope.storeQualitylist);
  434. for (var i = 0; i < $scope.storeQualitylist.length; i++) {
  435. // 当前为根.
  436. var obj = {
  437. id: $scope.storeQualitylist[i].id,
  438. name: $scope.storeQualitylist[i].name
  439. };
  440. for (var s = 0; s < $scope.qualitycheck.storeQuality.length; s++) {
  441. var strsv = $scope.qualitycheck.storeQuality;
  442. var strsa = strsv.substring(0, strsv.length - 1);
  443. var strs = strsa.split("#")
  444. for (var w = 0; w < strs.length; w++) {
  445. if ($scope.storeQualitylist[i].id == strs[w]) {
  446. obj.selected = true;
  447. }
  448. }
  449. }
  450. $scope.datastoreQuality3.push(obj);
  451. //console.log($scope.datastoreQuality3);
  452. }
  453. $scope.data4storeQuality = angular.copy($scope.datastoreQuality3);
  454. }
  455. /**
  456. * 级联仓房和货位号
  457. */
  458. $scope.getBasicData = function(depotId) {
  459. if($stateParams.depotType == "1"){//如果是1的话则是代储点点过来的
  460. if(depotId == undefined)return;
  461. StorehouseService.getAgentList(depotId,$rootScope.orgInfo.orgId,$stateParams.depotType).then(function(data){
  462. $scope.storehouseList = data.map(function(item) {
  463. return {
  464. ch: item.storehouseId,
  465. storehouseName: item.storehouseName
  466. }
  467. });
  468. },function(data){
  469. console.log(data);
  470. });
  471. }else{
  472. }
  473. }
  474. //通过仓房号,获取货位号.
  475. $scope.change = function (type) {
  476. if ($scope.qualitycheck.houseId != null && $scope.qualitycheck.houseId != undefined && $scope.qualitycheck.houseId != '') {
  477. if($stateParams.depotType == "1"){
  478. //按照单位获取单位下的仓房信息
  479. agentStorehouseService.getStorehouse($rootScope.orgInfo.orgId, $scope.qualitycheck.houseId).then(function(data){
  480. if(data.wareList.length > 0){
  481. $scope.warehouseList = data.wareList; //下拉列表数据
  482. $("#wareNameDis").attr("disabled",false);
  483. }else{
  484. $scope.warehouseList = '';
  485. $scope.changeGetInfo(0);
  486. $("#wareNameDis").attr("disabled",true);
  487. }
  488. },function (data) {
  489. console.log(data);
  490. });
  491. }else{
  492. warehouseService.getStorehouse($rootScope.orgInfo.orgId, $scope.qualitycheck.houseId, "0").then(function(data){
  493. if(data.wareList.length > 0){
  494. $scope.warehouseList = data.wareList; //下拉列表数据
  495. $scope.warehouseObj = data.wares; //查询数据列表货位信息转换
  496. $("#wareNameDis").attr("disabled",false);
  497. }else{
  498. $scope.warehouseList = '';
  499. $scope.changeGetInfo(0);
  500. $("#wareNameDis").attr("disabled",true);
  501. }
  502. },function(data){
  503. console.log(data);
  504. });
  505. if (type != 0) {
  506. $scope.findKeeperNames();
  507. }
  508. }
  509. } else {
  510. // 设置货位号为空.
  511. $scope.qualitycheck.warehouseId = null;
  512. }
  513. }
  514. //用于初检,验收,春秋普查,日常检查和第三方检查带出的保管员
  515. $scope.findKeeperNames = function () {
  516. //通过仓房号获取保管员,用于在第三方检查和日常检查中显示保管员的名字
  517. keeperService.getKeeperNamesByHouseId($scope.qualitycheck.houseId).then(function (data) {
  518. $scope.keeper = data;
  519. $scope.qualitycheck.keeper = $scope.keeper.keeperNames;
  520. }, function (data) {
  521. console.log(data);
  522. });
  523. }
  524. //校验是否已经有初检了
  525. $scope.isChuJian = function (stype) {
  526. if (stype==="0") {
  527. var datatype = $rootScope.storehouseObj[$scope.qualitycheck.houseId].datatype;
  528. //先判断表中是否已经存在初检,验收
  529. qualitycheckService.findByStoreWarehouse($scope.qualitycheck.houseId,$scope.qualitycheck.warehouseId,stype).then(function(data) {
  530. //$scope.qualitycheck = data;
  531. if (data) {
  532. //if ($stateParams.checkType == 0) {
  533. alert("该仓已经初检,不能再次初检,您可以从列表中选择进行修改!");
  534. if($stateParams.depotType == "1"){
  535. $state.go('app.business.agent.qualitycheck.fcklist', {type: 0});
  536. }else{
  537. $state.go('app.storage.qualitycheck.fcklist', {type: 0});
  538. }
  539. //}
  540. return true;
  541. }
  542. },function(data){
  543. console.log(data);
  544. });
  545. }
  546. }
  547. //得到分仓保管账中的信息
  548. $scope.changeGetInfo = function (type) {
  549. $scope.getzblbData();
  550. $scope.getstoreQualityData();
  551. if(type != 0 && ($scope.qualitycheck.warehouseId == null || typeof $scope.qualitycheck.warehouseId == undefined || $scope.qualitycheck.warehouseId == ''))return;
  552. if ($scope.qualitycheck.houseId != null && $scope.qualitycheck.houseId != undefined && $scope.qualitycheck.houseId != '') {
  553. if($stateParams.depotType == "1") return;
  554. var datatype = $rootScope.storehouseObj[$scope.qualitycheck.houseId].datatype;
  555. var lylx;
  556. if (datatype == "0") {//粮仓
  557. lylx = $rootScope.wares[$scope.qualitycheck.warehouseId].lylx;
  558. } else if (datatype == "1") {//油罐
  559. lylx = $rootScope.tankObj[$scope.qualitycheck.houseId].lylx;
  560. }
  561. if (lylx != null && lylx == 0) {
  562. //出入库--原粮(小麦、玉米、大豆、稻谷、大豆原油即压榨成品油)
  563. $scope.kcswStr = {ch : $scope.qualitycheck.houseId, hwh : $scope.qualitycheck.warehouseId, unitid : $rootScope.orgInfo.orgId};
  564. kcswService.getPageInfoOrRcsj($scope.kcswStr).then(function(data){
  565. //如果从分仓保管账查找到数据就取出赋值到对应的数据 否则清空上次的数据
  566. if (typeof(data[0]) != "undefined" && data.length > 0 ) {
  567. $scope.keepaccount = data[0];//根据仓房和货位获取分仓保管账的降序的第一条记录
  568. $scope.qualitycheck.subType = parseInt($scope.keepaccount.pz);//品种
  569. $scope.qualitycheck.subTypeDetailed = parseInt($scope.keepaccount.mxpz);//明细品种
  570. $scope.qualitycheck.numberUpdate = $scope.keepaccount.kcsl;//数量
  571. $scope.qualitycheck.harvestTime = parseInt($scope.keepaccount.scnf);//收货年度
  572. $scope.qualitycheck.inputTime = $scope.keepaccount.cjsj.substr(0,10);//入仓时间
  573. $scope.qualitycheck.zhycsj = $scope.keepaccount.rq.substr(0,10);//入仓时间
  574. // $scope.qualitycheck.checkTime = getNowFormatDate(); //检验日期
  575. $scope.qualitycheck.quality = $scope.keepaccount.hwxz; //货位性质 (储粮性质)主要用于封仓管理中验证某个性质
  576. $scope.qualitycheck.location = parseInt($scope.keepaccount.gb); //产地
  577. $scope.qualitycheck.subMold = 1; //类型1为粮油 2:成品粮油
  578. //用于判断品种的检验标准依据的值 该值从词典枚举中取出的()
  579. if ($scope.qualitycheck.subType == 3164) {
  580. // 小麦
  581. $scope.qualitycheck.inspectionStandardBasis = 5523;
  582. } else if($scope.qualitycheck.subType == 3165) {
  583. // 玉米
  584. $scope.qualitycheck.inspectionStandardBasis = 5524;
  585. }else if($scope.qualitycheck.subType == 3166) {
  586. // 稻谷
  587. $scope.qualitycheck.inspectionStandardBasis = 5526;
  588. }else if($scope.qualitycheck.subType == 2777) {
  589. // 大豆
  590. $scope.qualitycheck.inspectionStandardBasis = 5525;
  591. }else if($scope.qualitycheck.subType == 6905) {
  592. // 粮油
  593. $scope.qualitycheck.inspectionStandardBasis = 6908;
  594. }
  595. }else{
  596. $scope.qualitycheck.subType="";//品种
  597. $scope.qualitycheck.subTypeDetailed="";//明细品种
  598. $scope.qualitycheck.numberUpdate="";//数量
  599. $scope.qualitycheck.harvestTime="";//收货年度
  600. $scope.qualitycheck.inputTime="";//入仓日期
  601. }
  602. },function(data){
  603. console.log(data);
  604. });
  605. } else if (lylx != null && lylx == 1) {
  606. $scope.search = {houseId:$scope.qualitycheck.houseId, wareId:$scope.qualitycheck.warehouseId};
  607. productService.getNumberList(null, null, $scope.search).then(function(data){
  608. //如果从分仓保管账查找到数据就取出赋值到对应的数据 否则清空上次的数据
  609. if (typeof(data.list[0]) != "undefined" && data.list.length > 0 ) {
  610. $scope.qualityFinishedCard = data.list[0];//根据仓房和货位获取成品粮油卡
  611. $scope.qualitycheck.subType = parseInt($scope.qualityFinishedCard.lypz);//品种
  612. $scope.qualitycheck.subTypeDetailed = parseInt($scope.qualityFinishedCard.mxpz);//明细品种
  613. $scope.qualitycheck.numberUpdate = $scope.qualityFinishedCard.kcsl*1000;//数量
  614. var scny = $scope.qualityFinishedCard.scny;
  615. if (scny != "" && scny != null) {
  616. var scnd = scny.substr(0,4);//收货年度
  617. for (var i = 0;i < $rootScope.dicDataList[1004].length;i++) {
  618. if ($rootScope.dicDataList[1004][i].enumname==scnd) {
  619. $scope.qualitycheck.harvestTime = $rootScope.dicDataList[1004][i].enumid;
  620. }
  621. }
  622. }
  623. $scope.qualitycheck.inputTime = $scope.qualityFinishedCard.rksj.substr(0,10);//入仓时间
  624. $scope.qualitycheck.zhycsj = $scope.qualityFinishedCard.zhycsj.substr(0,10);//入库时间
  625. // $scope.qualitycheck.checkTime = getNowFormatDate(); //检验日期
  626. $scope.qualitycheck.quality = $scope.qualityFinishedCard.lyxz; //货位性质 (储粮性质)主要用于封仓管理中验证某个性质
  627. $scope.qualitycheck.location = parseInt($scope.qualityFinishedCard.lycd); //产地
  628. $scope.qualitycheck.subMold = 2; //类型1为粮油 2:成品粮油
  629. //用于判断品种的检验标准依据的值 该值从词典枚举中取出的()
  630. if ($scope.qualitycheck.subType == 7107) {
  631. // 大米
  632. $scope.qualitycheck.inspectionStandardBasis = 7573;
  633. } else if($scope.qualitycheck.subType == 7038) {
  634. // 小麦粉
  635. $scope.qualitycheck.inspectionStandardBasis = 7575;
  636. }else if($scope.qualitycheck.subType == 7050 || $scope.qualitycheck.subType == 7052) {
  637. // 压榨和浸出成品油
  638. $scope.qualitycheck.inspectionStandardBasis = 7574;
  639. }
  640. }else{
  641. $scope.qualitycheck.subType="";//品种
  642. $scope.qualitycheck.subTypeDetailed="";//明细品种
  643. $scope.qualitycheck.numberUpdate="";//数量
  644. $scope.qualitycheck.harvestTime="";//收货年度
  645. $scope.qualitycheck.inputTime="";//入仓日期
  646. }
  647. },function(data){
  648. console.log(data);
  649. });
  650. }
  651. }
  652. }
  653. $scope.qualitycheck = {};
  654. $scope.qualitycheckInspection = {}; //化验项
  655. if ($stateParams.id != 0) {//说明是的查看和修改
  656. $scope.loadDataById($stateParams.id);
  657. //这些新增可以变动,修改不可以
  658. $("#houseNameDis").attr("disabled",true);
  659. $("#wareNameDis").attr("disabled",true);
  660. $("#keeps").attr("disabled",true);
  661. }else{//新增
  662. //默认检验结论 储存品质 为合格和宜存
  663. $scope.qualitycheck.checkResult = "0";
  664. $scope.qualitycheck.storeQuality = "0";
  665. $scope.getBasicData();
  666. $scope.getAgentDepotData();
  667. }
  668. //打印
  669. $scope.print = function() {
  670. $("#printing").printArea();
  671. }
  672. $scope.getMath = function(v) {
  673. if (isNaN(v) || v == "") {
  674. v = 0.00;
  675. } else {
  676. v = Math.round(v*100)/100;
  677. v = v.toString();
  678. var rs = v.indexOf('.');
  679. if(rs < 0){
  680. v = v + ".00";
  681. }else{
  682. while(v.length <= rs + 2){v += '0';}
  683. }
  684. }
  685. return v;
  686. }
  687. $scope.getMath1 = function(v) {
  688. if (isNaN(v) || v == "") {
  689. v = 0.0;
  690. } else {
  691. v = Math.round(v*10)/10;
  692. v = v.toString();
  693. var rs = v.indexOf('.');
  694. if(rs < 0){
  695. v = v + ".0";
  696. }else{
  697. while(v.length <= rs + 1){v += '0';}
  698. }
  699. }
  700. return v;
  701. }
  702. // 计算总量
  703. $scope.zjzl = function() {
  704. var pz = $scope.qualitycheck.subType;
  705. if (pz=="3164") {
  706. var sf = parseFloat($scope.qualitycheck.water);//水分
  707. $scope.qualitycheck.water = $scope.getMath1(sf);
  708. var rz = parseFloat($scope.qualitycheckInspection.unitWeight);//容重
  709. $scope.qualitycheckInspection.unitWeight = $scope.getMath1(rz);
  710. var xmydzs = parseFloat($scope.qualitycheck.hardIndex);//小麦硬度指数
  711. $scope.qualitycheck.hardIndex = $scope.getMath1(xmydzs);
  712. var mineral = parseFloat($scope.qualitycheck.mineral);//矿物质
  713. //mineral = isNaN(mineral) ? 0.00 : mineral;
  714. $scope.qualitycheck.mineral = $scope.getMath(mineral);
  715. var black = parseFloat($scope.qualitycheckInspection.imperfectgrainsScabBlackembryo);//黒胚粒
  716. //black = isNaN(black) ? 0 : black;
  717. $scope.qualitycheckInspection.imperfectgrainsScabBlackembryo = $scope.getMath(black);
  718. var inorganic = parseFloat($scope.qualitycheckInspection.impurityInorganic);//无机杂质
  719. //inorganic = isNaN(inorganic) ? 0 : inorganic;
  720. $scope.qualitycheckInspection.impurityInorganic = $scope.getMath(inorganic);
  721. var gibberella = parseFloat($scope.qualitycheckInspection.imperfectgrainsScabGibberella);//赤霉病粒
  722. //gibberella = isNaN(gibberella) ? 0 : gibberella;
  723. $scope.qualitycheckInspection.imperfectgrainsScabGibberella = $scope.getMath(gibberella);
  724. var qtbl = parseFloat($scope.qualitycheckInspection.imperfectgrainsScabQtbl);//其它病粒
  725. //qtbl = isNaN(qtbl) ? 0 : qtbl;
  726. $scope.qualitycheckInspection.imperfectgrainsScabQtbl = $scope.getMath(qtbl);
  727. var organic = parseFloat($scope.qualitycheckInspection.impurityOrganic);//有机杂质
  728. //organic = isNaN(organic) ? 0 : organic;
  729. $scope.qualitycheckInspection.impurityOrganic = $scope.getMath(organic);
  730. var sieveResidue = parseFloat($scope.qualitycheckInspection.sieveResidue);//筛下物%
  731. //sieveResidue = isNaN(sieveResidue) ? 0 : sieveResidue;
  732. $scope.qualitycheckInspection.sieveResidue = $scope.getMath(sieveResidue);
  733. var csl = parseFloat($scope.qualitycheckInspection.imperfectgrainsInjuredkernel);//虫蚀粒%
  734. //csl = isNaN(csl) ? 0 : csl;
  735. $scope.qualitycheckInspection.imperfectgrainsInjuredkernel = $scope.getMath(csl);
  736. var psl = parseFloat($scope.qualitycheckInspection.imperfectgrainsDamage);//破损粒%
  737. //psl = isNaN(psl) ? 0 : psl;
  738. $scope.qualitycheckInspection.imperfectgrainsDamage = $scope.getMath(psl);
  739. var sml = parseFloat($scope.qualitycheck.mildewCount);//生霉粒%
  740. //sml = isNaN(sml) ? 0 : sml;
  741. $scope.qualitycheck.mildewCount = $scope.getMath(sml);
  742. var syl = parseFloat($scope.qualitycheckInspection.imperfectgrainsSproutedkernel);//生芽粒%
  743. //syl = isNaN(syl) ? 0 : syl;
  744. $scope.qualitycheckInspection.imperfectgrainsSproutedkernel = $scope.getMath(syl);
  745. var bblzl = ((parseFloat(black)*100) + (parseFloat(gibberella)*100) + (parseFloat(qtbl)*100))/100;//病斑粒总量%
  746. //bblzl = isNaN(bblzl) ? 0 : bblzl;
  747. //$scope.qualitycheckInspection.imperfectgrainsSproutedkernel = $scope.getMath(syl);
  748. var zdy = parseFloat($scope.qualitycheckInspection.inputTwo);//自定义属性
  749. $scope.qualitycheckInspection.inputTwo = $scope.getMath1(zdy);
  750. if($scope.qualitycheck !== undefined && $scope.qualitycheck !== ""){
  751. //杂质总量
  752. var zzzl = ((parseFloat(mineral)*100) + (parseFloat(inorganic)*100)+ (parseFloat(organic)*100)+ (parseFloat(sieveResidue)*100))/100;
  753. //$scope.qualitycheckInspection.impurityTotal = $scope.getMath($scope.qualitycheckInspection.impurityTotal);
  754. $scope.qualitycheckInspection.impurityTotal = isNaN(zzzl) ? '0.0' : $scope.getMath1(zzzl);
  755. //病斑粒总量
  756. var bblzl = ((parseFloat(black)*100) + (parseFloat(gibberella)*100) + (parseFloat(qtbl)*100))/100;
  757. //$scope.qualitycheckInspection.imperfectgrainsScabTotal = $scope.getMath($scope.qualitycheckInspection.imperfectgrainsScabTotal);
  758. $scope.qualitycheckInspection.imperfectgrainsScabTotal = isNaN(bblzl) ? '0.0' : $scope.getMath1(bblzl);
  759. //不完善粒总量
  760. var bwslzl = ((parseFloat(csl)*100) + (parseFloat(psl)*100)+(parseFloat(sml)*100) + (parseFloat(bblzl)*100) + (parseFloat(syl)*100))/100;
  761. //$scope.qualitycheckInspection.imperfectgrainsTotal = $scope.getMath($scope.qualitycheckInspection.imperfectgrainsTotal);
  762. $scope.qualitycheckInspection.imperfectgrainsTotal = isNaN(bwslzl) ? '0.0' : $scope.getMath1(bwslzl);
  763. }
  764. } else if (pz=="3166") {
  765. var sf = parseFloat($scope.qualitycheck.water);//水分
  766. $scope.qualitycheck.water = $scope.getMath1(sf);
  767. var ccl = parseFloat($scope.qualitycheck.huskedRation);//出糙率
  768. $scope.qualitycheck.huskedRation = $scope.getMath1(ccl);
  769. var wsl = parseFloat($scope.qualitycheckInspection.imperfectgrainsImmaturegrain);//未熟粒
  770. $scope.qualitycheckInspection.imperfectgrainsImmaturegrain = $scope.getMath(wsl);
  771. var zjml = parseFloat($scope.qualitycheck.fullGoodRation);//整精米率
  772. $scope.qualitycheck.fullGoodRation = $scope.getMath1(zjml);
  773. var csl = parseFloat($scope.qualitycheckInspection.imperfectgrainsInjuredkernel);//虫蚀粒
  774. $scope.qualitycheckInspection.imperfectgrainsInjuredkernel = $scope.getMath(csl);
  775. var bbl = parseFloat($scope.qualitycheckInspection.imperfectgrainsScab);//病斑粒
  776. $scope.qualitycheckInspection.imperfectgrainsScab = $scope.getMath(bbl);
  777. var sieveResidue = parseFloat($scope.qualitycheckInspection.sieveResidue);//筛下物%
  778. $scope.qualitycheckInspection.sieveResidue = $scope.getMath(sieveResidue);
  779. var syl = parseFloat($scope.qualitycheckInspection.imperfectgrainsSproutedkernel);//生芽粒
  780. $scope.qualitycheckInspection.imperfectgrainsSproutedkernel = $scope.getMath(syl);
  781. var yjzz = parseFloat($scope.qualitycheckInspection.impurityOrganic);//有机杂质
  782. $scope.qualitycheckInspection.impurityOrganic = $scope.getMath(yjzz);
  783. var sml = parseFloat($scope.qualitycheck.mildewCount);//生霉粒
  784. $scope.qualitycheck.mildewCount = $scope.getMath(sml);
  785. var wjzz = parseFloat($scope.qualitycheckInspection.impurityInorganic);//无机杂质
  786. $scope.qualitycheckInspection.impurityInorganic = $scope.getMath(wjzz);
  787. var gwcm = parseFloat($scope.qualitycheck.outHuskedRation);//谷外糙米
  788. $scope.qualitycheck.outHuskedRation = $scope.getMath1(gwcm);
  789. var cml = parseFloat($scope.qualitycheckInspection.riceYield);//出米率
  790. $scope.qualitycheckInspection.riceYield = $scope.getMath1(cml);
  791. var hlm = parseFloat($scope.qualitycheckInspection.yellowRice);//黄粒米
  792. $scope.qualitycheckInspection.yellowRice = $scope.getMath1(hlm);
  793. var hhl = parseFloat($scope.qualitycheck.intermixingRate);//互混率
  794. $scope.qualitycheck.intermixingRate = $scope.getMath1(hhl);
  795. var zdy = parseFloat($scope.qualitycheckInspection.inputTwo);//自定义属性
  796. $scope.qualitycheckInspection.inputTwo = $scope.getMath1(zdy);
  797. if($scope.qualitycheck !== undefined && $scope.qualitycheck !== ""){
  798. //杂质总量=筛下物+有机杂质+无机杂质,四舍五入,保留一位小数
  799. var zzzl = ((parseFloat(sieveResidue)*100) + (parseFloat(yjzz)*100)+ (parseFloat(wjzz)*100))/100;
  800. $scope.qualitycheckInspection.impurityTotal = isNaN(zzzl) ? '0.0' : $scope.getMath1(zzzl);
  801. //zzzl.toFixed(1);
  802. //$scope.qualitycheckInspection.impurityTotal = $scope.getMath1($scope.qualitycheckInspection.impurityTotal);
  803. //不完善粒总量=未熟粒+虫蚀粒+病斑粒+生芽粒+生霉粒
  804. var bwslzl = ((parseFloat(wsl)*100) + (parseFloat(csl)*100) + (parseFloat(bbl)*100) + (parseFloat(syl)*100) + (parseFloat(sml)*100))/100;
  805. $scope.qualitycheckInspection.imperfectgrainsTotal = isNaN(bwslzl) ? '0.0' : $scope.getMath1(bwslzl);
  806. }
  807. }
  808. };
  809. if($stateParams.isNotEdit != null){
  810. //新增或修改
  811. if ($stateParams.isNotEdit == "false") {
  812. $("#printId").hide();
  813. $scope.isNotEdit = false;
  814. //如果是代储点则需要另外判断
  815. if($stateParams.depotType == "1"){
  816. $scope.isShow = false;
  817. }
  818. //查看
  819. } else if ($stateParams.isNotEdit == "true") {
  820. $scope.isNotEdit = true;
  821. }
  822. }else{
  823. $scope.isNotEdit = false;
  824. }
  825. // 提交表单
  826. var validator = $("#qualitycheck-form").validate();
  827. $scope.saveData = function (checktype) {
  828. var zblbId ="";
  829. var storeQualityId ="";
  830. if($scope.qualitycheck.zblb == null || $scope.qualitycheck.zblb == ""){
  831. alert("请选择指标类别!");
  832. return false;
  833. }
  834. if($scope.qualitycheck.storeQuality == null || $scope.qualitycheck.storeQuality == ""){
  835. alert("请选择指标结果判定!");
  836. return false;
  837. }
  838. //质量检查类型checktype:0:初检 1:验收 2:春秋普查 3:出库检验 4:日常检验 5:第三方检查
  839. if (validator.form()) {
  840. if(checktype == 3){
  841. $scope.qualitycheck.typeUpdate = checktype;
  842. $scope.qualitycheck.jylb = '02';
  843. }else if(checktype == 0){
  844. $scope.qualitycheck.chooserOrgan = $rootScope.orgInfo.orgName;
  845. if($scope.qualitycheck.typeUpdate==0){
  846. $scope.qualitycheck.jylb = '05';
  847. }else if($scope.qualitycheck.typeUpdate==4){
  848. $scope.qualitycheck.jylb = '06';
  849. }
  850. }else if(checktype == 4){
  851. $scope.qualitycheck.jylb = '06';
  852. }
  853. $scope.qualitycheck.orgId = $rootScope.userInfo.orgId;
  854. /**************时间插件无法通过$scope获取数据,重新赋值一下****************/
  855. //入仓日期
  856. $("input[name='inputTime']").each(function(j,item){
  857. if(item.value != '' && item.value != null && typeof item.value != 'undefined'){
  858. $scope.qualitycheck.inputTime = $filter('date')(item.value, "yyyy-MM-dd");
  859. }
  860. });
  861. //入库日期
  862. $("input[name='zhycsj']").each(function(j,item){
  863. if(item.value != '' && item.value != null && typeof item.value != 'undefined'){
  864. $scope.qualitycheck.zhycsj = $filter('date')(item.value, "yyyy-MM-dd HH:mm:ss");
  865. }
  866. });
  867. //扦样日期
  868. $("input[name='chooseTime']").each(function(j,item){
  869. if(item.value != '' && item.value != null && typeof item.value != 'undefined'){
  870. $scope.qualitycheck.chooseTime = $filter('date')(item.value, "yyyy-MM-dd HH:mm:ss");
  871. }
  872. });
  873. //检验日期
  874. $("input[name='checkTime']").each(function(j,item){
  875. if(item.value != '' && item.value != null && typeof item.value != 'undefined'){
  876. $scope.qualitycheck.checkTime = $filter('date')(item.value, "yyyy-MM-dd HH:mm:ss");
  877. }
  878. });
  879. //入库日期早于检验日期的判断
  880. var rksj = new Date($scope.qualitycheck.inputTime.replace( /\-/g, "\/"));
  881. var qysj = new Date($scope.qualitycheck.chooseTime.replace( /\-/g, "\/"));
  882. var jysj = new Date($scope.qualitycheck.checkTime.replace( /\-/g, "\/"));
  883. if (rksj!= "" && qysj!= "" && rksj > qysj) {
  884. alert( "入库日期应该早于扦样时间!");
  885. return false;
  886. }
  887. if (qysj!= "" && jysj!= "" && qysj > jysj) {
  888. alert( "扦样时间应该早于检验时间!");
  889. return false;
  890. }
  891. //签发日期qualitycheck.qfrq
  892. $("input[name='qfrq']").each(function(j,item){
  893. if(item.value != '' && item.value != null && typeof item.value != 'undefined'){
  894. $scope.qualitycheck.qfrq = $filter('date')(item.value, "yyyy-MM-dd");
  895. }
  896. });
  897. var qfrq = new Date($scope.qualitycheck.qfrq.replace( /\-/g, "\/"));
  898. var n_jysj = $scope.qualitycheck.checkTime.substr(0,10);
  899. var new_jysj = new Date(n_jysj.replace( /\-/g, "\/"));
  900. if (qfrq!= "" && new_jysj!= "" && qfrq < new_jysj) {
  901. alert( "签发日期不得早于检验时间!");
  902. return false;
  903. }
  904. //报告出具日期checkResultTime
  905. $("input[name='checkResultTime']").each(function(j,item){
  906. if(item.value != '' && item.value != null && typeof item.value != 'undefined'){
  907. $scope.qualitycheck.checkResultTime = $filter('date')(item.value, "yyyy-MM-dd HH:mm:ss");
  908. }
  909. });
  910. /**************时间插件无法通过$scope获取数据,重新赋值一下****************/
  911. //移除subMold属性
  912. delete $scope.qualitycheck.subMold;
  913. if($stateParams.depotType == "1"){
  914. $scope.qualitycheck.subTypeDetailed = parseInt($scope.qualitycheck.subTypeDetailed[0].id);
  915. }
  916. $scope.zblb=angular.fromJson($scope.qualitycheck.zblb);
  917. for (var s = 0; s < $scope.zblb.length; s++) {
  918. zblbId=zblbId+$scope.zblb[s].id+"#";
  919. // $scope.zblb = zblbId.join("#");
  920. //$scope.qualitycheck.zblb = $scope.zblb[s].join("#");
  921. }
  922. $scope.storeQuality=angular.fromJson($scope.qualitycheck.storeQuality);
  923. for (var s = 0; s < $scope.storeQuality.length; s++) {
  924. storeQualityId=storeQualityId+$scope.storeQuality[s].id+"#";
  925. // $scope.zblb = zblbId.join("#");
  926. //$scope.qualitycheck.zblb = $scope.zblb[s].join("#");
  927. }
  928. $scope.qualitycheck.zblb = angular.copy(zblbId);
  929. $scope.qualitycheck.storeQuality = angular.copy(storeQualityId);
  930. $scope.qualitycheck.harvestTime = parseInt($scope.qualitycheck.harvestTime);
  931. qualitycheckService.save($scope.qualitycheck, $scope.qualitycheckInspection).then(function(datas){
  932. if (datas.status == "success") {
  933. var dataid = datas.dataid;
  934. businessFileService.getUpdateFile($scope.fileIds, dataid, "qualityCj").then(function(data){
  935. /*if (data.status == 'success') {
  936. alert("删除成功!");
  937. } else {
  938. alert("删除失败!");
  939. }*/
  940. },function(data){
  941. console.log(data);
  942. });
  943. alert("保存成功!");
  944. //0:自检 1:验收 2:质量普查 3:出库
  945. if (checktype == 0) {
  946. if($stateParams.depotType == "1"){
  947. $state.go('app.business.agent.qualitycheck.fcklist', {type: '0,4'});
  948. }else {
  949. $state.go('app.storage.qualitycheck.fcklist', {type: '0,4'});
  950. }
  951. }else if(checktype == 3){
  952. if($stateParams.depotType == "1"){
  953. $state.go('app.business.agent.qualitycheck.outlist', {type: 3});
  954. }else {
  955. $state.go('app.storage.qualitycheck.outlist', {type: 3});
  956. }
  957. }
  958. } else {
  959. alert("保存失败!");
  960. }
  961. },function(datas){
  962. console.log(datas);
  963. });
  964. }
  965. }
  966. //获取当前的日期时间 格式“yyyy-MM-dd HH:mm:ss”
  967. function getNowFormatDate() {
  968. var date = new Date();
  969. var seperator1 = "-";
  970. var seperator2 = ":";
  971. var month = date.getMonth() + 1;
  972. var strDate = date.getDate();
  973. if (month >= 1 && month <= 9) {
  974. month = "0" + month;
  975. }
  976. if (strDate >= 0 && strDate <= 9) {
  977. strDate = "0" + strDate;
  978. }
  979. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
  980. return currentdate;
  981. }
  982. // 自定义验证,验证检验时间不得早于入库日期
  983. $.validator.addMethod("validDrugTime",function(value,element, params) {
  984. var beginTime = $scope.qualitycheck.inputTime;
  985. var endTime = $scope.qualitycheck.checkTime;
  986. if(endTime <= beginTime){
  987. return this.optional(element)|| false;
  988. }else{
  989. return this.optional(element)|| true;
  990. }
  991. },"检验时间不得早于入库日期!");
  992. // 自定义验证,验证散气时间不得早于熏蒸开始时间和熏蒸结束时间
  993. $.validator.addMethod("validTime",function(value,element, params) {
  994. var beginTime = $scope.fumigationProcess.firstUseDrugTime;
  995. var endTime = $scope.fumigationProcess.taskEndTime;
  996. if(value <= beginTime || value <= endTime){
  997. return this.optional(element)|| false;
  998. }else{
  999. return this.optional(element)|| true;
  1000. }
  1001. },"散气时间不得早于熏蒸开始时间和结束时间!");
  1002. // 自定义验证
  1003. $.validator.addMethod("setState",function(value,element, params) {
  1004. if(value == "无" || value == "暂无" || value == "空"){
  1005. return this.optional(element)|| false;
  1006. }else{
  1007. return this.optional(element)|| true;
  1008. }
  1009. },"不能填写无,暂无,空等选项!");
  1010. // 自定义验证,验证数字
  1011. $.validator.addMethod("validNumber",function(value,element, params) {
  1012. var checkNumber = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
  1013. return this.optional(element)||(checkNumber.test(value));
  1014. },"请输入大于0的数字,最多两位小数!");
  1015. // 新增一行
  1016. $scope.addTR = function(qualitycheckId) {
  1017. $scope.addCheckSon.push({qualitycheckId:qualitycheckId});
  1018. }
  1019. // 删除一行
  1020. $scope.deleteTR = function(obj) {
  1021. var index;
  1022. // 如果有ID,说明当前数据已经是存在于数据库的,那么要郑重删除
  1023. if (obj.id != undefined) {
  1024. $scope.deleteSon(obj.id);
  1025. }
  1026. index = $scope.addCheckSon.indexOf(obj);
  1027. $scope.addCheckSon.splice(index, 1);
  1028. }
  1029. $scope.deleteSon = function(id) {
  1030. if (!confirm("当前数据已近存在于系统中,确定要删除吗?")) {
  1031. return;
  1032. }
  1033. // 提交
  1034. qualitycheckService.removeSon(id).then(function(data){
  1035. if (data.status == 'success') {
  1036. alert("删除成功!");
  1037. } else {
  1038. alert("删除失败!");
  1039. }
  1040. },function(data){
  1041. console.log(data);
  1042. });
  1043. }
  1044. // ----------------------------------------------- 文件上传下载相关 开始------------------------------------------------
  1045. var bid = null;
  1046. // 添加一行,取最大值加1放入数组
  1047. $scope.linenumber = 0;
  1048. $scope.linenumbers = [];
  1049. if ($stateParams.id == '') {
  1050. $scope.linenumbers = [0];
  1051. }
  1052. // 新增一行
  1053. $scope.addFile = function() {
  1054. if ($scope.linenumbers.length == 0 ) {
  1055. $scope.linenumbers.push(0);
  1056. } else {
  1057. var maxlinenumber = Math.max.apply(null, $scope.linenumbers);
  1058. $scope.linenumbers.push(maxlinenumber + 1);
  1059. }
  1060. }
  1061. // 文件上传实例
  1062. $scope.fileIds = [];
  1063. // 以linenumber为key,以新增的附件对应为value.
  1064. $scope.fileMap = new Map();
  1065. // 上传.
  1066. $scope.uploader = new FileUploader({
  1067. //url : APP_CONFIG.basicUrl + '/fileUpload/updateFileBusiness',
  1068. url : APP_CONFIG.businessUrl + '/depot/business/file/uploadFile',
  1069. autoUpload : true, // 将文件添加到队列后自动上传.
  1070. formData : [{type : 'qualityCj', userId:$rootScope.userInfo.userId,orgId:$rootScope.orgInfo.orgId}], // 与文件一起发送的数据
  1071. removeAfterUpload : true, // 从队列上传后删除文件
  1072. // 上传进度
  1073. onProgressItem : function(fileItem, progress) {
  1074. // console.info("正在上传:" + progress + "%");
  1075. },
  1076. // 回调函数,在一个文件上传成功后触发
  1077. onSuccessItem : function(fileItem, response, status, headers) {
  1078. // 将新fileId加入到fileIds,用于最后在保存的时候会写附件表的主表ID.
  1079. $scope.fileIds.push(response.id);
  1080. // 如果已经存在对应的fileId,先从$scope.fileIds中移除,再添加.
  1081. if ($scope.fileMap.has($scope.linenumber)) {
  1082. // 原fileId.
  1083. var fileId = $scope.fileMap.get($scope.linenumber).id;
  1084. // 从$scope.fileIds中移除原fileId.
  1085. var index = $scope.fileIds.indexOf(fileId);
  1086. if (index != -1) {
  1087. // 后台删除.
  1088. $scope.deleteFileByFileIds(fileId);
  1089. }
  1090. }
  1091. $scope.fileMap.set($scope.linenumber, response);
  1092. }
  1093. });
  1094. // 下载文件
  1095. $scope.download = function(filePath, originalFileName) {
  1096. $("#filePath").val(filePath);
  1097. $("#type").val("business");
  1098. $("#originalFileName").val(originalFileName);
  1099. $("#download-form").attr("action", APP_CONFIG.basicUrl + '/download');
  1100. $("#download-form").submit();
  1101. }
  1102. // 新增预览.
  1103. $scope.showFileByLinenumber = function(linenumber) {
  1104. if ($scope.fileMap.has($scope.linenumber)) {
  1105. // 以linenumber为key从$scope.fileMap获取filePath.
  1106. var filePath = $scope.fileMap.get($scope.linenumber).filePath;
  1107. window.open(APP_CONFIG.basicUrl+filePath);
  1108. }
  1109. }
  1110. // 回显预览.
  1111. $scope.showFile = function(filePath, originalFileName) {
  1112. window.open(APP_CONFIG.basicUrl+filePath);
  1113. }
  1114. // 点击浏览按钮.
  1115. $scope.clickFileInput = function(index) {
  1116. $scope.linenumber = index;
  1117. }
  1118. // 文件上传实例
  1119. $scope.deleteFileIds = [];
  1120. // 回显删除.
  1121. $scope.deleteFile = function(file) {
  1122. // 回显删除,先不真正删除,把要删除的附件id保存在数组中,再最后保存的时候传递给后台,进行删除.
  1123. $scope.deleteFileIds.push(file.id);
  1124. // 从$scope.fileList 移除.
  1125. var index = $scope.fileList.indexOf(file);
  1126. if (index != -1) {
  1127. $scope.fileList.splice(index, 1);
  1128. }
  1129. $scope.deleteFileByFileIds(file.id);
  1130. }
  1131. // 正常删除.
  1132. $scope.deleteFileByLinenumber = function(linenumber) {
  1133. var index = $scope.linenumbers.indexOf(linenumber);
  1134. if (index != -1) {
  1135. // 从linenumbers移除.
  1136. $scope.linenumbers.splice(index, 1);
  1137. if ($scope.fileMap.has($scope.linenumber)) {
  1138. // 以linenumber为key从$scope.fileMap获取fileId.
  1139. var fileId = $scope.fileMap.get($scope.linenumber).id;
  1140. // 后台删除数据和文件.
  1141. $scope.deleteFileByFileIds(fileId, index);
  1142. // 从$scope.fileMap移除.
  1143. $scope.fileMap.delete(linenumber);
  1144. }
  1145. }
  1146. }
  1147. $scope.deleteFileByFileIds = function(fileId) {
  1148. businessFileService.remove(fileId).then(function(data){
  1149. if (data.status == "success") {
  1150. // 删除成功.
  1151. var index = $scope.fileIds.indexOf(fileId);
  1152. if (index != -1) {
  1153. // 从$scope.fileIds中移除.
  1154. $scope.fileIds.splice(index, 1);
  1155. }
  1156. }
  1157. },function (data) {
  1158. console.log(data);
  1159. });
  1160. }
  1161. // ----------------------------------------------- 上传下载相关 结束 ------------------------------------------------
  1162. })