Packing.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.reserve.Packing', {
  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. 'core.form.Panel','scm.reserve.Packing','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  11. 'core.button.ResSubmit','core.button.CatchMadeIn',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. 'erpGridPanel2': {
  18. itemclick: this.onGridItemClick
  19. },
  20. 'erpSaveButton': {
  21. click: function(btn){
  22. var form = me.getForm(btn);
  23. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  24. me.BaseUtil.getRandomNumber();//自动添加编号
  25. }
  26. this.FormUtil.beforeSave(this);
  27. }
  28. },
  29. 'erpDeleteButton' : {
  30. afterrender: function(btn){
  31. var status = Ext.getCmp('pi_statuscode');
  32. if(status && status.value != 'ENTERING'){
  33. btn.hide();
  34. }
  35. },
  36. click: function(btn){
  37. me.FormUtil.onDelete(Ext.getCmp('pi_id').value);
  38. }
  39. },
  40. 'erpUpdateButton': {
  41. afterrender: function(btn){
  42. var status = Ext.getCmp('pi_statuscode');
  43. if(status && status.value != 'ENTERING'){
  44. btn.hide();
  45. }
  46. },
  47. click: function(btn){
  48. this.FormUtil.onUpdate(this);
  49. }
  50. },
  51. 'erpAddButton': {
  52. click: function(){
  53. me.FormUtil.onAdd('addPacking', '新增包装单', 'jsps/scm/reserve/packing.jsp');
  54. }
  55. },
  56. 'erpCloseButton': {
  57. click: function(btn){
  58. me.FormUtil.beforeClose(me);
  59. }
  60. },
  61. 'erpSubmitButton': {
  62. afterrender: function(btn){
  63. var status = Ext.getCmp('pi_statuscode');
  64. if(status && status.value != 'ENTERING'){
  65. btn.hide();
  66. }
  67. },
  68. click: function(btn){
  69. me.FormUtil.onSubmit(Ext.getCmp('pi_id').value);
  70. }
  71. },
  72. 'erpResSubmitButton': {
  73. afterrender: function(btn){
  74. var status = Ext.getCmp('pi_statuscode');
  75. if(status && status.value != 'COMMITED'){
  76. btn.hide();
  77. }
  78. },
  79. click: function(btn){
  80. me.FormUtil.onResSubmit(Ext.getCmp('pi_id').value);
  81. }
  82. },
  83. 'erpAuditButton': {
  84. afterrender: function(btn){
  85. var status = Ext.getCmp('pi_statuscode');
  86. if(status && status.value != 'COMMITED'){
  87. btn.hide();
  88. }
  89. },
  90. click: function(btn){
  91. me.FormUtil.onAudit(Ext.getCmp('pi_id').value);
  92. }
  93. },
  94. 'erpResAuditButton': {
  95. afterrender: function(btn){
  96. var status = Ext.getCmp('pi_statuscode');
  97. if(status && status.value != 'AUDITED'){
  98. btn.hide();
  99. }
  100. },
  101. click: function(btn){
  102. me.FormUtil.onResAudit(Ext.getCmp('pi_id').value);
  103. }
  104. },
  105. 'erpPrintButton': {
  106. click: function(btn){
  107. var reportName='';
  108. reportName="PIOPackinglist";
  109. var condition='{Packing.pi_id}='+Ext.getCmp('pi_id').value+'';
  110. var id=Ext.getCmp('pi_id').value;
  111. me.FormUtil.onwindowsPrint(id,reportName,condition);
  112. }
  113. },
  114. 'erpCatchMadeInButton' : {
  115. afterrender: function(btn){
  116. var status = Ext.getCmp('pi_statuscode');
  117. if(status && status.value != 'ENTERING'){
  118. btn.hide();
  119. }
  120. },
  121. click: function(btn){
  122. var form = btn.ownerCt.ownerCt,
  123. pi_id = Ext.getCmp('pi_id').value;
  124. form.setLoading(true);
  125. Ext.Ajax.request({
  126. url: basePath + 'scm/reserve/updateMadeIn.action',
  127. params: {
  128. pi_id: pi_id
  129. },
  130. callback: function(opt, s, r) {
  131. form.setLoading(false);
  132. var rs = Ext.decode(r.responseText);
  133. if(rs.success) {
  134. alert('更新成功!');
  135. me.GridUtil.loadNewStore(form.ownerCt.down('grid'), {caller: caller, condition: 'pd_piid=' + pi_id});
  136. }
  137. }
  138. });
  139. }
  140. },
  141. 'dbfindtrigger[name=pd_ordercode]': {
  142. focus: function(t){
  143. t.setHideTrigger(false);
  144. t.setReadOnly(false);
  145. if(Ext.getCmp('pi_custcode')){
  146. var code = Ext.getCmp('pi_custcode').value;
  147. if(code != null && code != ''){
  148. var obj = me.getCodeCondition();
  149. if(obj && obj.field){
  150. t.dbBaseCondition = obj.field + "='" + code + "'";
  151. }
  152. }
  153. }
  154. },
  155. aftertrigger: function(t){
  156. if(Ext.getCmp('pi_custcode')){
  157. var obj = me.getCodeCondition();
  158. if(obj && obj.fields){
  159. me.FormUtil.getFieldsValue(obj.tablename, obj.fields, obj.myfield + "='" + t.value + "'", obj.tFields);
  160. }
  161. }
  162. }
  163. },
  164. 'field[name=pi_code]': {
  165. afterrender:function(f){
  166. f.setFieldStyle({
  167. 'color': 'blue'
  168. });
  169. f.focusCls = 'mail-attach';
  170. var c = Ext.Function.bind(me.openInvoice, me);
  171. Ext.EventManager.on(f.inputEl, {
  172. mousedown : c,
  173. scope: f,
  174. buffer : 100
  175. });
  176. }
  177. },
  178. 'field[name=pi_relativecode]': {
  179. afterrender:function(f){
  180. f.setFieldStyle({
  181. 'color': 'blue'
  182. });
  183. f.focusCls = 'mail-attach';
  184. var c = Ext.Function.bind(me.openRelative, me);
  185. Ext.EventManager.on(f.inputEl, {
  186. mousedown : c,
  187. scope: f,
  188. buffer : 100
  189. });
  190. }
  191. },
  192. 'dbfindtrigger[name=pd_orderdetno]': {
  193. focus: function(t){
  194. t.setHideTrigger(false);
  195. t.setReadOnly(false);//用disable()可以,但enable()无效
  196. var record = Ext.getCmp('grid').selModel.lastSelected;
  197. var code = record.data['pd_ordercode'];
  198. if(code == null || code == ''){
  199. showError("请先选择关联单号!");
  200. t.setHideTrigger(true);
  201. t.setReadOnly(true);
  202. } else {
  203. t.dbBaseCondition = "sd_code='" + code + "'";
  204. }
  205. }
  206. },
  207. 'dbfindtrigger[name=pi_custcode2]': {
  208. afterrender:function(trigger){
  209. trigger.dbKey='pi_custcode';
  210. trigger.mappingKey='cu_code';
  211. trigger.dbMessage='请先选客户编号!';
  212. }
  213. },
  214. 'dbfindtrigger[name=pi_invoiceremark]': {
  215. afterrender:function(trigger){
  216. trigger.dbKey='pi_custcode';
  217. trigger.mappingKey='cu_code';
  218. trigger.dbMessage='请先选客户编号!';
  219. }
  220. },
  221. 'dbfindtrigger[name=pi_packingremark]': {
  222. afterrender:function(trigger){
  223. trigger.dbKey='pi_custcode';
  224. trigger.mappingKey='cu_code';
  225. trigger.dbMessage='请先选客户编号!';
  226. }
  227. },
  228. 'dbfindtrigger[name=pi_receivecode]': {
  229. afterrender:function(trigger){
  230. trigger.dbKey='pi_custcode';
  231. trigger.mappingKey='cu_code';
  232. trigger.dbMessage='请先选客户编号!';
  233. }
  234. }
  235. });
  236. },
  237. onGridItemClick: function(selModel, record){//grid行选择
  238. this.GridUtil.onGridItemClick(selModel, record);
  239. },
  240. getForm: function(btn){
  241. return btn.ownerCt.ownerCt;
  242. },
  243. getCodeCondition: function(){
  244. var field = null;
  245. var fields = '';
  246. var tablename = '';
  247. var myfield = '';
  248. var tFields = '';
  249. tFields = 'pi_custcode,pi_custname,pi_currency,pi_rate,pi_paymentcode,pi_payment,pi_sellercode,pi_seller,pi_address';
  250. fields = 'sa_custcode,sa_custname,sa_currency,sa_rate,sa_paymentscode,sa_payments,sa_sellercode,sa_seller,sa_toplace';
  251. tablename = 'Sale';
  252. myfield = 'sa_code';
  253. field = "sa_custcode";
  254. var obj = new Object();
  255. obj.field = field;
  256. obj.fields = fields;
  257. obj.tFields = tFields;
  258. obj.tablename = tablename;
  259. obj.myfield = myfield;
  260. return obj;
  261. },
  262. openInvoice: function(e, el, obj) {
  263. var f = obj.scope, form = f.ownerCt,
  264. i = form.down('#in_id');
  265. if(i && i.value) {
  266. url = 'jsps/scm/reserve/invoice.jsp?formCondition=in_idIS' + i.value + '&gridCondition=id_inidIS' + i.value;
  267. openUrl(url);
  268. }
  269. },
  270. openRelative: function(e, el, obj) {
  271. var f = obj.scope;
  272. if(f.value) {
  273. this.FormUtil.onAdd('ProdInOut', f.ownerCt.down('#pi_source').value,
  274. this.getRelativeUrl(f));
  275. }
  276. },
  277. getRelativeUrl: function(f) {
  278. var v = f.value, form = f.ownerCt,
  279. s = form.down('#pi_source'),
  280. cal = this.getRelativeCaller(s.value),
  281. u = '';
  282. if(!Ext.isEmpty(v)) {
  283. if(v.indexOf(',') > 0) {
  284. var _v = v.split(',');
  285. for(var i in _v) {
  286. _v[i] = "'" + _v[i] + "'";
  287. }
  288. var id = this.getRelativeId(_v.join(','), s.value);
  289. u = 'jsps/common/datalist.jsp?whoami=' + cal + '&urlcondition=pi_class=\''
  290. + s.value + '\' and pi_id in(' + id + ')';
  291. } else {
  292. var id = this.getRelativeId('\'' + v + '\'', s.value);
  293. u = 'jsps/scm/reserve/prodInOut.jsp?whoami=' + cal + '&formCondition=pi_idIS' +
  294. id + '&gridCondition=pd_piidIS' + id;
  295. }
  296. }
  297. return u;
  298. },
  299. getRelativeId: function(c, s) {
  300. var id = 0;
  301. Ext.Ajax.request({
  302. url : basePath + 'common/getFieldData.action',
  303. async: false,
  304. params: {
  305. caller: 'ProdInOut',
  306. field: 'wmsys.wm_concat(pi_id)',
  307. condition: 'pi_inoutno in(' + c + ') and pi_class=\'' + s + '\''
  308. },
  309. method : 'post',
  310. callback : function(o, s, r){
  311. var rs = new Ext.decode(r.responseText);
  312. if(rs.exceptionInfo){
  313. showError(rs.exceptionInfo);return;
  314. }
  315. if(rs.success){
  316. if(rs.data != null){
  317. id = rs.data;
  318. }
  319. }
  320. }
  321. });
  322. return id;
  323. },
  324. getRelativeCaller: function(v) {
  325. var c = '';
  326. switch (v) {
  327. case '出货单':
  328. c = 'ProdInOut!Sale';break;
  329. case '销售退货单':
  330. c = 'ProdInOut!SaleReturn';break;
  331. }
  332. return c;
  333. }
  334. });