feedback.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var feedbackTypeList = {};
  3. var processStatusList = {};
  4. var statusList = {};
  5. var Controller = {
  6. index: function () {
  7. // 初始化表格参数配置
  8. Table.api.init({
  9. extend: {
  10. index_url: 'feedback/index' + location.search,
  11. add_url: 'feedback/add',
  12. edit_url: 'feedback/edit',
  13. del_url: 'feedback/del',
  14. multi_url: 'feedback/multi',
  15. import_url: 'feedback/import',
  16. table: 'shop_feedback',
  17. }
  18. });
  19. var table = $("#table");
  20. feedbackTypeList = JSON.parse(Config.feedbackTypeSearchList);
  21. processStatusList = JSON.parse(Config.processStatusSearchList);
  22. statusList = JSON.parse(Config.statusSearchList);
  23. console.log(feedbackTypeList);
  24. console.log(processStatusList);
  25. console.log(statusList);
  26. // 初始化表格
  27. table.bootstrapTable({
  28. url: $.fn.bootstrapTable.defaults.extend.index_url,
  29. pk: 'id',
  30. sortName: 'id',
  31. fixedColumns: true,
  32. fixedRightNumber: 1,
  33. columns: [
  34. [
  35. {checkbox: true},
  36. {field: 'id', title: __('Id')},
  37. {
  38. field: 'user.username', title: __('User_id'), operate: false,
  39. formatter: function (value, row, index) {
  40. // 显示用户头像和用户名
  41. var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
  42. var username = row.user && row.user.username ? row.user.username : '游客';
  43. return '<div style="display:flex;align-items:center;">' +
  44. '<img src="' + avatar + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
  45. '<span style="color:#a55bff;">' + username + '</span>' +
  46. '</div>';
  47. }
  48. },
  49. {field: 'type', title: __('Type'), searchList: feedbackTypeList,formatter: Controller.api.formatter.type},
  50. {field: 'content', title: __('Content'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  51. {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  52. {field: 'phone', title: __('Phone'), operate: 'LIKE'},
  53. {field: 'process_status', title: __('Process_status'), searchList: processStatusList,formatter:Controller.api.formatter.process_status},
  54. {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.remark},
  55. {field: 'status', title: __('Status'), searchList: statusList, formatter:Table.api.formatter.status},
  56. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  57. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  58. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  59. ]
  60. ]
  61. });
  62. // 为表格绑定事件
  63. Table.api.bindevent(table);
  64. },
  65. recyclebin: function () {
  66. // 初始化表格参数配置
  67. Table.api.init({
  68. extend: {
  69. 'dragsort_url': ''
  70. }
  71. });
  72. var table = $("#table");
  73. // 初始化表格
  74. table.bootstrapTable({
  75. url: 'feedback/recyclebin' + location.search,
  76. pk: 'id',
  77. sortName: 'id',
  78. columns: [
  79. [
  80. {checkbox: true},
  81. {field: 'id', title: __('Id')},
  82. {
  83. field: 'deletetime',
  84. title: __('Deletetime'),
  85. operate: 'RANGE',
  86. addclass: 'datetimerange',
  87. formatter: Table.api.formatter.datetime
  88. },
  89. {
  90. field: 'operate',
  91. width: '140px',
  92. title: __('Operate'),
  93. table: table,
  94. events: Table.api.events.operate,
  95. buttons: [
  96. {
  97. name: 'Restore',
  98. text: __('Restore'),
  99. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  100. icon: 'fa fa-rotate-left',
  101. url: 'feedback/restore',
  102. refresh: true
  103. },
  104. {
  105. name: 'Destroy',
  106. text: __('Destroy'),
  107. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  108. icon: 'fa fa-times',
  109. url: 'feedback/destroy',
  110. refresh: true
  111. }
  112. ],
  113. formatter: Table.api.formatter.operate
  114. }
  115. ]
  116. ]
  117. });
  118. // 为表格绑定事件
  119. Table.api.bindevent(table);
  120. },
  121. add: function () {
  122. Controller.api.bindevent();
  123. },
  124. edit: function () {
  125. Controller.api.bindevent();
  126. },
  127. api: {
  128. bindevent: function () {
  129. Form.api.bindevent($("form[role=form]"));
  130. },
  131. formatter: {
  132. type: function(value, row, index) {
  133. var type = feedbackTypeList[value] || value;
  134. var cssClass = '';
  135. // 根据不同类型设置不同的样式
  136. if (value === 'PRODUCT_FUNCTION_FEEDBACK') {
  137. cssClass = 'success'; // 绿色
  138. } else if (value === 'PRODUCT_BUG_FEEDBACK') {
  139. cssClass = 'danger'; // 红色
  140. } else if (value === 'OTHER_FEEDBACK') {
  141. cssClass = 'info'; // 蓝色
  142. }
  143. return '<span class="label label-' + cssClass + '">' + type + '</span>';
  144. },
  145. process_status: function(value, row, index) {
  146. var processStatus = processStatusList[value] || value;
  147. var cssClass = value == 1 ? 'warning' : 'success';
  148. return '<span class="label label-' + cssClass + '">' + processStatus + '</span>';
  149. }
  150. }
  151. }
  152. };
  153. return Controller;
  154. });