B2CPurchase.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.purchase.B2CPurchase', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'scm.purchase.B2CPurchase'
  8. ],
  9. init:function(){
  10. var me = this;
  11. this.control({
  12. 'erpSubmitButton': {
  13. afterrender: function(btn){
  14. var status = Ext.getCmp('ve_auditstatuscode');
  15. if(status && status.value != 'ENTERING'){
  16. btn.hide();
  17. }
  18. },
  19. click: function(btn){
  20. me.FormUtil.onSubmit(Ext.getCmp('ve_id').value);
  21. }
  22. },
  23. '#priceSort':{
  24. click:function(btn){
  25. var myGrid = Ext.getCmp("reserveGrid");
  26. var pro = myGrid.store.sorters.map.gb_minprice;
  27. var direction, icon;
  28. if(!pro || pro.direction =='DESC'){
  29. direction = 'ASC';
  30. icon = 'x-button-icon-up';
  31. }else if(pro.direction =='ASC'){
  32. direction = 'DESC';
  33. icon = 'x-button-icon-down';
  34. }
  35. //清除deliverySort 颜色
  36. Ext.getCmp('deliverySort').el.setStyle('background-color','');
  37. Ext.getCmp('deliverySort').setIconCls('');
  38. myGrid.store.sort([
  39. {property: 'gb_minprice', direction: direction }
  40. ]);
  41. btn.setIconCls(icon);
  42. btn.el.setStyle('background','#e3e3e3');
  43. }
  44. },
  45. '#deliverySort':{
  46. click:function(btn){
  47. var myGrid = Ext.getCmp("reserveGrid");
  48. var pro = myGrid.store.sorters.map.gb_deliverytime;
  49. var direction, icon;
  50. if(!pro || pro.direction =='DESC'){
  51. direction = 'ASC';
  52. icon = 'x-button-icon-up';
  53. }else if(pro.direction =='ASC'){
  54. direction = 'DESC';
  55. icon = 'x-button-icon-down';
  56. }
  57. //清除priceSort 颜色
  58. Ext.getCmp('priceSort').el.setStyle('background-color','');;
  59. Ext.getCmp('priceSort').setIconCls('');
  60. myGrid.store.sort([
  61. {property: 'gb_deliverytime', direction: direction }
  62. ]);
  63. btn.setIconCls(icon);
  64. btn.el.setStyle('background-color','#e3e3e3');
  65. }
  66. },
  67. '#reserveGrid':{
  68. beforerender:function(){
  69. me.getReserve(pr_code);
  70. },
  71. afterrender:function(e){
  72. e.store.sort([
  73. {property: 'gb_minprice', direction: 'ASC' }
  74. ]);
  75. }
  76. },
  77. '#buyQty':{
  78. change:function(e){
  79. if(e.getValue()> e.originalValue){
  80. e.setValue(e.originalValue);
  81. showError("购买数量不允许超过勾选请购转采购的数量之和["+e.originalValue+"]");
  82. }
  83. }
  84. },
  85. '#autoBtn':{
  86. click:function(){//自动分配数量
  87. var buyqty = Ext.getCmp("buyQty").getValue();
  88. if(buyqty==0 || buyqty==""){
  89. //请输入购买数量
  90. showError('请输入购买数量');
  91. return ;
  92. }
  93. var grid = Ext.getCmp("reserveGrid");
  94. var gdata = [];
  95. var records = grid.getStore().data.items;
  96. //根据当前的排序方式进行自动分配算法
  97. var bo = true,d;
  98. Ext.Array.each(records,function(value,key){
  99. var d = value.data;
  100. if(buyqty >= d.gb_minbuyqty && d.gb_onsaleqty>=d.gb_minbuyqty) {
  101. if(d.gb_onsaleqty >= buyqty) {
  102. if(buyqty % d.gb_minpackqty > 0) {
  103. value.data.buyQty = buyqty - (buyqty % d.gb_minpackqty) + d.gb_minpackqty;
  104. } else {
  105. value.data.buyQty = buyqty;
  106. }
  107. } else {
  108. value.data.buyQty = d.gb_onsaleqty - (d.gb_onsaleqty % d.gb_minpackqty);
  109. }
  110. buyqty -= value.data.buyQty;
  111. }else {
  112. value.data.buyQty = null;
  113. }
  114. gdata.push(value.data);
  115. });
  116. Ext.getCmp("reserveGrid").getStore().loadData(gdata);
  117. }
  118. },
  119. '#confirmBuyBtn':{
  120. click:function(btn){//确认平台采购
  121. //判断采购的数量不允许已勾选采购总数,已选批次号
  122. var sum1=0;
  123. var grid = Ext.getCmp("reserveGrid");
  124. var data = [];
  125. grid.store.each(function(record){
  126. sum1 += Number(record.data.buyQty);
  127. if(Number(record.data.buyQty)>0){
  128. data.push(record.data);
  129. }
  130. });
  131. if(sum1 > qty){
  132. showError("已选的批次数量总计不允许超过勾选请购转采购的数量之和["+qty+"]");
  133. }else if(sum1 == 0){
  134. showError("未选择需要采购的数据");
  135. }else{
  136. //记录已选批次数据,传送至后台进行
  137. data = unescape(escape(Ext.JSON.encode(data)));
  138. me.confirmB2CPurchase(data);
  139. }
  140. }
  141. }
  142. });
  143. },
  144. getReserve:function(code){
  145. Ext.Ajax.request({//设置列表caller
  146. url : basePath + "scm/turnPurchase/getReserveByUUid.action",
  147. params: {
  148. pr_code : code
  149. },
  150. method : 'post',
  151. async: false,
  152. callback : function(options,success,response){
  153. var res = new Ext.decode(response.responseText);
  154. if(res.exceptionInfo){
  155. showError(res.exceptionInfo);return;
  156. }
  157. if(res.success){
  158. if(res.data){
  159. Ext.each(res.data,function(value, key){
  160. if(value.gb_price) {
  161. value.gb_minprice = new Ext.decode(value.gb_price)[0].price;
  162. value.gb_minpackqty = value.gb_minpackqty || 1;
  163. value.gb_minbuyqty = value.gb_minbuyqty || 1;
  164. }
  165. });
  166. Ext.getCmp("reserveGrid").getStore().loadData(res.data);
  167. }
  168. }
  169. }
  170. });
  171. },
  172. confirmB2CPurchase:function(param){
  173. //需从平台下单数据
  174. var data = window.parent.Ext.getCmp('B2CPurchaseButton').getTurnData();
  175. //param 需转采购数据
  176. Ext.Ajax.request({
  177. url : basePath + "scm/turnPurchase/comfirmB2CPurchase.action",
  178. params: {
  179. param:param,
  180. data:data.data,
  181. caller: data.caller
  182. },
  183. method : 'post',
  184. async: false,
  185. callback : function(options,success,response){
  186. var res = new Ext.decode(response.responseText);
  187. if(res.exceptionInfo){
  188. showError(res.exceptionInfo);return;
  189. }
  190. if(res.success){
  191. if(res.log){
  192. showMessage("提示", res.log, 15000);
  193. }
  194. Ext.Msg.alert("提示", "处理成功!", function(){
  195. window.parent.Ext.getCmp("batchDealGridPanel").multiselected = new Array();
  196. window.parent.Ext.getCmp('dealform').onQuery();
  197. });
  198. parent.Ext.getCmp("dlwin").close();
  199. }
  200. }
  201. });
  202. }
  203. });