detail.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const _Http = getApp().globalData.http;
  2. import {
  3. fileList
  4. } from "../../utils/FormatTheAttachment";
  5. Page({
  6. data: {
  7. loading: true
  8. },
  9. onLoad(options) {
  10. if (options.id) this.setData({
  11. sa_itemgroupid: options.id,
  12. itemno: 'BM8270 0150000'
  13. })
  14. this.getDetail();
  15. },
  16. /* 获取详情 */
  17. getDetail() {
  18. _Http.basic({
  19. "id": "20221223165503",
  20. "content": {
  21. "sa_itemgroupid": this.data.sa_itemgroupid,
  22. itemno: this.data.itemno
  23. }
  24. }).then(res => {
  25. console.log("商品详情", res)
  26. if (res.msg != '成功') return wx.showToast({
  27. title: res.msg,
  28. icon: "none"
  29. })
  30. this.handleFiles(res.data.item[0].attinfos)
  31. this.setData({
  32. detail: res.data.item[0],
  33. rows: res.data.rows,
  34. loading: false
  35. })
  36. })
  37. },
  38. /* 预览媒体 */
  39. viewMedias(e) {
  40. const {
  41. index,
  42. type
  43. } = e.currentTarget.dataset;
  44. wx.previewMedia({
  45. current: index,
  46. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  47. })
  48. },
  49. /* 处理附件 */
  50. handleFiles(arr) {
  51. let files = {
  52. images: [],
  53. viewImages: [],
  54. videos: [],
  55. viewVideos: [],
  56. files: []
  57. },
  58. list = fileList(arr);
  59. list.forEach(v => {
  60. switch (v.fileType) {
  61. case "video":
  62. files.videos.push(v)
  63. files.viewVideos.push({
  64. url: v.url,
  65. type: "video",
  66. poster: v.subfiles[0].url
  67. })
  68. break;
  69. case "image":
  70. files.images.push(v)
  71. files.viewImages.push({
  72. url: v.url,
  73. type: "image"
  74. })
  75. break;
  76. default:
  77. files.files.push(v)
  78. break;
  79. }
  80. });
  81. this.setData({
  82. files
  83. })
  84. },
  85. /* 切换产品 */
  86. changeItemno(e) {
  87. const {
  88. item
  89. } = e.currentTarget.dataset;
  90. if (item.itemno == this.data.itemno) return;
  91. this.setData({
  92. itemno: item.itemno
  93. });
  94. this.getDetail();
  95. },
  96. /* 加入购物车 */
  97. storage() {
  98. _Http.basic({
  99. "id": "20220926142403",
  100. "content": {
  101. "sa_itemgroupid": this.data.sa_itemgroupid
  102. }
  103. }).then(res => {
  104. console.log(res)
  105. if (res.msg != '成功') return wx.showToast({
  106. title: res.msg,
  107. icon: "none"
  108. })
  109. })
  110. },
  111. onShow() {
  112. this.selectComponent("#Float").setNum(getApp().globalData.num)
  113. },
  114. onReady() {
  115. }
  116. })