VerifyApplyDetail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.purchase.VerifyApplyDetail', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'scm.purchase.VerifyApplyDetail.Form','scm.purchase.VerifyApplyDetail.GridPanel','core.toolbar.Toolbar','core.button.BatchGenBO',
  9. 'core.button.ClearSubpackage','core.button.Subpackage','core.button.Close','core.button.SaveBarcode','core.button.PrintAllPackage',
  10. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.button.GenerateBarcode','core.button.BatchGenBarcode','core.button.PrintAll','core.button.DeleteAllDetails'
  11. ],
  12. init:function(){
  13. var me = this;
  14. var LODOP = null;
  15. var lps_barcaller = 'VerifyAP!BarPrint';
  16. var lps_obcaller = 'VerifyAP!ObxPrint';
  17. var statusCode = window.parent.Ext.getCmp("va_statuscode").value;
  18. this.control({
  19. 'erpVerifyApplyDetailGridPanel':{
  20. itemclick : function(selModel, record){
  21. if(statusCode != 'AUDITED' && statusCode!='已审核')
  22. this.GridUtil.onGridItemClick(selModel, record);
  23. },
  24. afterrender:function(m){
  25. var grid =Ext.getCmp("verifyApplyDetailGridPanel");
  26. Ext.each(grid.columns, function(c){
  27. if(c.dataIndex == 'vadp_printstatus'){
  28. c.editor = null;
  29. }
  30. });
  31. },
  32. beforeedit: function(){//如果是单件管控则明细行中的入库数量不允许修改
  33. var grid =Ext.getCmp("verifyApplyDetailGridPanel");
  34. var pr_tracekind = Ext.getCmp("pr_tracekind").value;
  35. if(pr_tracekind == 1 || pr_tracekind == "单件管控"){
  36. Ext.each(grid.columns, function(c){
  37. if(c.dataIndex == 'vadp_qty'){
  38. c.editor = null;
  39. }
  40. });
  41. }
  42. }
  43. },
  44. 'erpCloseButton': {
  45. click: function(btn){
  46. me.FormUtil.beforeClose(me);
  47. }
  48. },
  49. 'erpBatchGenBOButton':{//批量生成条码和箱号
  50. afterrender: function(btn){
  51. if(statusCode == 'AUDITED' || statusCode=='已审核'){
  52. btn.disable(true);
  53. }
  54. },
  55. enable: function (btn){
  56. if(statusCode == 'AUDITED' || statusCode=='已审核'){
  57. btn.disable(true);
  58. }
  59. },
  60. click:function(btn){
  61. var pr_zxbzs = Ext.getCmp("pr_zxbzs").value;
  62. if((pr_zxbzs == 0) || pr_zxbzs < 0 ||pr_zxbzs ==null){
  63. showError("最小包装数必须大于0!");
  64. return ;
  65. }
  66. var pr_tracekind = Ext.getCmp("pr_tracekind").value;
  67. if(pr_tracekind == 1 || pr_tracekind == "单件管控"){
  68. if(pr_zxbzs!=1){
  69. showError("单件管控类型的物料最小包装数只能为1 !");
  70. return ;
  71. }
  72. }
  73. var baqty = Ext.getCmp("vadp_baqty");//vadp_baqty 批总量,vad_qty:来料总量
  74. if(baqty && (Number(baqty.value)== '0' ||Number(baqty.value) == 0 )){
  75. showError('批总量不允许为0!'); return;
  76. }
  77. if(baqty && (Number(baqty.value) > Number(Ext.getCmp("vad_qty").value))){
  78. showError("批总量不允许大于来料总量");return;
  79. }
  80. var pk_qty = Ext.getCmp("vadp_pkqty");
  81. if(pk_qty &&(pk_qty.value == ''|| pk_qty.value == 0 ||pk_qty.value == '0' ||pk_qty.value == null)){
  82. showError("请输入箱内总数");return ;
  83. }else {
  84. var qty = pk_qty.value;
  85. var pr_zxbzs = Ext.getCmp("pr_zxbzs").value;
  86. if(pr_zxbzs == ''||pr_zxbzs == 0 || pr_zxbzs == '0'||pr_zxbzs ==null){
  87. showError("请输入最小包装数");return ;
  88. }else {
  89. if( qty%pr_zxbzs !=0 ){
  90. showError("箱内总数必须是最小包装数的整数倍!");return ;
  91. }
  92. }
  93. }
  94. var r = me.getData();
  95. var param = unescape(escape(Ext.JSON.encode(me.getData(r))));
  96. me.FormUtil.setLoading(true);
  97. Ext.Ajax.request({
  98. url : basePath + "scm/purchase/BatchGenBO.action",
  99. params: {
  100. caller: caller,
  101. formStore:param
  102. },
  103. method : 'post',
  104. callback : function(options,success,response){
  105. me.FormUtil.setLoading(false);
  106. var res = new Ext.decode(response.responseText);
  107. if(res.exceptionInfo != null){
  108. showError(res.exceptionInfo);return;
  109. }else {
  110. window.location.href = basePath +'jsps/scm/purchase/verifyApplyDetail.jsp?_noc=1&whoami='+caller+'&formCondition='+formCondition+'&gridCondition='+gridCondition;
  111. }
  112. }
  113. })
  114. }
  115. },
  116. 'erpSaveBarcodeButton': {
  117. afterrender: function(btn){
  118. if(statusCode == 'AUDITED' || statusCode=='已审核'){
  119. btn.disable(true);
  120. }
  121. },
  122. click: function (btn){
  123. var grid =Ext.getCmp("verifyApplyDetailGridPanel");
  124. if( grid.selModel.getCount() == 0 ){
  125. showError("没有需要处理的数据!");
  126. return;
  127. }
  128. var items = grid.selModel.getSelection();
  129. Ext.each(items, function(item, index){
  130. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  131. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  132. item.index = this.data[grid.keyField];
  133. grid.multiselected.push(item);
  134. }
  135. var records = Ext.Array.unique(grid.multiselected);
  136. if(records.length > 0){
  137. var params = new Object();
  138. params.caller = 'VerifyApplyDetailP';
  139. var data = new Array();
  140. var bool = false;
  141. Ext.each(records, function(record, index){
  142. if((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  143. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)){
  144. bool = true;
  145. var o = new Object();
  146. if(grid.keyField){
  147. o[grid.keyField] = record.data[grid.keyField];
  148. }
  149. if(grid.toField){
  150. Ext.each(grid.toField, function(f, index){
  151. var v = Ext.getCmp(f).value;
  152. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  153. o[f] = v;
  154. }
  155. });
  156. }
  157. if(grid.necessaryFields){
  158. Ext.each(grid.necessaryFields, function(f, index){
  159. var v = record.data[f];
  160. if(Ext.isDate(v)){
  161. v = Ext.Date.toString(v);
  162. }
  163. o[f] = v;
  164. });
  165. }
  166. data.push(o);
  167. }
  168. });
  169. if(bool){
  170. params.gridStore = unescape(Ext.JSON.encode(data).replace(/\\/g,"%"));
  171. Ext.Ajax.request({
  172. url : basePath + "scm/purchase/saveBarcodeDetail.action",
  173. params: params,
  174. method : 'post',
  175. callback : function(options,success,response){
  176. var res = new Ext.decode(response.responseText);
  177. if(res.exceptionInfo != null){
  178. showError(res.exceptionInfo);return;
  179. }else {
  180. var formCondition = getUrlParam('formCondition');//从url解析参数
  181. formCondition = (formCondition == null) ? "" : formCondition.replace(/IS/g,"=");
  182. window.location.href = basePath +'jsps/scm/purchase/verifyApplyDetail.jsp?_noc=1&whoami='+caller+'&formCondition='+formCondition+'&gridCondition='+gridCondition;
  183. }
  184. }
  185. })
  186. } else {
  187. showError("没有需要处理的数据!");
  188. }
  189. }
  190. })
  191. }
  192. },
  193. 'erpBatchGenBarcodeButton':{
  194. afterrender: function(btn){
  195. if(statusCode == 'AUDITED' || statusCode=='已审核'){
  196. btn.disable(true);
  197. }
  198. },
  199. enable: function (btn){
  200. if(statusCode == 'AUDITED' || statusCode=='已审核'){
  201. btn.disable(true);
  202. }
  203. },
  204. click: function (btn){
  205. //产生新的条码并插到grid行中
  206. var pr_zxbzs = Ext.getCmp("pr_zxbzs").value;
  207. if((pr_zxbzs == 0)|| pr_zxbzs <0){
  208. showError("最小包装数必须大于等于0");
  209. return ;
  210. }
  211. var pr_tracekind = Ext.getCmp("pr_tracekind").value;
  212. if(pr_tracekind == 1 || pr_tracekind == "单件管控"){
  213. if(pr_zxbzs!=1){
  214. showError("单件管控类型的物料最小包装数只能为1 !");
  215. return ;
  216. }
  217. }
  218. var r = me.getData();
  219. var param = unescape(escape(Ext.JSON.encode(r)));
  220. Ext.Ajax.request({
  221. url : basePath + "scm/purchase/batchGenBarcode.action",
  222. params: {
  223. caller: 'VerifyApplyDetailP',
  224. formStore:param
  225. },
  226. method : 'post',
  227. callback : function(options,success,response){
  228. var res = new Ext.decode(response.responseText);
  229. if(res.exceptionInfo != null){
  230. showError(res.exceptionInfo);return;
  231. }else {
  232. var formCondition = getUrlParam('formCondition');//从url解析参数
  233. formCondition = (formCondition == null) ? "" : formCondition.replace(/IS/g,"=");
  234. var gridConditon = getUrlParam('gridCondition');
  235. window.location.href = basePath +'jsps/scm/purchase/verifyApplyDetail.jsp?_noc=1&whoami='+caller+'&formCondition='+formCondition+'&gridCondition='+gridCondition;
  236. }
  237. }
  238. })
  239. }
  240. },
  241. //删除全部明细
  242. 'erpDeleteAllDetailsButton':{
  243. afterrender: function(btn){
  244. if(statusCode == 'AUDITED' || statusCode=='已审核'){
  245. btn.disable(true);
  246. }
  247. },
  248. click:function (btn){
  249. var grid =Ext.getCmp("verifyApplyDetailGridPanel");
  250. var items = grid.store.data.items;
  251. var bool = false;
  252. Ext.each(items, function(item, index){
  253. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  254. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  255. bool = true;
  256. }
  257. });
  258. if(!bool){
  259. showError("没有需要处理的数据!");
  260. return;
  261. }else{
  262. warnMsg("确定清空所有明细", function(btn){
  263. if(btn == 'yes'){
  264. Ext.Ajax.request({
  265. url : basePath + "scm/purchase/deleteAllBarDetails.action",
  266. params: {
  267. caller: 'VerifyApplyDetailP',
  268. code:Ext.getCmp("vad_code").value,
  269. detno:Ext.getCmp("vad_detno").value
  270. },
  271. method : 'post',
  272. callback : function(options,success,response){
  273. var res = new Ext.decode(response.responseText);
  274. if(res.exceptionInfo != null){
  275. showError(res.exceptionInfo);return;
  276. }else {
  277. var formCondition = getUrlParam('formCondition');//从url解析参数
  278. formCondition = (formCondition == null) ? "" : formCondition.replace(/IS/g,"=");
  279. var gridConditon = getUrlParam('gridCondition');
  280. window.location.href = basePath +'jsps/scm/purchase/verifyApplyDetail.jsp?_noc=1&whoami='+caller+'&formCondition='+formCondition+'&gridCondition='+gridCondition;
  281. }
  282. }
  283. })
  284. }else{
  285. return;
  286. }
  287. })
  288. }
  289. }
  290. },
  291. //全部打印
  292. 'erpPrintAllButton':{
  293. click:function (btn){
  294. var win = new Ext.window.Window({
  295. id : 'win',
  296. maximizable : true,
  297. buttonAlign : 'center',
  298. layout : 'anchor',
  299. title: '打印模板选择',
  300. modal : true,
  301. items: [{
  302. tag : 'iframe',
  303. frame : true,
  304. anchor : '100% 100%',
  305. layout : 'fit',
  306. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/scm/reserve/selPrintTemplate.jsp?whoami='+lps_barcaller +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  307. }]
  308. });
  309. win.show();
  310. }
  311. },
  312. 'erpPrintAllPackageButton':{//打印全部箱号
  313. click : function (btn){
  314. var win = new Ext.window.Window({
  315. id : 'win',
  316. maximizable : true,
  317. buttonAlign : 'center',
  318. layout : 'anchor',
  319. title: '打印模板选择',
  320. modal : true,
  321. items: [{
  322. tag : 'iframe',
  323. frame : true,
  324. anchor : '100% 100%',
  325. layout : 'fit',
  326. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/scm/reserve/selPrintTemplate.jsp?whoami='+lps_obcaller +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  327. }]
  328. });
  329. win.show();
  330. }
  331. }
  332. });
  333. },
  334. getData : function (){
  335. var form = Ext.getCmp('verifyApplyDetailForm');
  336. if(form.getForm().isValid()){
  337. // form里面数据
  338. Ext.each(form.items.items, function(item){
  339. if(item.xtype == 'numberfield'){
  340. // number类型赋默认值,不然sql无法执行
  341. if(item.value == null || item.value == ''){
  342. item.setValue(0);
  343. }
  344. }
  345. });
  346. var r = form.getValues();
  347. Ext.each(form.items.items, function(item){
  348. if(item.xtype == 'itemgrid'){
  349. // number类型赋默认值,不然sql无法执行
  350. if(item.value != null && item.value != ''){
  351. r[item.name]=item.value;
  352. }
  353. }
  354. });
  355. // 去除ignore字段
  356. var keys = Ext.Object.getKeys(r), f;
  357. var reg = /[!@#$%^&*()'":,\/?]/;
  358. Ext.each(keys, function(k){
  359. f = form.down('#' + k);
  360. if(f && f.logic == 'ignore') {
  361. delete r[k];
  362. }
  363. if(f) {
  364. if(f.logic != 'ignore' && f.logic){
  365. r[f.logic] = r[k];
  366. delete r[k];
  367. }
  368. }
  369. // codeField值强制大写,自动过滤特殊字符
  370. if(k == form.codeField && !Ext.isEmpty(r[k])) {
  371. r[k] = r[k].trim().toUpperCase().replace(reg, '');
  372. }
  373. });
  374. Ext.each(Ext.Object.getKeys(r), function(k){// 去掉页面非表单定义字段
  375. if(contains(k, 'ext-', true)){
  376. delete r[k];
  377. }
  378. });
  379. }
  380. return r;
  381. }
  382. });