Ext.define('saas.view.selfmakebalance-Gridpanel', { extend: 'Ext.grid.Panel', xtype: 'sale-selfmakebalance-gridpanel', requires: [ 'Ext.grid.plugin.Exporter' ], cls: 'core-base-gridpanel', plugins: [{ ptype: 'gridexporter', }, { ptype: 'menuclipboard' }, { ptype: 'cellediting', clicksToEdit: 1 }], layout: 'fit', //基础属性 border: 1, anchor: '100% 70%', loadMask: true, showIndex: true, columnWidth: 1.0, rootProperty: 'data', selModel: { checkOnly: true, type: 'checkboxmodel' }, viewConfig: { getRowClass: function (record) { return record.get('hasAuditedBom') ? null : 'x-noauditedbom-2'; } }, calcuMakeBalance: false, // idField: 'id', // turnQtyField: 'mr_thisqty', columns: [{ text: '本次数量', xtype: 'widgetcolumn', dataIndex: 'thisQty', width: 110, widget: { xtype: "numberfield", cls: 'widget-number', decimalPrecision: 8, minValue: 0, bind: '{record.thisQty}' } }, { text: '计划开工日期', xtype: 'widgetcolumn', dataIndex: 'planBeginDate', width: 150, widget: { xtype: "datefield", cls: 'widget-date', format: 'Y-m-d', bind: '{record.planBeginDate}' } }, { text: '物料id', dataIndex: 'prId', hidden: true }, { text: '物料编号', dataIndex: 'prCode', width: 150 }, { text: '物料名称', dataIndex: 'prDetail', width: 150 }, { text: '型号', dataIndex: 'prOrispeccode', width: 200 }, { text: '供需平衡', dataIndex: 'balanceQty' }, { text: '需求', columns: [{ text: '总需求', dataIndex: 'needQty', }, { text: '备货未核销', dataIndex: 'unClashQty', }, { text: '订单未发货', dataIndex: 'unSendQty', }, { text: '工单未领料', dataIndex: 'unPickQty', }, { text: '安全库存', dataIndex: 'safeStockQty', }] }, { text: '供应', columns: [{ text: '总供应', dataIndex: 'supplyQty', }, { text: '良品库存', dataIndex: 'greatTotal', }, { text: '采购未交', dataIndex: 'purUnInQty', }, { text: '工单未完工', dataIndex: 'unMakeInQty', }] }], initComponent: function () { var me = this; me.store = Ext.create('Ext.data.Store', { autoLoad: false, data: [], listeners: { beforeload: function (store, op) { var gridpanel = me, params = {}, keyWords = me.ownerCt.dockedItems.items[0].down('[name="keyWords"]').value; var params = JSON.stringify({ keyWords: keyWords, calcuMakeBalance: gridpanel.calcuMakeBalance }); me.setLoading(true); saas.util.BaseUtil.request({ url: '/api/make/makeBalance/list', method: 'POST', params: params }) .then(function (localJson) { me.setLoading(false); if (localJson.success) { gridpanel.getStore().loadData(localJson.data); } }) .catch(function (e) { me.setLoading(false); saas.util.BaseUtil.showErrorToast('计算失败: ' + e.message); }); } } }); Ext.apply(me, { dockedItems: [{ xtype: 'toolbar', dock: 'top', items: [{ text: '平衡计算', handler: function (b) { me.calcuMakeBalance = true; me.getStore().load(); me.calcuMakeBalance = false; }, }, { xtype: 'checkbox', name: '', columnWidth: 0.3, margin: '0 0 0 10', isFilter: true, boxLabel: '只显示供需平衡为负数的物料', checked: false, getFilter: function () { var me = this; let value = me.value, filter = {}; if (value) {//已勾选 filter = { filterFn: function (rec) { return rec.get('balanceQty') < 0; }, anyMatch: true, caseSensitive: false }; } return filter; }, listeners: { change: function () { me.onFilter(); } } }, { xtype: 'radiogroup', name: 'redio_vend', width: 200, margin: '0 0 0 80', cls: 'vendRadiogroup', simpleValue: true, items: [ { boxLabel: '单级', inputValue: 'SINGLE', checked: true }, { boxLabel: '多级', inputValue: 'MULTI' } ] }, '->', { iconCls: 'x-fa fa-question-circle', reference: 'qMark', name: 'qMark', cls: 'qMark', ui: 'header', tooltip: { text: '底色标识部分产品无BOM或者BOM未审核', anchor: 'top', title: '提示:', width: 350, dismissDelay: 7200000 } }, { text: '生成工单', cls: 'x-formpanel-btn-blue', handler: function (btn) { me.turnMake(); } }, { text: '导出', handler: me.onExport }] }] }); me.callParent(arguments); }, turnMake: function () { var me = this, makeType = me.dockedItems.items[1].query('[xtype="radiogroup"]')[0].lastValue, data = me.getGridSelected(); if (data && data.length > 0) { me.setLoading(true); var params = JSON.stringify({ baseDTOs: data, makeType: makeType }); console.log(params); saas.util.BaseUtil.request({ url: '/api/make/makeBalance/turnMake', params: params, method: 'POST', async: false }) .then(function (res) { if (res.success) { me.setLoading(false); me.selModel.deselectAll(); saas.util.BaseUtil.showSuccessToast('转单成功'); // var orderList=res.data; // if(orderList){ // orderList.forEach(function(order) { // let intValue = order.id, codeValue = order.code, name = order.name, // opage = 'make-makebase-formpanel'; // if(name == ''){ // opage = 'osmake-osmake-formpanel' // } // saas.util.BaseUtil.openTab(opage, name + "(" + codeValue + ")", codeValue + intValue, { // initId: intValue // }); // }); // } } }) .catch(function (res) { me.setLoading(false); saas.util.BaseUtil.showErrorToast(('操作失败: ') + res.message); }); } else { saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。'); } }, getGridSelected: function () { var me = this, items = me.selModel.getSelection(), data = new Array(); Ext.each(items, function (item, index) { if (!Ext.isEmpty(item.data['prCode']) && item.data['thisQty'] > 0 && item.data['planBeginDate'] != null) { data.push({ planBeginDate: Ext.isDate(item.data['planBeginDate']) ? item.data['planBeginDate'].getTime() : Ext.Date.parseDate(item.data['planBeginDate'],'Y-m-d H:i:s').getTime(), prCode: item.data['prCode'], prId: item.data['prId'], thisQty: item.data['thisQty'] }); } }); return data; }, onExport: function (me) { var grid = me.ownerCt.ownerCt; var cfg = { type: 'xlsx', title: '自制品供需平衡', fileName: '自制品供需平衡' + Ext.Date.format(new Date(), 'Y-m-d_H-i-s') + '.xlsx' }; grid.setLoading(true); grid.saveDocumentAs(cfg); Ext.defer(function () { grid.setLoading(false); }, 5000); }, onFilter: function () { var grid = this, filterFields = grid.query('[isFilter=true]'); var filters = []; Ext.each(filterFields, function (filterField) { if (filterField.getFilter && filterField.getFilter()) { let filter = filterField.getFilter(); if (filter) { filters.push(filter); } } }); grid.store.clearFilter(); grid.store.addFilter(filters); } });