Ext.namespace('Shipping');//创建用于范围变量和类的命名空间,指定的最后一个节点的命名空间隐式创建的所有其他节点 Shipping.MsOpFenDetailIndex = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.Shipping.MsOpFenDetailIndex.superclass.constructor.call(this); }; var _this;//当前实例 Ext.extend(Shipping.MsOpFenDetailIndex, Ext.Panel, { NowIndex:0, OprationStatus: null, //仅当弹出界面时使用 SelectedRecord: null, initUIComponents: function () { this.bsnoNum = null, this.toolBarItems = [ { text: "新增", iconCls: "btnadd", handler: function (button, event) { this.addDetail(); }, scope: this }, '-', { text: "删除", iconCls: "btndelete", handler: function (button, event) { this.onDeleteClick(button, event); }, scope: this }, '-', { text: "保存", iconCls: "btnsave", handler: function (button, event) { this.onPostDetailClick(button, event); }, scope: this }, '-', { text: "查询", iconCls: "btnsearch", handler: function (button, event) { this.onRefreshClick(button, event); }, scope: this }, '-', { text: "分箱", iconCls: "fenxiang", handler: function (button, event) { this.onFenXiangClick(button, event); }, scope: this }, '-', { text: "导入", iconCls: "openfolder", handler: function (button, event) { this.onImportClick(button, event); }, scope: this }]; this.toolBar = new Ext.Toolbar({ items: this.toolBarItems }); this.GridCheckBoxModel = Ext.create('Ext.selection.CheckboxModel'); this.storeList = Ext.create('Ext.data.Store', { model: 'MsOpFenDetail', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsOpFenDetail/GetList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); this.storeList_1 = Ext.create('Ext.data.Store', { model: 'MsOpFenDetail', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsOpFenDetail/GetList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); this.gridList = new Ext.grid.GridPanel({ store: this.storeList, enableHdMenu: false, region: 'center', loadMask: { msg: "数据加载中,请稍等..." }, plugins: [this.gridListCellEditing], trackMouseOver: true, disableSelection: false, selType: 'cellmodel', selModel: this.GridCheckBoxModel, columns: [ { sortable: true, dataIndex: 'GID', header: '主键', hidden: true }, { header: '序号', width: 50, sortable: true, renderer: function (value, metadata, record, rowIndex) { return rowIndex + 1; // 获取序号,方法2 } }, { sortable: true, dataIndex: 'COILNO', header: '批次号', width: 160, editor: { xtype: 'textfield', selectOnFocus: true } }, { sortable: true, dataIndex: 'SIZE', header: '规格', width: 100, editor: { xtype: 'textfield', selectOnFocus: true } }, { sortable: true, dataIndex: 'COLOUR', header: '颜色', width: 160, editor: { xtype: 'textfield', selectOnFocus: true } }, { sortable: true, dataIndex: 'NWKGS', header: '净重', width: 160, xtype: 'numbercolumn', renderer: function (value) { return Ext.util.Format.number(value, '0.0000');; }, editor: { xtype: 'numberfield', selectOnFocus: true, allowDecimals: true, decimalPrecision: 3 } }, { sortable: true, dataIndex: 'GWKGS', header: '毛重', width: 160, xtype: 'numbercolumn', renderer: function (value) { return Ext.util.Format.number(value, '0.0000');; }, editor: { xtype: 'numberfield', selectOnFocus: true, allowDecimals: true, decimalPrecision: 3 } }, { sortable: true, dataIndex: 'NLENGTH', header: '长度', width: 160, editor: { xtype: 'numberfield', selectOnFocus: true, allowDecimals: true, decimalPrecision: 0 } } ] }); this.gridList_1 = new Ext.grid.GridPanel({ store: this.storeList_1, id:'grid_1', enableHdMenu: false, region: 'center', loadMask: { msg: "数据加载中,请稍等..." }, trackMouseOver: true, disableSelection: true, selType: 'cellmodel', columns: [ { sortable: true, dataIndex: 'GID', header: '主键', hidden: true }, { header: '序号', width: 50, sortable: true, renderer: function (value, metadata, record, rowIndex) { return rowIndex + 1; // 获取序号,方法2 }, align: 'center' }, { sortable: true, dataIndex: 'FXCOLNO', header: '业务编号', width: 120, align:'center' }, { sortable: true, dataIndex: 'COILNO', header: '批次号', width: 120, align: 'center' }, { sortable: true, dataIndex: 'SIZE', header: '规格', width: 120, align: 'center' }, { sortable: true, dataIndex: 'COLOUR', header: '颜色', width: 120, align: 'center' }, { sortable: true, dataIndex: 'FXNO', header: '分箱编号', width: 80, align: 'center' }, { sortable: true, dataIndex: 'NWKGS', header: '净重', width: 80, xtype: 'numbercolumn', renderer: function (value) { return Ext.util.Format.number(value, '0.0000');; }, align: 'center' }, { sortable: true, dataIndex: 'GWKGS', header: '毛重', width: 80, xtype: 'numbercolumn', renderer: function (value) { return Ext.util.Format.number(value, '0.0000');; }, align: 'center' }, { sortable: true, dataIndex: 'TGKGS', header: '标签毛重', width: 80, xtype: 'numbercolumn', align: 'center' },{ sortable: true, dataIndex: 'NLENGTH', header: '长度', width: 80, align: 'center' }, { dataIndex: null, header: '件数', width: 60, align: 'center' }, { dataIndex: null, header: '毛重(kg)', width: 80, align: 'center' }, { dataIndex: null, header: '箱号', width: 80, align: 'center' }, { dataIndex: null, header: '铅封号', width: 80, align: 'center' }, { dataIndex: null, header: '箱皮重', width: 80, align: 'center' } ] }); this.panelBtn = new Ext.Panel({ region: "north", tbar: this.toolBar }); this.panelTop = new Ext.Panel({ layout: "border", region: "north", height: 30, items: [this.panelBtn] }); this.panelCtn = new Ext.Panel({ layout: "border", title: '鼎世钢卷(未分箱)', id: 'pnlctn', region: "center", items: [this.gridList], listeners: { activate: function () { _this.NowIndex = 0; _this.onRefreshClick(); //动态修改tbar _this.toolBar.removeAll(false); _this.toolBar.add(_this.toolBarItems); } } }); this.panelCtn_1 = new Ext.Panel({ layout: "border", title: '鼎世钢卷(已分箱)', id: 'pnlctn_1', region: "center", items: [this.gridList_1], listeners: { activate: function () { _this.NowIndex = 1; _this.onRefreshClick(); _this.toolBar.removeAll(false); //动态修改tbar _this.toolBar.add([{ text: "查询", iconCls: "btnsearch", handler: function (button, event) { _this.onRefreshClick(button, event); }, scope: this },'-',{ id: "exportBtn", text: "导出", iconCls: "download", handler: function (button, event) { _this.onExportClick(button, event); }, scope: this }, '-',{ id: "exportBtn_11", text: "历史导出", iconCls: "download", handler: function (button, event) { _this.onHistoryExportClick(button, event); }, scope: this }]); } } }); this.MainCenter = new Ext.TabPanel({ activeTab: 0, autoWidth: true, border: true, frame: false, region: 'center', enableTabScroll: true, items: [ this.panelCtn, this.panelCtn_1 ] }); Ext.apply(this,{items: [this.panelTop, this.MainCenter]}); this.storeList.on('beforeload', function (store) { var sql = this.getCondition(); Ext.apply(store.proxy.extraParams, { condition: sql, sort: '' }); }, this); this.storeList_1.on('beforeload', function (store) { var sql = this.getCondition(); Ext.apply(store.proxy.extraParams, { condition: sql, sort: '' }); },this); this.onRefreshClick(); this.gridList_1.getStore().on('load', function () { _this.MerginCells(_this.gridList_1, [6], true); },this); _this = this; }, onRefreshClick: function (button, event) { this.bsnoNum = null;//初始化 var sql = this.getCondition(); if (this.NowIndex == 0) { this.storeList.load({ params: { start: 0, limit: 1000, sort: '', condition: sql }, waitMsg: "正在查询数据...", scope: this }); } else { this.storeList_1.load({ params: { start: 0, limit: 1000, sort: '', condition: sql }, waitMsg: "正在查询数据...", scope: this }); } }, //查询 getCondition: function () { //拼sql语句 查询条件 var sqlstr = " FXMARK='" + this.NowIndex + "' AND IOMARK='0'"; if (this.bsnoNum != null) sqlstr = " FXCOLNO='" + this.bsnoNum +"' AND IOMARK='1'"; return sqlstr; }, //拼sql语句 addDetail: function () { var record = Ext.create('MsOpFenDetail', { GID: '', COILNO: '', SIZE: '', COLOUR: '', NWKGS: '0.00', GWKGS: '0.00', NLENGTH: '', TGKGS: '0.00', FXNO: '', XMODEL: '', LIKGS: '0.00', FXMARK: '0', IOMARK:'0', FXCOLNO: '', OPERUSER:'', OPERTIME:new Date() }); this.storeList.add(record); var n = this.storeList.getCount(); this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 1 }); },//新增 onDeleteClick: function (button, event) { var selections = this.gridList.getSelectionModel().getSelection(); if (selections.length == 0) { Ext.Msg.show({ title: '提示', msg: '请先选择单据!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; } var record = []; for(var item in selections) if (selections.hasOwnProperty(item)) record.push(selections[item].data); Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) { if (btn === 'yes') { Ext.Msg.wait('正在删除数据...'); Ext.Ajax.request({ waitMsg: '正在删除数据...', url: '/MvcShipping/MsOpFenDetail/Delete', params: { data: Ext.JSON.encode(record) }, callback: function (options, success, response) { if (success) { var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { this.storeList.remove(selections); Ext.Msg.hide(); } else { Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); } } }, failure: function (response, options) { Ext.Msg.show({ title: '警告', msg: '服务器响应出错,请重试', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); }, success: function (response, options) { }, scope: this }); } }, this); },//删除 onPostDetailClick: function (button, event) { var bodyDrChFeeDatas = []; for (var i = 0; i < this.storeList.getCount(); i += 1) { var memberyf = this.storeList.getAt(i); bodyDrChFeeDatas.push(memberyf); }; var jsonChFeeBody = ConvertGIDRecordsToJson(bodyDrChFeeDatas); Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsOpFenDetail/Save', scope: this, params: { body: jsonChFeeBody }, callback: function (options, success, response) { if (success) { Ext.MessageBox.hide(); var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { this.onRefreshClick(); } else { Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); } } else { Ext.Msg.show({ title: '请重试', msg: '服务器响应出错', icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); } } }); },//保存 onFenXiangClick: function (button, event) { var selections = this.GridCheckBoxModel.getSelection(); if (selections.length > 0) { if (Ext.get("optionWin") == null) { this.storeCtn = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CodeCtnModel', proxy: { url: '/CommMng/BasicDataRef/GetCodeCtnList' } }); this.storeCtn.load(); var limitWeight = Ext.create('Ext.form.field.Number', { region: "north", margins: '6 12 6 12', name: 'LIKGS', fieldLabel: "限重", labelAlign: 'right', labelWidth: 30, //value: 18.000, maxValue: 100000, width: 180, minValue: 0, allowDecimals: true, decimalPrecision: 3 }); //限重 var comboxCtn = Ext.create('DsExt.ux.RefTableCombox', { id:"ctnCombo", region: "north", store: this.storeCtn, margins: '12 12 6 12', forceSelection: true, fieldLabel: '箱型', labelAlign: 'right', labelWidth: 30, name: 'XMODEL', valueField: 'DLIKGS',//默认限重 displayField: 'CTN', listeners: { afterRender: function (combo) { this.getStore().on("load", function (s, r, o) { comboxCtn.setValue(r[5].get('DLIKGS'));//第一个值 }); }, change: function(obj,value) { limitWeight.setValue(value); } } }); //箱型 var buttonCtn = Ext.create('Ext.Button', { text: '确认分箱', renderTo: Ext.getBody(), region: "south", margins: '6 12 6 12', handler: function() { //Ajax分箱处理 var record = []; for (var item in selections) if (selections.hasOwnProperty(item)) record.push(selections[item].data); Ext.Msg.wait('正在做分箱处理...'); Ext.Ajax.request({ waitMsg: '正在分箱...', url: '/MvcShipping/MsOpFenDetail/FenXiangOpera', params: { data: Ext.JSON.encode(record), limit: limitWeight.getValue(), xmodel: comboxCtn.getDisplayValue() }, callback: function (options, success, response) { if (success) { var jsonresult = Ext.JSON.decode(response.responseText); //成功 if (jsonresult.Success) { //关闭提示框 Ext.Msg.close(); //关闭分箱窗体 Ext.getCmp("optionWin").close(); //切换到已分箱Tab页 _this.MainCenter.setActiveTab("pnlctn_1"); } //异常 else { Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.ERROR }); } } }, failure: function (response, options) { Ext.Msg.show({ title: '警告', msg: '服务器响应出错,请重试', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); }, success: function (response, options) { }, scope: this }); } }); //确认分箱 var layerPanel = new Ext.Panel({ layout: "border", width: 200, height: 160, id: 'pnlctn_11', region: "center", items: [comboxCtn, limitWeight, buttonCtn] }); var win = Ext.create('Ext.window.Window', { title: '分箱', layout: 'fit', id: 'optionWin', draggable: true, //拖动 x: event.clientX, y: event.clientY, resizable: false, items: { // Let's put an empty grid in just to illustrate fit layout xtype: 'panel', border: true, items: [layerPanel] } }); win.show(); } //弹层判断 } //获取选中项 else { Ext.Msg.show({ title: '缺少必要操作', msg: '请先选择要分箱的钢卷' }); } },//分箱 onImportClick: function (button, event) { if (Ext.get("importWin") == null) { var upform = Ext.create('Ext.form.Panel', { width: 500, bodyPadding: '6 6 6 6', id: "upform", defaults: { anchor: '100%', allowBlank: false, msgTarget: 'side', labelWidth: 100 }, items: [{ xtype: 'filefield', id: 'form-file', emptyText: '请选择文件', fieldLabel: '文件路径', name: 'file', buttonText: '浏览', regex: /^.+\.(xls|xlsx)$/, regexText: "只能选择xls|xlsx格式的文件", buttonConfig: { iconCls: 'upload-icon' } }], buttons: [{ text: '开始导入', handler: function () { var form = this.up('form').getForm(); if (form.isValid()) { form.submit({ method: 'post', url: '/mvcshipping/msopfendetail/FileUpload', waitMsg: '正在上传您的文件,请耐心等候...', success: function (form, action) { _this.storeList.add(eval(action.result.data)); Ext.getCmp("importWin").close(); Ext.Msg.alert("提示信息", "导入成功!"); }, failure: function (form, action) { Ext.Msg.alert("提示信息", "导入失败,请重试!"); } }); } } }, { text: '重置', handler: function () { this.up('form').getForm().reset(); } }] }); var win = Ext.create('Ext.window.Window', { title: '导入文件', layout: 'fit', id: 'importWin', draggable: true, //拖动 x: event.clientX, y: event.clientY, resizable: false, items: { xtype: 'panel', border: true, items: [upform] } }); win.show(); } },//导入 onExportClick: function (button, event) { var downTab = Ext.getDom("grid_1").getElementsByTagName('table')[0].cloneNode(true);//深度克隆对象,克隆节点以及节点下面的子内容 var columns = ["", "序号", "业务编号", "批次号", "规格", "颜色", "分箱编号", "净重", "毛重", "标签毛重", "长度", "件数", "毛重(kg)", "箱号", "铅封号", "箱皮重"]; var colnRow = downTab.rows[0].cloneNode(true);//克隆空行 var insertArry = [];//分箱件数数组 var gweightArry = [];//分箱毛重数组 var gwTotal = 0.000;//当前总毛重 var ctTotal = 0;//当前总件数 //增加表头 for (var i = 0; i < columns.length; i++) downTab.rows[0].cells[i].innerHTML = columns[i]; //移除隐藏的cell var elementsByClassName = downTab.getElementsByClassName("hiddenTd"); for (var k = elementsByClassName.length-1; k >= 0; k--) elementsByClassName[k].parentNode.removeChild(elementsByClassName[k]); //加总计行、加颜色处理、加小数格式处理 for (var j = 0; j < downTab.rows.length; j++) { downTab.rows[j].cells[1].style.textAlign = "center";//排序列 downTab.rows[j].cells[2].style.textAlign = "center";//业务编号列 downTab.rows[j].cells[3].style.textAlign = "center";//批次列 downTab.rows[j].cells[4].style.textAlign = "center";//规格列 var colCellObj = downTab.rows[j].cells[5];//COLOUR 列 colCellObj.style.textAlign = "center"; var rowCellObj = downTab.rows[j].cells[6];//分箱列 //* 被合并的行的列索引【列索引 - 1】 var nwCellObj = downTab.rows[j].cells[6];//净重 var gwCellObj = downTab.rows[j].cells[7];//毛重 var tgCellObj = downTab.rows[j].cells[8];//标签毛重 var leCellObj = downTab.rows[j].cells[9];//长度 var ctCellObj = downTab.rows[j].cells[10];//件数 var zwCellObj = downTab.rows[j].cells[11];//总毛重 if (rowCellObj.hasAttribute('rowspan')) { if (j !== 1) { insertArry.push(ctTotal); gweightArry.push(gwTotal); gwTotal = 0.000;//初始化总毛重 ctTotal = 0;//初始化总件数 } //修正 rowspan 列索引 nwCellObj = downTab.rows[j].cells[7];//净重 gwCellObj = downTab.rows[j].cells[8];//毛重 tgCellObj = downTab.rows[j].cells[9];//标签毛重 leCellObj = downTab.rows[j].cells[10];//长度 ctCellObj = downTab.rows[j].cells[11];//件数 zwCellObj = downTab.rows[j].cells[12];//总毛重 } //去掉td中的div nwCellObj.innerHTML = nwCellObj.innerText;//净重 gwCellObj.innerHTML = gwCellObj.innerText;//毛重 tgCellObj.innerHTML = tgCellObj.innerText;//标签 zwCellObj.innerHTML = zwCellObj.innerText;//总毛 leCellObj.innerHTML = leCellObj.innerText;//长度 ctCellObj.innerHTML = ctCellObj.innerText;//件数 //小数保留3位 nwCellObj.className += ' numcell';//净重 gwCellObj.className += ' numcell';//毛重 tgCellObj.className += ' numcell';//标签毛重 zwCellObj.className += ' numcell';//总毛重 //保留整数 leCellObj.className += ' intcell';//长度 ctCellObj.className += ' intcell';//件数 //累加毛重 gwTotal += j === 0 ? 0 : parseFloat(gwCellObj.innerText); ctTotal += j === 0 ? 0 : 1; switch (colCellObj.innerText) { case "MAROON RED": colCellObj.style.color = "#D20000"; break; case "RED MERAPI": colCellObj.style.color = "#984806"; break; case "GREEN": colCellObj.style.color = "#00B050"; break; default: colCellObj.style.color = "#000"; break; } } //最后一组分箱数据 insertArry.push(ctTotal);//件数 gweightArry.push(gwTotal);//毛重 var rowIndex = 0;//统计行索引 var ctTotalS = 0;//批次总件数 var gwTotalS = 0.000;//批次总毛重 for (var l = 0; l < insertArry.length; l++) { var ncolnRow = colnRow.cloneNode(true);//再次克隆节点 rowIndex += insertArry[l]+1; downTab.childNodes[0].insertBefore(ncolnRow, downTab.rows[rowIndex]);//downTab.childNodes[0]==(tbody) downTab.rows[rowIndex].cells[10].innerText = "单箱小计:"; downTab.rows[rowIndex].cells[10].style.textAlign = "right"; //计算总件数 downTab.rows[rowIndex].cells[11].innerText = insertArry[l]; //计算总毛重 downTab.rows[rowIndex].cells[12].innerText = gweightArry[l]; ctTotalS += insertArry[l]; gwTotalS += gweightArry[l]; } //添加总计行 downTab.childNodes[0].appendChild(colnRow); downTab.rows[downTab.rows.length - 1].cells[10].innerText = "合计:"; downTab.rows[downTab.rows.length - 1].cells[10].style.textAlign = "right"; downTab.rows[downTab.rows.length - 1].cells[11].innerText = ctTotalS; downTab.rows[downTab.rows.length - 1].cells[12].innerText = gwTotalS; // 使用outerHTML属性获取整个table元素的HTML代码(包括