Ext.namespace('Shipping'); String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); } Shipping.MsCrmKeyCodeSetIndex = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.Shipping.MsCrmKeyCodeSetIndex.superclass.constructor.call(this); }; Ext.extend(Shipping.MsCrmKeyCodeSetIndex, Ext.Panel, { OprationStatus: null, //仅当弹出界面时使用 SelectedRecord: null, strACCDATE: null, initUIComponents: function () { this.formname = "formMsCrmKeyCodeSetIndex"; //页面名称 //#region formSearch 下拉框信息加载 this.StoreCrmKeyCodeSet = Ext.create('DsExt.ux.RefTableStore', { model: 'MsCrmKeyCodeSetModel', proxy: { url: '/MvcShipping/MsCrmKeyCodeSet/GetCrmKeyCodeSet' } }); this.StoreCrmKeyCodeSet.load({ params: { condition: ""} }); this.comboxCrmKeyCodeSet = Ext.create('DsExt.ux.RefTableCombox', { fieldLabel: '键值类别', store: this.StoreCrmKeyCodeSet, id: 'KEYTYPE', name: 'KEYTYPE', valueField: 'KEYTYPE', displayField: 'KEYTYPE', allowBlank: false, enableKeyEvents: true, //激活键盘事件 listeners: { scope: this, 'select': function (combo, records, eOpts) { this.onRefreshClick(); } } }); //#endregion //#region formSearch 查询面板 this.formSearch = Ext.widget('form', { frame: true, region: 'center', bodyPadding: 5, fieldDefaults: { margins: '2 2 2 2', labelAlign: 'right', flex: 1, labelWidth: 60, msgTarget: 'qtip' }, items: [{//fieldset 1 xtype: 'container', defaultType: 'textfield', items: [this.comboxCrmKeyCodeSet] }]//end items(fieldset 1) }); //#endregion formSearch //#region 定义数据集 this.storeList = Ext.create('Ext.data.Store', { model: 'MsCrmKeyCodeSetModel', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsCrmKeyCodeSet/GetDataList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); //#endregion //#region 定义数据集2 this.storeList2 = Ext.create('Ext.data.Store', { model: 'Sys_EnumerationModel', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsCrmKeyCodeSet/GetDataList2', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); //#endregion //#region 列定义 this.girdcolums = [{ sortable: false, dataIndex: 'ID', text: '唯一编码', hidden: true, width: 0 }, { sortable: false, dataIndex: 'KEYTYPE', text: '键值类别', hidden: true, width: 0 }, { sortable: false, dataIndex: 'KEYVALUE', header: '键值', align: 'center', width: 300, editor: { xtype: 'textfield', selectOnFocus: true } }]; //#endregion //#region gridList列表显示信息 this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 //1单击,2双击 }); this.gridList = new Ext.grid.GridPanel({ title: '一般键值', id:'page_1', region: 'center', store: this.storeList, enableHdMenu: false, //是否显示表格列的菜单 hideHeaders: false, //是否隐藏表头 rowLines: true, columnLines: true, loadMask: { msg: "数据加载中,请稍等..." }, plugins: [this.gridListCellEditing], selType: 'cellmodel', columns: this.girdcolums }); //#endregion //#region 列定义2 this.girdcolums2 = [{ sortable: false, dataIndex: 'GID', text: '唯一编码', hidden: true, width: 0 }, { sortable: false, dataIndex: 'VALUE', text: '键值', width: 100, editor: { xtype: 'textfield', selectOnFocus: true } }, { sortable: false, dataIndex: 'NAME', header: '键值名称', align: 'center', width: 160, editor: { xtype: 'textfield', selectOnFocus: true } }, { sortable: false, dataIndex: 'TYPE', header: '键值类型', align: 'center', width: 160, editor: { xtype: 'textfield', selectOnFocus: true } }]; //#endregion //#region gridList列表显示信息 this.gridListCellEditing2 = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 //1单击,2双击 }); this.gridList2 = new Ext.grid.GridPanel({ title: '报关业务等分类键值', id: 'page_2', region: 'center', store: this.storeList2, enableHdMenu: false, //是否显示表格列的菜单 hideHeaders: false, //是否隐藏表头 rowLines: true, columnLines: true, loadMask: { msg: "数据加载中,请稍等..." }, plugins: [this.gridListCellEditing2], selType: 'cellmodel', columns: this.girdcolums2 }); //#endregion //#region 按钮工具条 this.panelBtn = new Ext.Panel({ region: "north", tbar: [{ text: "查询", tooltip: '查询', iconCls: "btnrefresh", handler: function (button, event) { this.onRefreshClick(); }, scope: this }, '-', { text: '添加', tooltip: '添加', iconCls: "btnadd", handler: function (button, event) { this.onAddClick(button, event); }, scope: this }, { text: "保存", tooltip: '保存', iconCls: "btnsave", handler: function (button, event) { this.Save(); }, scope: this }, { text: '删除', tooltip: '删除', iconCls: "btndelete", handler: function (button, event) { this.onDelClick(button, event); }, scope: this }] }); //#endregion //#region 页面布局 this.panelTop = new Ext.Panel({ layout: "border", region: "north", height: 70, items: [this.panelBtn, this.formSearch] }); _this = this; this.MainTab = new Ext.tab.Panel({ layout: "border", region: "center", items: [this.gridList, this.gridList2], listeners: { tabchange: function (tp, p) { if (_this.checkpage('page_1')) { _this.StoreCrmKeyCodeSet.getProxy().url ='/MvcShipping/MsCrmKeyCodeSet/GetCrmKeyCodeSet' ; _this.StoreCrmKeyCodeSet.load({ params: { condition: "" } }); } if (_this.checkpage('page_2')) { _this.StoreCrmKeyCodeSet.getProxy().url ='/MvcShipping/MsCrmKeyCodeSet/GetEnumerationType' ; _this.StoreCrmKeyCodeSet.load({ params: { condition: "" } }); } } } }); Ext.apply(this, { items: [this.panelTop, this.MainTab] }); //#endregion //加载事件 this.onRefreshClick(); }, //end initUIComponents getActivePage() { return this.MainTab.getActiveTab().id; }, checkpage(page) { if (this.getActivePage() == page) return true; else return false; }, //#region 按钮函数 onRefreshClick: function () { if (!this.formSearch.getForm().isValid()) { return false; } var sKEYTYPE = Ext.getCmp('KEYTYPE').getValue(); if (this.getActivePage() == 'page_1') this.storeList.load({ params: { condition: sKEYTYPE }, waitMsg: "正在查询数据...", scope: this }); if (this.getActivePage() == 'page_2') this.storeList2.load({ params: { condition: "TYPE='" + sKEYTYPE+"'" }, waitMsg: "正在查询数据...", scope: this }); }, Save: function () { if (this.checkpage('page_1')) { var sKEYTYPE = Ext.getCmp('KEYTYPE').getValue(); var bodydatas = []; for (var i = 0; i < this.storeList.getCount(); i += 1) { var member = this.storeList.getAt(i); bodydatas.push(member); } if (bodydatas.length > 0) { var jsonBody = ConvertRecordsToJsonAll(bodydatas); Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsCrmKeyCodeSet/Save', scope: this, params: { body: jsonBody, condition: sKEYTYPE }, 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.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 }); } } }); } } if (this.checkpage('page_2')) { var sKEYTYPE = Ext.getCmp('KEYTYPE').getValue(); var bodydatas = []; for (var i = 0; i < this.storeList2.getCount(); i += 1) { var member = this.storeList2.getAt(i); bodydatas.push(member); } if (bodydatas.length > 0) { var jsonBody = ConvertRecordsToJsonAll(bodydatas); Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsCrmKeyCodeSet/Save2', scope: this, params: { body: jsonBody, condition: sKEYTYPE }, 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.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 }); } } }); } } }, onAddClick: function () { if (this.checkpage('page_1')) { var sKEYTYPE = Ext.getCmp('KEYTYPE').getValue(); var record = Ext.create('MsCrmKeyCodeSetModel', { ID: '*', KEYTYPE: sKEYTYPE, KEYVALUE: '' }); this.storeList.add(record); var n = this.storeList.getCount(); this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 0 }); } if (this.checkpage('page_2')) { var sKEYTYPE = Ext.getCmp('KEYTYPE').getValue(); var record = Ext.create('Sys_EnumerationModel', { GID: '*', TYPE: sKEYTYPE, NAME: '', VALUE:'' }); this.storeList2.add(record); var n = this.storeList2.getCount(); this.gridListCellEditing2.startEditByPosition({ row: n - 1, column: 0 }); } }, onDelClick: function () { if (this.checkpage('page_1')) { var selectedRecords = this.gridList.selModel.getSelection(); if (selectedRecords.length <= 0) { Ext.Msg.show({ title: '警告', msg: '请先选中要操作的数据!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; } var rec = selectedRecords[0]; Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) { if (btn == 'yes') { Ext.Msg.wait('正在删除数据...'); Ext.Ajax.request({ waitMsg: '正在删除数据...', url: '/MvcShipping/MsCrmKeyCodeSet/Delete', 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.onRefreshClick(); //Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); 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 }); }, scope: this }); //end Ext.Ajax.request } }, this); } if (this.checkpage('page_2')) { var selectedRecords = this.gridList2.selModel.getSelection(); if (selectedRecords.length <= 0) { Ext.Msg.show({ title: '警告', msg: '请先选中要操作的数据!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; } var rec = selectedRecords[0]; Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) { if (btn == 'yes') { Ext.Msg.wait('正在删除数据...'); Ext.Ajax.request({ waitMsg: '正在删除数据...', url: '/MvcShipping/MsCrmKeyCodeSet/Delete2', 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.onRefreshClick(); //Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); 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 }); }, scope: this }); //end Ext.Ajax.request } }, this); } } //#endregion });