CustomerAddress.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.sale.CustomerAddress', {
  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.sale.CustomerAddress','core.grid.Panel2','core.toolbar.Toolbar', 'core.form.MultiField',
  9. 'core.button.Save','core.button.Upload','core.button.Close','core.button.Update',
  10. 'core.button.Add','core.button.DeleteDetail',
  11. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger'
  12. ],
  13. init:function(){
  14. var me = this;
  15. me.allowinsert = true;
  16. this.control({
  17. 'erpGridPanel2': {
  18. itemclick: this.onGridItemClick
  19. },
  20. 'erpAddButton': {
  21. click: function(){
  22. me.FormUtil.onAdd('addCustomerAddress', '新增客户收货地址', 'jsps/scm/sale/customerAddress.jsp');
  23. }
  24. },
  25. 'erpSaveButton': {
  26. click: function(btn){
  27. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  28. var cuid = Ext.getCmp('cu_id').value;
  29. var i=0;
  30. Ext.Array.each(items, function(item){
  31. item.set('ca_cuid', cuid);
  32. if (item.data['ca_remark'] == '是') {
  33. i++;
  34. }
  35. });
  36. if (i > 1) {
  37. showError('默认收货地址只能选择一个,请重新选择!');
  38. return;
  39. }
  40. if(i == 0){
  41. Ext.Msg.alert("提示","请选择默认送货地址!");
  42. return;
  43. }
  44. this.FormUtil.onUpdate(this);
  45. }
  46. },
  47. 'erpUpdateButton': {
  48. click: function(btn){
  49. var grid = Ext.getCmp('grid'),items = grid.store.data.items;
  50. var i = 0;
  51. Ext.each(items, function(item){
  52. if (item.data['ca_remark'] == '是') {
  53. i++;
  54. }
  55. });
  56. if (i > 1) {
  57. showError('默认收货地址只能选择一个,请重新选择!');
  58. return;
  59. }
  60. this.FormUtil.onUpdate(this);
  61. }
  62. },
  63. 'erpCloseButton': {
  64. click: function(btn){
  65. me.FormUtil.beforeClose(me);
  66. }
  67. },
  68. 'dbfindtrigger[name=cu_code]':{
  69. afterrender: function(t){
  70. if (t.fieldConfig == 'PT') {
  71. t.dbBaseCondition = "cd_sellercode='" + em_code + "'";
  72. }
  73. },
  74. aftertrigger: function(){
  75. var id = Ext.getCmp('cu_id').value;
  76. var address = Ext.getCmp('cu_add1').value,
  77. contact = Ext.getCmp('cu_contact').value,
  78. phone = Ext.getCmp('cu_tel').value,
  79. fax = Ext.getCmp('cu_fax').value,
  80. shcustname = Ext.getCmp('cu_shadd').value;
  81. if(id != null & id != ''){
  82. this.getAddressStore('ca_cuid=' + id, address, contact, phone, fax, shcustname);
  83. }
  84. }
  85. }
  86. });
  87. },
  88. onGridItemClick: function(selModel, record){//grid行选择
  89. this.GridUtil.onGridItemClick(selModel, record);
  90. },
  91. getForm: function(btn){
  92. return btn.ownerCt.ownerCt;
  93. },
  94. getAddressStore: function(condition, address, contact, phone, fax, shcustname){
  95. var me = this;
  96. var grid = Ext.getCmp('grid');
  97. grid.store.removeAll(false);
  98. me.BaseUtil.getActiveTab().setLoading(true);//loading...
  99. Ext.Ajax.request({//拿到grid的columns
  100. url : basePath + "common/singleGridPanel.action",
  101. params: {
  102. caller: "CustomerAddress",
  103. condition: condition
  104. },
  105. method : 'post',
  106. callback : function(options,success,response){
  107. me.BaseUtil.getActiveTab().setLoading(false);
  108. var res = new Ext.decode(response.responseText);
  109. if(res.exceptionInfo){
  110. showError(res.exceptionInfo);return;
  111. }
  112. var data = [];
  113. if(!res.data || res.data.length == 2){
  114. me.GridUtil.add10EmptyItems(grid);
  115. } else {
  116. data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  117. if(data.length > 0){
  118. grid.store.loadData(data);
  119. }
  120. }
  121. var bool = false;
  122. grid.store.each(function(item){
  123. if(item.get('ca_address') == address) {
  124. bool = true;
  125. }
  126. if(item.get('ca_person') == contact) {
  127. bool = true;
  128. }
  129. if(item.get('ca_phone') == phone) {
  130. bool = true;
  131. }
  132. if(item.get('ca_fax') == fax) {
  133. bool = true;
  134. }
  135. if(item.get('ca_shcustname') == shcustname) {
  136. bool = true;
  137. }
  138. });
  139. if(!bool) {
  140. var items = grid.store.data.items, item = null;
  141. for(var i in items) {
  142. item = items[i];
  143. if(Ext.isEmpty(item.get('ca_address'))) {
  144. item.set('ca_address', address);
  145. item.set('ca_person', contact);
  146. item.set('ca_phone', phone);
  147. item.set('ca_fax', fax);
  148. item.set('ca_shcustname', shcustname);
  149. item.set('ca_remark', '是');
  150. break;
  151. }
  152. }
  153. }
  154. }
  155. });
  156. }
  157. });