ProductForm.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. Ext.define('erp.view.plm.base.ProductForm',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpProductFormPanel',
  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. keyField: '',
  25. codeField: '',
  26. statusField: '',
  27. params: null,
  28. caller: null,
  29. Contextvalue:null,
  30. LastValue:null,
  31. enableTools: true,
  32. enableKeyEvents: true,
  33. initComponent : function(){
  34. formCondition = getUrlParam('formCondition');//从url解析参数
  35. formCondition = (formCondition == null) ? "" : formCondition.replace(/IS/g,"=");
  36. var param = {caller: this.caller || caller, condition: formCondition};
  37. this.FormUtil.getItemsAndButtons(this, 'common/singleFormItems.action', this.params || param);//从后台拿到formpanel的items
  38. this.callParent(arguments);
  39. //加prev、next、refresh等tool
  40. if(this.enableTools) {
  41. this.setTools();
  42. }
  43. //给页面加上ctrl+alt+s键盘事件,自动跳转form配置界面
  44. if(this.enableKeyEvents) {
  45. this.addKeyBoardEvents();
  46. }
  47. },
  48. getItemsAndButtons:function(){
  49. var me = this;
  50. Ext.Ajax.request({//拿到form的items
  51. url : basePath + url,
  52. params: param,
  53. method : 'post',
  54. callback : function(options,success,response){
  55. me.getActiveTab().setLoading(false);
  56. var res = new Ext.decode(response.responseText);
  57. if(res.exceptionInfo != null){
  58. showError(res.exceptionInfo);return;
  59. }
  60. form.fo_id = res.fo_id;
  61. form.fo_keyField = res.fo_keyField;
  62. form.tablename = res.tablename;//表名
  63. if(res.keyField){//主键
  64. form.keyField = res.keyField;
  65. }
  66. if(res.statusField){//状态
  67. form.statusField = res.statusField;
  68. }
  69. if(res.statuscodeField){//状态码
  70. form.statuscodeField = res.statuscodeField;
  71. }
  72. if(res.codeField){//Code
  73. form.codeField = res.codeField;
  74. }
  75. form.fo_detailMainKeyField = res.fo_detailMainKeyField;//从表外键字段
  76. //data&items
  77. var items = me.setItems(form, res.items, res.data, res.limits);
  78. form.add(items);
  79. //title
  80. if(res.title && res.title != ''){
  81. form.setTitle(res.title);
  82. }
  83. //解析buttons
  84. me.setButtons(form, res.buttons);
  85. //form第一个可编辑框自动focus
  86. me.focusFirst(form);
  87. }
  88. });
  89. } ,
  90. setItems: function(form, items, data, limits){
  91. var edit = true,hasData = true,limitArr = new Array();
  92. if(limits != null && limits.length > 0) {//权限外字段
  93. limitArr = Ext.Array.pluck(limits, 'lf_field');
  94. }
  95. if (data) {
  96. data = Ext.decode(data);
  97. if(form.statuscodeField && data[form.statuscodeField] != null &&
  98. !(data[form.statuscodeField] == 'ENTERING' || data[form.statuscodeField] == 'UNAUDIT')){//非在录入和已提交均设置为只读// && data[form.statuscodeField] != 'COMMITED'
  99. form.readOnly = true;
  100. edit = false;
  101. }
  102. } else {
  103. hasData = false;
  104. }
  105. var bool = false;
  106. if(items.length > 110){
  107. bool = true;
  108. }
  109. Ext.each(items, function(item){
  110. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  111. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  112. item.columnWidth = 1/3;
  113. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  114. item.columnWidth = 2/3;
  115. } else if(item.columnWidth >= 1){
  116. item.columnWidth = 1;
  117. }
  118. } else {
  119. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  120. item.columnWidth = 1/3;
  121. } else if(item.columnWidth > 0.5 && item.columnWidth < 0.75){
  122. item.columnWidth = 2/3;
  123. }
  124. }
  125. if(item.name == form.statusField){//状态加特殊颜色
  126. item.fieldStyle = item.fieldStyle + ';font-weight:bold;';
  127. } else if(item.name == form.statuscodeField){//状态码字段强制隐藏
  128. item.xtype = 'hidden';
  129. }
  130. if (hasData) {
  131. item.value = data[item.name];
  132. if(item.secondname){//针对合并型的字段MultiField
  133. item.secondvalue = data[item.secondname];
  134. }
  135. if(!edit){
  136. form.readOnly = true;
  137. item.fieldStyle = item.fieldStyle + ';background:#f1f1f1;';
  138. item.readOnly = true;
  139. }
  140. if(item.xtype == 'checkbox' && Math.abs(item.value || 0) == 1){
  141. item.checked = true;
  142. }
  143. }
  144. if(limitArr.length > 0 && Ext.Array.contains(limitArr, item.name)) {
  145. item.hidden = true;
  146. }
  147. if(bool) {
  148. item.columnWidth = item.columnWidth*0.83;
  149. }
  150. });
  151. return items;
  152. },
  153. });