Ext.namespace('DsTruck'); DsTruck.LTJYDistanceIndex = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.DsTruck.LTJYDistanceIndex.superclass.constructor.call(this); }; //201405161239 Ext.extend(DsTruck.LTJYDistanceIndex, 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: 'LTJYDistancemb', remoteSort: true, proxy: { type: 'ajax', url: '/TruckMng/LTJYDistance/GetDataList', reader: { id: 'id', root: 'data', totalProperty: 'totalCount' } } }); Ext.define('PRICETYPEmd', { extend: 'Ext.data.Model', fields: [ { name: 'PRICETYPE', type: 'string' } ] }); //吨,吨公里,公斤公里,趟 var PRICETYPEData = [//{ "PRICETYPE": "吨公里" }, //{ "PRICETYPE": "公斤公里" }, { "PRICETYPE": "吨" }, { "PRICETYPE": "公斤" }, { "PRICETYPE": "趟"}]; this.storePRICETYPE = Ext.create('Ext.data.Store', { model: 'PRICETYPEmd', data: PRICETYPEData }); this.comboxPRICETYPE = Ext.create('DsExt.ux.RefEnumCombox', { //fieldLabel: '运费类型', forceSelection: true, store: this.storePRICETYPE, name: 'PRICETYPE', valueField: 'PRICETYPE', displayField: 'PRICETYPE' }); //客户加载_委托单位 this.storeCustCode = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CustomRefModel', proxy: { url: '/CommMng/BasicDataRef/GetCustomRefListController' } }); // var astoreCustCode = parentWin.storeCustCode; // if (astoreCustCode == NaN || astoreCustCode == null) { // this.storeCustCode.load({ params: { condition: "ISCONTROLLER='1'"} }); // } else // this.storeCustCode.loadData(astoreCustCode.data.items); //委托单位 this.comboxCustCode = Ext.create('DsExt.ux.RefTableCombox', { fieldLabel: Zi.LAN.CUSTOMERNAME, //'委托单位', store: this.storeCustCode, forceSelection: true, queryMode: 'remote', minChars: 0, queryParam: 'CODENAME', name: 'CUSTOMERNAME', valueField: 'CustName', displayField: 'CodeAndName', allowBlank: false, listeners: { scope: this, 'select': function (combo, records, eOpts) { if (records.length > 0) { var data = combo.value; this.formHead.getForm().findField('SALECORPID').setValue(records[0].data.SALECORPID); var recordCustCode = Ext.create('DsShipping.ux.UserRefModel', { GId: NewGuid(), UserCode: records[0].data.SALE, UserName: records[0].data.SALE, CodeAndName: records[0].data.SALE }); _this.storeOpCode2.add(recordCustCode); this.formHead.getForm().findField('SALE').setValue(records[0].data.SALE); if (records[0].data.BSSOURCE != '') { this.formHead.getForm().findField('BSSOURCE').setValue(records[0].data.BSSOURCE); var recs = DsStoreQueryBy(this.storeSource, 'SourceName', records[0].data.BSSOURCE); if (recs.getCount() > 0) { var data = recs.getAt(0).data; var s = "SOURCEID='" + data.SourceID + "'"; this.storeSourceDetail.load({ params: { condition: s} }); } else { var BSSOURCEDETAIL = this.formHead.getForm().findField('BSSOURCEDETAIL'); BSSOURCEDETAIL.setValue(''); } } var s = " ISOPERATOR=1 and LINKID in (select gid from [info_client] where SHORTNAME='" + combo.value + "')"; this.storeInfoClientContact.load({ params: { condition: s }, callback: function (r, options, success) { if (success) { if (this.storeInfoClientContact.getCount() > 0) { var member = this.storeInfoClientContact.getAt(0); this.comboxInfoClientContact.setValue(member.data.SHOWNAME); // this.formHead.getForm().findField('OPERATOREMAIL').setValue(member.data.EMAIL); this.formHead.getForm().findField('OPERATORTEL').setValue(member.data.TEL); // this.formHead.getForm().findField('OPERATORFAX').setValue(member.data.FAX); } else { this.comboxInfoClientContact.setValue(''); // this.formHead.getForm().findField('OPERATOREMAIL').setValue(''); this.formHead.getForm().findField('OPERATORTEL').setValue(''); // this.formHead.getForm().findField('OPERATORFAX').setValue(''); } } }, scope: this }); var sF = " ISFINANCIALSTAFF=1 and LINKID in (select gid from [info_client] where SHORTNAME='" + combo.value + "')"; this.storeInfoClientContactFF.load({ params: { condition: sF }, callback: function (r, options, success) { if (success) { if (this.storeInfoClientContactFF.getCount() > 0) { var member = this.storeInfoClientContactFF.getAt(0); this.comboxClientFCContact.setValue(member.data.SHOWNAME); // this.formHead.getForm().findField('FINANCIALSTAFFEMAIL').setValue(member.data.EMAIL); // this.formHead.getForm().findField('FINANCIALSTAFFTEL').setValue(member.data.TEL); // this.formHead.getForm().findField('FINANCIALSTAFFFAX').setValue(member.data.FAX); } else { this.comboxClientFCContact.setValue(''); // this.formHead.getForm().findField('FINANCIALSTAFFEMAIL').setValue(''); // this.formHead.getForm().findField('FINANCIALSTAFFTEL').setValue(''); // this.formHead.getForm().findField('FINANCIALSTAFFFAX').setValue(''); } } }, scope: this }); // this.storeShipper.load({ params: { condition: "shippertype=2 AND (ISPUBLIC=1 OR CODENAME IN (SELECT CODENAME FROM info_client WHERE SHORTNAME='" + combo.value + "') )"} }); // this.storeConsignee.load({ params: { condition: "shippertype=1 AND (ISPUBLIC=1 OR CODENAME IN (SELECT CODENAME FROM info_client WHERE SHORTNAME='" + combo.value + "') )"} }); // this.storenotifyparty.load({ params: { condition: "shippertype=3 AND (ISPUBLIC=1 OR CODENAME IN (SELECT CODENAME FROM info_client WHERE SHORTNAME='" + combo.value + "') )"} }); // this.storeagent.load({ params: { condition: "shippertype=4 AND (ISPUBLIC=1 OR CODENAME IN (SELECT CODENAME FROM info_client WHERE SHORTNAME='" + combo.value + "') )"} }); } } } }); this.formname = "LTJYDistance"; this.column = [{ sortable: true, dataIndex: '', header: '', width: 120 }, { dataIndex: 'id', header: 'id', width: 80, hidden: true }, { dataIndex: 'NAME', header: '目的地', width: 100, editor: { xtype: 'textfield', selectOnFocus: true } },{ sortable: true, dataIndex: 'CUSTOMERNAME', header: '客户', width: 100, renderer: function (value, p, record) { if (value == null || value == '') return ''; else return record.data.CUSTOMERNAME; }, editor: this.comboxCustCode }, { dataIndex: 'PRICETYPE', header: '重量单位', width: 100, renderer: function (value, p, record) { if (value == null || value == '') return ''; else return record.data.PRICETYPE; }, editor: this.comboxPRICETYPE }, { dataIndex: 'PRICE', header: '单价', width: 100, editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true } }, { dataIndex: 'DISTANCE', header: '里程', width: 100, editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true } } ]; 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()], bbar: Ext.create('Ext.PagingToolbar', { store: this.storeList, displayInfo: true, displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录', emptyMsg: "没有数据" }) }); /////////////以下部分为获取存储的gridpanel显示样式 this.column = DsTruck.GetGridPanel(USERID, this.formname, this.column, 1); //使用者id,表名 ,中间column数组,跳过一开始的几列 this.gridList.reconfigure(this.storeList, this.column); this.gridList.columns[0] = new Ext.grid.RowNumberer(); this.gridList.on('edit', function (editor, e, eOpts) { this.gridAfterEdit(editor, e, eOpts); }, this); //////////////////////////// //#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: 'BLNO', flex: 1 }, { fieldLabel: '项目编号', name: 'PROJECTNO', flex: 1 }, { fieldLabel: '项目类型', name: 'PROTYPE', flex: 1 }, this.comboxBLNOTYPE_1, this.comboxTF_1 ] } ]//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: '增加明细', tooltip: '增加明细', iconCls: "btnadddetail", handler: function (button, event) { this.onAddClick(button, event); }, scope: this }, { text: '删除明细', tooltip: '删除明细', iconCls: "btndeletedetail", handler: function (button, event) { this.onDelClick(button, event); }, scope: this }, { id: "btnSave", text: '保存更改', tooltip: '保存更改', iconCls: "btnsave", handler: function (button, event) { this.Save(); //alert(USERID); }, scope: this }, '-', { text: "导出Excel", id: "btnExportExcel", iconCls: 'btnexportexcel', handler: function (button, event) { this.onExportClick(button, event); }, scope: this } ] }); //#endregion this.panelTop = new Ext.Panel({ layout: "border", region: "north", height: 30, 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.gridList.on('edit', function (editor, e, eOpts) { this.ProjectAfterEdit(editor, e, eOpts); }, this); /////////////onRefreshClick if (!this.checkSearchCondition()) return; var sql = this.getCondition(); this.storeList.load({ params: { start: 0, limit: this.PageSize, condition: sql }, waitMsg: "正在查询数据...", scope: this }); this.bodyDel = []; ////////////// }, //end initUIComponents ProjectAfterEdit: function (editor, e, eOpts) { if (e.field == 'IN_PROVINCE') { var _r = DsStoreQueryBy(this.storeIN_PROVINCE, 'IN_PROVINCE', e.value); if (_r.getCount() > 0) { var _d = _r.getAt(0).data; e.record.set('IN_PROVINCE_REF', _d.IN_PROVINCE_REF); } else { e.record.set('IN_PROVINCE_REF', ''); } } }, 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 COMPANYID = form.findField('PROJECTNO').getValue(); //sql = sql + getAndConSql(sql, COMPANYID, "COMPANYID = '" + COMPANYID + "'"); /* var BLNO = form.findField('BLNO').getValue(); sql = sql + getAndConSql(sql, BLNO, "BLNO like '%" + BLNO + "%'"); var PROTYPE = form.findField('PROTYPE').getValue(); sql = sql + getAndConSql(sql, PROTYPE, "PROTYPE like '%" + PROTYPE + "%'"); var BLNOTYPE = form.findField('BLNOTYPE').getValue(); sql = sql + getAndConSql(sql, BLNOTYPE, "BLNOTYPE like '%" + BLNOTYPE + "'%"); */ 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; }, onAddClick: function (button, event) { var record = Ext.create('LTJYDistancemb', { 'id': '', 'NAME': '', 'CUSTOMERNAME': '', 'PRICETYPE': '', 'PRICE': '0', 'DISTANCE': '0' }); this.storeList.add(record); var n = this.storeList.getCount(); this.cellEditing.startEditByPosition({ row: n - 1, column: 2 }); }, onDelClick: function (button, event) { var selectedRecords = this.gridList.selModel.getSelection(); Ext.MessageBox.confirm('提示', '确定删除记录吗?', function (btn) { if (btn == 'yes') { if (selectedRecords.length > 1) { alert("为防止误删,一次只允许删除一行数据"); return; } for (var i = 0; i < selectedRecords.length; i++) { var rec = selectedRecords[i]; if (rec.id != "") //如果是新增但没有保存的数据,没有必要提交到后台 { this.bodyDel.push(rec); } this.storeList.remove(selectedRecords[i]); } } }, this); }, Save: function (type) { //费用 var bodyList = []; for (i = 0; i < this.storeList.getCount(); i += 1) { var member = this.storeList.getAt(i); 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: '/TruckMng/LTJYDistance/Save', scope: this, params: { ProjectBody: jsonBody, ProjectDelBody: 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'); } }); }, gridAfterEdit: function (editor, e, eOpts) { } });