detail.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.setData({
  15. userrole: wx.getStorageSync('userrole')
  16. })
  17. this.getDetail();
  18. },
  19. /* 获取详情 */
  20. getDetail() {
  21. _Http.basic({
  22. "id": "20220926142403",
  23. "content": {
  24. "sa_itemgroupid": this.data.sa_itemgroupid,
  25. // itemno: this.data.itemno
  26. }
  27. }).then(res => {
  28. console.log("商品详情", res)
  29. if (res.msg != '成功') return wx.showToast({
  30. title: res.msg,
  31. icon: "none"
  32. })
  33. if (res.data.length == 0) {
  34. wx.showToast({
  35. title: '未查询到商品',
  36. icon: "none",
  37. mask: true
  38. })
  39. setTimeout(() => {
  40. wx.navigateBack();
  41. }, 500)
  42. return;
  43. }
  44. this.handleFiles(res.data[0].attinfos)
  45. this.setData({
  46. detail: res.data[0],
  47. rows: res.data,
  48. loading: false
  49. })
  50. })
  51. },
  52. /* 预览媒体 */
  53. viewMedias(e) {
  54. const {
  55. index,
  56. type
  57. } = e.currentTarget.dataset;
  58. wx.previewMedia({
  59. current: index,
  60. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  61. })
  62. },
  63. /* 处理附件 */
  64. handleFiles(arr) {
  65. let files = {
  66. images: [],
  67. viewImages: [],
  68. videos: [],
  69. viewVideos: [],
  70. files: []
  71. },
  72. list = fileList(arr);
  73. list.forEach(v => {
  74. switch (v.fileType) {
  75. case "video":
  76. files.videos.push(v)
  77. files.viewVideos.push({
  78. url: v.url,
  79. type: "video",
  80. poster: v.subfiles[0].url
  81. })
  82. break;
  83. case "image":
  84. files.images.push(v)
  85. files.viewImages.push({
  86. url: v.url,
  87. type: "image"
  88. })
  89. break;
  90. default:
  91. files.files.push(v)
  92. break;
  93. }
  94. });
  95. this.setData({
  96. files
  97. })
  98. },
  99. /* 切换产品 */
  100. changeItemno(e) {
  101. const {
  102. item
  103. } = e.currentTarget.dataset;
  104. if (item.itemno == this.data.itemno) return;
  105. this.handleFiles(item.attinfos)
  106. this.setData({
  107. detail: item,
  108. itemno: item.itemno
  109. })
  110. },
  111. clickBut() {
  112. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  113. title: '请选择加入产品领域',
  114. icon: "none",
  115. duration: 3000
  116. }) : this.handleStorage(0);
  117. },
  118. /* 选择领域 */
  119. storage(e) {
  120. this.handleStorage(e.detail.value)
  121. },
  122. handleStorage(index) {
  123. let detail = this.data.detail;
  124. _Http.basic({
  125. "id": 20220924095102,
  126. "content": {
  127. "sa_brandid": detail.brand, //品牌id
  128. "itemid": detail.itemid, //货品id
  129. "qty": 1, //数量
  130. "itemno": this.data.itemno, //货品编号
  131. tradefield: detail.tradefield[index].tradefield
  132. },
  133. }).then(res => {
  134. console.log("加入购物车", res)
  135. if (res.msg != '成功') return wx.showToast({
  136. title: res.msg,
  137. icon: "none"
  138. });
  139. _Http.basic({
  140. "id": 20220927093202,
  141. "content": {}
  142. }, false).then(res => {
  143. console.log("购物车数量", res)
  144. getApp().globalData.num = res.data.num;
  145. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(res.data.num)
  146. setTimeout(() => {
  147. wx.showToast({
  148. title: '加入成功',
  149. icon: "none",
  150. icon: "none"
  151. });
  152. }, 200);
  153. });
  154. })
  155. },
  156. onShow() {
  157. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
  158. },
  159. })