Ext.namespace('Shipping'); Shipping.MsOpCtnDetailEdit = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.Shipping.MsOpCtnDetailEdit.superclass.constructor.call(this); }; Ext.extend(Shipping.MsOpCtnDetailEdit, Ext.Panel, { parentWin: null, editRecord: null, initUIComponents: function () { this.serialNo = 0; this.itemindex = 1; //#region 加载父类值 parentWin = window.parent.opener; if (parentWin) { var ret = parentWin.OprationSwapOpCtnDetail(); this.editRecord = ret[0]; } //#endregion //#region 下拉框信息加载 //箱型_集装箱列表中的下拉框加载 this.storeCodeCtn = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CodeCtnModel', proxy: { url: '/CommMng/BasicDataRef/GetCodeCtnList' } }); this.storeCodeCtn.load(); this.comboxCTNALL = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '箱型', store: this.storeCodeCtn, forceSelection: true, name: 'CTNALL', valueField: 'CTN', displayField: 'CTN' }); //件数包装_集装箱列表中的下拉框加载 this.storeCodePackage = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CodePackageModel', proxy: { url: '/CommMng/BasicDataRef/GetCodePackageList' } }); this.storeCodePackage.load(); this.comboxKINDPKGS_CTN = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '件数包装', store: this.storeCodePackage, forceSelection: true, name: 'KINDPKGS', valueField: 'PKGS', displayField: 'PKGS' }); //#endregion //#region 集装箱-主列表 this.storeList = Ext.create('Ext.data.Store', { model: 'MsOpSeaeDetail', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsOpSeae/GetBodyList', reader: { id: 'BsNo,CTNCODE,CTN_ID', root: 'data', totalProperty: 'totalCount' } } }); this.girdcolums = [{ sortable: true, dataIndex: 'CTN_ID', header: '编号', hidden: true, width: 0 }, { sortable: true, dataIndex: 'BSNO', header: '业务编号', hidden: true, width: 0 }, { sortable: true, dataIndex: 'CTNCODE', header: '序号', width: 35 }, { dataIndex: 'CTNALL', header: '箱型', width: 70 }, { dataIndex: 'CTNNUM', header: '箱量', width: 50 }, { dataIndex: 'CNTRNO', header: '箱号', width: 100 }, { dataIndex: 'SEALNO', header: '封号', width: 80 }, { sortable: true, dataIndex: 'PKGS', header: '件数', width: 80, align: 'right', summaryType: 'sum', summaryRenderer: Ext.util.Format.numberRenderer() }, { dataIndex: 'KINDPKGS', header: '件数包装', width: 120 }, { dataIndex: 'KGS', header: '重量', width: 100, align: 'right', summaryType: 'sum', summaryRenderer: Ext.util.Format.numberRenderer('00.0000'), summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 4, '', true); return value; } }, { dataIndex: 'CBM', header: '尺码', width: 100, align: 'right', summaryType: 'sum', summaryRenderer: Ext.util.Format.numberRenderer('00.0000'), summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 4, '', true); return value; } }, { dataIndex: 'TAREWEIGHT', header: '箱皮重', width: 100, align: 'right', summaryType: 'sum', summaryRenderer: Ext.util.Format.numberRenderer('00.0000'), summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 4, '', true); return value; } }, { dataIndex: 'REMARK', header: '备注', width: 150 }]; //定义Grid this.gridListMain = new Ext.grid.GridPanel({ title: '主提单号:' + this.editRecord.data.MBLNO.toString() + ' 集装箱信息', store: this.storeList, enableHdMenu: false, //region: 'west', region: 'north', height: 400, frame: true, loadMask: { msg: "数据加载中,请稍等..." }, trackMouseOver: true, disableSelection: false, columns: this.girdcolums, features: [{ ftype: 'summary'//Ext.grid.feature.Summary表格汇总特性 }], tbar: [{ text: '预览打印', tooltip: '预览打印', id: "btnprint", iconCls: "btnprint", handler: function (button, event) { this.Print(button, event); }, scope: this }] }); _this = this; this.gridListMain.addListener('itemclick', function (dataview, record, item, index, e, b) { this.storeBodyList.load({ params: { condition: "CTN_ID='" + record.data.CTN_ID + "'" }, scope: this }); }, this); //#endregion //#region 集装箱-明细表 this.storeBodyList = Ext.create('Ext.data.Store', { model: 'MsOpCtnDetail', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsOpSeae/GetOpCtnDetailList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); this.girdcolums2 = [{ sortable: true, dataIndex: 'GID', header: '编号', hidden: true, width: 0 }, { sortable: true, dataIndex: 'CTN_ID', header: 'CTN编号', hidden: true, width: 0 }, { sortable: true, dataIndex: 'PKGS', header: '件数', width: 80, align: 'right', editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true, //得到焦点时自动选择文本 allowDecimals: false, //允许输入小数 nanText: '请输入有效整数', value: 0 }, summaryType: 'sum', summaryRenderer: Ext.util.Format.numberRenderer() }, { dataIndex: 'KINDPKGS', header: '包装', width: 120, editor: this.comboxKINDPKGS_CTN }, { dataIndex: 'KGS', header: '重量', width: 100, align: 'right', editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true, //得到焦点时自动选择文本 allowDecimals: true, //允许输入小数 decimalPrecision: 4, //允许保留的小数位数,并四舍五入 nanText: '请输入有效小数', value: 0.00000 }, summaryType: 'sum', summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 4, '', true); return value; } }, { dataIndex: 'CBM', header: '尺码', width: 100, align: 'right', editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true, //得到焦点时自动选择文本 allowDecimals: true, //允许输入小数 decimalPrecision: 4, //允许保留的小数位数,并四舍五入 nanText: '请输入有效小数', value: 0.00000 }, summaryType: 'sum', summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 4, '', true); return value; } }, { dataIndex: 'HSCODE', header: 'HS编码', width: 100, editor: { xtype: 'textareafield', selectOnFocus: true, allowBlank: false } }, { dataIndex: 'DESCRIPTION', header: '货物描述(品名)', width: 200, editor: { xtype: 'textareafield', selectOnFocus: true, allowBlank: false, enableKeyEvents: true, //激活键盘事件 listeners: { scope: this, 'blur': function blur(combo, eOpts, obj) { this.formEdit.getForm().findField('DESCRIPTION').setValue(combo.value); } } } }, { dataIndex: 'MARKS', header: '唛头', width: 200, editor: { xtype: 'textareafield', selectOnFocus: true, allowBlank: false, enableKeyEvents: true, //激活键盘事件 listeners: { scope: this, 'blur': function blur(combo, eOpts, obj) { this.formEdit.getForm().findField('MARKS').setValue(combo.value); } } } }]; this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); this.gridList = new Ext.grid.GridPanel({ title: '多品名信息', store: this.storeBodyList, enableHdMenu: false, //region: 'north', region: 'west', width: 900, frame: true, loadMask: { msg: "数据加载中,请稍等..." }, trackMouseOver: true, disableSelection: false, plugins: [this.gridListCellEditing], selType: 'cellmodel', columns: this.girdcolums2, features: [{ ftype: 'summary'//Ext.grid.feature.Summary表格汇总特性 }], tbar: [{ text: '添加明细', tooltip: '添加明细', id: "btnadddetail", iconCls: "btnadddetail", handler: function (button, event) { this.onAddDetailClick(button, event); }, scope: this }, { id: 'btnESave', text: "保存明细", iconCls: "btnsave", handler: function (button, event) { this.Save('0'); }, scope: this }, '-', { text: '删除明细', tooltip: '删除明细', id: "btndeldetail", iconCls: "btndeletedetail", handler: function (button, event) { this.onDelDetailClick(button, event); }, scope: this }, '-', { text: '引入EXCEL数据', handler: function (button, event) { this.onImportCtnDetailClick(button, event); }, scope: this }] }); this.gridList.addListener('itemclick', function (dataview, record, item, index, e, b) { this.formEdit.getForm().findField('DESCRIPTION').setValue(record.data.DESCRIPTION); this.formEdit.getForm().findField('MARKS').setValue(record.data.MARKS); }, this); //#endregion //#region 编辑formEdit 基本信息 this.formEdit = Ext.widget('form', { title: '货物描述(品名)与唛头信息', region: 'center', frame: true, border: false, trackResetOnLoad: true, items: [{ fieldLabel: 'GID', name: 'GID', hidden: true }, { xtype: 'label', flex: 1, id: 'DESCRIPTIONSTR', html: "" }, { xtype: 'textareafield', grow: true, //字段是否自动伸展和收缩,默认为false labelSeparator: '', //标签分隔字符 name: 'DESCRIPTION', height: 170, anchor: '100%', enableKeyEvents: true, //激活键盘事件 listeners: { scope: this, 'blur': function blur(combo, eOpts, obj) { var selections = this.gridList.getSelectionModel().getSelection(); if (selections.length > 0) { this.SetShipperLable('DESCRIPTION', 35); selections[0].set('DESCRIPTION', combo.value); } this.formEdit.getForm().findField('DESCRIPTION') .setValue(combo.value.toUpperCase()); } // } }, { xtype: 'label', flex: 1, id: 'MARKSSTR', html: "" }, { xtype: 'textareafield', grow: true, //字段是否自动伸展和收缩,默认为false labelSeparator: '', //标签分隔字符 name: 'MARKS', height: 170, anchor: '100%', enableKeyEvents: true, //激活键盘事件 listeners: { scope: this, 'blur': function blur(combo, eOpts, obj) { var selections = this.gridList.getSelectionModel().getSelection(); if (selections.length > 0) { this.SetShipperLable('MARKS', 24); selections[0].set('MARKS', combo.value); } this.formEdit.getForm().findField('MARKS') .setValue(combo.value.toUpperCase()); } // } }] }); //#endregion //#region 框架结构 Ext.apply(this, { border: false, items: [this.gridListMain, this.gridList, this.formEdit] }); //#endregion //#region 加载列表 this.storeList.load({ params: { condition: "BSNO='" + this.editRecord.data.BSNO.toString() + "'" }, scope: this }); //#endregion }, //#region 保存明细 Save: function (type) { var basicForm = this.formEdit.getForm(); if (!basicForm.isValid()) { return; } // var selections = this.gridListMain.getSelectionModel().getSelection(); var sCTN_ID = selections[0].data.CTN_ID; var iPKGS = selections[0].data.PKGS; var dKGS = selections[0].data.KGS; var dCBM = selections[0].data.CBM; // var data = this.formEdit.getForm().getValues(false, false, false); var bodydatas = []; var iPKGS2 = 0; var dKGS2 = 0; var dCBM2 = 0; for (var i = 0; i < this.storeBodyList.getCount(); i += 1) { iPKGS2 += this.storeBodyList.getAt(i).get("PKGS"); dKGS2 = Add(dKGS2, this.storeBodyList.getAt(i).get("KGS")); var ctncbm=this.storeBodyList.getAt(i).get("CBM"); dCBM2 = Add(dCBM2, parseFloat(ctncbm).toFixed(4)); var member = this.storeBodyList.getAt(i); bodydatas.push(member); } var jsonBody = ConvertRecordsToJsonAll(bodydatas); // //if (iPKGS2 > iPKGS) { // Ext.Msg.show({ title: '错误', msg: "多品名中 件数总和 超出 集装箱件数!", icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); // return; //} //if (dKGS2 > dKGS) { // Ext.Msg.show({ title: '错误', msg: "多品名中 重量总和 超出 集装箱重量!", icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); // return; //} //if (dCBM2 > dCBM) { // Ext.Msg.show({ title: '错误', msg: "多品名中 立方数总 超出 集装箱立方数!", icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); // return; //} // Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsOpSeae/SaveOpCtnDetail', scope: this, params: { body: jsonBody, pkgs: iPKGS, kgs: dKGS, cbm: dCBM }, callback: function (options, success, response) { if (success) { Ext.MessageBox.hide(); var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { var returnData = jsonresult.Data; this.storeBodyList.load({ params: { condition: "CTN_ID='" + sCTN_ID + "'" }, scope: this }); } 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 }); } } }); }, //end save //#endregion //#region 添加明细 onAddDetailClick: function (button, event) { var descrip = this.editRecord.get('DESCRIPTION'); var sMARKS = this.editRecord.get('MARKS'); if (sMARKS.toString().trim() == "N/M") { sMARKS = ""; } var iPKGS2 = 0; var dKGS2 = 0; var dCBM2 = 0; for (var i = 0; i < this.storeBodyList.getCount(); i += 1) { iPKGS2 += this.storeBodyList.getAt(i).get("PKGS"); dKGS2 = Add(dKGS2, this.storeBodyList.getAt(i).get("KGS"), 4); dCBM2 = Add(dCBM2, this.storeBodyList.getAt(i).get("CBM"), 4); } var selections = this.gridListMain.getSelectionModel().getSelection(); if (selections.length > 0) { var sCTN_ID = selections[0].data.CTN_ID; var iPKGS = selections[0].data.PKGS; var sKINDPKGS = selections[0].data.KINDPKGS; var dKGS = selections[0].data.KGS; var dCBM = selections[0].data.CBM; iPKGS = iPKGS - iPKGS2; dKGS = Add(dKGS, -dKGS2, 4); dCBM = Add(dCBM, -dCBM2, 4); var record = Ext.create('MsOpCtnDetail', { GID: '*', CTN_ID: sCTN_ID, PKGS: iPKGS, KINDPKGS: sKINDPKGS, KGS: dKGS, CBM: dCBM, HSCODE: '', DESCRIPTION: descrip, MARKS: sMARKS }); this.storeBodyList.add(record); var n = this.storeBodyList.getCount(); this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 2 }); } else { Ext.Msg.show({ title: '警告', msg: '请先选择集装箱!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); } }, onImportCtnDetailClick: function (button, event) { var selections = this.gridListMain.getSelectionModel().getSelection(); if (selections.length > 0) { var sCTN_ID = selections[0].data.CTN_ID; } else { Ext.Msg.show({ title: '警告', msg: '请先选择集装箱!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); } var condition = " CTN_ID='" + sCTN_ID + "'"; me = this; var imgform = new Ext.FormPanel({ region: 'center', labelWidth: 20, frame: true, autoScroll: false, border: false, fileUpload: true, items: [{ xtype: 'fileuploadfield', id: 'LoadExcel', name: 'LoadExcel', emptyText: '请选择EXCEL文件', fieldLabel: 'EXCEL', buttonText: '选择文件', allowBlank: false, width: 200, buttonCfg: { iconCls: 'uploaddialog' }, anchor: '98%' }], buttons: [{ text: '上传', type: 'submit', handler: function () { var UserFilePath = Ext.getCmp('LoadExcel').getValue(); if (!CheckFileExt(UserFilePath, /.xls|.xlsx/i)) { Ext.Msg.show({ title: '错误', msg: '请确认你上传的文件为EXCEL文件!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; } if (!imgform.form.isValid()) { return; } imgform.form.submit({ url: '/MvcShipping/MsOpSeae/ImportCtnDetail', waitMsg: '正在上传', method: 'POST', params: { CTN_ID: sCTN_ID }, success: function (form, action) { win.close(this); Ext.Msg.show({ title: '提示', msg: '上传成功!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); me.storeBodyList.load({ params: { condition: condition} }); }, failure: function (form, action) { form.reset(); if (action.failureType == Ext.form.Action.SERVER_INVALID) Ext.MessageBox.alert('警告', action.result.errors.msg); } }); } }, { text: '关闭', type: 'submit', handler: function () { win.close(this); } }] }); var win = new Ext.Window({ title: "上传EXCEL", width: 380, height: 120, modal: true, resizable: false, border: false, items: imgform }); win.show(); return; }, //#endregion //#region 删除明细 onDelDetailClick: function (button, event) { var selections = this.gridListMain.getSelectionModel().getSelection(); var sCTN_ID = selections[0].data.CTN_ID; var selectedRecords = this.gridList.selModel.getSelection(); for (var i = 0; i < selectedRecords.length; i++) { var rec = selectedRecords[i]; if (rec.data.GID == "" || rec.data.GID == "*")//如果是新增但没有保存的数据,没有必要提交到后台 { this.storeBodyList.remove(selectedRecords[i]); } else { Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) { if (btn == 'yes') { Ext.Msg.wait('正在删除数据...'); Ext.Ajax.request({ waitMsg: '正在删除数据...', url: '/MvcShipping/MsOpSeae/DeleteOpCtnDetail', params: { data: Ext.JSON.encode(rec.data) }, callback: function (options, success, response) { if (success) { var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { //this.storeBodyList.remove(rec); this.storeBodyList.load({ params: { condition: "CTN_ID='" + sCTN_ID + "'" }, scope: this }); Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); } 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 }); }, scope: this }); } }, this); } } }, //#endregion //#region 打印 Print: function () { var billNo = this.editRecord.data.BSNO.toString(); var selectedRecords = this.gridListMain.getSelectionModel().getSelection(); var feeGidSql = ''; for (var i = 0; i < selectedRecords.length; i++) { var record = selectedRecords[i]; var feeGId = "'" + record.get('CTN_ID') + "'"; if (feeGidSql == '') { feeGidSql = feeGId; } else { feeGidSql = feeGidSql + "," + feeGId; } }; if (feeGidSql == '') feeGidSql = 'aaaaa' var printType = 'MSOPSEAECTNDETAIL'; var sql1 = "SET LANGUAGE 'us_english' SELECT d.CTN_ID,d.PKGS,d.KINDPKGS,d.KGS,d.CBM,d.HSCODE,d.DESCRIPTION,d.MARKS,c.CNTRNO,c.SEALNO,b.MBLNO,c.BSNO FROM op_ctn_detail d left join op_ctn c on (c.CTN_ID=d.CTN_ID) left join op_seae b on (b.BSNO=c.BSNO) WHERE c.BSNO = '" + billNo + "' order by d.CTN_ID,d.ID "; var sql2 = "SET LANGUAGE 'us_english' SELECT d.CTN_ID,d.PKGS,d.KINDPKGS,d.KGS,d.CBM,d.HSCODE,d.DESCRIPTION,d.MARKS,c.CNTRNO,c.SEALNO,b.MBLNO,c.BSNO FROM op_ctn_detail d left join op_ctn c on (c.CTN_ID=d.CTN_ID) left join op_seae b on (b.BSNO=c.BSNO) WHERE c.BSNO = '" + billNo + "' AND c.CTN_ID IN (" + feeGidSql + ") order by d.CTN_ID,d.ID "; var sql3 = ""; var sql4 = ""; var sql5 = ""; var sql6 = ""; PrintComm(printType, sql1, sql2, sql3, sql4, sql5, sql6, ''); }, //#endregion //#region 判断一行字符数是否超标 SetShipperLable: function (fieldname, len) { var basicForm = this.formEdit.getForm(); var field = basicForm.findField(fieldname); var SHIPPERSTR = Ext.getCmp(fieldname + 'STR'); var str = Billstrnum(field.getValue(), len); SHIPPERSTR.setText(str, false); } //#endregion });