keyword.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'weixin/reply/keyword/index' + location.search,
  8. add_url: 'weixin/reply/keyword/add',
  9. edit_url: 'weixin/reply/keyword/edit',
  10. del_url: 'weixin/reply/keyword/del',
  11. multi_url: 'weixin/reply/keyword/multi',
  12. table: 'weixin_reply',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'key', title: __('Key')},
  26. {field: 'type', title: __('Type'), searchList: {"text":__('Text'),"image":__('Image'),"news":__('News'),"voice":__('Voice')}, formatter: Table.api.formatter.normal},
  27. {field: 'status', title: __('Status'), operate: false, formatter: Controller.api.formatter.status},
  28. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  29. ]
  30. ]
  31. });
  32. // 为表格绑定事件
  33. Table.api.bindevent(table);
  34. },
  35. add: function () {
  36. Controller.api.bindevent();
  37. $("input[name='row[type]']:checked").trigger("click");
  38. },
  39. edit: function () {
  40. Controller.api.bindevent();
  41. $("input[name='row[type]']:checked").trigger("click");
  42. },
  43. api: {
  44. bindevent: function () {
  45. //不可见的元素不验证
  46. $("form[role=form]").data("validator-options", {ignore: ':hidden'});
  47. Form.api.bindevent($("form[role=form]"));
  48. //显示和隐藏
  49. $(document).on("click", "input[name='row[type]']", function () {
  50. var type = $("input[name='row[type]']:checked").val();
  51. $('.isshow').hide();
  52. $('.' + type).show();
  53. });
  54. },
  55. formatter: {//渲染的方法
  56. status: function (value, row, index) {
  57. if(row.status == "1"){
  58. return '<a class="btn-change text-success" data-url="weixin/template/routine/multi" data-params="status=0" data-id="' + row.id + '"><i class="fa fa-toggle-on fa-2x"></i></a>';
  59. }else{
  60. return '<a class="btn-change text-success" data-url="weixin/template/routine/multi" data-params="status=1" data-id="' + row.id + '"><i class="fa fa-toggle-on fa-flip-horizontal text-gray fa-2x"></i></a>';
  61. }
  62. }
  63. }
  64. }
  65. };
  66. return Controller;
  67. });