Ext.QuickTips.init(); Ext.define('erp.controller.scm.purchase.B2CPurchase', { extend: 'Ext.app.Controller', FormUtil: Ext.create('erp.util.FormUtil'), BaseUtil: Ext.create('erp.util.BaseUtil'), views:[ 'scm.purchase.B2CPurchase' ], init:function(){ var me = this; this.control({ 'erpSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('ve_auditstatuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onSubmit(Ext.getCmp('ve_id').value); } }, '#priceSort':{ click:function(btn){ var myGrid = Ext.getCmp("reserveGrid"); var pro = myGrid.store.sorters.map.gb_minprice; var direction, icon; if(!pro || pro.direction =='DESC'){ direction = 'ASC'; icon = 'x-button-icon-up'; }else if(pro.direction =='ASC'){ direction = 'DESC'; icon = 'x-button-icon-down'; } //清除deliverySort 颜色 Ext.getCmp('deliverySort').el.setStyle('background-color',''); Ext.getCmp('deliverySort').setIconCls(''); myGrid.store.sort([ {property: 'gb_minprice', direction: direction } ]); btn.setIconCls(icon); btn.el.setStyle('background','#e3e3e3'); } }, '#deliverySort':{ click:function(btn){ var myGrid = Ext.getCmp("reserveGrid"); var pro = myGrid.store.sorters.map.gb_deliverytime; var direction, icon; if(!pro || pro.direction =='DESC'){ direction = 'ASC'; icon = 'x-button-icon-up'; }else if(pro.direction =='ASC'){ direction = 'DESC'; icon = 'x-button-icon-down'; } //清除priceSort 颜色 Ext.getCmp('priceSort').el.setStyle('background-color','');; Ext.getCmp('priceSort').setIconCls(''); myGrid.store.sort([ {property: 'gb_deliverytime', direction: direction } ]); btn.setIconCls(icon); btn.el.setStyle('background-color','#e3e3e3'); } }, '#reserveGrid':{ beforerender:function(){ me.getReserve(pr_code); }, afterrender:function(e){ e.store.sort([ {property: 'gb_minprice', direction: 'ASC' } ]); } }, '#buyQty':{ change:function(e){ if(e.getValue()> e.originalValue){ e.setValue(e.originalValue); showError("购买数量不允许超过勾选请购转采购的数量之和["+e.originalValue+"]"); } } }, '#autoBtn':{ click:function(){//自动分配数量 var buyqty = Ext.getCmp("buyQty").getValue(); if(buyqty==0 || buyqty==""){ //请输入购买数量 showError('请输入购买数量'); return ; } var grid = Ext.getCmp("reserveGrid"); var gdata = []; var records = grid.getStore().data.items; //根据当前的排序方式进行自动分配算法 var bo = true,d; Ext.Array.each(records,function(value,key){ var d = value.data; if(buyqty >= d.gb_minbuyqty && d.gb_onsaleqty>=d.gb_minbuyqty) { if(d.gb_onsaleqty >= buyqty) { if(buyqty % d.gb_minpackqty > 0) { value.data.buyQty = buyqty - (buyqty % d.gb_minpackqty) + d.gb_minpackqty; } else { value.data.buyQty = buyqty; } } else { value.data.buyQty = d.gb_onsaleqty - (d.gb_onsaleqty % d.gb_minpackqty); } buyqty -= value.data.buyQty; }else { value.data.buyQty = null; } gdata.push(value.data); }); Ext.getCmp("reserveGrid").getStore().loadData(gdata); } }, '#confirmBuyBtn':{ click:function(btn){//确认平台采购 //判断采购的数量不允许已勾选采购总数,已选批次号 var sum1=0; var grid = Ext.getCmp("reserveGrid"); var data = []; grid.store.each(function(record){ sum1 += Number(record.data.buyQty); if(Number(record.data.buyQty)>0){ data.push(record.data); } }); if(sum1 > qty){ showError("已选的批次数量总计不允许超过勾选请购转采购的数量之和["+qty+"]"); }else if(sum1 == 0){ showError("未选择需要采购的数据"); }else{ //记录已选批次数据,传送至后台进行 data = unescape(escape(Ext.JSON.encode(data))); me.confirmB2CPurchase(data); } } } }); }, getReserve:function(code){ Ext.Ajax.request({//设置列表caller url : basePath + "scm/turnPurchase/getReserveByUUid.action", params: { pr_code : code }, method : 'post', async: false, callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exceptionInfo){ showError(res.exceptionInfo);return; } if(res.success){ if(res.data){ Ext.each(res.data,function(value, key){ if(value.gb_price) { value.gb_minprice = new Ext.decode(value.gb_price)[0].price; value.gb_minpackqty = value.gb_minpackqty || 1; value.gb_minbuyqty = value.gb_minbuyqty || 1; } }); Ext.getCmp("reserveGrid").getStore().loadData(res.data); } } } }); }, confirmB2CPurchase:function(param){ //需从平台下单数据 var data = window.parent.Ext.getCmp('B2CPurchaseButton').getTurnData(); //param 需转采购数据 Ext.Ajax.request({ url : basePath + "scm/turnPurchase/comfirmB2CPurchase.action", params: { param:param, data:data.data, caller: data.caller }, method : 'post', async: false, callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exceptionInfo){ showError(res.exceptionInfo);return; } if(res.success){ if(res.log){ showMessage("提示", res.log, 15000); } Ext.Msg.alert("提示", "处理成功!", function(){ window.parent.Ext.getCmp("batchDealGridPanel").multiselected = new Array(); window.parent.Ext.getCmp('dealform').onQuery(); }); parent.Ext.getCmp("dlwin").close(); } } }); } });