Ext.namespace('Shipping'); Shipping.MsCodeGoodsEdit = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.Shipping.MsCodeGoodsEdit.superclass.constructor.call(this); }; Ext.extend(Shipping.MsCodeGoodsEdit, Ext.Panel, { ParentWin: null, OpStatus: 'add', StoreList: null, EditRecord: null, initUIComponents: function () { //#region 编辑form //编辑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', allowBlank: false, hidden: true }, { fieldLabel: '姓名', name: 'NAME', allowBlank: false, flex: 1 }, { fieldLabel: '简写编码', flex: 1, name: 'CODE' }, { fieldLabel: '手机号', flex: 1, name: 'PHONE' }] }, { xtype: 'container', layout: 'hbox', defaultType: 'textfield', items: [{ fieldLabel: '装卸费(每件)', name: 'PriceJian', flex: 1 },{ fieldLabel: '装卸费(每吨)', name: 'PriceLiangTon', flex: 1 },{ fieldLabel: '备注', name: 'OTHER', flex: 1 }] } ]//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) { window.close(); }, scope: this } ] }); //end 按钮Toolbar //#endregion //#region 布局 //控件布局 this.panelTop = new Ext.Panel({ layout: "border", region: "north", height: 180, items: [this.panelBtn, this.formEdit] }); Ext.apply(this, { items: [this.panelTop] }); //#endregion //绑定查询窗体 //初始化数据 this.ParentWin = window.parent.opener; this.InitData(); }, //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') + "'"; this.LoadData(this.opStatus, condition); }, //end InitData LoadData: function (opstatus, condition) { this.serialNo = 0; this.workSerialNo = 0; this.opStatus = opstatus; Ext.Ajax.request({ waitMsg: '正在查询主表数据...', url: '/MvcShipping/MsStevedores/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); } else { Ext.MessageBox.alert('请求出现错误,请重试', response.responseText); } }, scope: this }); }, // end LoadDate Save: function (type) { var basicForm = this.formEdit.getForm(); if (!basicForm.isValid()) { return; } var data = basicForm.getValues(); Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsStevedores/Save', scope: this, params: { opstatus: this.opStatus, data: Ext.JSON.encode(data) }, callback: function (options, success, response) { if (success) { Ext.MessageBox.hide(); var jsonresult = Ext.JSON.decode(response.responseText); var returnData = jsonresult.Data; if (jsonresult.Success) { Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.OK, buttons: Ext.Msg.OK }); if (this.opStatus == 'add') { var arrNewRecords = this.StoreList.add(returnData); this.editRecord = arrNewRecords[0]; } else if (this.opStatus == 'edit') { var mod = Ext.create('MsStevedoresModel', returnData); this.editRecord.fields.each(function (field) { if (field.persist) { name = field.name; if (name != 'GID') { this.editRecord.set(name, mod.get(name)); } } }, this); this.editRecord.commit(); //this.onRefreshClick(button, event); } if (type == '1') {//保存并关闭 window.close(); } } 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) { } });