detail.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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: options.itemno
  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": 20220924095102,
  100. "content": {
  101. "sa_brandid": this.data.detail.brand[0].sa_brandid, //品牌id
  102. "itemid": this.data.detail.itemid, //货品id
  103. "qty": 1, //数量
  104. "itemno": this.data.itemno //货品编号
  105. },
  106. }).then(res => {
  107. console.log("加入购物车", res)
  108. wx.showToast({
  109. title: res.msg != '成功' ? res.msg : '已加入到购物车',
  110. icon: "none"
  111. });
  112. if (res.msg == '成功') _Http.basic({
  113. "id": 20220927093202,
  114. "content": {}
  115. }, false).then(res => {
  116. console.log("购物车数量", res)
  117. getApp().globalData.num = res.data.num;
  118. this.selectComponent("#Float").setNum(res.data.num)
  119. });
  120. })
  121. },
  122. onShow() {
  123. this.selectComponent("#Float").setNum(getApp().globalData.num)
  124. },
  125. onReady() {
  126. }
  127. })