comment.js 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: 'shop/comment/index' + location.search,
  8. add_url: 'shop/comment/add',
  9. edit_url: 'shop/comment/edit',
  10. del_url: 'shop/comment/del',
  11. multi_url: 'shop/comment/multi',
  12. import_url: 'shop/comment/import',
  13. table: 'shop_comment',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search},
  29. {field: 'user.nickname', title: __('Nickname')},
  30. {field: 'order_id', title: __('Order_id')},
  31. // {field: 'pid', title: __('Pid')},
  32. {field: 'goods.title', title: __('Goods')},
  33. {field: 'star', title: __('Star')},
  34. {field: 'content', title: __('Content'), formatter: Controller.api.content},
  35. {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  36. // {field: 'subscribe', title: __('Subscribe')},
  37. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
  38. {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, visible: false},
  39. {field: 'status', title: __('Status'), searchList: {"normal": __('Normal'), "hidden": __('Hidden')}, formatter: Table.api.formatter.status},
  40. {
  41. field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [{
  42. name: '回复',
  43. title: function (row) {
  44. return '回复(' + (row.user ? row.user.nickname : '未知') + ')';
  45. },
  46. classname: 'btn btn-xs btn-primary btn-dialog',
  47. text: function (row) {
  48. return '回复(' + row.comments + ')';
  49. },
  50. icon: 'fa fa-comment',
  51. url: 'shop/comment/reply/pid/{id}'
  52. }]
  53. }
  54. ]
  55. ]
  56. });
  57. // 为表格绑定事件
  58. Table.api.bindevent(table);
  59. },
  60. add: function () {
  61. Controller.api.bindevent();
  62. },
  63. edit: function () {
  64. Controller.api.bindevent();
  65. },
  66. reply: function () {
  67. let refresh = function () {
  68. window.location.reload();
  69. parent.$("#table").bootstrapTable('refresh', {});
  70. }
  71. $(document).on('click', '.btn-reply', function () {
  72. Form.api.submit($("form[role=form]"));
  73. setTimeout(refresh, 1500)
  74. })
  75. $('.btn-delone').data('success', refresh)
  76. $('.btn-dialog').data('end', refresh)
  77. Controller.api.bindevent();
  78. },
  79. api: {
  80. bindevent: function () {
  81. Form.api.bindevent($("form[role=form]"));
  82. },
  83. content: function (value, row, index) {
  84. var width = this.width != undefined ? (this.width.match(/^\d+$/) ? this.width + "px" : this.width) : "250px";
  85. return "<div style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + ";' title='" + value + "' data-toggle='tooltip' data-placement='right'>" + value + "</div>";
  86. },
  87. }
  88. };
  89. return Controller;
  90. });