CurrencysMonthGrid.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * ERP项目gridpanel通用样式1
  3. */
  4. Ext.define('erp.view.fa.fix.CurrencysMonthGrid',{
  5. extend: 'Ext.grid.Panel',
  6. alias: 'widget.currencysMonthGrid',
  7. region: 'south',
  8. layout : 'fit',
  9. id: 'grid',
  10. emptyText : $I18N.common.grid.emptyText,
  11. columnLines : true,
  12. autoScroll : true,
  13. store: [],
  14. columns: [],
  15. tbar:[{
  16. xtype:'monthdatefield',
  17. id:'monthfield',
  18. editable:false
  19. },{
  20. id:'searchCurrency',
  21. cls: 'x-btn-gray',
  22. iconCls: 'x-button-icon-query',
  23. width: 60,
  24. text:'查看'
  25. },{
  26. xtype:'erpSaveButton'
  27. },{
  28. xtype:'erpDeleteButton'
  29. },{
  30. text: '取上期月末汇率',
  31. name: 'getlastend',
  32. cls: 'x-btn-gray',
  33. margin: '0 0 0 5'
  34. },{
  35. text: '取月初汇率',
  36. name: 'getcrrate',
  37. cls: 'x-btn-gray',
  38. margin: '0 0 0 5'
  39. },{
  40. xtype:'erpCloseButton'
  41. },{
  42. xtype:'erpSyncButton'
  43. }],
  44. GridUtil: Ext.create('erp.util.GridUtil'),
  45. BaseUtil: Ext.create('erp.util.BaseUtil'),
  46. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  47. clicksToEdit: 1
  48. }),
  49. initComponent : function(){
  50. var gridCondition = this.BaseUtil.getUrlParam('gridCondition');
  51. gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
  52. var conf = ' 1=1 ';
  53. if(Ext.String.trim(gridCondition)==''||Ext.String.trim(gridCondition)==null||Ext.String.trim(gridCondition)=='null'){
  54. var searchfield = Number(Ext.Date.format(new Date(), 'Ym'));
  55. conf = conf+' and cm_yearmonth='+searchfield;
  56. }else{
  57. conf = conf+gridCondition;
  58. }
  59. var gridParam = {caller: caller, condition: conf};
  60. this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");
  61. this.callParent(arguments);
  62. },
  63. getGridStore: function(){
  64. var grid = this;
  65. var jsonGridData = new Array();
  66. var s = grid.getStore().data.items;//获取store里面的数据
  67. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  68. var data = s[i].data;
  69. if(s[i].dirty){
  70. var bool = true;
  71. Ext.each(grid.necessaryField, function(f){
  72. if(data[f] == null){
  73. bool = false;
  74. showError("有必填项未填写!代号:" + f);return;
  75. }
  76. });
  77. if(bool){
  78. Ext.each(grid.columns, function(c){
  79. if(c.xtype == 'datecolumn'){
  80. if(Ext.isDate(data[c.dataIndex])){
  81. data[c.dataIndex] = Ext.Date.toString(data[c.dataIndex]);//在这里把GMT日期转化成Y-m-d格式日期
  82. } else {
  83. data[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d');//如果用户没输入日期,或输入有误,就给个默认日期,
  84. //或干脆return;并且提示一下用户
  85. }
  86. } else if(c.xtype == 'datetimecolumn'){
  87. if(Ext.isDate(data[c.dataIndex])){
  88. data[c.dataIndex] = Ext.Date.format(data[c.dataIndex], 'Y-m-d H:i:s');//在这里把GMT日期转化成Y-m-d H:i:s格式日期
  89. } else {
  90. data[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');//默认日期,
  91. }
  92. } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  93. if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  94. data[c.dataIndex] = '0';//也可以从data里面去掉这些字段
  95. }
  96. }
  97. });
  98. jsonGridData.push(Ext.JSON.encode(data));
  99. }
  100. }
  101. }
  102. return jsonGridData;
  103. }
  104. });