detail.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. clickBut() {
  97. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  98. title: '请选择加入产品领域',
  99. icon: "none",
  100. duration: 3000
  101. }) : this.handleStorage(0);
  102. },
  103. /* 选择领域 */
  104. storage(e) {
  105. this.handleStorage(e.detail.value)
  106. },
  107. handleStorage(index) {
  108. let detail = this.data.detail;
  109. _Http.basic({
  110. "id": 20220924095102,
  111. "content": {
  112. "sa_brandid": detail.brand[0].sa_brandid, //品牌id
  113. "itemid": detail.itemid, //货品id
  114. "qty": 1, //数量
  115. "itemno": this.data.itemno, //货品编号
  116. tradefield: detail.tradefield[index].tradefield
  117. },
  118. }).then(res => {
  119. console.log("加入购物车", res)
  120. wx.showToast({
  121. title: res.msg != '成功' ? res.msg : '已将产品加入到购物车',
  122. icon: "none"
  123. });
  124. if (res.msg == '成功') _Http.basic({
  125. "id": 20220927093202,
  126. "content": {}
  127. }, false).then(res => {
  128. console.log("购物车数量", res)
  129. getApp().globalData.num = res.data.num;
  130. this.selectComponent("#Float").setNum(res.data.num)
  131. });
  132. })
  133. },
  134. onShow() {
  135. this.selectComponent("#Float").setNum(getApp().globalData.num)
  136. },
  137. })