Ext.namespace('DsTruck'); DsTruck.ClientCompanyIndex = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.DsTruck.ClientCompanyIndex.superclass.constructor.call(this); }; //201405161239 Ext.extend(DsTruck.ClientCompanyIndex, Ext.Panel, { PageSize: 500, OprationStatus: null, //仅当弹出界面时使用 SelectedRecord: null, initUIComponents: function () { this.bodyDel = []; //定义数据集 this.storeList = Ext.create('Ext.data.Store', { pageSize: this.PageSize, idProperty: 'GID', model: 'ClientCompanymb', remoteSort: true, proxy: { type: 'ajax', url: '/OA/ClientCompany/GetDataList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); this.storeCompany = Ext.create('DsExt.ux.RefTableStore', { model: 'companymb', proxy: { url: '/CommMng/BasicDataRef/GetcompanyList' } }); this.storeCompany.load({ params: { condition: ""} }); this.comboxCompany = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '用证公司', forceSelection: true, store: this.storeCompany, name: 'company', valueField: 'gid', displayField: 'name' }); this.cellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); this.ProjectCBModel = Ext.create('Ext.selection.CheckboxModel', { checkOnly: true }); Ext.grid.RowNumberer = Ext.extend(Ext.grid.RowNumberer, { width: 50 }); //定义Grid this.gridList = new Ext.grid.GridPanel({ store: this.storeList, enableHdMenu: false, region: 'center', trackResetOnLoad: true, //height: 160, title: '费用明细', loadMask: { msg: "数据加载中,请稍等..." }, trackMouseOver: true, disableSelection: false, plugins: [this.cellEditing], stateful: false, selModel: this.ProjectCBModel, selType: 'cellmodel', columns: [new Ext.grid.RowNumberer(), { sortable: true, hidden:true, dataIndex: 'CustomerGID', header: 'CustomerGID', width: 80 }, { sortable: true, //hidden:true, dataIndex: 'CustomerName', header: '往来单位名称', width: 150 }, { sortable: true, dataIndex: 'CompanyID', header: '分公司', width: 150 , renderer: function(value, p, record) { if (value == null || value == '') return ''; else return record.data.CompanyName; }, editor: this.comboxCompany, }, { sortable: true, dataIndex: 'RelationShipName', header: '关系名', width: 80 , editor: { xtype: 'textfield' } }, { sortable: true, dataIndex: 'FieldName', header: '字段名', width: 110 , editor: { xtype: 'textfield' } }, { sortable: true, dataIndex: 'Value', header: '关系值', width: 160 , editor: { xtype: 'textfield' } }, { sortable: true, dataIndex: 'Value1', header: '关系值1', width: 80 , editor: { xtype: 'textfield' } }, { sortable: true, dataIndex: 'Value2', header: '关系值2', width: 80 , editor: { xtype: 'textfield' } }, { sortable: true, dataIndex: 'NumValue', header: '关系值(数字)', width: 80 , editor: { xtype: 'numberfield' } }, { sortable: true,hidden:true, dataIndex: 'INSERTED', header: 'INSERTED', width: 80 }, { sortable: true, hidden:true, dataIndex: 'CompanyName', header: 'CompanyName', width: 80 } ], bbar: Ext.create('Ext.PagingToolbar', { store: this.storeList, displayInfo: true, displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录', emptyMsg: "没有数据" }) }); //#region formSearch this.formSearch = Ext.widget('form', { frame: true, region: 'center', bodyPadding: 5, 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: '往来单位代码', name: 'CODE', flex: 1 }, { fieldLabel: '往来单位名称', name: 'NAME', flex: 1 },{ fieldLabel: '分公司名称', name: 'company', flex: 1 },{ xtype: 'hiddenfield', flex: 2 } ] } ]//end items(fieldset 1) }, //end fieldset 1 {//fieldset 2 xtype: 'container', defaultType: 'textfield', layout: 'anchor', defaults: { anchor: '100%' }, items: [{ xtype: 'container', layout: 'hbox', defaultType: 'textfield', items: [] } ]//end items(fieldset 2) }//end fieldset 2 , {//fieldset 2 xtype: 'container', defaultType: 'textfield', layout: 'anchor', defaults: { anchor: '100%' }, items: [{ xtype: 'container', layout: 'hbox', defaultType: 'textfield', items: [] }]//end items(fieldset 2) }//end fieldset 2 ]//end root items }); //查询工具条 this.panelBtn = new Ext.Panel({ region: "north", tbar: [ { text: "执行查询", iconCls: "btnrefresh", handler: function (button, event) { this.onRefreshClick(button, event); }, scope: this }, { text: "导出Excel", id: "btnExportExcel", iconCls: 'btnexportexcel', handler: function (button, event) { this.onExportClick(button, event); }, scope: this },'-',{ id: "btnSave", text: '保存更改', tooltip: '保存更改', iconCls: "btnsave", handler: function (button, event) { this.Save(); //alert(USERID); }, scope: this }, '-' ] }); //#endregion this.panelTop = new Ext.Panel({ layout: "border", region: "north", height:75, items: [this.formSearch, this.panelBtn] }); Ext.apply(this, { items: [this.panelTop, this.gridList] }); this.storeList.on('beforeload', function (store) { if (!this.checkSearchCondition()) return; var sql = this.getCondition(); Ext.apply(store.proxy.extraParams, { condition: sql }); }, this); this.cellEditing.on('beforeedit', function (editor, e) { return this.CBBeforeEdit(editor, e); }, this); this.gridList.on('edit', function (editor, e, eOpts) { this.ProjectAfterEdit(editor, e, eOpts); }, this); }, //end initUIComponents ProjectAfterEdit: function(editor, e, eOpts) { if (e.field == 'CompanyID') { var records = DsStoreQueryBy(this.storeCompany, 'gid', e.value); if (records.getCount() > 0) { var data = records.getAt(0).data; e.record.set('CompanyName', data.name); } else { e.record.set('CompanyName', ''); } } }, CBBeforeEdit: function (editor, e) { var canedit=true; if (e.field == 'CompanyID'){ //alert(e.isDirty()); if (e.record.get('INSERTED')=="1"){ alert("不能修改已存在数据的分公司或"); canedit=false; } } return canedit; }, onRefreshClick: function (button, event) { if (!this.checkSearchCondition()) return; var sql = this.getCondition(); this.storeList.load({ params: { start: 0, limit: this.PageSize, condition: sql }, waitMsg: "正在查询数据...", scope: this }); this.bodyDel = []; }, getCondition: function () { var form = this.formSearch.getForm(); if (!form.isValid()) { Ext.Msg.alert('提示', '查询条件赋值错误,请检查。'); return ''; } var sql = ''; var CODE = form.findField('CODE').getValue(); sql = sql + getAndConSql(sql, CODE, " tt.CODENAME like '%" + CODE + "%'"); var NAME = form.findField('NAME').getValue(); sql = sql + getAndConSql(sql, NAME, " tt.customername like '%" + NAME + "%'"); var company = form.findField('company').getValue(); sql = sql + getAndConSql(sql, company, " tt.companyname like '%" + company + "%'"); return sql; }, checkSearchCondition: function () { /*var form = this.formSearch.getForm(); if (!form.isValid()) { Ext.Msg.alert('提示', '查询条件赋值错误,请检查。'); return false; }*/ return true; }, onExportClick: function (button, event) { GridExportExcelPage(this.gridList); }, getStrValue: function (list) { var _list = []; for (var _i = 0; _i < list.length; _i++) { _list.push("'" + list[_i] + "'"); } return _list; }, Save: function (type) { //费用 var bodyList = []; for (i = 0; i < this.storeList.getCount(); i += 1) { var member = this.storeList.getAt(i); //alert(member.data.Value); if (member.data.Value==''){ alert("关系值不允许为空"); return; } if (member.data.CompanyID==''){ alert("分公司不允许为空"); return; } bodyList.push(member); /* var BLNO = member.data.BLNO; var PROJECTNO = member.data.PROJECTNO; if (BLNO == ''||PROJECTNO == '') { Ext.Msg.show({ title: '警告', msg: '项目单号和项目编码均不允许为空,请修改后再保存', icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); return; }*/ }; var jsonBody = ConvertRecordsToJson(bodyList); var jsonDelBody = ConvertRecordsToJsonAll(this.bodyDel); if (jsonBody == '' && jsonDelBody == ''){ return; } Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/OA/ClientCompany/Save', scope: this, params: { CCBody: jsonBody, CCDelBody:jsonDelBody }, callback: function (options, success, response) { if (success) { Ext.MessageBox.hide(); var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { //alert("保存成功"); var returnData = jsonresult.Data; this.storeList.commitChanges(); } 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 }); } //alert('03'); } }); }, });