universalform.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. define(['core', 'tpl'], function(core, tpl) {
  2. var modal = {};
  3. modal.getData = function(element) {
  4. var container = $(element);
  5. var cells = container.find('.fui-cell');
  6. var data = {};
  7. var stop = false;
  8. cells.each(function() {
  9. var $this = $(this);
  10. var itemid = $this.data('itemid'),
  11. field = '#' + itemid,
  12. must = $this.data('must') == '1',
  13. type = $this.data('type'),
  14. name = $this.data('name'),
  15. tp_is_default = $this.data('tp_is_default'),
  16. key = $this.data('key');
  17. if (must) {
  18. if (type == 0 || type == 1) {
  19. if ($(field).isEmpty()) {
  20. FoxUI.toast.show('请填写' + name);
  21. stop = true;
  22. return false
  23. }
  24. if (type == 0 && tp_is_default == 3) {
  25. if (!$(field).isMobile()) {
  26. FoxUI.toast.show('请填写' + name);
  27. stop = true;
  28. return false
  29. }
  30. }
  31. }
  32. if (type == 2) {
  33. if ($(field).isEmpty()) {
  34. FoxUI.toast.show('请选择' + name);
  35. stop = true;
  36. return false
  37. }
  38. }
  39. if (type == 3) {
  40. var j = 0;
  41. var checkeds = $(":checkbox[name^='" + itemid + "']:checked", $this).length;
  42. if (checkeds <= 0) {
  43. FoxUI.toast.show('请选择' + name);
  44. stop = true;
  45. return false
  46. }
  47. }
  48. if (type == 5) {
  49. if ($(field + '_images').find('li').length <= 0) {
  50. FoxUI.toast.show('请选择' + name);
  51. stop = true;
  52. return false
  53. }
  54. }
  55. if (type == 6) {
  56. if ($(field).isEmpty() || !$(field).isIDCard()) {
  57. FoxUI.toast.show('请填写正确的' + name);
  58. stop = true;
  59. return false
  60. }
  61. }
  62. if (type == 7) {
  63. if ($(field).isEmpty()) {
  64. FoxUI.toast.show('请选择' + name);
  65. stop = true;
  66. return false
  67. }
  68. }
  69. if (type == 8) {
  70. if ($(field + '_0').isEmpty() || $(field + '_1').isEmpty()) {
  71. FoxUI.toast.show('请选择' + name);
  72. stop = true;
  73. return false
  74. }
  75. }
  76. if (type == 9) {
  77. if ($(field).isEmpty()) {
  78. FoxUI.toast.show('请选择' + name);
  79. stop = true;
  80. return false
  81. }
  82. }
  83. }
  84. if (type == 0 && tp_is_default == 3) {
  85. if (!$(field).isEmpty() && !$(field).isMobile()) {
  86. FoxUI.toast.show('请填写' + name);
  87. stop = true;
  88. return false
  89. }
  90. }
  91. if (type == 6) {
  92. if (!$(field).isEmpty() && !$(field).isIDCard()) {
  93. FoxUI.toast.show('请填写正确的' + name);
  94. stop = true;
  95. return false
  96. }
  97. }
  98. if (type == 3) {
  99. data[key] = [];
  100. $("input[name^='" + itemid + "']:checked").each(function() {
  101. data[key].push($(this).val())
  102. })
  103. } else if (type == 5) {
  104. data[key] = [];
  105. $(field + '_images').find('li').each(function() {
  106. data[key].push($(this).data('filename'))
  107. })
  108. } else if (type == 8) {
  109. data[key + '_0'] = $(field + '_0').val();
  110. data[key + '_1'] = $(field + '_1').val()
  111. } else if (type == 9) {
  112. var citys = $(field).val().split(' ');
  113. var province = citys.length >= 1 ? citys[0] : '';
  114. var city = citys.length >= 2 ? citys[1] : '';
  115. data[key] = [province, city]
  116. } else {
  117. data[key] = $(field).val()
  118. }
  119. });
  120. if (stop) {
  121. return false
  122. }
  123. return data
  124. };
  125. return modal
  126. });