getAttributeDetail.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. export default function getAttributeDetail (payload = {}) {
  2. return new Promise(async (resolve) => {
  3. // 属性
  4. const attributeComponentData = {
  5. nodeType: 'item',
  6. required: true,
  7. label: '属性',
  8. nodeList: [
  9. {
  10. nodeType: 'select',
  11. keyword: 'attribute_category_id',
  12. hub: 'attribute-detail',
  13. props: {
  14. placeholder: '选择属性',
  15. },
  16. },
  17. ],
  18. }
  19. // 名称
  20. const nameComponentData = {
  21. nodeType: 'item',
  22. required: true,
  23. label: `${payload.attribute_type ? '参数' : '规格'}名称`,
  24. nodeList: [
  25. {
  26. nodeType: 'input',
  27. keyword: 'name',
  28. hub: 'attribute-detail',
  29. props: {
  30. placeholder: `输入${payload.attribute_type ? '参数' : '规格'}名称`,
  31. },
  32. },
  33. ],
  34. }
  35. // 可选列表
  36. const listComponentData = {
  37. nodeType: 'item',
  38. required: false,
  39. size: 'large',
  40. label: '可选列表',
  41. nodeList: [
  42. {
  43. nodeType: 'inputTag',
  44. keyword: 'input_list',
  45. hub: 'attribute-detail',
  46. props: {},
  47. },
  48. ],
  49. }
  50. // 手动新增
  51. const handComponentData = {
  52. nodeType: 'item',
  53. required: true,
  54. label: '商家手动新增',
  55. nodeList: [
  56. {
  57. nodeType: 'radioGroup',
  58. keyword: 'hand_add_status',
  59. hub: 'attribute-detail',
  60. props: {},
  61. },
  62. ],
  63. }
  64. // 排序
  65. const sortComponentData = {
  66. nodeType: 'item',
  67. required: true,
  68. label: '排序',
  69. nodeList: [
  70. {
  71. nodeType: 'inputNumber',
  72. keyword: 'sort',
  73. hub: 'attribute-detail',
  74. props: {
  75. min: 1,
  76. },
  77. },
  78. ],
  79. }
  80. // 整体组件数据
  81. const componentData = [
  82. attributeComponentData,
  83. nameComponentData,
  84. listComponentData,
  85. handComponentData,
  86. sortComponentData,
  87. ]
  88. const value = {
  89. attribute_type: payload.attribute_type,
  90. name: null,
  91. attribute_category_id: null,
  92. input_list: [],
  93. hand_add_status: null,
  94. sort: 999,
  95. }
  96. const error = {}
  97. const option = {
  98. attribute_category_id: {
  99. type: 'async',
  100. list: [],
  101. },
  102. hand_add_status: {
  103. list: [],
  104. },
  105. }
  106. value.attribute_category_id = payload.attribute_category_id
  107. option.attribute_category_id.list = [
  108. {
  109. value: payload.attribute_category_id,
  110. label: payload.attribute_category_name,
  111. },
  112. ]
  113. if (payload.id) {
  114. value.id = payload.id
  115. value.name = payload.name
  116. value.input_list = payload.input_list.split(',')
  117. value.hand_add_status = payload.hand_add_status
  118. value.sort = payload.sort
  119. }
  120. const attributeDetailData = {
  121. componentData,
  122. value,
  123. error,
  124. option,
  125. }
  126. resolve(attributeDetailData)
  127. })
  128. }