Ext.namespace('Shipping'); Shipping.MsCodeServiceFeeTemplateEdit = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.Shipping.MsCodeServiceFeeTemplateEdit.superclass.constructor.call(this); }; Ext.extend(Shipping.MsCodeServiceFeeTemplateEdit, Ext.Panel, { ParentWin: null, OpStatus: 'add', StoreList: null, EditRecord: null, initUIComponents: function () { this.serialNo = 0; this.workSerialNo = 0; this.bodyDel = []; //#region 编辑form //枚举参照相关(编辑form) //表参照相关(编辑form) this.storeOpType = Ext.create('DsExt.ux.RefEnumStore', {}); this.storeOpType.load({ params: { enumTypeId: 96005} }); this.comboxOpType = Ext.create('DsExt.ux.RefEnumCombox', { fieldLabel: '业务类型', store: this.storeOpType, name: 'OPTYPE', listeners: { scope: this, 'select': function (combo, records, eOpts) { if (records.length > 0) { var recs = DsStoreQueryBy(this.storeOpType, 'EnumValueId', records[0].data.EnumValueId); if (recs.getCount() > 0) { var data = recs.getAt(0).data; var s = " OPTYPE='" + data.EnumValueId + "'"; this.storecodeservice.load({ params: { condition: s } }); } else { var OPField = this.formEdit.getForm().findField('OPField'); OPField.setValue(''); } if (records[0].data.EnumValueName == '报关业务') { this.StoreCustType.removeAll(); this.StoreCustType.add({ "SCUSTTYPE": "WTDW-委托单位", "CUSTTYPE": "委托单位", "CUSTNAME": "CUSTOMERNAME" }); this.StoreCustType.add({ "SCUSTTYPE": "BGH-报关行", "CUSTTYPE": "报关行", "CUSTNAME": "CUSTOMSER" }); } if (records[0].data.EnumValueName == '综合业务') { this.StoreCustType.removeAll(); this.StoreCustType.add({ "SCUSTTYPE": "WTDW-委托单位", "CUSTTYPE": "委托单位", "CUSTNAME": "CUSTOMERNAME" }); } } } } }); this.storeCustCode = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CustomRefModel', proxy: { url: '/CommMng/BasicDataRef/GetCustomRefList' } }); this.storeCustCode.load({ params: { condition: "ISCONTROLLER='1'"} }); this.comboxCustCode = Ext.create('DsExt.ux.RefTableCombox', { fieldLabel: '客户名称', store: this.storeCustCode, forceSelection: true, name: 'CUSTOMERNAME', valueField: 'CustName', displayField: 'CodeAndName' }); //编辑form this.formEdit = Ext.widget('form', { region: 'center', frame: true, bodyPadding: 5, autoScroll: true, fieldDefaults: { margins: '2 2 2 2', labelAlign: 'right', flex: 1, labelWidth: 90, msgTarget: 'qtip' }, items: [ {//fieldset 1 xtype: 'fieldset', defaultType: 'textfield', layout: 'anchor', defaults: { anchor: '100%' }, items: [{ xtype: 'container', layout: 'hbox', defaultType: 'textfield', items: [{ fieldLabel: 'GID', name: 'GID', flex: 0, hidden: true, margins: '0' }, this.comboxCustCode, this.comboxOpType, { fieldLabel: '模板名称', name: 'NAME' } ] }, { xtype: 'container', layout: 'hbox', defaultType: 'textfield', items: [{ fieldLabel: '模板说明', name: 'DESCRIPTION' }] } ]//end items(fieldset 1) }//end fieldset 1 ]//end root items }); //end this.formEdit //#endregion //#region 按钮Toolbar this.panelBtn = new Ext.Panel({ region: "north", tbar: [ { text: "保存", iconCls: "btnsave", handler: function (button, event) { this.Save('0'); }, scope: this }, { text: "保存并关闭", handler: function (button, event) { this.Save('1'); }, scope: this }, '-', { text: "保存并新建", handler: function (button, event) { this.Save('2'); }, scope: this } ] }); //end 按钮Toolbar //#endregion //#region 明细表 //明细表表格相关 //明细表-数据集 this.storeBodyList = Ext.create('Ext.data.Store', { model: 'MsCodeServiceFeeTemplateDetail', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsCodeServiceFeeTemplate/GetBodyList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); //明细表表格 this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); this.StoreCurr = Ext.create('DsExt.ux.RefTableStore', { model: 'MsFeeCurr', proxy: { url: '/MvcShipping/MsChFee/GetFeeCurrList' } }); this.StoreCurr.load({ params: { condition: ""} }); this.comboxCurr = Ext.create('DsExt.ux.RefTableCombox', { store: this.StoreCurr, forceSelection: true, name: 'Currency', valueField: 'CURR', displayField: 'CURR' }); this.storeFeeNameRef = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.FeeTypeRefModel', proxy: { url: '/MvcShipping/MsChFee/GetFeeTypeRefList' } }); this.storeFeeNameRef.load({ params: { condition: ""} }); this.comboxFeeNameRef = Ext.create('DsExt.ux.RefTableCombox', { store: this.storeFeeNameRef, forceSelection: true, name: 'FeeName', valueField: 'Name', displayField: 'CodeAndName' }); this.storeCustomerNameRef = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CustomRefModel', proxy: { url: '/CommMng/BasicDataRef/GetCustomRefList' } }); this.storeCustomerNameRef.load({ params: { condition: ""} }); this.comboxCustomerNameRef = Ext.create('DsExt.ux.RefTableCombox', { store: this.storeCustomerNameRef, forceSelection: true, name: 'CustomerName', valueField: 'CustName', displayField: 'CodeAndName' }); this.StoreCustType = Ext.create('Ext.data.Store', { fields: ['SCUSTTYPE', 'CUSTTYPE', 'CUSTNAME'] }); this.comboxCustType = Ext.create('DsExt.ux.RefTableCombox', { store: this.StoreCustType, forceSelection: true, name: 'CustomerType', valueField: 'CUSTTYPE', displayField: 'SCUSTTYPE' }); this.StoreUnit = Ext.create('Ext.data.Store', { fields: ['UNIT'] }); this.StoreUnit.add({ "UNIT": "单票" }); this.StoreUnit.add({ "UNIT": "件数" }); this.StoreUnit.add({ "UNIT": "尺码" }); this.StoreUnit.add({ "UNIT": "20GP" }); this.StoreUnit.add({ "UNIT": "40GP" }); this.StoreUnit.add({ "UNIT": "20RF" }); this.StoreUnit.add({ "UNIT": "40RF" }); this.StoreUnit.add({ "UNIT": "bill" }); this.comboxUnit = Ext.create('DsExt.ux.RefTableCombox', { store: this.StoreUnit, name: 'Unit', valueField: 'UNIT', displayField: 'UNIT' }); this.storecodeservice = Ext.create('DsExt.ux.RefTableStore', { model: 'MsCodeOpService', proxy: { url: '/MvcShipping/MsCodeOpService/GetDataList' } }); this.comboxCodeService = Ext.create('DsExt.ux.RefTableCombox', { store: this.storecodeservice, forceSelection: true, name: 'OPField', valueField: 'OPField', displayField: 'SERVICENAME' }); this.storeAddDCType = Ext.create('Ext.data.Store', { fields: ['DC', 'NAME'] }); this.storeAddDCType.add({ "DC": "1", "NAME": "应收" }); this.storeAddDCType.add({ "DC": "2", "NAME": "应付" }); this.comboxaddDCType = Ext.create('DsExt.ux.RefTableCombox', { store: this.storeAddDCType, valueField: 'DC', displayField: 'NAME', forceSelection: true, name: 'DC', enableKeyEvents: true }); this.gridList = new Ext.grid.GridPanel({ store: this.storeBodyList, enableHdMenu: false, region: 'center', loadMask: { msg: "数据加载中,请稍等..." }, trackMouseOver: true, disableSelection: false, plugins: [this.gridListCellEditing], selType: 'cellmodel', tbar: [{ text: '增加明细', tooltip: '增加明细', iconCls: "btnadddetail", handler: function (button, event) { this.onAddDetailClick(button, event, 1); }, scope: this }, '-', { text: '删除明细', tooltip: '删除明细', iconCls: "btndeletedetail", handler: function (button, event) { this.onDelDetailClick(button, event, 1); }, scope: this }], columns: [{ sortable: true, dataIndex: 'GID', header: 'GID', hidden: true, width: 100 }, { sortable: true, dataIndex: 'TemplateID', header: 'TemplateID', hidden: true, width: 100 }, { sortable: true, dataIndex: 'CustomerType', header: '客户类别', editor: this.comboxCustType, width: 160 }, { sortable: true, dataIndex: 'CustomerName', header: '客户名称', editor: this.comboxCustomerNameRef, width: 160 }, { sortable: true, dataIndex: 'OPField', header: '服务项目', renderer: function (value, p, record) { if (value == null || value == '') return ''; else return record.data.SERVICENAME; }, editor: this.comboxCodeService, width: 160 }, { sortable: true, dataIndex: 'FeeName', header: '费用名称', editor: this.comboxFeeNameRef, width: 160 }, { sortable: true, dataIndex: 'FeeType', header: '收/付', editor: this.comboxaddDCType, width: 160, renderer: function (value, p, record) { if (value == 2) return '付'; else return '收'; } }, { sortable: true, dataIndex: 'Unit', header: '单位标准', editor: this.comboxUnit, width: 60 }, { sortable: true, dataIndex: 'UnitPrice', header: '单价', editor: { xtype: 'numberfield', selectOnFocus: true }, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { try { var lsValue = usMoney(value, 2, '', false); if (lsValue != "NaN") { value = lsValue; if (parseFloat(lsValue) < 0) { return '' + lsValue + ''; } } else { return value; } } catch (e) { return value; } return value; }, width: 80 }, { sortable: true, dataIndex: 'TAXRATE', header: '税率', editor: { xtype: 'numberfield', selectOnFocus: true }, width: 80 }, { sortable: true, dataIndex: 'Currency', header: '币别', editor: this.comboxCurr, width: 40 }, { sortable: true, dataIndex: 'ExchangeRate', header: '汇率', editor: { xtype: 'numberfield', selectOnFocus: true }, width: 60 }, { sortable: true, dataIndex: 'Remark', header: '备注', editor: { xtype: 'textfield', selectOnFocus: true }, width: 150 } ] }); this.panelService = new Ext.Panel({ title: '费用方案明细', layout: "border", region: 'center', margin: '5 10', items: [this.gridList] }); //#endregion 明细表 //#region 布局 //控件布局 this.panelTop = new Ext.Panel({ layout: "border", region: "north", height: 120, items: [this.panelBtn, this.formEdit] }); Ext.apply(this, { items: [this.panelTop, this.panelService] }); //#endregion //绑定查询窗体 this.ParentWin = window.parent.opener; //初始化数据 this.InitData(); //绑定事件 this.gridList.on('edit', function (editor, e, eOpts) { this.gridAfterEdit(editor, e, eOpts); }, this); }, //end initUIComponents InitData: function () { this.opStatus = 'add'; var condition = ''; if (this.ParentWin) { var ret = this.ParentWin.OprationSwap(); this.opStatus = ret[0]; this.StoreList = ret[1]; this.editRecord = ret[2]; } if (this.opStatus == 'edit') { condition = " GID='" + this.editRecord.get('GID') + "'"; var s = " OPTYPE='" + this.editRecord.get('OPTYPE') + "'"; this.storecodeservice.load({ params: { condition: s} }); } this.LoadData(this.opStatus, condition); }, //end InitData LoadData: function (opstatus, condition) { this.serialNo = 0; this.workSerialNo = 0; this.bodyDel = []; this.opStatus = opstatus; Ext.Ajax.request({ waitMsg: '正在查询主表数据...', url: '/MvcShipping/MsCodeServiceFeeTemplate/GetData', params: { handle: opstatus, condition: condition }, callback: function (options, success, response) { if (success) { var result = Ext.JSON.decode(response.responseText); if (!result.Success) { Ext.Msg.show({ title: '提示', msg: result.Message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK }); return; } var data = result.data; this.formEdit.getForm().reset(); this.formEdit.getForm().setValues(data); if (data.OPTYPE == '5') { this.StoreCustType.removeAll(); this.StoreCustType.add({ "SCUSTTYPE": "WTDW-委托单位", "CUSTTYPE": "委托单位", "CUSTNAME": "CUSTOMERNAME" }); this.StoreCustType.add({ "SCUSTTYPE": "BGH-报关行", "CUSTTYPE": "报关行", "CUSTNAME": "CUSTOMSER" }); } else if (data.OPTYPE == '7') { this.StoreCustType.removeAll(); this.StoreCustType.add({ "SCUSTTYPE": "WTDW-委托单位", "CUSTTYPE": "委托单位", "CUSTNAME": "CUSTOMERNAME" }); } } else { Ext.MessageBox.alert('请求出现错误,请重试', response.responseText); } }, scope: this }); var billno = '*'; var cargoid = 0; if (this.opStatus == 'edit') { cargoid = this.editRecord.get('GID'); } this.storeBodyList.load({ params: { condition: " TemplateID='" + cargoid + "'"} }); }, // end LoadDate Save: function (type) { var basicForm = this.formEdit.getForm(); if (!basicForm.isValid()) { return; } //判断表格数据是否合法 if (!validateEditorGridPanel(this.gridList)) { return; } basicForm.findField('GID').setDisabled(false); var data = basicForm.getValues(); basicForm.findField('GID').setDisabled(true); if (this.opStatus == 'add') { if (data.GID == '*') { data.GID = NewGuid(); } } var bodydatas = []; for (var i = 0; i < this.storeBodyList.getCount(); i += 1) { var member = this.storeBodyList.getAt(i); bodydatas.push(member); } var jsonBody = ConvertRecordsToJsonAll(bodydatas); Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsCodeServiceFeeTemplate/Save', scope: this, params: { opstatus: this.opStatus, data: Ext.JSON.encode(data), body: jsonBody }, 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.formEdit.getForm().setValues(returnData); if (this.opStatus == 'add') { var arrNewRecords = this.StoreList.add(returnData); this.editRecord = arrNewRecords[0]; } else if (this.opStatus == 'edit') { this.editRecord.commit(); } if (type == '0') { this.opStatus = 'edit'; basicForm.findField('GID').setDisabled(true); for (var j = 0; j < this.storeBodyList.getCount(); j += 1) { var memberbody = this.storeBodyList.getAt(j); memberbody.set("TemplateID", this.editRecord.get('GID')); memberbody.commit(); }; } else if (type == '1') { window.close(); } else { this.LoadData('add', ''); basicForm.findField('GID').setDisabled(false); } } 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 onAddDetailClick: function (button, event, type) { this.addDetail(type); }, //end onAddDetailClick onDelDetailClick: function (button, event, type) { this.deleteDetail(type); }, //onDelDetailClick gridAfterEdit: function (editor, e, eOpts) { //需要自己实现里面的事件 }, addDetail: function (type) { var basicForm = this.formEdit.getForm(); var custname = basicForm.findField('CUSTOMERNAME').getValue(); var newSerialno = 0; store = this.storeBodyList; newSerialno = DsGetNewSerialNo(store, this.serialNo); this.serialNo = newSerialno; var record = Ext.create('MsCodeServiceFeeTemplateDetail', { GID: NewGuid(), TemplateID: '*', OPField: '', FeeName: "", CustomerType: '', CustomerName: custname, UnitPrice: 0, TAXRATE: 0, Unit: '', Currency: '', FeeType: 1, ExchangeRate: 1, Remark: "" }); store.add(record); var n = store.getCount(); this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 1 }); }, gridAfterEdit: function (editor, e, eOpts) { if (e.field == 'OPField') { var czstaterecords = DsStoreQueryBy(this.storecodeservice, 'OPField', e.value); if (czstaterecords.getCount() > 0) { var czstatedata = czstaterecords.getAt(0).data; e.record.set('SERVICENAME', czstatedata.SERVICENAME); } else { e.record.set('SERVICENAME', ''); } } }, deleteDetail: function (type) { var selectedRecords = this.gridList.selModel.getSelection(); for (var i = 0; i < selectedRecords.length; i++) { var rec = selectedRecords[i]; this.storeBodyList.remove(rec); } } });