Form.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. Ext.define('erp.view.common.CommonChange.Form',{
  2. requires: ['erp.view.core.form.Panel'],
  3. extend: 'erp.view.core.form.Panel',
  4. alias: 'widget.erpCommonChangeFormPanel',
  5. LogFields:null,
  6. changeFields:new Array(),
  7. changeCodeField:null,
  8. initComponent : function(){
  9. formCondition = getUrlParam('formCondition');//从url解析参数
  10. formCondition = (formCondition == null) ? "" : formCondition.replace(/IS/g,"=");
  11. //集团版
  12. var master=getUrlParam('newMaster');
  13. var datalistId = getUrlParam('datalistId');
  14. var datalist = parent.Ext.getCmp(datalistId);
  15. if(datalist){
  16. var record = datalist.currentRecord;
  17. caller=record.get('cl_caller');
  18. }
  19. var param = {caller: this.caller || caller, condition:this.formCondition||formCondition, _noc: (getUrlParam('_noc') || this._noc)};
  20. if(master){
  21. param.master=master;
  22. }
  23. this.addEvents({alladded: true});
  24. this.callParent(arguments);
  25. },
  26. getItemsAndButtons:function(form,url,param){
  27. var me = this, tab = me.FormUtil.getActiveTab(),buttons=null;
  28. param.condition=null;
  29. me.setLoading(true);
  30. Ext.Ajax.request({//拿到form的items
  31. url : basePath + url,
  32. params: param,
  33. method : 'post',
  34. callback : function(options, success, response){
  35. me.setLoading(false);
  36. if (!response) return;
  37. var res = new Ext.decode(response.responseText);
  38. if(res.exceptionInfo != null){
  39. showError(res.exceptionInfo);return;
  40. }
  41. form.fo_id = res.fo_id;
  42. form.fo_keyField = res.keyField;
  43. form.tablename = res.tablename;//表名
  44. form.uulistener = res.uulistener;//uu监听字段
  45. if(res.keyField){//主键
  46. form.keyField = res.keyField;
  47. }
  48. if(res.statusField){//状态
  49. form.statusField = res.statusField;
  50. }
  51. if(res.statuscodeField){//状态码
  52. form.statuscodeField = res.statuscodeField;
  53. }
  54. if(res.codeField){//Code
  55. form.codeField = res.codeField;
  56. }
  57. if(res.dealUrl){
  58. form.dealUrl = res.dealUrl;
  59. }
  60. form.fo_detailMainKeyField = res.fo_detailMainKeyField;//从表外键字段
  61. var grids = Ext.ComponentQuery.query('gridpanel');
  62. //如果该页面只有一个form,而且form字段少于8个,则布局改变
  63. if(!form.fixedlayout && !form.minMode && grids.length == 0 && res.items.length <= 8){
  64. Ext.each(res.items, function(item){
  65. item.columnWidth = 0.5;
  66. });
  67. form.layout = 'column';
  68. }
  69. var record=null;
  70. if(formCondition==null || formCondition=='') buttons=res.buttons;
  71. else {
  72. record=me.getRecord(formCondition);
  73. buttons=me.getbuttons(caller);
  74. }
  75. var items=me.setItems(form,res.items,record);
  76. form.add(items.baseItems);
  77. form.add(me.getChangeGroupItem());
  78. form.add(items.changeItems);
  79. me.fireEvent('afterload', me);
  80. me.FormUtil.setButtons(form, buttons);
  81. }
  82. });
  83. },
  84. setItems: function(form, items, data, limits){
  85. var edit = true,hasData = true,limitArr = new Array(),itemId=null,o=new Object(),array=new Array(),baseItems=new Array(),changeAfterItems=new Array(),allItems=new Object();
  86. form.LogFields=new Array();
  87. if(limits != null && limits.length > 0) {//权限外字段
  88. limitArr = Ext.Array.pluck(limits, 'lf_field');
  89. }
  90. if (data) {
  91. if(form.statuscodeField && data[form.statuscodeField] != null && data[form.statuscodeField] != '' &&
  92. ['ENTERING', 'UNAUDIT', 'UNPOST', 'CANUSE'].indexOf(data[form.statuscodeField]) == -1){//非在录入和已提交均设置为只读// && data[form.statuscodeField] != 'COMMITED'
  93. form.readOnly = true;
  94. edit = false;
  95. }
  96. } else {
  97. hasData = false;
  98. }
  99. var bool = 'a';
  100. if(items.length > 110&&items.length <=190){
  101. bool = 'b';
  102. }else if(items.length>190){
  103. bool = 'c';
  104. }
  105. Ext.each(items, function(item){
  106. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  107. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  108. item.columnWidth = 1/3;
  109. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  110. item.columnWidth = 2/3;
  111. } else if(item.columnWidth >= 1){
  112. item.columnWidth = 1;
  113. }
  114. } else {
  115. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  116. item.columnWidth = 1/3;
  117. } else if(item.columnWidth > 0.5 && item.columnWidth < 0.75){
  118. item.columnWidth = 2/3;
  119. }
  120. }
  121. if(item.name != null) {
  122. if(item.name == form.statusField){//状态加特殊颜色
  123. item.fieldStyle = item.fieldStyle + ';font-weight:bold;';
  124. } else if(item.name == form.statuscodeField){//状态码字段强制隐藏
  125. item.xtype = 'hidden';
  126. }
  127. }
  128. if(item.xtype == 'hidden') {
  129. item.columnWidth = 0;
  130. item.margin = '0';
  131. }
  132. if(item.xtype == 'checkbox') {
  133. item.focusCls = '';
  134. }
  135. if (hasData) {
  136. item.value = data[item.name];
  137. if(item.secondname){//针对合并型的字段MultiField
  138. item.secondvalue = data[item.secondname];
  139. }
  140. if(!edit){
  141. form.readOnly = true;
  142. item.fieldStyle = item.fieldStyle + ';background:#f1f1f1;';
  143. item.readOnly = true;
  144. }
  145. if(item.xtype == 'checkbox'){
  146. item.checked = Math.abs(item.value || 0) == 1;
  147. item.fieldStyle = '';
  148. }
  149. }
  150. if(limitArr.length > 0 && Ext.Array.contains(limitArr, item.name)) {
  151. item.hidden = true;
  152. }
  153. if(item.html&&item.name == null&&item.value==''){
  154. }else{
  155. if(bool == 'b') {
  156. item.columnWidth = item.columnWidth*0.83;
  157. }
  158. if(bool == 'c') {
  159. item.columnWidth = item.columnWidth*0.85;
  160. }
  161. }
  162. if(item.logic=='changeCodeField'){
  163. form.changeCodeField=item.name;
  164. }
  165. if(item.logic!='changeKeyField' && item.logic!='changeCodeField' && item.xtype=='dbfindtrigger'){
  166. item.readOnly=true;
  167. }
  168. if(item.id!=null && (item.table ==null || item.table !='commonchangelog') && item.logic!='changeKeyField' && item.logic!='changeCodeField'){
  169. o=Ext.clone(item);
  170. o.id=o.id+"-new";
  171. o.triggerName=o.name;
  172. o.name=o.name+"-new";
  173. o.isCommonChange=true;
  174. if (data!=null) o.value=data[o.name];
  175. o.readOnly=false;
  176. if(item.logic=='readOnly'){
  177. o.readOnly=true;
  178. }
  179. o.group=10;
  180. array.push(o);
  181. if(data&&data[item.id]!=data[o.id]){
  182. o.labelStyle = 'color:red';
  183. }
  184. item.readOnly=true;
  185. form.changeFields.push(item.name);
  186. }else form.LogFields.push(item.name);
  187. });
  188. // 字段少的form
  189. if(form.minMode) {
  190. Ext.each(array, function(item){
  191. if(item.columnWidth >= 0 && item.columnWidth < 0.5){
  192. item.columnWidth = 0.5;
  193. } else if(item.columnWidth >= 0.5) {
  194. item.columnWidth = 1;
  195. }
  196. });
  197. }
  198. allItems.changeItems=array;
  199. allItems.baseItems=items;
  200. return allItems;
  201. },
  202. getChangeGroupItem:function(){
  203. var o=new Object();
  204. o.html = "<div onclick=\"javascript:collapse(" + 10+ ");\" class=\"x-form-group-label\" id=\"group"
  205. + 10 + "\" style=\"background-color: #bfbfbe;\" title=\"收拢\"><h6>变更后</h6></div>";
  206. o.columnWidth = 1;
  207. o.xtype = "label";
  208. o.cls = "";
  209. return o;
  210. },
  211. getLogValues:function(form){
  212. var values=form.getForm.getValues(),logvalues=new Object();
  213. Ext.Array.each(form.LogFields,function(field){
  214. logvalues[field]=values[field];
  215. });
  216. return logvalues;
  217. },
  218. getRecord:function(formCondition){
  219. var record=null;
  220. Ext.Ajax.request({
  221. url : basePath + 'common/getFieldsData.action',
  222. params : {
  223. fields:'cl_data,cl_status,cl_statuscode,cl_auditman,cl_auditdate',
  224. caller:'commonchangelog',
  225. condition:formCondition
  226. },
  227. async:false,
  228. method : 'post',
  229. callback : function(options,success,response){
  230. var localJson = new Ext.decode(response.responseText);
  231. if(localJson.success){
  232. var data=localJson.data;
  233. data.cl_data.cl_status=data.cl_status;
  234. data.cl_data.cl_statuscode=data.cl_statuscode;
  235. data.cl_data.cl_auditman=data.cl_auditman;
  236. data.cl_data.cl_auditdate=data.cl_auditdate;
  237. record=data.cl_data;
  238. }
  239. }
  240. });
  241. return record;
  242. },
  243. getbuttons:function(caller){
  244. var buttons=null;
  245. Ext.Ajax.request({
  246. url : basePath + 'common/getFieldData.action',
  247. params : {
  248. field:'Fo_Button4rw',
  249. caller:'Form',
  250. condition:"fo_caller='"+caller+"'"
  251. },
  252. async:false,
  253. method : 'post',
  254. callback : function(options,success,response){
  255. var localJson = new Ext.decode(response.responseText);
  256. if(localJson.success){
  257. buttons=localJson.data;
  258. }
  259. }
  260. });
  261. return buttons;
  262. },
  263. loadInitData:function(form,field){
  264. var me=this;
  265. Ext.Ajax.request({
  266. url : basePath + 'common/getFieldsData.action',
  267. async: false,
  268. params: {
  269. caller: form.tablename,
  270. fields: form.changeFields.join(","),
  271. condition: field.name+'=\'' + field.value + '\''
  272. },
  273. method : 'post',
  274. callback : function(opt, s, res){
  275. var r = new Ext.decode(res.responseText);
  276. if(r.exceptionInfo){
  277. showError(r.exceptionInfo);return;
  278. } else if(r.success && r.data){
  279. me.setFormData(form,r.data);
  280. }
  281. }
  282. });
  283. },
  284. setFormData:function(form,data){
  285. Ext.Array.each(form.changeFields,function(f){
  286. data[f+'-new']=data[f];
  287. });
  288. form.getForm().setValues(data);
  289. }
  290. });