detail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. openDocument(e) {
  120. const {
  121. item
  122. } = e.currentTarget.dataset;
  123. console.log(item)
  124. wx.showLoading({
  125. title: '加载中...',
  126. mask: true,
  127. })
  128. wx.downloadFile({
  129. url: item.url,
  130. success: function (res) {
  131. const filePath = res.tempFilePath
  132. wx.openDocument({
  133. filePath: filePath,
  134. showMenu: true,
  135. fileType: item.postfix,
  136. success: function (res) {
  137. wx.hideLoading();
  138. console.log('打开文档成功')
  139. },
  140. fail(e) {
  141. console.log(e)
  142. wx.showToast({
  143. title: '打开失败',
  144. icon: "error",
  145. mask: true
  146. })
  147. }
  148. })
  149. },
  150. fail(e) {
  151. console.log(e)
  152. wx.showToast({
  153. title: '打开失败',
  154. icon: "error",
  155. mask: true
  156. })
  157. }
  158. })
  159. },
  160. /* 选择领域 */
  161. storage(e) {
  162. this.handleStorage(e.detail.value)
  163. },
  164. handleStorage(index) {
  165. let detail = this.data.detail;
  166. _Http.basic({
  167. "id": 20220924095102,
  168. "content": {
  169. "sa_brandid": detail.brand, //品牌id
  170. "itemid": detail.itemid, //货品id
  171. "qty": 1, //数量
  172. "itemno": this.data.itemno, //货品编号
  173. tradefield: detail.tradefield[index].tradefield
  174. },
  175. }).then(res => {
  176. console.log("加入购物车", res)
  177. if (res.msg != '成功') return wx.showToast({
  178. title: res.msg,
  179. icon: "none"
  180. });
  181. _Http.basic({
  182. "id": 20220927093202,
  183. "content": {}
  184. }, false).then(res => {
  185. console.log("购物车数量", res)
  186. getApp().globalData.num = res.data.num;
  187. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(res.data.num)
  188. setTimeout(() => {
  189. wx.showToast({
  190. title: '加入成功',
  191. icon: "none",
  192. icon: "none"
  193. });
  194. }, 200);
  195. });
  196. })
  197. },
  198. onShow() {
  199. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
  200. },
  201. })