CustomerPayments.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.sale.CustomerPayments', {
  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 : [ 'core.form.Panel', 'scm.sale.CustomerPayments',
  8. 'core.grid.Panel2', 'core.toolbar.Toolbar', 'core.button.Save',
  9. 'core.button.Close', 'core.button.Update', 'core.button.Add','core.button.Sync',
  10. 'core.button.DeleteDetail', 'core.trigger.DbfindTrigger' ],
  11. init : function() {
  12. var me = this;
  13. me.allowinsert = true;
  14. this.control({
  15. 'erpGridPanel2' : {
  16. itemclick : this.onGridItemClick,
  17. afterrender : function(grid) {
  18. grid.plugins[0].on('beforeedit', function(args){
  19. var field = args.field, y = args.rowIdx,
  20. grid = args.grid, record = args.record;
  21. var x = grid.store.find('cp_isdefault', '是');
  22. if (x > -1 && x != y) {
  23. record.set('cp_isdefault', '否');
  24. if(field == 'cp_isdefault')
  25. return false;
  26. return true;
  27. }
  28. return true;
  29. });
  30. }
  31. },
  32. 'erpAddButton' : {
  33. click : function() {
  34. me.FormUtil.onAdd('addCustomerPayments', '新增客户收款方式',
  35. 'jsps/scm/sale/customerPayments.jsp');
  36. }
  37. },
  38. 'erpSaveButton' : {
  39. click : function(btn) {
  40. var grid = Ext.getCmp('grid');
  41. var cuid = Ext.getCmp('cu_id').value;
  42. var i = 0;
  43. Ext.Array.each(grid.store.data.items, function(item) {
  44. item.set('cp_cuid', cuid);
  45. });
  46. Ext.Array.each(grid.store.data.items, function(item) {
  47. if (item.data.cp_isdefault == '是') {
  48. i++;
  49. }
  50. });
  51. if (i == 0) {
  52. Ext.Msg.alert("提示", "请选择默认收款方式!");
  53. return;
  54. }
  55. if (i > 1) {
  56. Ext.Msg.alert("提示", "默认收款方式只能选择一个,请重新选择!");
  57. return;
  58. }
  59. this.FormUtil.onUpdate(this);
  60. }
  61. },
  62. 'erpUpdateButton' : {
  63. click : function(btn) {
  64. this.FormUtil.onUpdate(this);
  65. }
  66. },
  67. 'erpCloseButton' : {
  68. click : function(btn) {
  69. me.FormUtil.beforeClose(me);
  70. }
  71. },
  72. 'dbfindtrigger[name=cu_code]' : {
  73. aftertrigger : function() {
  74. var id = Ext.getCmp('cu_id').value;
  75. var paymentcode = Ext.getCmp('cu_paymentscode').value;
  76. var payment = Ext.getCmp('cu_payments').value;
  77. if (id != null & id != '') {
  78. this.getPaymentsStore('cp_cuid=' + id, paymentcode,
  79. payment);
  80. }
  81. }
  82. }
  83. });
  84. },
  85. onGridItemClick : function(selModel, record) {// grid行选择
  86. this.GridUtil.onGridItemClick(selModel, record);
  87. },
  88. getForm : function(btn) {
  89. return btn.ownerCt.ownerCt;
  90. },
  91. getPaymentsStore : function(condition, paymentcode, payment) {
  92. var me = this;
  93. var grid = Ext.getCmp('grid');
  94. grid.store.removeAll(false);
  95. me.BaseUtil.getActiveTab().setLoading(true);// loading...
  96. Ext.Ajax.request({// 拿到grid的columns
  97. url : basePath + "common/singleGridPanel.action",
  98. params : {
  99. caller : "CustomerPayments",
  100. condition : condition
  101. },
  102. method : 'post',
  103. callback : function(options, success, response) {
  104. me.BaseUtil.getActiveTab().setLoading(false);
  105. var res = new Ext.decode(response.responseText);
  106. if (res.exceptionInfo) {
  107. showError(res.exceptionInfo);
  108. return;
  109. }
  110. var data = [];
  111. if (!res.data || res.data.length == 2) {
  112. me.GridUtil.add10EmptyItems(grid);
  113. } else {
  114. data = Ext.decode(res.data.replace(/,}/g, '}').replace(
  115. /,]/g, ']'));
  116. if (data.length > 0) {
  117. grid.store.loadData(data);
  118. }
  119. }
  120. var bool = false;
  121. grid.store.each(function(item) {
  122. if (item.get('cp_paymentcode') == paymentcode) {
  123. bool = true;
  124. }
  125. });
  126. if (!bool) {
  127. var items = grid.store.data.items, item = null;
  128. for ( var i in items) {
  129. item = items[i];
  130. if (Ext.isEmpty(item.get('cp_paymentcode'))) {
  131. item.set('cp_paymentcode', paymentcode);
  132. item.set('cp_payment', payment);
  133. item.set('cp_isdefault', '是');
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. });
  140. }
  141. });