yvselect.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. define(function (require) {
  2. return function () {
  3. var $form, $select1;
  4. var data1 = [
  5. { id: '千米', text: '千米(km)' },
  6. { id: '米', text: '米(m)' },
  7. { id: '分米', text: '分米(dm)' },
  8. { id: '厘米', text: '厘米(cm)' },
  9. { id: '毫米', text: '毫米(mm)' },
  10. { id: '微米', text: '微米(um)' },
  11. { id: '纳米', text: '纳米(nm)' },
  12. { id: '皮米', text: '皮米(pm)' },
  13. { id: '光年', text: '光年(ly)' },
  14. { id: '天文单位', text: '天文单位(AU)' },
  15. { id: '英寸', text: '英寸(in)' },
  16. { id: 'inch', text: 'inch(in)' },
  17. { id: '英尺', text: '英尺(ft)' },
  18. { id: '码', text: '码(yd)' },
  19. { id: '英里', text: '英里(mi)' },
  20. { id: '海里', text: '海里(nmi)' },
  21. { id: '英寻', text: '英寻(fm)' },
  22. { id: '弗隆', text: '弗隆(fur)' },
  23. { id: '里', text: '里' },
  24. { id: '丈', text: '丈' },
  25. { id: '尺', text: '尺' },
  26. { id: '寸', text: '寸' },
  27. { id: '分', text: '分' },
  28. { id: '厘', text: '厘' },
  29. { id: '毫', text: '毫' },
  30. ];
  31. var data2 = [
  32. {
  33. text: '公制', children: [
  34. { id: '千米', text: '千米(km)' },
  35. { id: '米', text: '米(m)' },
  36. { id: '分米', text: '分米(dm)' },
  37. { id: '厘米', text: '厘米(cm)' },
  38. { id: '毫米', text: '毫米(mm)' },
  39. { id: '微米', text: '微米(um)' },
  40. { id: '纳米', text: '纳米(nm)' },
  41. { id: '皮米', text: '皮米(pm)' },
  42. { id: '光年', text: '光年(ly)' },
  43. { id: '天文单位', text: '天文单位(AU)' },
  44. ],
  45. }, {
  46. text: '英制', children: [
  47. { id: '英寸', text: '英寸(in)' },
  48. { id: 'inch', text: 'inch(in)' },
  49. { id: '英尺', text: '英尺(ft)' },
  50. { id: '码', text: '码(yd)' },
  51. { id: '英里', text: '英里(mi)' },
  52. { id: '海里', text: '海里(nmi)' },
  53. { id: '英寻', text: '英寻(fm)' },
  54. { id: '弗隆', text: '弗隆(fur)' },
  55. ],
  56. }, {
  57. text: '市制', children: [
  58. { id: '里', text: '里' },
  59. { id: '丈', text: '丈' },
  60. { id: '尺', text: '尺' },
  61. { id: '寸', text: '寸' },
  62. { id: '分', text: '分' },
  63. { id: '厘', text: '厘' },
  64. { id: '毫', text: '毫' },
  65. ],
  66. }
  67. ];
  68. return {
  69. center: {
  70. items: {
  71. xtype: 'form',
  72. onRender: function () {
  73. $form = $(this);
  74. },
  75. items: [
  76. [
  77. {
  78. xtype: 'yvselect', name: 'packingType', label: '系统标准', required: true,
  79. onRender: function () {
  80. $select1 = $(this);
  81. },
  82. data: data1,
  83. onChange: function (newValue, e) {
  84. console.log('packingType onChange:"' + newValue + '"', e);
  85. }
  86. },
  87. ], [
  88. {
  89. xtype: 'yvselect', name: 'unit', label: '单位转换', required: true,
  90. data: data2,
  91. onChange: function (newValue, e) {
  92. console.log('unit onChange:"' + newValue + '"', e);
  93. }
  94. },
  95. ], [
  96. {
  97. xtype: 'yvselect', name: 'unit2', label: '多选', required: true,
  98. span: 2,
  99. multiple: true,
  100. minTagLength: 1,
  101. maxTagLength: 3,
  102. data: data2,
  103. onChange: function (newValue, e) {
  104. console.log('unit2 onChange:"' + newValue + '"', e);
  105. }
  106. },
  107. ], [
  108. {
  109. xtype: 'textbox', name: 'custom', label: '自定义', required: true
  110. },
  111. {
  112. xtype: 'textbox', name: 'custom2', label: '自定义2', required: true
  113. },
  114. ], [
  115. { xtype: 'offset' },
  116. {
  117. xtype: 'button', text: '设值', onClick: function () {
  118. $form.formSet({
  119. custom: '自定义1',
  120. custom2: '自定义2',
  121. packingType: '米',
  122. unit: '英寸',
  123. unit2: '米,光年'
  124. });
  125. }
  126. },
  127. {
  128. xtype: 'button', text: '取值', onClick: function () {
  129. $.yvan.alert(JSON.stringify(
  130. $form.formGet(),
  131. null, " "));
  132. }
  133. },
  134. {
  135. xtype: 'button', text: '清空', onClick: function () {
  136. $form.formClear();
  137. }
  138. },
  139. {
  140. xtype: 'button', text: '校验', onClick: function () {
  141. $.yvan.postForm($form, {
  142. url: demoApi('/aaa')
  143. });
  144. }
  145. }
  146. ], [
  147. { xtype: 'offset' },
  148. {
  149. xtype: 'button', text: 'mulpGet', onClick: function () {
  150. var $unit2 = $form.item('unit2');
  151. $.yvan.alert(JSON.stringify(
  152. $unit2.yvselect('getValue'),
  153. null, " "));
  154. }
  155. },
  156. {
  157. xtype: 'button', text: 'mulpSet', onClick: function () {
  158. var $unit2 = $form.item('unit2');
  159. $unit2.yvselect('setValue', ['米', '千米']);
  160. }
  161. },
  162. ], [
  163. { xtype: 'offset' },
  164. {
  165. xtype: 'button',
  166. text: '动态更改',
  167. onClick: function () {
  168. $select1.yvselect({ data: data2 });
  169. }
  170. },
  171. ]
  172. ]
  173. }
  174. }
  175. };
  176. };
  177. });