ComboButton.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. Ext.define('erp.view.core.button.ComboButton',{
  2. extend: 'Ext.Button',
  3. alias: 'widget.erpComboButton',
  4. cls: 'x-btn-gray',
  5. text: '下拉框设置',
  6. cls: 'x-btn-gray',
  7. hidden: false,
  8. disabled:true,
  9. style: {
  10. marginLeft: '10px'
  11. },
  12. width: 120,
  13. initComponent : function(){
  14. this.callParent(arguments);
  15. },
  16. comboSet:function(caller, field){
  17. var me=this;
  18. var combodata=me.getComboData(caller,field);
  19. Ext.create('Ext.Window', {
  20. width: '80%',
  21. height: '80%',
  22. autoShow: true,
  23. layout: 'border',
  24. buttonAlign : 'center',
  25. title:'<h1>下拉配置</h1>',
  26. items: [{
  27. region:'center',
  28. xtype: 'grid',
  29. id:'combogrid',
  30. columnLines:true,
  31. bodyStyle: 'background-color:#f1f1f1;',
  32. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  33. clicksToEdit: 1
  34. }),
  35. listeners:{
  36. itemclick:function(selModel, record,e,index){
  37. var grid=selModel.ownerCt;
  38. Ext.getCmp('deletecombo').setDisabled(false);
  39. if(index.toString() == 'NaN'){
  40. index = '';
  41. }
  42. if(index == grid.store.data.items.length-1){//如果选择了最后一行
  43. var items=grid.store.data.items;
  44. var detno=Math.ceil(items[index].data.dlc_detno);
  45. for(var i=0;i<10;i++){
  46. detno++;
  47. var o = new Object();
  48. o.dlc_caller=caller;
  49. o.dlc_fieldname=field;
  50. o.dlc_value=null;
  51. o.dlc_value_en=null;
  52. o.dlc_value_tw=null;
  53. o.dlc_display=null;
  54. o.dlc_detno=detno;
  55. grid.store.insert(items.length, o);
  56. items[items.length-1]['index'] = items.length-1;
  57. }
  58. }
  59. }
  60. },
  61. columns: [{
  62. text:'ID',
  63. dataIndex:'dlc_id',
  64. width:0
  65. },{
  66. cls : "x-grid-header-1",
  67. text:'序号',
  68. dataIndex: 'dlc_detno',
  69. xtype: 'numbercolumn',
  70. flex: 0.5,
  71. format: '0,000',
  72. editor: {
  73. format:'0',
  74. xtype: 'numberfield',
  75. hideTrigger:true,
  76. minValue:0
  77. },
  78. renderer: function(val, meta, record){
  79. if(!val){
  80. val=0;
  81. }
  82. return Math.ceil(val);
  83. }
  84. },{
  85. cls : "x-grid-header-1",
  86. text: '中文值',
  87. dataIndex: 'dlc_value',
  88. flex: 1,
  89. editor: {
  90. format:'',
  91. xtype: 'textfield'
  92. },
  93. renderer: function(val, meta, record){
  94. if(!val){
  95. val="";
  96. }
  97. return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
  98. '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
  99. }
  100. },{
  101. cls : "x-grid-header-1",
  102. text: '英文值',
  103. dataIndex: 'dlc_value_en',
  104. flex: 1,
  105. editor: {
  106. format:'',
  107. xtype: 'textfield'
  108. }
  109. },{
  110. cls : "x-grid-header-1",
  111. text:'繁文',
  112. dataIndex: 'dlc_value_tw',
  113. flex: 1,
  114. editor: {
  115. format:'',
  116. xtype: 'textfield'
  117. }
  118. },{
  119. cls : "x-grid-header-1",
  120. text:'实际值',
  121. dataIndex:'dlc_display',
  122. flex:1,
  123. editor: {
  124. format:'',
  125. xtype: 'textfield'
  126. },
  127. renderer: function(val, meta, record){
  128. if(!val){
  129. val="";
  130. }
  131. return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
  132. '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
  133. }
  134. },{
  135. cls : "x-grid-header-1",
  136. text:'Caller',
  137. dataIndex: 'dlc_caller',
  138. flex:1,
  139. readOnly:true
  140. },{
  141. cls : "x-grid-header-1",
  142. text:'字段名',
  143. dataIndex:'dlc_fieldname',
  144. flex:1,
  145. readOnly:true
  146. }]
  147. }],
  148. buttons:['->',{
  149. xtype:'button',
  150. text: $I18N.common.button.erpSaveButton,
  151. iconCls: 'x-button-icon-save',
  152. cls: 'x-btn-gray',
  153. formBind: true,//form.isValid() == false时,按钮disabled
  154. width: 60,
  155. style: {
  156. marginLeft: '10px'
  157. },
  158. handler:function(){
  159. me.saveCombo(caller,field);
  160. }
  161. },{
  162. xtype:'button',
  163. text: $I18N.common.button.erpDeleteButton,
  164. iconCls: 'x-button-icon-delete',
  165. cls: 'x-btn-gray',
  166. id:'deletecombo',
  167. width: 60,
  168. style: {
  169. marginLeft: '10px'
  170. },
  171. handler:function(){
  172. me.deleteCombo(me);
  173. }
  174. },{
  175. xtype:'button',
  176. text: $I18N.common.button.erpCloseButton,
  177. iconCls: 'x-button-icon-close',
  178. cls: 'x-btn-gray',
  179. formBind: true,//form.isValid() == false时,按钮disabled
  180. width: 60,
  181. style: {
  182. marginLeft: '10px'
  183. },
  184. handler:function(btn){
  185. btn.ownerCt.ownerCt.close();
  186. }
  187. },'->']
  188. });
  189. Ext.getCmp('combogrid').getStore().loadData(combodata);
  190. },
  191. getComboData:function(caller,field){
  192. var combodata=null;
  193. Ext.Ajax.request({
  194. url : basePath +'common/getComboDataByCallerAndField.action',
  195. params: {
  196. caller:caller,
  197. field:field
  198. },
  199. async: false,
  200. method : 'post',
  201. callback : function(options,success,response){
  202. var res = new Ext.decode(response.responseText);
  203. if(res.exceptionInfo != null){
  204. showError(res.exceptionInfo);
  205. return;
  206. }
  207. if(res.success){
  208. combodata=res.data;
  209. }
  210. }
  211. });
  212. if(combodata.length<1){
  213. this.add10EmptyData(combodata,caller, field);
  214. }
  215. return combodata;
  216. },
  217. saveCombo:function(caller,field){
  218. var me=this;
  219. var grid=Ext.getCmp('combogrid');
  220. grid.necessaryField='dlc_value';
  221. var jsonGridData = new Array();
  222. var dd;
  223. var s = grid.getStore().data.items;
  224. for(var i=0;i<s.length;i++){
  225. var data = s[i].data;
  226. dd = new Object();
  227. if(data[grid.necessaryField] != null && data[grid.necessaryField] != ""){
  228. Ext.each(grid.columns, function(c){
  229. dd[c.dataIndex] = s[i].data[c.dataIndex];
  230. });
  231. jsonGridData.push(Ext.JSON.encode(dd));
  232. }
  233. }
  234. var param=jsonGridData;
  235. if(param == null || param == ''){
  236. showError($I18N.common.grid.emptyDetail);
  237. }else {
  238. var params = new Object();
  239. params.gridStore = unescape(param.toString().replace(/\\/g,"%"));
  240. Ext.Ajax.request({
  241. url : basePath + 'common/saveCombo.action',
  242. params : params,
  243. method : 'post',
  244. callback : function(options,success,response){
  245. var res=new Ext.decode(response.responseText);
  246. if(res.exceptionInfo != null){
  247. showError(res.exceptionInfo);return;
  248. }
  249. if(res.success){
  250. Ext.Msg.alert('提示','保存成功!',function(){
  251. grid.getStore().loadData(me.getComboData(caller,field));
  252. });
  253. }
  254. }
  255. });
  256. }
  257. },
  258. deleteCombo:function(){
  259. var grid= Ext.getCmp('combogrid');
  260. var id= grid.getSelectionModel().lastSelected.data['dlc_id'];
  261. if(id!=null&&id!="null"){
  262. //存在数据后台删除
  263. Ext.Ajax.request({
  264. url : basePath + 'common/deleteCombo.action',
  265. params : {
  266. id:id
  267. },
  268. method : 'post',
  269. callback : function(options,success,response){
  270. var res=new Ext.decode(response.responseText);
  271. if(res.exceptionInfo != null){
  272. showError(res.exceptionInfo);return;
  273. }
  274. if(res.success){
  275. Ext.Msg.alert('提示','删除成功!');
  276. grid.getStore().remove(grid.getSelectionModel().getSelection());
  277. }
  278. }
  279. });
  280. }else {
  281. //不存在数据直接remove
  282. grid.getStore().remove(grid.getSelectionModel().getSelection());
  283. }
  284. Ext.getCmp('deletecombo').setDisabled(true);
  285. },
  286. add10EmptyData: function(data,caller, field){
  287. for(var i=0;i<10;i++){
  288. var o = new Object();
  289. o.dlc_caller=caller;
  290. o.dlc_fieldname=field;
  291. o.dlc_value=null;
  292. o.dlc_value_en=null;
  293. o.dlc_value_tw=null;
  294. o.dlc_display=null;
  295. o.dlc_detno=i;
  296. data.push(o);
  297. }
  298. }
  299. });