Ext.namespace('Shipping'); String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); } Shipping.MsCwGenlegAccitemsEdit = function (config) { Ext.applyIf(this, config); this.initUIComponents(); window.Shipping.MsCwGenlegAccitemsEdit.superclass.constructor.call(this); }; Ext.extend(Shipping.MsCwGenlegAccitemsEdit, Ext.Panel, { ParentWin: null, StoreList: null, EditRecord: null, initUIComponents: function () { this.serialNo = 0; this.itemindex = 1; //#region 定义数据集 this.storeCGAList = Ext.create('Ext.data.Store', { model: 'MsCwGenlegAccitemsModel', remoteSort: true, proxy: { type: 'ajax', url: '/MvcShipping/MsCwGenlegAccitems/GetDataEdit', reader: { id: 'GID', root: 'data', totalProperty: 'totalCount' } } }); //#endregion //#region formSearch 下拉框信息加载 //项目加载 this.storeCwItem = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CwItemModel', proxy: { url: '/CommMng/BasicDataRef/GetCwItemList' } }); //this.storeLimit.load({ params: { condition: "ISCONTROLLER='1'"} }); this.storeCwItem.load(); this.comboxCwItem = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '项目', store: this.storeCwItem, forceSelection: true, name: 'ITEMNAME', valueField: 'ITEMNAME', displayField: 'CodeAndName', allowBlank: false }); //部门加载 this.storeDept = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.DeptModel', proxy: { url: '/CommMng/BasicDataRef/GetDeptList' } }); //this.storeLimit.load({ params: { condition: "ISCONTROLLER='1'"} }); this.storeDept.load(); this.comboxDept = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '部门', store: this.storeDept, forceSelection: true, name: 'DeptName', valueField: 'DeptName', displayField: 'DeptName', allowBlank: false }); //客户加载 this.storeCustCode = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CustomRefModel', proxy: { url: '/CommMng/BasicDataRef/GetCustomRefList' } }); this.storeCustCode.load({ params: { condition: ""} }); this.comboxCust = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '客户', store: this.storeCustCode, forceSelection: true, name: 'CustNAME', valueField: 'CustName', displayField: 'CodeAndName', allowBlank: false }); //人员信息加载 this.storeOpCode = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.UserRefModel', proxy: { url: '/CommMng/BasicDataRef/GetUserRefList' } }); this.storeOpCode.load(); //揽货人 this.comboxSALE = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '人员', store: this.storeOpCode, forceSelection: true, name: 'SALE', valueField: 'UserName', displayField: 'CodeAndName', value: SHOWNAME }); //币别选项 this.storeCwAccitemsCurrency = Ext.create('DsExt.ux.RefTableStore', { model: 'DsShipping.ux.CwAccitemsCurrencyModel', proxy: { url: '/CommMng/BasicDataRef/GetCwAccitemsCurrencyList' } }); this.storeCwAccitemsCurrency.load({ params: { condition: "LINKGID=''"} }); this.comboxCodeCurrency = Ext.create('DsExt.ux.RefTableCombox', { //fieldLabel: '币别', store: this.storeCwAccitemsCurrency, forceSelection: true, name: 'CURRENCY', valueField: 'CURRENCY', displayField: 'CURRENCY', enableKeyEvents: true, //激活键盘事件 listeners: { scope: this, 'focus': function (_this, eOpts) { var condition = "LINKGID='" + this.EditRecord.GID + "'"; this.storeCwAccitemsCurrency.load({ params: { condition: condition }, waitMsg: "正在刷新数据...", scope: this }); } } }); //#endregion //#region 列定义 this.girdcolums = [{ sortable: false, dataIndex: 'GID', text: '唯一编码', width: 0 }, { sortable: false, id: 'idDEPTACC', text: '核算部门', dataIndex: 'DEPTACC', width: 100, align: 'center', editor: this.comboxDept }, { sortable: false, id: 'idEMPLACC', text: '核算人员', dataIndex: 'EMPLACC', width: 100, align: 'center', editor: this.comboxSALE }, { sortable: false, id: 'idCORPACC', text: '核算客户', dataIndex: 'CORPACC', width: 150, align: 'center', editor: this.comboxCust }, { sortable: false, id: 'idITEMACC', text: '核算项目', dataIndex: 'ITEMACC', width: 150, align: 'center', editor: this.comboxCwItem }, { sortable: false, id: 'idCURRENCY', text: '核算外币', dataIndex: 'CURRENCY', width: 80, align: 'center', editor: this.comboxCodeCurrency }, { sortable: false, text: '借', dataIndex: 'DR', width: 100, align: 'right', summaryType: 'sum', //renderer: Ext.util.Format.numberRenderer('00.00'), editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true, //精确到小数点后2位(执行4舍5入) allowDecimals: true, //允许输入小数 nanText: '请输入有效小数', //minValue: 0, //maxValue: 100000, value: 0.00 }, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; }, summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; } }, { sortable: false, text: '贷', dataIndex: 'CR', width: 100, align: 'right', summaryType: 'sum', //renderer: Ext.util.Format.numberRenderer('00.00'), editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true, //精确到小数点后2位(执行4舍5入) allowDecimals: true, //允许输入小数 nanText: '请输入有效小数', //minValue: 0, //maxValue: 100000, value: 0.00 }, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; }, summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; } }, { sortable: false, text: '损益类累计借方', dataIndex: 'PFADR', width: 100, align: 'right', summaryType: 'sum', //renderer: Ext.util.Format.numberRenderer('00.00'), editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true, //精确到小数点后2位(执行4舍5入) allowDecimals: true, //允许输入小数 nanText: '请输入有效小数', //style:'direction:rtl', value: 0.00 }, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; }, summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; } }, { sortable: false, text: '损益类累计贷方', dataIndex: 'PFACR', width: 100, align: 'right', summaryType: 'sum', //renderer: Ext.util.Format.numberRenderer('00.00'), editor: { xtype: 'numberfield', allowBlank: false, selectOnFocus: true, //精确到小数点后2位(执行4舍5入) allowDecimals: true, //允许输入小数 nanText: '请输入有效小数', //style: 'direction:rtl', value: 0.00 }, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; }, summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) { value = usMoney(value, 2, '', true); return value; } }, { sortable: false, text: '是否启用', dataIndex: 'ISENABLE', hidden: true, width: 0 }, { sortable: false, text: '月', dataIndex: 'MONTH', hidden: true, width: 0 }]; //#endregion //#region gridList列表显示信息 this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 //1单击,2双击 }); this.gridList = new Ext.grid.GridPanel({ //title: this.EditRecord.NAME.toString(), region: 'center', store: this.storeCGAList, enableHdMenu: false, //是否显示表格列的菜单 //disableSelection: false, //是否禁止选择表格行或列,默认为false hideHeaders: false, //是否隐藏表头 //trackMouseOver: true, //高亮显示鼠标所在的行,默认为true, //stripeRows: true, //斑马线效果 rowLines: true, columnLines: true, loadMask: { msg: "数据加载中,请稍等..." }, plugins: [this.gridListCellEditing], selType: 'cellmodel', columns: this.girdcolums, features: [{ ftype: 'summary'//Ext.grid.feature.Summary表格汇总特性 }], listeners: { scope: this, 'cellclick': function (_thisTable, td, cellIndex, record, tr, rowIndex, e, eOpts) { if (cellIndex == 1 && this.EditRecord.ISDEPTACC.toString() == 'false') { return false; } if (cellIndex == 2 && this.EditRecord.ISEMPLACC.toString() == 'false') { return false; } if (cellIndex == 3 && this.EditRecord.ISCORPACC.toString() == 'false') { return false; } if (cellIndex == 4 && this.EditRecord.ISITEMACC.toString() == 'false') { return false; } if (cellIndex == 5 && this.EditRecord.ISFCY.toString() == 'false') { return false; } if ((cellIndex == 6 || cellIndex == 8) && this.EditRecord.DC.toString() == '贷') { return false; } if ((cellIndex == 7 || cellIndex == 9) && this.EditRecord.DC.toString() == '借') { return false; } if ((cellIndex == 6 || cellIndex == 7) && record.data.ACCATTRIBUTE == '损益') { return false; } if ((cellIndex == 8 || cellIndex == 9) && record.data.ACCATTRIBUTE != '损益') { return false; } return true; } } }); //#endregion //#region 按钮Toolbar/框架/加载 this.panelBtn = new Ext.Panel({ region: "north", tbar: [{ text: '添加', tooltip: '添加', id: "btnadd", iconCls: "btnadd", handler: function (button, event) { this.onAddClick(button, event); }, scope: this }, '-', { id: 'btnsave', text: "保存", iconCls: "btnsave", handler: function (button, event) { this.Save('0'); }, scope: this }, { id: 'btnsaveAndClose', text: "保存并关闭", handler: function (button, event) { this.Save('1'); }, scope: this }, { text: "关闭", handler: function (button, event) { window.close(); }, scope: this }, '-', { text: '删除', tooltip: '删除', id: "btndel", iconCls: "btndelete", handler: function (button, event) { this.onDelClick(button, event); }, scope: this }] }); //end 按钮Toolbar Ext.apply(this, { items: [this.panelBtn, this.gridList] }); ParentWin = window.parent.opener; this.InitData(); //#endregion }, //end initUIComponents //#region 加载事件 InitData: function () { _this = this; if (ParentWin) { var ret = ParentWin.OprationSwap(); //this.opStatus = ret[0]; this.StoreList = ret[1]; this.EditRecord = ret[2]; } // var condition = "LINKGID='" + this.EditRecord.GID + "' and IsInitialEntry=1"; this.storeCGAList.load({ params: { condition: condition }, waitMsg: "正在刷新数据...", scope: this }); var condition2 = "LINKGID='" + this.EditRecord.GID + "'"; this.storeCwAccitemsCurrency.load({ params: { condition: condition2 }, waitMsg: "正在刷新数据...", scope: this }); this.onColumnsHidden(); this.setBtnStatusDisable(this.EditRecord.ISENABLE); }, //end InitData //#endregion //#region 按钮函数 onColumnsHidden: function () { var colu = this.gridList.columns; //获取列对象 if (this.EditRecord.ISDEPTACC.toString() == 'false') { colu[1].hidden = true; //设置第几列隐藏 } else { colu[1].hidden = false; //设置第几列隐藏 } if (this.EditRecord.ISEMPLACC.toString() == 'false') { colu[2].hidden = true; //设置第几列隐藏 } else { colu[2].hidden = false; //设置第几列隐藏 } if (this.EditRecord.ISCORPACC.toString() == 'false') { colu[3].hidden = true; //设置第几列隐藏 } else { colu[3].hidden = false; //设置第几列隐藏 } if (this.EditRecord.ISITEMACC.toString() == 'false') { colu[4].hidden = true; //设置第几列隐藏 } else { colu[4].hidden = false; //设置第几列隐藏 } if (this.EditRecord.ISFCY.toString() == 'false') { colu[5].hidden = true; //设置第几列隐藏 } else { colu[5].hidden = false; //设置第几列隐藏 } if (this.EditRecord.MONTH.toString() == '01' || this.EditRecord.MONTH.toString() == '1') { colu[8].hidden = true; //设置第几列隐藏 colu[9].hidden = true; //设置第几列隐藏 } else { colu[8].hidden = false; //设置第几列隐藏 colu[9].hidden = false; //设置第几列隐藏 } }, Save: function (type) { var j = 0; var bodydatas = []; for (var i = 0; i < this.storeCGAList.getCount(); i += 1) { var member = this.storeCGAList.getAt(i); var ISENABLE = member.get("ISENABLE"); //获取字段的名字 if (ISENABLE) { j++; continue; } bodydatas.push(member); } if (bodydatas.length > 0) { var jsonBody = ConvertRecordsToJsonAll(bodydatas); // Ext.Msg.wait('正在保存数据, 请稍侯..'); Ext.Ajax.request({ waitMsg: '正在保存数据...', url: '/MvcShipping/MsCwGenlegAccitems/SaveEdit', scope: this, params: { data: Ext.JSON.encode(this.EditRecord), body: jsonBody }, callback: function (options, success, response) { if (success) { Ext.MessageBox.hide(); var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { var returnData = jsonresult.Data; var condition = "LINKGID='" + returnData.LINKGID + "' and IsInitialEntry=1"; this.storeCGAList.load({ params: { condition: condition }, waitMsg: "正在刷新数据...", scope: this }); ParentWin.OprationRefresh(); // if (type == '1') { window.close(); } } 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 (j > 0) { var condition = "LINKGID='" + this.EditRecord.GID + "' and IsInitialEntry=1"; this.storeCGAList.load({ params: { condition: condition }, waitMsg: "正在刷新数据...", scope: this }); alert("已经启用的数据不予更改!"); } } else { var condition = "LINKGID='" + this.EditRecord.GID + "' and IsInitialEntry=1"; this.storeCGAList.load({ params: { condition: condition }, waitMsg: "正在刷新数据...", scope: this }); alert("已经启用的数据不予更改!"); } }, //end save onAddClick: function () { var record = Ext.create('MsCwGenlegAccitemsModel', { GID: '*', DEPTACC: '', EMPLACC: '', CORPACC: '', ITEMACC: '', CURRENCY: '',//RMB DR: 0, CR: 0, PFADR: 0, PFACR: 0 }); this.storeCGAList.add(record); //var n = this.storeCGAList.getCount(); //this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 1 }); }, onDelClick: function () { var selectedRecords = this.gridList.selModel.getSelection(); var rec = selectedRecords[0]; Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) { if (btn == 'yes') { Ext.Msg.wait('正在删除数据...'); Ext.Ajax.request({ waitMsg: '正在删除数据...', url: '/MvcShipping/MsCwGenlegAccitems/DeleteDetail', params: { dataER: Ext.JSON.encode(this.EditRecord), data: Ext.JSON.encode(rec.data) }, callback: function (options, success, response) { if (success) { var jsonresult = Ext.JSON.decode(response.responseText); if (jsonresult.Success) { this.storeCGAList.remove(rec); 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 }); }, scope: this }); //end Ext.Ajax.request } }, this); }, //#endregion //#region 编辑时按钮等的状态 setBtnStatusDisable: function (enable) { var sbtnadd = Ext.getCmp('btnadd'); var sbtnsave = Ext.getCmp('btnsave'); var sbtnsaveAndClose = Ext.getCmp('btnsaveAndClose'); var sbtndel = Ext.getCmp('btndel'); if (enable) { sbtnadd.disable(); sbtnsave.disable(); sbtnsaveAndClose.disable(); sbtndel.disable(); } else { sbtnadd.enable(); sbtnsave.enable(); sbtnsaveAndClose.enable(); sbtndel.enable(); } } //#endregion });