getAttributeList.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import Vue from 'vue'
  2. export default function getAttributeList (payload = {}) {
  3. return new Promise(async (resolve, reject) => {
  4. const isSpec = payload.attribute_type === 0
  5. const actions = [
  6. {
  7. title: '添加',
  8. action: 'goAttributeDetail',
  9. actionOption: {
  10. type: payload.attribute_type,
  11. id: payload.attribute_category_id,
  12. name: Vue.stack.getStack().list.attribute.find(i => i.name === 'attribute-list').title,
  13. },
  14. props: {
  15. type: 'primary',
  16. },
  17. },
  18. ]
  19. // 表格项
  20. const columns = {
  21. name: {
  22. title: `${isSpec ? '规格' : '参数'}名称`,
  23. key: 'name',
  24. align: 'center',
  25. },
  26. attribute_category_name: {
  27. title: '商品属性',
  28. key: 'attribute_category_name',
  29. align: 'center',
  30. },
  31. input_list: {
  32. title: '可选值',
  33. key: 'input_list',
  34. align: 'center',
  35. },
  36. sort: {
  37. title: '排序',
  38. key: 'sort',
  39. align: 'center',
  40. },
  41. }
  42. const columnsExtra = {
  43. nodeType: 'action',
  44. payload: {
  45. title: '操作',
  46. list: [
  47. {
  48. title: '编辑',
  49. action: 'goAttributeDetail',
  50. props: {
  51. type: 'primary',
  52. loading: false,
  53. },
  54. },
  55. {
  56. title: '删除',
  57. action: 'deleteAttributeDetail',
  58. },
  59. ],
  60. },
  61. }
  62. const isOption = !payload.attribute_type && payload.attribute_type !== 0
  63. const requestBody = !isOption
  64. ? payload
  65. : {
  66. attribute_category_id: payload.attribute_category_id,
  67. per_page: 1000,
  68. }
  69. try {
  70. const { data, extra, meta } = await Vue.http.get('/product/attribute/item', {
  71. params: requestBody,
  72. })
  73. if (isOption) return resolve(data)
  74. const response = {
  75. filters: [],
  76. actions,
  77. data,
  78. columns: extra.columns
  79. .map(key => columns[key])
  80. .filter(Boolean)
  81. .concat(columnsExtra),
  82. page: meta.pagination,
  83. title: isSpec ? '规格列表' : '参数列表',
  84. }
  85. resolve(response)
  86. } catch (e) {
  87. reject(e)
  88. }
  89. })
  90. }