comment.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // 绑定评价状态tab事件
  18. $('.panel-heading .nav-tabs[data-field="evaluate_status"] a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  19. var value = $(this).data("value");
  20. var options = table.bootstrapTable('getOptions');
  21. var queryParams = options.queryParams;
  22. options.pageNumber = 1;
  23. options.queryParams = function (params) {
  24. if (value) {
  25. params.filter = JSON.stringify({evaluate_status: value});
  26. params.op = JSON.stringify({evaluate_status: '='});
  27. }
  28. params = queryParams.call(this, params);
  29. return params;
  30. };
  31. table.bootstrapTable('refresh', {});
  32. return false;
  33. });
  34. // 初始化表格
  35. table.bootstrapTable({
  36. url: $.fn.bootstrapTable.defaults.extend.index_url,
  37. pk: 'id',
  38. sortName: 'id',
  39. fixedColumns: true,
  40. fixedRightNumber: 1,
  41. columns: [
  42. [
  43. {checkbox: true},
  44. {field: 'id', title: __('Id')},
  45. {field: 'user_id', title: __('会员信息'), formatter: Table.api.formatter.search,visible: false},
  46. {
  47. field: 'user.username',
  48. title: __('会员信息'),
  49. operate: 'LIKE',
  50. formatter: function (value, row, index) {
  51. // 显示用户头像和用户名
  52. console.log(row);
  53. var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
  54. var username = row.user && row.user.username ? row.user.username : '游客';
  55. return '<div style="display:flex;align-items:center;">' +
  56. '<img src="' + avatar + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
  57. '<span style="color:#a55bff;">' + username + '</span>' +
  58. '</div>';
  59. }
  60. },
  61. {field: 'order_id', title: __('订单序号')},
  62. // {field: 'pid', title: __('Pid')},
  63. {field: 'goods.title', title: __('Goods')},
  64. {field: 'star', title: __('Star')},
  65. {field: 'content', title: __('Content'), formatter: Controller.api.content},
  66. {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  67. // {field: 'subscribe', title: __('Subscribe')},
  68. {field: 'evaluate_status', title: __('Evaluate_status'), searchList: Controller.api.parseConfigJson('evaluateStatusSearchList'), formatter: Table.api.formatter.status},
  69. {field: 'status', title: __('Status'), searchList: Controller.api.parseConfigJson('statusSearchList'), formatter: Table.api.formatter.status},
  70. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
  71. {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, visible: false},
  72. {
  73. field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
  74. buttons: [
  75. {
  76. name: '审核通过',
  77. title: '审核通过',
  78. classname: 'btn btn-xs btn-success btn-ajax',
  79. text: '审核通过',
  80. icon: 'fa fa-check',
  81. url: 'shop/comment/audit/evaluate_status/2',
  82. visible: function (row) {
  83. //返回true时按钮显示,返回false隐藏
  84. return row.evaluate_status == 1;
  85. },
  86. confirm: '确认审核通过吗',
  87. success: function (data, ret) {
  88. table.bootstrapTable('refresh'); //自动刷新
  89. },
  90. error: function (data, ret) {
  91. console.log(data, ret);
  92. Layer.alert(ret.msg);
  93. return false;
  94. }
  95. },
  96. {
  97. name: '审核拒绝',
  98. title: '审核拒绝',
  99. classname: 'btn btn-xs btn-danger btn-ajax',
  100. text: '审核拒绝',
  101. icon: 'fa fa-close',
  102. url: 'shop/comment/audit/evaluate_status/3',
  103. visible: function (row) {
  104. //返回true时按钮显示,返回false隐藏
  105. return row.evaluate_status == 1;
  106. },
  107. confirm: '确认审核拒绝吗',
  108. success: function (data, ret) {
  109. table.bootstrapTable('refresh'); //自动刷新
  110. },
  111. error: function (data, ret) {
  112. console.log(data, ret);
  113. Layer.alert(ret.msg);
  114. return false;
  115. }
  116. },
  117. // {
  118. // name: '回复',
  119. // title: function (row) {
  120. // return '回复(' + (row.user ? row.user.nickname : '未知') + ')';
  121. // },
  122. // classname: 'btn btn-xs btn-primary btn-dialog',
  123. // text: function (row) {
  124. // return '回复(' + row.comments + ')';
  125. // },
  126. // icon: 'fa fa-comment',
  127. // url: 'shop/comment/reply/pid/{id}'
  128. // }
  129. ]
  130. }
  131. ]
  132. ]
  133. });
  134. // 为表格绑定事件
  135. Table.api.bindevent(table);
  136. },
  137. add: function () {
  138. Controller.api.bindevent();
  139. },
  140. edit: function () {
  141. Controller.api.bindevent();
  142. },
  143. reply: function () {
  144. let refresh = function () {
  145. window.location.reload();
  146. parent.$("#table").bootstrapTable('refresh', {});
  147. }
  148. $(document).on('click', '.btn-reply', function () {
  149. Form.api.submit($("form[role=form]"));
  150. setTimeout(refresh, 1500)
  151. })
  152. $('.btn-delone').data('success', refresh)
  153. $('.btn-dialog').data('end', refresh)
  154. Controller.api.bindevent();
  155. },
  156. api: {
  157. // 解析Config中的JSON字符串的辅助函数
  158. parseConfigJson: function(configKey, defaultValue) {
  159. var configValue = Config[configKey] || defaultValue || {};
  160. // 如果是字符串,尝试解析JSON
  161. if (typeof configValue === 'string') {
  162. try {
  163. return JSON.parse(configValue);
  164. } catch (e) {
  165. return defaultValue || {};
  166. }
  167. }
  168. return configValue;
  169. },
  170. bindevent: function () {
  171. Form.api.bindevent($("form[role=form]"));
  172. },
  173. content: function (value, row, index) {
  174. var width = this.width != undefined ? (this.width.match(/^\d+$/) ? this.width + "px" : this.width) : "250px";
  175. return "<div style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + ";' title='" + value + "' data-toggle='tooltip' data-placement='right'>" + value + "</div>";
  176. }
  177. }
  178. };
  179. return Controller;
  180. });