dynamic.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. define(function (require) {
  2. var $dynamicDiv, pcontext;
  3. function buildForm(props) {
  4. var items = [];
  5. for (var i = 0; i < props.length; i++) {
  6. var prop = props[i];
  7. var item = { name: prop.lotField, label: prop.lotName };
  8. switch ($.trim(prop.lotAttFlag)) {
  9. case '1':
  10. item.disabled = true;
  11. break;
  12. case '2':
  13. item.required = true;
  14. break;
  15. case '3':
  16. item.required = false;
  17. break;
  18. case '4':
  19. item.readonly = true;
  20. break;
  21. }
  22. switch ($.trim(prop.lotType)) {
  23. case '1':
  24. item.xtype = 'textbox';
  25. break;
  26. case '2':
  27. item.xtype = 'numberbox';
  28. break;
  29. case '3':
  30. item.xtype = 'datebox';
  31. break;
  32. case '4':
  33. item.xtype = 'datetimebox';
  34. break;
  35. default:
  36. item.xtype = 'textbox';
  37. break;
  38. }
  39. if ($.trim(prop.lotValue)) {
  40. item.xtype = 'combobox';
  41. item.data = $.yvan.bizDict(prop.lotValue).combo();
  42. }
  43. //items.push($.extend({}, $.fn[item.xtype].defaults, item));
  44. items.push(item);
  45. }
  46. $dynamicDiv.empty();
  47. $dynamicDiv.power('renderEach', {
  48. $target: $dynamicDiv,
  49. items: [items],
  50. context: pcontext
  51. });
  52. }
  53. return function (context) {
  54. var pcontext = context;
  55. return {
  56. center: {
  57. border: false,
  58. items: [
  59. {
  60. xtype: 'toolbar',
  61. title: '动态表单',
  62. items: [
  63. {
  64. text: '表单1', onClick: function () {
  65. $.yvan.ajax({
  66. url: whUrl('/lotAttributesRule/queryLotAttributesRuleDetail'),
  67. data: {
  68. lotRuleId: 'LOT00000005'
  69. },
  70. success: function (data) {
  71. buildForm(data.data);
  72. }
  73. });
  74. }
  75. },
  76. {
  77. text: '表单2', onClick: function () {
  78. $.yvan.ajax({
  79. url: whUrl('/lotAttributesRule/queryLotAttributesRuleDetail'),
  80. data: {
  81. lotRuleId: 'LOT00000006'
  82. },
  83. success: function (data) {
  84. buildForm(data.data);
  85. }
  86. });
  87. }
  88. },
  89. {
  90. text: '表单3', onClick: function () {
  91. $.yvan.ajax({
  92. url: whUrl('/lotAttributesRule/queryLotAttributesRuleDetail'),
  93. data: {
  94. lotRuleId: 'LOT00000007'
  95. },
  96. success: function (data) {
  97. buildForm(data.data);
  98. }
  99. });
  100. }
  101. }
  102. ]
  103. }, {
  104. onRender: function () {
  105. $dynamicDiv = $(this);
  106. },
  107. xtype: 'form'
  108. }, [
  109. { xtype: 'offset' },
  110. {
  111. xtype: 'button', text: '提交', onClick: function () {
  112. var vr = $dynamicDiv.formGet(true);
  113. console.log(vr);
  114. }
  115. },
  116. {
  117. xtype: 'button', text: '清空', onClick: function () {
  118. $dynamicDiv.formClear();
  119. }
  120. }
  121. ]
  122. ]
  123. }
  124. };
  125. };
  126. }
  127. );