getProduct.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. import Vue from 'vue'
  2. import store from '@/store'
  3. export default function getPattern (payload = {}) {
  4. const role = store.state.user.role
  5. return new Promise(async (resolve, reject) => {
  6. const id = payload.id
  7. // 城市
  8. const cityComponentData = {
  9. nodeType: 'item',
  10. required: true,
  11. label: `可售卖城市`,
  12. nodeList: [
  13. {
  14. nodeType: 'select',
  15. keyword: 'city_ids',
  16. hub: 'product-detail',
  17. props: {
  18. placeholder: `请选择可售卖城市`,
  19. multiple: true,
  20. },
  21. },
  22. ],
  23. }
  24. // 对应商品
  25. const codeComponentData = {
  26. nodeType: 'item',
  27. required: false,
  28. label: `对应商品`,
  29. nodeList: [
  30. {
  31. nodeType: 'input',
  32. keyword: 'other_code',
  33. hub: 'product-detail',
  34. props: {
  35. placeholder: `请选择对应商品`,
  36. },
  37. },
  38. ],
  39. }
  40. // 商品名称
  41. const nameComponentData = {
  42. nodeType: 'item',
  43. required: true,
  44. label: '商品名称',
  45. nodeList: [
  46. {
  47. nodeType: 'input',
  48. keyword: 'name',
  49. hub: 'product-detail',
  50. props: {
  51. placeholder: `请输入商品名称`,
  52. },
  53. },
  54. ],
  55. }
  56. // 上架名称
  57. const saleComponentData = {
  58. nodeType: 'item',
  59. required: true,
  60. label: '上架名称',
  61. nodeList: [
  62. {
  63. nodeType: 'input',
  64. keyword: 'sale_name',
  65. hub: 'product-detail',
  66. props: {
  67. placeholder: `请输入上架名称`,
  68. },
  69. },
  70. ],
  71. }
  72. // 子标题
  73. const subtitleComponentData = {
  74. nodeType: 'item',
  75. required: false,
  76. label: '子标题',
  77. nodeList: [
  78. {
  79. nodeType: 'input',
  80. keyword: 'subtitle',
  81. hub: 'product-detail',
  82. props: {
  83. placeholder: `请选输入子标题`,
  84. },
  85. },
  86. ],
  87. }
  88. // 分类
  89. const levelComponentData = {
  90. nodeType: 'item',
  91. required: true,
  92. label: '商品分类',
  93. nodeList: [
  94. {
  95. nodeType: 'select',
  96. keyword: 'category_id1',
  97. hub: 'product-detail',
  98. props: {
  99. placeholder: '选择一级分类',
  100. filterable: true,
  101. clearable: true,
  102. },
  103. },
  104. {
  105. nodeType: 'select',
  106. keyword: 'category_id2',
  107. hub: 'product-detail',
  108. props: {
  109. placeholder: '选择二级分类',
  110. filterable: true,
  111. clearable: true,
  112. },
  113. dependency: {
  114. type: 'hide',
  115. keyword: 'category_id1',
  116. },
  117. },
  118. {
  119. nodeType: 'select',
  120. keyword: 'category_id3',
  121. hub: 'product-detail',
  122. props: {
  123. placeholder: '选择三级分类',
  124. filterable: true,
  125. clearable: true,
  126. },
  127. dependency: {
  128. type: 'hide',
  129. keyword: 'category_id2',
  130. },
  131. },
  132. ],
  133. }
  134. // 商品主图
  135. const imgComponentData = {
  136. nodeType: 'item',
  137. required: true,
  138. label: '商品主图',
  139. tip: '图片建议尺寸:240*240像素',
  140. nodeList: [
  141. {
  142. nodeType: 'uploader',
  143. keyword: 'img',
  144. hub: 'product-detail',
  145. props: {},
  146. },
  147. ],
  148. }
  149. // 通栏大图
  150. const bigImgComponentData = {
  151. nodeType: 'item',
  152. required: false,
  153. label: '通栏大图',
  154. tip: '图片建议尺寸:750*300像素,用于通栏模式下的商品列表页展示',
  155. nodeList: [
  156. {
  157. nodeType: 'uploader',
  158. keyword: 'big_img',
  159. hub: 'product-detail',
  160. props: {},
  161. },
  162. ],
  163. }
  164. // 商品视频
  165. const videoComponentData = {
  166. nodeType: 'item',
  167. required: false,
  168. label: '商品视频',
  169. tip: '视频建议时长9-30秒,建议视频宽高比16:9',
  170. nodeList: [
  171. {
  172. nodeType: 'uploader',
  173. keyword: 'video',
  174. hub: 'product-detail',
  175. props: {
  176. type: 'video',
  177. },
  178. },
  179. ],
  180. }
  181. // 商品图集
  182. const imgsComponentData = {
  183. nodeType: 'item',
  184. required: true,
  185. label: '商品图集',
  186. size: 'flow',
  187. tip: '建议尺寸:340*340像素,比例为1:1,最多上传15张',
  188. nodeList: [
  189. {
  190. nodeType: 'uploader',
  191. keyword: 'imgs',
  192. hub: 'product-detail',
  193. props: {
  194. max: 15,
  195. },
  196. },
  197. ],
  198. }
  199. // 储藏方式
  200. const storeTypeComponentData = {
  201. nodeType: 'item',
  202. required: true,
  203. label: '储藏方式',
  204. nodeList: [
  205. {
  206. nodeType: 'checkboxGroup',
  207. keyword: 'store_type_ids',
  208. hub: 'product-detail',
  209. props: {},
  210. },
  211. ],
  212. }
  213. // 储藏方式
  214. const tagComponentData = {
  215. nodeType: 'item',
  216. required: true,
  217. label: '检测标签',
  218. nodeList: [
  219. {
  220. nodeType: 'tag',
  221. keyword: 'label',
  222. hub: 'product-detail',
  223. props: {},
  224. },
  225. ],
  226. }
  227. // 检测报告
  228. const reportComponentData = {
  229. nodeType: 'item',
  230. required: false,
  231. label: '检测报告',
  232. nodeList: [
  233. {
  234. nodeType: 'uploader',
  235. keyword: 'report',
  236. hub: 'product-detail',
  237. props: {
  238. max: 9,
  239. },
  240. },
  241. ],
  242. }
  243. const attributeComponentData = {
  244. nodeType: 'item',
  245. required: true,
  246. label: '规格属性分类',
  247. nodeList: [
  248. {
  249. nodeType: 'attribute',
  250. keyword: 'attribute_category_id',
  251. hub: 'product-detail',
  252. props: {},
  253. },
  254. ],
  255. }
  256. const patternComponentData = {
  257. nodeType: 'item',
  258. required: true,
  259. label: '规格属性',
  260. size: 'flow',
  261. nodeList: [
  262. {
  263. nodeType: 'pattern',
  264. keyword: 'sku',
  265. hub: 'product-detail',
  266. props: {},
  267. },
  268. ],
  269. }
  270. const parameterComponentData = {
  271. nodeType: 'item',
  272. required: true,
  273. label: '商品参数',
  274. size: 'flow',
  275. nodeList: [
  276. {
  277. nodeType: 'parameter',
  278. keyword: 'parameter',
  279. hub: 'product-detail',
  280. props: {},
  281. },
  282. ],
  283. }
  284. const deliverTypeComponentData = {
  285. nodeType: 'item',
  286. required: true,
  287. label: '配送方式',
  288. nodeList: [
  289. {
  290. nodeType: 'radioGroup',
  291. keyword: 'deliver_type',
  292. hub: 'product-detail',
  293. props: {},
  294. },
  295. ],
  296. }
  297. const confirmSaleComponentData = {
  298. nodeType: 'item',
  299. required: true,
  300. label: '审核后立即上架',
  301. nodeList: [
  302. {
  303. nodeType: 'radioGroup',
  304. keyword: 'is_confirm_sale',
  305. hub: 'product-detail',
  306. props: {},
  307. },
  308. ],
  309. }
  310. const receiveComponentData = {
  311. nodeType: 'item',
  312. required: true,
  313. label: '预计配送时间',
  314. nodeList: [
  315. {
  316. nodeType: 'receive',
  317. keyword: 'receive_type',
  318. hub: 'product-detail',
  319. props: {},
  320. },
  321. ],
  322. }
  323. const limitNumComponentData = {
  324. nodeType: 'item',
  325. required: true,
  326. label: '限购数量',
  327. tip: '数量为0则不限购',
  328. nodeList: [
  329. {
  330. nodeType: 'inputNumber',
  331. keyword: 'limit_number',
  332. hub: 'product-detail',
  333. props: {
  334. min: 0,
  335. },
  336. },
  337. ],
  338. }
  339. const limitTypeComponentData = {
  340. nodeType: 'item',
  341. required: true,
  342. label: '限购类型',
  343. nodeList: [
  344. {
  345. nodeType: 'radioGroup',
  346. keyword: 'limit_type',
  347. hub: 'product-detail',
  348. props: {},
  349. },
  350. ],
  351. }
  352. const descComponentData = {
  353. nodeType: 'item',
  354. required: false,
  355. label: '商品详情',
  356. size: 'flow',
  357. nodeList: [
  358. {
  359. nodeType: 'editor',
  360. keyword: 'desc',
  361. hub: 'product-detail',
  362. props: {},
  363. },
  364. ],
  365. }
  366. // 整体组件数据
  367. const componentData = [
  368. {
  369. nodeType: 'note',
  370. text: '',
  371. },
  372. {
  373. nodeType: 'block',
  374. nodeList: [
  375. {
  376. nodeType: 'note',
  377. text: '基本信息',
  378. },
  379. cityComponentData,
  380. codeComponentData,
  381. nameComponentData,
  382. saleComponentData,
  383. subtitleComponentData,
  384. levelComponentData,
  385. imgComponentData,
  386. bigImgComponentData,
  387. videoComponentData,
  388. imgsComponentData,
  389. storeTypeComponentData,
  390. tagComponentData,
  391. reportComponentData,
  392. ],
  393. },
  394. {
  395. nodeType: 'block',
  396. nodeList: [
  397. {
  398. nodeType: 'note',
  399. text: '价格库存',
  400. },
  401. attributeComponentData,
  402. patternComponentData,
  403. parameterComponentData,
  404. ],
  405. },
  406. {
  407. nodeType: 'block',
  408. nodeList: [
  409. {
  410. nodeType: 'note',
  411. text: '物流信息',
  412. },
  413. deliverTypeComponentData,
  414. ],
  415. },
  416. {
  417. nodeType: 'block',
  418. nodeList: [
  419. {
  420. nodeType: 'note',
  421. text: '其他信息',
  422. },
  423. confirmSaleComponentData,
  424. receiveComponentData,
  425. limitNumComponentData,
  426. limitTypeComponentData,
  427. descComponentData,
  428. ],
  429. },
  430. ]
  431. const value = {
  432. city_ids: [],
  433. other_code: null,
  434. name: null,
  435. sale_name: null,
  436. subtitle: null,
  437. category_id1: null,
  438. category_id2: null,
  439. category_id3: null,
  440. img: null,
  441. big_img: null,
  442. video: null,
  443. imgs: [],
  444. store_type_ids: [],
  445. label: [],
  446. report: [],
  447. attribute_category_id: null,
  448. sku: [],
  449. parameter: [],
  450. deliver_type: null,
  451. is_confirm_sale: null,
  452. receive_type: 0,
  453. receive_time: '',
  454. limit_number: 0,
  455. limit_type: 0,
  456. desc: '',
  457. // 组件使用数据:规格、参数
  458. patternData: [],
  459. parameterData: [],
  460. }
  461. const option = {
  462. city_ids: {
  463. list: [],
  464. },
  465. category_id1: {
  466. type: 'async',
  467. refresh: true,
  468. list: [],
  469. },
  470. category_id2: {
  471. type: 'async',
  472. refresh: true,
  473. dependency: {
  474. keyword: 'category_id1',
  475. },
  476. list: [],
  477. },
  478. category_id3: {
  479. type: 'async',
  480. refresh: true,
  481. dependency: {
  482. keyword: 'category_id2',
  483. },
  484. list: [],
  485. },
  486. attribute_category_id: {
  487. type: 'async',
  488. list: [],
  489. },
  490. label: {
  491. list: [],
  492. },
  493. store_type_ids: {
  494. list: [],
  495. },
  496. deliver_type: {
  497. list: [],
  498. },
  499. is_confirm_sale: {
  500. list: [],
  501. },
  502. limit_type: {
  503. list: [],
  504. },
  505. }
  506. const patternDetailData = {
  507. componentData,
  508. value,
  509. error: {},
  510. option,
  511. }
  512. if (id) {
  513. try {
  514. const { data } = await Vue.http.get(`/product/product/detail?id=${id}`)
  515. data.store_type_ids = data.store_type_ids.split(',').map(Number)
  516. data.limit_type = Number(data.limit_type)
  517. data.city_ids = data.city_ids.map(Number)
  518. value.parameterData = data.parameter.map(i => {
  519. return {
  520. name: i.name,
  521. list: [i.value],
  522. selected: i.value,
  523. }
  524. })
  525. value.patternData = data.spec.map(i => {
  526. return {
  527. name: i.name,
  528. list: i.value,
  529. selected: i.value,
  530. }
  531. })
  532. Object.assign(value, data)
  533. option.category_id1.list.push({ label: data.category_name1, value: data.category_id1 })
  534. option.category_id2.list.push({ label: data.category_name2, value: data.category_id2 })
  535. option.category_id3.list.push({ label: data.category_name3, value: data.category_id3 })
  536. resolve({
  537. componentData,
  538. value,
  539. error: {},
  540. option,
  541. preview: role === 'admin',
  542. })
  543. } catch (e) {
  544. console.log(e)
  545. }
  546. }
  547. resolve(patternDetailData)
  548. })
  549. }