comment.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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: __('User_id'), formatter: Table.api.formatter.search,visible: false},
  46. {
  47. field: 'user.username',
  48. title: __('User_id'),
  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: __('Order_id')},
  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: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
  69. {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, visible: false},
  70. {field: 'status', title: __('Status'), searchList: Controller.api.parseConfigJson('statusSearchList'), formatter: Table.api.formatter.status},
  71. {
  72. field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
  73. buttons: [
  74. {
  75. name: '审核通过',
  76. title: '审核通过',
  77. classname: 'btn btn-xs btn-success btn-ajax',
  78. text: '审核通过',
  79. icon: 'fa fa-check',
  80. url: 'shop/comment/audit/evaluate_status/2',
  81. visible: function (row) {
  82. //返回true时按钮显示,返回false隐藏
  83. return row.evaluate_status == 1;
  84. },
  85. confirm: '确认审核通过吗',
  86. success: function (data, ret) {
  87. Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
  88. //如果需要阻止成功提示,则必须使用return false;
  89. //return false;
  90. },
  91. error: function (data, ret) {
  92. console.log(data, ret);
  93. Layer.alert(ret.msg);
  94. return false;
  95. }
  96. },
  97. {
  98. name: '审核拒绝',
  99. title: '审核拒绝',
  100. classname: 'btn btn-xs btn-danger btn-ajax',
  101. text: '审核拒绝',
  102. icon: 'fa fa-close',
  103. url: 'shop/comment/audit/evaluate_status/3',
  104. visible: function (row) {
  105. //返回true时按钮显示,返回false隐藏
  106. return row.evaluate_status == 1;
  107. },
  108. confirm: '确认审核拒绝吗',
  109. success: function (data, ret) {
  110. Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
  111. //如果需要阻止成功提示,则必须使用return false;
  112. //return false;
  113. },
  114. error: function (data, ret) {
  115. console.log(data, ret);
  116. Layer.alert(ret.msg);
  117. return false;
  118. }
  119. },
  120. // {
  121. // name: '回复',
  122. // title: function (row) {
  123. // return '回复(' + (row.user ? row.user.nickname : '未知') + ')';
  124. // },
  125. // classname: 'btn btn-xs btn-primary btn-dialog',
  126. // text: function (row) {
  127. // return '回复(' + row.comments + ')';
  128. // },
  129. // icon: 'fa fa-comment',
  130. // url: 'shop/comment/reply/pid/{id}'
  131. // }
  132. ]
  133. }
  134. ]
  135. ]
  136. });
  137. // 为表格绑定事件
  138. Table.api.bindevent(table);
  139. },
  140. add: function () {
  141. Controller.api.bindevent();
  142. },
  143. edit: function () {
  144. Controller.api.bindevent();
  145. },
  146. reply: function () {
  147. let refresh = function () {
  148. window.location.reload();
  149. parent.$("#table").bootstrapTable('refresh', {});
  150. }
  151. $(document).on('click', '.btn-reply', function () {
  152. Form.api.submit($("form[role=form]"));
  153. setTimeout(refresh, 1500)
  154. })
  155. $('.btn-delone').data('success', refresh)
  156. $('.btn-dialog').data('end', refresh)
  157. Controller.api.bindevent();
  158. },
  159. api: {
  160. // 解析Config中的JSON字符串的辅助函数
  161. parseConfigJson: function(configKey, defaultValue) {
  162. var configValue = Config[configKey] || defaultValue || {};
  163. // 如果是字符串,尝试解析JSON
  164. if (typeof configValue === 'string') {
  165. try {
  166. return JSON.parse(configValue);
  167. } catch (e) {
  168. return defaultValue || {};
  169. }
  170. }
  171. return configValue;
  172. },
  173. bindevent: function () {
  174. Form.api.bindevent($("form[role=form]"));
  175. },
  176. content: function (value, row, index) {
  177. var width = this.width != undefined ? (this.width.match(/^\d+$/) ? this.width + "px" : this.width) : "250px";
  178. return "<div style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + ";' title='" + value + "' data-toggle='tooltip' data-placement='right'>" + value + "</div>";
  179. }
  180. }
  181. };
  182. return Controller;
  183. });