response.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte'], function ($, undefined, Backend, Table, Form, Adminlte) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'wechat/response/index',
  8. add_url: 'wechat/response/add',
  9. edit_url: 'wechat/response/edit',
  10. del_url: 'wechat/response/del',
  11. multi_url: 'wechat/response/multi',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url: $.fn.bootstrapTable.defaults.extend.index_url,
  18. sortName: 'id',
  19. columns: [
  20. [
  21. {field: 'state', checkbox: true,},
  22. {field: 'id', title: 'ID'},
  23. {field: 'type', title: __('Type')},
  24. {field: 'title', title: __('Resource title')},
  25. {field: 'eventkey', title: __('Event key')},
  26. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, operate: false},
  27. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  28. ]
  29. ]
  30. });
  31. // 为表格绑定事件
  32. Table.api.bindevent(table);
  33. },
  34. select: function () {
  35. // 初始化表格参数配置
  36. Table.api.init({
  37. extend: {
  38. index_url: 'wechat/response/index',
  39. }
  40. });
  41. var table = $("#table");
  42. // 初始化表格
  43. table.bootstrapTable({
  44. url: $.fn.bootstrapTable.defaults.extend.index_url,
  45. sortName: 'id',
  46. columns: [
  47. [
  48. {field: 'state', checkbox: true,},
  49. {field: 'id', title: 'ID'},
  50. {field: 'type', title: __('Type')},
  51. {field: 'title', title: __('Title')},
  52. {field: 'eventkey', title: __('Event key')},
  53. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, operate: false},
  54. {
  55. field: 'operate', title: __('Operate'), events: {
  56. 'click .btn-chooseone': function (e, value, row, index) {
  57. Fast.api.close(row);
  58. },
  59. }, formatter: function () {
  60. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  61. }
  62. }
  63. ]
  64. ]
  65. });
  66. // 为表格绑定事件
  67. Table.api.bindevent(table);
  68. },
  69. add: function () {
  70. Form.api.bindevent($("form[role=form]"), function (data) {
  71. Fast.api.close(data);
  72. });
  73. Controller.api.bindevent();
  74. },
  75. edit: function () {
  76. Form.api.bindevent($("form[role=form]"));
  77. Controller.api.bindevent();
  78. },
  79. api: {
  80. bindevent: function () {
  81. var getAppFileds = function (id) {
  82. var app = apps[id];
  83. var appConfig = app['config'];
  84. var str = '';
  85. for (var i in appConfig) {
  86. var type = appConfig[i]['type'];
  87. var field = appConfig[i]['field'];
  88. var caption = appConfig[i]['caption'];
  89. var defaultvalue = typeof appConfig[i]['defaultvalue'] != 'undefined' ? appConfig[i]['defaultvalue'] : '';
  90. if (type == 'text' || type == 'textarea') {
  91. if (type == 'textarea') {
  92. str += '<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">' + caption + ':</label><div class="col-xs-12 col-sm-8"><textarea ' + appConfig[i]['extend'] + ' class="form-control" name="row[content][' + field + ']" data-rule="' + appConfig[i]['rule'] + '">' + defaultvalue + '</textarea> </div> </div>';
  93. } else {
  94. str += '<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">' + caption + ':</label><div class="col-xs-12 col-sm-8"><input ' + appConfig[i]['extend'] + ' class="form-control" name="row[content][' + field + ']" type="text" value="' + defaultvalue + '" data-rule="' + appConfig[i]['rule'] + '"> </div> </div>';
  95. }
  96. } else {
  97. var options = appConfig[i]['options'];
  98. var html = '';
  99. if (type == 'select') {
  100. for (var j in options) {
  101. html += '<option value="' + j + '">' + options[j] + '</option>';
  102. }
  103. html = '<select ' + appConfig[i]['extend'] + ' class="form-control" name="row[content][' + field + ']">' + html + '</select>';
  104. } else if (type == 'checkbox') {
  105. for (var j in options) {
  106. html += '<input type="checkbox" name="row[content][' + field + '][]" value="' + j + '"> <span>' + options[j] + '</span> ';
  107. }
  108. } else if (type == 'radio') {
  109. var index = 0;
  110. for (var j in options) {
  111. html += '<input type="radio" name="row[content][' + field + ']" value="' + j + '" ' + (index == 0 ? 'checked' : '') + '> <span>' + options[j] + '</span> ';
  112. index++;
  113. }
  114. }
  115. str += '<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">' + caption + ':</label><div class="col-xs-12 col-sm-8">' + html + ' </div> </div>';
  116. }
  117. }
  118. return str;
  119. };
  120. $(document).on('change', "#app", function () {
  121. var app = $(this).val();
  122. $("#appfields").html(getAppFileds(app));
  123. if (datas.app == app) {
  124. delete (datas.app);
  125. var form = $("form.form-ajax");
  126. $.each(datas, function (i, j) {
  127. console.log(i, j);
  128. form.field("row[content][" + i + "]" + ($("input[name='row[content][" + i + "][]']", form).size() > 0 ? '[]' : ''), j);
  129. });
  130. }
  131. Form.api.bindevent("#appfields");
  132. });
  133. $(document).on('click', "input[name='row[type]']", function () {
  134. var type = $(this).val();
  135. if (type == 'text') {
  136. $("#expand").html('<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">文本内容:</label><div class="col-xs-12 col-sm-8"><textarea class="form-control" name="row[content][content]" data-rule="required"></textarea></div></div>');
  137. $("form[role='form']").field("row[content][content]", datas.content);
  138. } else if (type == 'app') {
  139. $("#expand").html('<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">应用:</label><div class="col-xs-12 col-sm-8"><select class="form-control" name="row[content][app]" id="app">' + $("select[name=applist]").html() + '</select></div></div><div id="appfields"><div>');
  140. $("form[role='form']").field("row[content][app]", datas.app);
  141. $("#app").trigger('change');
  142. }
  143. });
  144. $("input[name='row[type]']:checked").trigger("click");
  145. }
  146. }
  147. };
  148. return Controller;
  149. });