Ext.namespace('DsTruck'); DsTruck.EnumEdit = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.DsTruck.EnumEdit.superclass.constructor.call(this); }; Ext.extend(DsTruck.EnumEdit, Ext.Panel, { ParentWin: null, OpStatus: 'add', StoreList: null, EditRecord: null, initUIComponents: function () { this.serialNo = 0; this.bodyDel = []; //#region 编辑form //枚举参照相关(编辑form) //表参照相关(编辑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: 'container', defaultType: 'textfield', layout: 'anchor', defaults: { anchor: '100%' }, items: [, { xtype: 'container', layout: 'hbox', defaultType: 'textfield', items: [{ fieldLabel: '语言ID', name: 'LangID', flex: 0, hidden: true, margins: '0' }, { fieldLabel: '版本', name: 'VerNo', flex: 0, hidden: true, margins: '0' }, { fieldLabel: '枚举类型', xtype: 'numberfield', allowBlank: false, name: 'EnumTypeID' }, { fieldLabel: '类型名称', allowBlank: false, name: 'EnumTypeName' }//, {xtype:'hiddenfield',flex:2} ] } ]//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: 'SysEnumValue', remoteSort: false, proxy: { type: 'ajax', url: '/SysMng/Enum/GetBodyList', reader: { id: 'LangID,EnumTypeID,EnumValueID', root: 'data', totalProperty: 'totalCount' } } }); //明细表表格 this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); 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); }, scope: this }, '-', { text: '删除明细', tooltip: '删除明细', iconCls: "btndeletedetail", handler: function (button, event) { this.onDelDetailClick(button, event); }, scope: this }], columns: [{ sortable: true, dataIndex: 'LangID', header: '语言ID', hidden: true, width: 100 }, { sortable: true, dataIndex: 'EnumTypeID', header: '枚举类型', hidden: true, width: 120 }, { sortable: true, dataIndex: 'EnumValueID', header: '成员常量', editor: { xtype: 'textfield', allowBlank: false, selectOnFocus: true }, width: 120 }, { sortable: true, dataIndex: 'EnumValueName', header: '成员名称', editor: { xtype: 'textfield', allowBlank: false, selectOnFocus: true }, width: 160 }, { sortable: true, dataIndex: 'EnumValueName_2', header: '成员名称_2', editor: { xtype: 'textfield', allowBlank: false, selectOnFocus: true }, width: 160 }, { sortable: true, dataIndex: 'IsDefault', header: '缺省', hidden: true, width: 80 }, { sortable: true, dataIndex: 'DispIndex', header: '显示顺序', hidden: true, width: 120 }, { sortable: true, dataIndex: 'VerNo', header: '版本', //hidden: true, editor: { xtype: 'textfield', allowBlank: false, selectOnFocus: true }, width: 80 } ] }); //#endregion 明细表 //#region 布局 //控件布局 this.panelTop = new Ext.Panel({ layout: "border", region: "north", height: 80, items: [this.panelBtn, this.formEdit] }); Ext.apply(this, { items: [this.panelTop, this.gridList] }); //#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 = " LangID=" + this.editRecord.get('LangID') + " and EnumTypeID=" + this.editRecord.get('EnumTypeID'); this.LoadData(this.opStatus, condition); }, //end InitData LoadData: function (opstatus, condition) { this.serialNo = 0; this.bodyDel = []; this.opStatus = opstatus; Ext.Ajax.request({ waitMsg: '正在查询主表数据...', url: '/SysMng/Enum/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 }); var billno = '*'; if (this.opStatus == 'edit') { billno = this.editRecord.get('EnumTypeID'); this.formEdit.getForm().findField('EnumTypeID').setDisabled(true); //this.formEdit.getForm().findField('EnumTypeName').setDisabled(true); } if (billno != '*') { this.storeBodyList.load({ params: { billno: billno} }); } }, // end LoadDate checkedit: function () { var result = true; if (this.storeBodyList.getCount() == 0) { result = true; return; } else { for (var i = 0; i < this.storeBodyList.getCount(); i += 1) { var Enummember = this.storeBodyList.getAt(i).data; if (Enummember.EnumValueID == "") { alert("成员常量不能为空"); result = false; return result; } else if (Enummember.EnumValueName == "") { alert("成员名称不能为空"); result = false; return result; } } //end for } //end if return result; }, Save: function (type) { var basicForm = this.formEdit.getForm(); if (!basicForm.isValid()) { return; } //判断表格数据是否合法 /* if (!validateEditorGridPanel(this.gridList)) { return; }*/ if (!this.checkedit()) { if (type == '0' || type == '1') { window.close(); } if (type == '2'){ this.LoadData('add', ''); basicForm.findField('EnumTypeID').setDisabled(false); } return; } basicForm.findField('EnumTypeID').setDisabled(false); var data = basicForm.getValues(); basicForm.findField('EnumTypeID').setDisabled(true); var bodydatas = []; for (var i = 0; i < this.storeBodyList.getCount(); i += 1) { var member = this.storeBodyList.getAt(i); bodydatas.push(member); } var jsonBody = ConvertRecordsToJson(bodydatas); var jsonDelBody = ConvertRecordsToJsonAll(this.bodyDel); Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/SysMng/Enum/Save', scope: this, params: { opstatus: this.opStatus, data: Ext.JSON.encode(data), body: jsonBody, Delbody: jsonDelBody }, 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') { var editp = Ext.create('SysEnumType', returnData); this.editRecord.fields.each(function (field) { if (field.persist) { name = field.name; if (name != 'id') this.editRecord.set(name, editp.get(name)); } }, this); this.editRecord.commit(); } if (type == '0') { this.opStatus = 'edit'; basicForm.findField('EnumTypeID').setDisabled(true); for (var j = 0; j < this.storeBodyList.getCount(); j += 1) { var memberbody = this.storeBodyList.getAt(j); memberbody.set("EnumTypeID", this.editRecord.get('EnumTypeID')); memberbody.commit(); }; } else if (type == '1') { window.close(); } else { this.LoadData('add', ''); basicForm.findField('EnumTypeID').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) { this.addDetail(); }, //end onAddDetailClick onDelDetailClick: function (button, event) { this.deleteDetail(); }, //onDelDetailClick gridAfterEdit: function (editor, e, eOpts) { //判断成员变量是否重复 _thisID = e.record.get('EnumValueID'); _count = 0; _max = 0; this.storeBodyList.each(function (record) { var _r = record.get('EnumValueID'); if (parseInt(_r) > _max) { _max = parseInt(_r); } if (_r == _thisID) { _count = _count + 1; } }); _max = _max + 1; if (_count > 1) { alert("注意,成员常量不能重复!"); e.record.set('EnumValueID', _max); } }, addDetail: function () { _max = 0; this.storeBodyList.each(function (record) { var _r = record.get('EnumValueID'); if (parseInt(_r) > _max) { _max = parseInt(_r); } }); _max = _max + 1; var record = Ext.create('SysEnumValue', { LangID: 0, EnumTypeID: "", EnumValueID: _max, EnumValueName: "", IsDefault: "0", DispIndex: 0, VerNo: "1.00" }); this.storeBodyList.add(record); var n = this.storeBodyList.getCount(); this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 2 }); }, deleteDetail: function () { var selectedRecords = this.gridList.selModel.getSelection(); for (var i = 0; i < selectedRecords.length; i++) { var rec = selectedRecords[i]; this.storeBodyList.remove(rec); if (rec.get('EnumTypeID') != "") { this.bodyDel.push(rec); } } } });