人民医院前端

myflow.editors.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. (function ($) {
  2. var o = $.myflow;
  3. $.extend(true, o.editors, {
  4. inputEditor: function () {
  5. var d, _k, _div, _src, _r;
  6. this.init = function (a, k, b, c, r) {
  7. d = a;
  8. _k = k;
  9. _div = b;
  10. _src = c;
  11. _r = r;
  12. $('<input style="width:calc(100% - 6px);" title="' + (a[_k].title ? a[_k].title : '') + '"/>').val(a[_k].value).change(function () {
  13. a[_k].value = $(this).val()
  14. }).appendTo('#' + _div);
  15. $('#' + _div).data('editor', this)
  16. };
  17. this.destroy = function () {
  18. $('#' + _div + ' input').each(function () {
  19. d[_k].value = $(this).val()
  20. })
  21. }
  22. },
  23. selectEditor: function (i) {
  24. var j, _k, _div, _src, _r;
  25. this.init = function (d, k, e, f, r) {
  26. j = d;
  27. _k = k;
  28. _div = e;
  29. _src = f;
  30. _r = r;
  31. var g = $('<select style="width:100%;"/>').val(d[_k].value).change(function () {
  32. d[_k].value = $(this).val()
  33. }).appendTo('#' + _div);
  34. if (typeof i === 'string') {
  35. $.ajax({
  36. type: "GET",
  37. url: i,
  38. success: function (a) {
  39. var b = eval(a);
  40. if (b && b.length) {
  41. for (var c = 0; c < b.length; c++) {
  42. g.append('<option value="' + b[c].value + '">' + b[c].name + '</option>')
  43. };
  44. g.val(j[_k].value)
  45. }
  46. }
  47. })
  48. } else {
  49. for (var h = 0; h < i.length; h++) {
  50. g.append('<option value="' + i[h].value + '">' + i[h].name + '</option>')
  51. }
  52. g.val(j[_k].value)
  53. }
  54. $('#' + _div).data('editor', this)
  55. };
  56. this.destroy = function () {
  57. $('#' + _div + ' select').each(function () {
  58. j[_k].value = $(this).val()
  59. })
  60. }
  61. },
  62. tableEditor: function (h) {
  63. var j, _k, _div, _src, _r, _this = this;
  64. this.init = function (c, k, d, e, r) {
  65. j = c;
  66. _k = k;
  67. _div = d;
  68. _src = e;
  69. _r = r;
  70. var f = '<table id="children" style="width:calc(100% - 6px);" border="1" cellpadding="0" cellspacing="0"><tr>';
  71. for (var l in h) {
  72. f += '<th>' + h[l].label + '</th>'
  73. }
  74. f += '<th><button type="button" class="addrow" >+</button></th></tr></table>';
  75. $(f).appendTo('#' + _div).find(".addrow").click(function () {
  76. var a = '<tr class="item">';
  77. for (var l in h) {
  78. switch (h[l].type) {
  79. case 'input':
  80. a += '<td><input style="width:calc(100% - 6px);" class="' + h[l].name + '"/></td>';
  81. break;
  82. case 'select':
  83. a += '<td style="width:80px;"><select style="width:calc(100% - 6px);" class="' + h[l].name + '">';
  84. $(h[l].options).each(function (i, n) {
  85. a += '<option value="' + n.value + '">' + n.name + '</option>'
  86. });
  87. a += '</select></td>';
  88. break
  89. }
  90. };
  91. a += '<th><button type="button" class="delrow" >-</button></th></tr>';
  92. var b = $(a).appendTo('#children');
  93. b.find(".delrow").click(function () {
  94. $(this).parent().parent().remove();
  95. _this.destroy()
  96. });
  97. b.find('input').change(function () {
  98. _this.destroy()
  99. });
  100. b.find('select').change(function () {
  101. _this.destroy()
  102. });
  103. _this.destroy()
  104. });
  105. if (c[_k].value) {
  106. var g = JSON.parse(c[_k].value);
  107. $(g).each(function (i, n) {
  108. var a = '<tr class="item">';
  109. for (var l in h) {
  110. switch (h[l].type) {
  111. case 'input':
  112. a += '<td><input style="width:calc(100% - 6px);" class="' + h[l].name + '" value="' + n[h[l].name] + '"/></td>';
  113. break;
  114. case 'select':
  115. a += '<td style="width:80px;"><select style="width:calc(100% - 6px);" class="' + h[l].name + '">';
  116. $(h[l].options).each(function (i, m) {
  117. a += '<option value="' + m.value + '" ' + (m.value == n[h[l].name] ? 'selected' : '') + '>' + m.name + '</option>'
  118. });
  119. a += '</select></td>';
  120. break
  121. }
  122. };
  123. a += '<th><button type="button" class="delrow" >-</button></th></tr>';
  124. var b = $(a).appendTo('#children');
  125. b.find(".delrow").click(function () {
  126. $(this).parent().parent().remove();
  127. _this.destroy()
  128. });
  129. b.find('input').change(function () {
  130. _this.destroy()
  131. });
  132. b.find('select').change(function () {
  133. _this.destroy()
  134. })
  135. })
  136. };
  137. $('#' + _div).data('editor', this)
  138. };
  139. this.destroy = function () {
  140. var b = [];
  141. $('#' + _div + ' .item').each(function () {
  142. var a = {};
  143. for (var l in h) {
  144. a[h[l].name] = $(this).find("." + h[l].name).val()
  145. }
  146. b.push(a)
  147. });
  148. j[_k].value = JSON.stringify(b)
  149. }
  150. },
  151. })
  152. })(jQuery);