Ext.namespace('Shipping'); Shipping.MsInfoSaleProfitShareSetIndex = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.Shipping.MsInfoSaleProfitShareSetIndex.superclass.constructor.call(this); }; Ext.extend(Shipping.MsInfoSaleProfitShareSetIndex, Ext.Panel, { OprationStatus: null, //仅当弹出界面时使用 SelectedRecord: null, initUIComponents: function () { //定义数据集 this.storeList = Ext.create('Ext.data.Store', { model: 'InfoSaleProfitSharePlan', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsInfoSaleProfitShareSet/GetDataList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); //定义Grid this.gridList = new Ext.grid.GridPanel({ store: this.storeList, enableHdMenu: false, region: 'center', loadMask: { msg: "数据加载中,请稍等..." }, trackMouseOver: true, disableSelection: false, plugins: [this.gridListCellEditing], selType: 'cellmodel', columns: [{ sortable: true, dataIndex: 'GID', header: 'GID', hidden: true, width: 120 }, { sortable: true, dataIndex: 'PLANNAME', header: '方案名称', width: 160 }, { sortable: true, dataIndex: 'ISSTOPMONTH', header: '死账月数', width: 160 }, { sortable: true, dataIndex: 'POORDAY', header: '允许误差天数', width: 100 }, { sortable: true, dataIndex: 'REMARKS', header: '说明', width: 160 } ] }); this.gridList.addListener('itemdblclick', function (dataview, record, item, index, e, b) { this.SelectedRecord = record; this.OprationStatus = 'edit'; DsOpenEditWin('/MvcShipping/MsInfoSaleProfitShareSet/Edit'); }, this); this.storeListSet = Ext.create('Ext.data.Store', { model: 'InfoSaleProfitShareSet', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsInfoSaleProfitShareSet/GetSaleProfitSetDataList', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); this.comboxPLAN = Ext.create('DsExt.ux.RefTableCombox', { store: this.storeList, forceSelection: true, valueField: 'GID', displayField: 'PLANNAME' }); this.storeOpCode = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.UserRefModel', proxy: { url: '/CommMng/BasicDataRef/GetUserLinkRefList' } }); this.storeOpCode.load(); this.comboxSALE = Ext.create('DsExt.ux.RefTableCombox', { store: this.storeOpCode, forceSelection: true, valueField: 'UserName', displayField: 'CodeAndName', value: SHOWNAME }); this.gridListCustCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); //定义Grid this.gridListSet = new Ext.grid.GridPanel({ store: this.storeListSet, enableHdMenu: false, region: 'center', loadMask: { msg: "数据加载中,请稍等..." }, trackMouseOver: true, disableSelection: false, plugins: [this.gridListCustCellEditing], selType: 'cellmodel', columns: [{ sortable: true, dataIndex: 'GID', header: 'GID', hidden: true, width: 120 }, { sortable: true, dataIndex: 'SALEID', header: 'SALEID', hidden: true, width: 120 },{ sortable: true, dataIndex: 'SALE', header: '业务员', width: 160, editor: this.comboxSALE }, { sortable: true, dataIndex: 'PLANID', header: '提成方案', width: 100, editor: this.comboxPLAN, renderer: function (value, p, record) { return record.data.PLANREF; } }, { sortable: true, dataIndex: 'PROFITPLAN', header: '毛利计划金额', editor: { xtype: 'numberfield', keyNavEnabled: false, decimalPrecision: 2, selectOnFocus: true, mouseWheelEnabled: false, enableKeyEvents: true }, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { try { var lsValue = usMoney(value, 2, '', false); if (lsValue != "NaN") { value = lsValue; if (parseFloat(lsValue) < 0) { return '' + lsValue + ''; } else return lsValue; } else { return value; } } catch (e) { return value; } return value; }, width: 70 } ] }); //查询工具条 this.panelBtn = new Ext.Panel({ region: "north", tbar: [ { text: "新增", iconCls: "btnadd", handler: function (button, event) { this.addDetail(); }, scope: this }, { text: "保存", iconCls: "btnsave", handler: function (button, event) { this.onPostDetailClick(button, event); }, scope: this }, '-', { text: "删除", iconCls: "btndelete", handler: function (button, event) { this.onDeleteClick(button, event); }, scope: this } ] }); this.panelTop = new Ext.Panel({ layout: "border", region: "north", height: 30, items: [this.panelBtn] }); this.panelCtn = new Ext.Panel({ layout: "border", title: '提成方案设置', id: 'pnlctn', region: "center", items: [this.gridList] }); this.panelCust = new Ext.Panel({ layout: "border", title: '业务员提成方案', id: 'pnlcust', region: "center", items: [this.gridListSet] }); this.MainCenter = new Ext.TabPanel({ activeTab: 0, autoWidth: true, border: true, frame: false, region: 'center', enableTabScroll: true, items: [ this.panelCust,this.panelCtn ] }); Ext.apply(this, { items: [this.panelTop, this.MainCenter] }); this.storeList.on('beforeload', function (store) { var sql = this.getCondition(); Ext.apply(store.proxy.extraParams, { condition: sql }); }, this); // this.gridList.on('edit', function (editor, e, eOpts) { // this.gridListAfterEdit(editor, e, eOpts); // }, this); this.storeListSet.on('beforeload', function (store) { var sql = this.getCondition(); Ext.apply(store.proxy.extraParams, { condition: sql }); }, this); this.gridListSet.on('edit', function (editor, e, eOpts) { this.gridListAfterEdit(editor, e, eOpts); }, this); this.onRefreshClick(); }, //end initUIComponents onRefreshClick: function (button, event) { var sql = this.getCondition(); this.storeList.load({ params: { start: 0, limit: 500, sort: '', condition: sql }, waitMsg: "正在查询数据...", scope: this }); this.storeListSet.load({ params: { start: 0, limit: 500, sort: '', condition: sql }, waitMsg: "正在查询数据...", scope: this }); }, addDetail: function () { //var newSerialno = DsGetNewSerialNo(this.storeBodyList, this.serialNo); if (this.MainCenter.activeTab.id == 'pnlctn') { this.OprationStatus = 'add'; DsOpenEditWin('/MvcShipping/MsInfoSaleProfitShareSet/Edit'); } else if (this.MainCenter.activeTab.id == 'pnlcust') { var record = Ext.create('InfoSaleProfitShareSet', { GID: '*', PLANID: '', SALEID: '', SALE: '', REMARKS: '' }); this.storeListSet.add(record); var n = this.storeListSet.getCount(); this.gridListCustCellEditing.startEditByPosition({ row: n - 1, column: 1 }); } }, onPostDetailClick: function (button, event) { if (this.MainCenter.activeTab.id == 'pnlctn') { } else if (this.MainCenter.activeTab.id == 'pnlcust') { this.onPostCustDetailClick(button, event); } }, onPostCustDetailClick: function (button, event) { var bodyDrChFeeDatas = []; var i; for (i = 0; i < this.storeListSet.getCount(); i += 1) { var memberyf = this.storeListSet.getAt(i); var PLANID = memberyf.data.PLANID; if (PLANID == '') { Ext.Msg.show({ title: '提示', msg: '方案不能为空!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; }; var SALE = memberyf.data.SALE; if (SALE == '') { Ext.Msg.show({ title: '提示', msg: '业务员不能为空!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; }; if (PLANID != '' && SALE != '') bodyDrChFeeDatas.push(memberyf); }; var jsonChFeeBody = ConvertRecordsToJsonAll(bodyDrChFeeDatas); _thisfee = this; Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsInfoSaleProfitShareSet/SaveSaleProfitSet', scope: this, params: { body: jsonChFeeBody }, callback: function (options, success, response) { if (success) { Ext.MessageBox.hide(); var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { 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 }); } } }); }, //end save onDeleteClick: function (button, event) { if (this.MainCenter.activeTab.id == 'pnlctn') { this.onDeleteCtnClick(button, event); } else if (this.MainCenter.activeTab.id == 'pnlcust') { this.onDeleteCustClick(button, event); } }, onDeleteCtnClick: function (button, event) { var selections = this.gridList.getSelectionModel().getSelection(); if (selections.length == 0) { Ext.Msg.show({ title: '提示', msg: '请先选择单据!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; } var record = selections[0]; Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) { if (btn == 'yes') { Ext.Msg.wait('正在删除数据...'); Ext.Ajax.request({ waitMsg: '正在删除数据...', url: '/MvcShipping/MsInfoSaleProfitShareSet/Delete', params: { data: Ext.JSON.encode(record.data) }, callback: function (options, success, response) { if (success) { var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { this.storeList.remove(record); Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); } 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 }); }, success: function (response, options) { }, scope: this }); //end Ext.Ajax.request } }, this); }, //onDeleteClick onDeleteCustClick: function (button, event) { var selections = this.gridListSet.getSelectionModel().getSelection(); if (selections.length == 0) { Ext.Msg.show({ title: '提示', msg: '请先选择单据!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); return; } var record = selections[0]; Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) { if (btn == 'yes') { Ext.Msg.wait('正在删除数据...'); Ext.Ajax.request({ waitMsg: '正在删除数据...', url: '/MvcShipping/MsInfoSaleProfitShareSet/DeleteSaleProfitSet', params: { data: Ext.JSON.encode(record.data) }, callback: function (options, success, response) { if (success) { var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { this.storeListSet.remove(record); Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); } 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 }); }, success: function (response, options) { }, scope: this }); //end Ext.Ajax.request } }, this); }, //onDeleteClick gridListAfterEdit: function (editor, e, eOpts) { if (e.value == e.originalValue) return; if (e.field == 'SALE') { var selectrecords = DsStoreQueryBy(this.storeOpCode, 'UserName', e.value); if (selectrecords.getCount() > 0) { var selectdata = selectrecords.getAt(0).data; e.record.set('SALEID', selectdata.GID); } else { e.record.set('SALEID', ''); } } else if (e.field == 'PLANID') { var selectrecords = DsStoreQueryBy(this.storeList, 'GID', e.value); if (selectrecords.getCount() > 0) { var selectdata = selectrecords.getAt(0).data; e.record.set('PLANREF', selectdata.PLANNAME); } else { e.record.set('PLANREF', ''); } } }, getCondition: function () { // var form = this.formSearch.getForm(); // if (!form.isValid()) { // Ext.Msg.alert('提示', '查询条件赋值错误,请检查。'); // return ''; // } var sql = ''; // var SERVICENAME = form.findField('EDINAME').getValue(); // sql = sql + getAndConSql(sql, SERVICENAME, "EDINAME like '%" + SERVICENAME + "%'"); return sql; }, OprationSwap: function () { var ret = new Array(); ret[0] = this.OprationStatus; ret[1] = this.storeList; ret[2] = this.SelectedRecord; return ret; } });