getCommentList.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import Vue from 'vue'
  2. export default function getCommentList (payload = {}, option = {}) {
  3. return new Promise(async (resolve, reject) => {
  4. // 筛选项
  5. const filters = {
  6. shop_id: {
  7. type: 'input',
  8. title: '商家',
  9. key: 'shop_id',
  10. props: {
  11. placeholder: '请选择商家',
  12. filterable: true,
  13. clearable: true,
  14. },
  15. },
  16. star: {
  17. type: 'select',
  18. title: '星级',
  19. key: 'star',
  20. props: {
  21. placeholder: '评价星级',
  22. filterable: true,
  23. clearable: true,
  24. },
  25. option: {
  26. list: [],
  27. },
  28. },
  29. username: {
  30. type: 'input',
  31. title: '用户昵称',
  32. key: 'username',
  33. props: {
  34. placeholder: '用户昵称',
  35. clearable: true,
  36. },
  37. },
  38. keyword: {
  39. type: 'input',
  40. title: '关键词',
  41. key: 'keyword',
  42. props: {
  43. placeholder: '评价关键词/上架名称',
  44. clearable: true,
  45. },
  46. },
  47. }
  48. // 操作项
  49. const actions = []
  50. const sortActions = []
  51. // 表格项
  52. // "sale_name"
  53. const columns = {
  54. username: {
  55. title: '用户昵称',
  56. key: 'username',
  57. align: 'center',
  58. width: 100,
  59. },
  60. product_name: {
  61. title: '上架名称',
  62. key: 'product_name',
  63. align: 'center',
  64. width: 80,
  65. },
  66. shop_name: {
  67. title: '所属商家',
  68. key: 'shop_name',
  69. align: 'center',
  70. width: 80,
  71. },
  72. category_name1: {
  73. title: '一级分类',
  74. key: 'category_name1',
  75. align: 'center',
  76. },
  77. category_name2: {
  78. title: '二级分类',
  79. key: 'category_name2',
  80. align: 'center',
  81. },
  82. category_name3: {
  83. title: '三级分类',
  84. key: 'category_name3',
  85. align: 'center',
  86. },
  87. star: {
  88. nodeType: 'rating',
  89. payload: {
  90. title: '评价',
  91. key: 'star',
  92. width: 200,
  93. props: {
  94. disabled: true,
  95. },
  96. },
  97. },
  98. content: {
  99. title: '评论内容',
  100. key: 'content',
  101. align: 'center',
  102. },
  103. purchase_no: {
  104. title: '订单号',
  105. key: 'purchase_no',
  106. align: 'center',
  107. },
  108. created_at: {
  109. title: '评价时间时间',
  110. key: 'created_at',
  111. align: 'center',
  112. },
  113. }
  114. const sortColumns = {}
  115. // 表格扩展(数据操作)
  116. const columnsExtra = {}
  117. const sortColumnsExtra = {}
  118. try {
  119. const isSort = option.type === 'sort'
  120. if (isSort) payload.per_page = 1000
  121. const { data, extra, meta } = await Vue.http.get('/product/comment', {
  122. params: payload,
  123. })
  124. const response = {
  125. filters: isSort ? [] : extra.filters.map(key => filters[key]).filter(Boolean),
  126. actions: isSort ? sortActions : actions,
  127. data: data,
  128. columns: extra.columns
  129. .map(key => (isSort ? sortColumns : columns)[key])
  130. .filter(Boolean)
  131. .concat(isSort ? sortColumnsExtra : columnsExtra),
  132. page: isSort ? {} : meta.pagination,
  133. title: '评价列表',
  134. }
  135. resolve(response)
  136. } catch (e) {
  137. reject(e)
  138. }
  139. })
  140. }