Form.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. Ext.define('erp.view.oa.attention.Form',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpAttentionFormPanel',
  4. id: 'form',
  5. region: 'north',
  6. frame : true,
  7. layout : 'column',
  8. autoScroll : true,
  9. defaultType : 'textfield',
  10. labelSeparator : ':',
  11. buttonAlign : 'center',
  12. fieldDefaults : {
  13. margin : '2 2 2 2',
  14. fieldStyle : "background:#FFFAFA;color:#515151;",
  15. focusCls: 'x-form-field-cir',//fieldCls
  16. labelAlign : "right",
  17. msgTarget: 'side',
  18. blankText : $I18N.common.form.blankText
  19. },
  20. FormUtil: Ext.create('erp.util.FormUtil'),
  21. saveUrl: '',
  22. updateUrl: '',
  23. deleteUrl: '',
  24. getIdUrl: '',
  25. keyField: '',
  26. codeField: '',
  27. statusField: '',
  28. params: null,
  29. caller:null,
  30. formCondition:null,
  31. initComponent : function(){
  32. formCondition = getUrlParam('formCondition');//从url解析参数
  33. formCondition = (formCondition == null) ? this.formCondition : formCondition.replace(/IS/g,"=");
  34. var param = {caller: this.caller, condition: formCondition};
  35. this.getItemsAndButtons(this, 'common/singleFormItems.action', this.params || param);//从后台拿到formpanel的items
  36. this.callParent(arguments);
  37. },
  38. save:function(){
  39. var me = this;
  40. var params = new Object();
  41. var form = Ext.getCmp('form');
  42. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  43. me.getSeqId(form);
  44. }
  45. if(form.getForm().isValid()){
  46. //form里面数据
  47. Ext.each(form.items.items, function(item){
  48. if(item.xtype == 'numberfield'){
  49. //number类型赋默认值,不然sql无法执行
  50. if(item.value == null || item.value == ''){
  51. item.setValue(0);
  52. }
  53. }
  54. });
  55. var r = form.getValues();
  56. var param=[];
  57. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  58. if(contains(k, 'ext-', true)){
  59. delete r[k];
  60. }
  61. });
  62. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  63. params.param = unescape(param.toString().replace(/\\/g,"%"));
  64. Ext.Ajax.request({
  65. url : basePath + form.saveUrl,
  66. params : params,
  67. method : 'post',
  68. async: false,
  69. callback : function(options,success,response){
  70. var localJson = new Ext.decode(response.responseText);
  71. if(localJson.exceptionInfo){
  72. var str = localJson.exceptionInfo;
  73. showError(str);
  74. }
  75. }
  76. });
  77. }
  78. },
  79. update: function(){
  80. var params = new Object();
  81. var r=Ext.getCmp('form').getValues();
  82. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  83. var form = Ext.getCmp('form');
  84. Ext.Ajax.request({
  85. url : basePath + form.updateUrl,
  86. params: params,
  87. async: false,
  88. method : 'post',
  89. callback : function(options,success,response){
  90. var localJson = new Ext.decode(response.responseText);
  91. if(localJson.exceptionInfo){
  92. var str = localJson.exceptionInfo;
  93. showError(str);
  94. }
  95. }
  96. });
  97. },
  98. ondelete: function(id){
  99. var me = this;
  100. warnMsg($I18N.common.msg.ask_del_main, function(btn){
  101. if(btn == 'yes'){
  102. var form = Ext.getCmp('form');
  103. Ext.Ajax.request({
  104. url : basePath + form.deleteUrl,
  105. params: {
  106. id: id
  107. },
  108. method : 'post',
  109. callback : function(options,success,response){
  110. me.getActiveTab().setLoading(false);
  111. var localJson = new Ext.decode(response.responseText);
  112. if(localJson.exceptionInfo){
  113. showError(localJson.exceptionInfo);return;
  114. }
  115. }
  116. });
  117. }
  118. });
  119. },
  120. getSeqId: function(form){
  121. if(!form){
  122. form = Ext.getCmp('form');
  123. }
  124. Ext.Ajax.request({
  125. url : basePath + 'common/getCommonId.action?caller=' +form.caller,
  126. method : 'get',
  127. async: false,
  128. callback : function(options,success,response){
  129. var rs = new Ext.decode(response.responseText);
  130. if(rs.exceptionInfo){
  131. showError(rs.exceptionInfo);return;
  132. }
  133. if(rs.success){
  134. Ext.getCmp(form.keyField).setValue(rs.id);
  135. }
  136. }
  137. });
  138. },
  139. getItemsAndButtons: function(form, url, param){
  140. var me = this;
  141. Ext.Ajax.request({//拿到form的items
  142. url : basePath + url,
  143. params: param,
  144. method : 'post',
  145. callback : function(options,success,response){
  146. var res = new Ext.decode(response.responseText);
  147. if(res.exceptionInfo != null){
  148. showError(res.exceptionInfo);return;
  149. }
  150. form.fo_id = res.fo_id;
  151. form.fo_keyField = res.fo_keyField;
  152. form.tablename = res.tablename;
  153. if(res.keyField){
  154. form.keyField = res.keyField;
  155. }
  156. if(res.statusField){
  157. form.statusField = res.statusField;
  158. }
  159. if(res.statuscodeField){
  160. form.statuscodeField = res.statuscodeField;
  161. }
  162. if(res.codeField){
  163. form.codeField = res.codeField;
  164. }
  165. form.fo_detailMainKeyField = res.fo_detailMainKeyField;
  166. var grids = Ext.ComponentQuery.query('gridpanel');
  167. //如果该页面只有一个form,而且form字段少于8个,则布局改变
  168. if(grids.length == 0 && res.items.length <= 8){
  169. Ext.each(res.items, function(item){
  170. item.columnWidth = 0.5;
  171. });
  172. form.layout = 'column';
  173. }
  174. if(res.data){
  175. var data = Ext.decode(res.data);
  176. if(form.statuscodeField && data[form.statuscodeField] != null &&
  177. data[form.statuscodeField] != 'ENTERING' && data[form.statuscodeField] != 'COMMITED'){//非在录入和已提交均设置为只读
  178. form.readOnly = true;
  179. Ext.each(res.items, function(item){
  180. if(screen.width >= 1280){//根据屏幕宽度,调整列显示宽度
  181. if(item.columnWidth > 0 && item.columnWidth <= 0.34){
  182. item.columnWidth = 0.25;
  183. } else if(item.columnWidth > 0.34 && item.columnWidth <= 0.67){
  184. item.columnWidth = 0.5;
  185. }
  186. }
  187. item.value = data[item.name];
  188. if(item.secondname){//针对合并型的字段
  189. item.secondvalue = data[item.secondname];
  190. }
  191. if(item.name == form.statusField){//状态加特殊颜色
  192. item.fieldStyle = item.fieldStyle + ';font-weight:bold;';
  193. } else if(item.name == form.statuscodeField){//状态码字段强制隐藏
  194. item.xtype = 'hidden';
  195. }
  196. item.fieldStyle = item.fieldStyle + ';background:#f1f1f1;';
  197. item.readOnly = true;
  198. });
  199. } else {
  200. Ext.each(res.items, function(item){
  201. if(screen.width >= 1280){//根据屏幕宽度,调整列显示宽度
  202. if(item.columnWidth > 0 && item.columnWidth <= 0.34){
  203. item.columnWidth = 0.25;
  204. } else if(item.columnWidth > 0.34 && item.columnWidth <= 0.67){
  205. item.columnWidth = 0.5;
  206. }
  207. }
  208. item.value = data[item.name];
  209. if(item.secondname){//针对合并型的字段
  210. item.secondvalue = data[item.secondname];
  211. }
  212. if(item.name == form.statusField){//状态加特殊颜色
  213. item.fieldStyle = item.fieldStyle + ';font-weight:bold;';
  214. }
  215. });
  216. }
  217. //form.getForm().setValues(data);
  218. // form.getForm().getFields().each(function (item,index,length){
  219. // item.originalValue = item.getValue();
  220. // });
  221. } else {
  222. Ext.each(res.items, function(item){
  223. if(screen.width >= 1280){//根据屏幕宽度,调整列显示宽度
  224. if(item.columnWidth > 0 && item.columnWidth <= 0.34){
  225. item.columnWidth = 0.25;
  226. } else if(item.columnWidth > 0.34 && item.columnWidth <= 0.67){
  227. item.columnWidth = 0.5;
  228. }
  229. }
  230. if(item.name == form.statusField){//状态加特殊颜色
  231. item.fieldStyle = item.fieldStyle + ';font-weight:bold;';
  232. }
  233. });
  234. }
  235. form.add(res.items);
  236. if(res.title && res.title != ''){
  237. form.setTitle(res.title);
  238. }
  239. var bool = true;
  240. Ext.each(form.items.items, function(item){
  241. if(bool && item.hidden == false && item.readOnly == false && item.editable == true){
  242. this.focus(false, 200);
  243. bool = false;
  244. }
  245. });
  246. }
  247. });
  248. },
  249. });