BarStockCode.js 14 KB

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