getTrashList.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import Vue from 'vue'
  2. export default function getTrashList (payload = {}, option = {}) {
  3. return new Promise(async (resolve, reject) => {
  4. // 筛选项
  5. const filters = {
  6. keyword: {
  7. type: 'input',
  8. title: '商品名称',
  9. key: 'keyword',
  10. props: {
  11. placeholder: '商品名称',
  12. clearable: true,
  13. },
  14. },
  15. category_id1: {
  16. type: 'select',
  17. title: '商品分类',
  18. key: 'category_id1',
  19. props: {
  20. placeholder: '商品分类',
  21. filterable: true,
  22. clearable: true,
  23. },
  24. option: {
  25. type: 'async',
  26. list: [],
  27. },
  28. },
  29. }
  30. // 操作项
  31. const actions = []
  32. const sortActions = []
  33. // 表格项
  34. // "sale_name"
  35. const columns = {
  36. spu_code: {
  37. title: 'SKU编码',
  38. key: 'spu_code',
  39. align: 'center',
  40. width: 110,
  41. },
  42. id: {
  43. title: '商品ID',
  44. key: 'id',
  45. align: 'center',
  46. width: 80,
  47. },
  48. img: {
  49. nodeType: 'image',
  50. payload: {
  51. key: 'img',
  52. title: '商品图片',
  53. width: 80,
  54. height: 80,
  55. },
  56. },
  57. sale_name: {
  58. title: '商品名称',
  59. key: 'sale_name',
  60. align: 'center',
  61. },
  62. category_name1: {
  63. title: '一级分类',
  64. key: 'category_name1',
  65. align: 'center',
  66. },
  67. category_name2: {
  68. title: '二级分类',
  69. key: 'category_name2',
  70. align: 'center',
  71. },
  72. category_name3: {
  73. title: '三级分类',
  74. key: 'category_name3',
  75. align: 'center',
  76. },
  77. price: {
  78. title: '商品价格',
  79. key: 'price',
  80. align: 'center',
  81. },
  82. }
  83. const sortColumns = {}
  84. // 表格扩展(数据操作)
  85. const columnsExtra = {
  86. nodeType: 'action',
  87. payload: {
  88. title: '操作',
  89. list: [
  90. {
  91. title: '还原',
  92. action: 'handleTrashList',
  93. actionOption: {
  94. status: 1,
  95. type: 'one',
  96. },
  97. props: {
  98. loading: false,
  99. type: 'primary',
  100. },
  101. },
  102. {
  103. title: '删除',
  104. action: 'handleTrashList',
  105. actionOption: {
  106. status: 0,
  107. type: 'one',
  108. },
  109. props: {
  110. loading: false,
  111. type: 'warning',
  112. },
  113. },
  114. ],
  115. },
  116. }
  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/product?is_delete=1', {
  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. batches: [
  135. { value: 'handleTrashList', label: '批量删除', option: { status: 0 } },
  136. { value: 'handleTrashList', label: '批量还原', option: { status: 1 } },
  137. ],
  138. }
  139. // 是否有批量操作
  140. response.columns.unshift({
  141. type: 'selection',
  142. width: 60,
  143. align: 'center',
  144. })
  145. resolve(response)
  146. } catch (e) {
  147. reject(e)
  148. }
  149. })
  150. }