autoreply.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'wechat/autoreply/index',
  8. add_url: 'wechat/autoreply/add',
  9. edit_url: 'wechat/autoreply/edit',
  10. del_url: 'wechat/autoreply/del',
  11. multi_url: 'wechat/autoreply/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: 'title', title: __('Title')},
  24. {field: 'text', title: __('Text')},
  25. {field: 'eventkey', title: __('Event key')},
  26. {field: 'remark', title: __('Remark')},
  27. {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  28. {field: 'updatetime', title: __('Update time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  29. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  30. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  31. ]
  32. ]
  33. });
  34. // 为表格绑定事件
  35. Table.api.bindevent(table);
  36. },
  37. add: function () {
  38. Controller.api.bindevent();
  39. },
  40. edit: function () {
  41. Controller.api.bindevent();
  42. },
  43. api: {
  44. bindevent: function () {
  45. Form.api.bindevent($("form[role=form]"));
  46. var refreshkey = function (data) {
  47. $("input[name='row[eventkey]']").val(data.eventkey).trigger("change");
  48. Layer.closeAll();
  49. var keytitle = data.title;
  50. var cont = $(".clickbox .create-click:first");
  51. $(".keytitle", cont).remove();
  52. if (keytitle) {
  53. cont.append('<div class="keytitle">' + __('Event key') + ':' + keytitle + '</div>');
  54. }
  55. };
  56. $(document).on('click', "#select-resources", function () {
  57. var key = $("input[name='row[eventkey]']").val();
  58. parent.Backend.api.open($(this).attr("href") + "?key=" + key, __('Select'), {callback: refreshkey});
  59. return false;
  60. });
  61. $(document).on('click', "#add-resources", function () {
  62. parent.Backend.api.open($(this).attr("href") + "?key=", __('Add'), {callback: refreshkey});
  63. return false;
  64. });
  65. }
  66. }
  67. };
  68. return Controller;
  69. });