detail.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. const _Http = getApp().globalData.http;
  2. let sa_brandid = null;
  3. import {
  4. fileList
  5. } from "../../utils/FormatTheAttachment";
  6. Page({
  7. data: {
  8. loading: true
  9. },
  10. onLoad(options) {
  11. if (options.id) this.setData({
  12. sa_itemgroupid: options.id,
  13. itemno: options.itemno
  14. })
  15. sa_brandid = options.sa_brandid;
  16. this.setData({
  17. userrole: wx.getStorageSync('userrole')
  18. })
  19. this.getDetail();
  20. },
  21. /* 获取详情 */
  22. getDetail() {
  23. _Http.basic({
  24. "id": "20220926142403",
  25. "content": {
  26. "sa_itemgroupid": this.data.sa_itemgroupid,
  27. // itemno: this.data.itemno
  28. }
  29. }).then(res => {
  30. console.log("商品详情", res)
  31. if (res.msg != '成功') return wx.showToast({
  32. title: res.msg,
  33. icon: "none"
  34. })
  35. if (res.data.length == 0) {
  36. wx.showToast({
  37. title: '未查询到商品',
  38. icon: "none",
  39. mask: true
  40. })
  41. setTimeout(() => {
  42. wx.navigateBack();
  43. }, 500)
  44. return;
  45. }
  46. this.handleFiles(res.data[0].attinfos)
  47. this.setData({
  48. detail: res.data[0],
  49. rows: res.data,
  50. loading: false
  51. })
  52. })
  53. },
  54. /* 预览媒体 */
  55. viewMedias(e) {
  56. const {
  57. index,
  58. type
  59. } = e.currentTarget.dataset;
  60. wx.previewMedia({
  61. current: index,
  62. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  63. })
  64. },
  65. /* 处理附件 */
  66. handleFiles(arr) {
  67. let files = {
  68. images: [],
  69. viewImages: [],
  70. videos: [],
  71. viewVideos: [],
  72. files: []
  73. },
  74. list = fileList(arr);
  75. list.forEach(v => {
  76. switch (v.fileType) {
  77. case "video":
  78. files.videos.push(v)
  79. files.viewVideos.push({
  80. url: v.url,
  81. type: "video",
  82. poster: v.subfiles[0].url
  83. })
  84. break;
  85. case "image":
  86. files.images.push(v)
  87. files.viewImages.push({
  88. url: v.url,
  89. type: "image"
  90. })
  91. break;
  92. default:
  93. files.files.push(v)
  94. break;
  95. }
  96. });
  97. this.setData({
  98. files
  99. })
  100. },
  101. /* 切换产品 */
  102. changeItemno(e) {
  103. const {
  104. item
  105. } = e.currentTarget.dataset;
  106. if (item.itemno == this.data.itemno) return;
  107. this.handleFiles(item.attinfos)
  108. this.setData({
  109. detail: item,
  110. itemno: item.itemno
  111. })
  112. },
  113. clickBut() {
  114. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  115. title: '请选择加入产品领域',
  116. icon: "none",
  117. duration: 3000
  118. }) : this.handleStorage(0);
  119. },
  120. /* 打开文档 */
  121. openDocument(e) {
  122. const {
  123. item
  124. } = e.currentTarget.dataset;
  125. console.log(item)
  126. wx.showLoading({
  127. title: '加载中...',
  128. mask: true,
  129. })
  130. wx.downloadFile({
  131. url: item.url,
  132. success: function (res) {
  133. const filePath = res.tempFilePath
  134. wx.openDocument({
  135. filePath: filePath,
  136. showMenu: true,
  137. fileType: item.postfix,
  138. success: function (res) {
  139. wx.hideLoading();
  140. console.log('打开文档成功')
  141. },
  142. fail(e) {
  143. console.log(e)
  144. wx.showToast({
  145. title: '打开失败',
  146. icon: "error",
  147. mask: true
  148. })
  149. }
  150. })
  151. },
  152. fail(e) {
  153. console.log(e)
  154. wx.showToast({
  155. title: '打开失败',
  156. icon: "error",
  157. mask: true
  158. })
  159. }
  160. })
  161. },
  162. /* 选择领域 */
  163. storage(e) {
  164. this.handleStorage(e.detail.value)
  165. },
  166. handleStorage(index) {
  167. let detail = this.data.detail;
  168. _Http.basic({
  169. "id": 20220924095102,
  170. "content": {
  171. sa_brandid,
  172. "itemid": detail.itemid, //货品id
  173. "qty": detail.orderminqty, //数量
  174. "itemno": this.data.itemno, //货品编号
  175. tradefield: detail.tradefield[index].tradefield
  176. },
  177. }).then(res => {
  178. console.log("加入购物车", res)
  179. if (res.msg != '成功') return wx.showToast({
  180. title: res.msg,
  181. icon: "none"
  182. });
  183. _Http.basic({
  184. "id": 20220927093202,
  185. "content": {}
  186. }, false).then(res => {
  187. console.log("购物车数量", res)
  188. getApp().globalData.num = res.data.num;
  189. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(res.data.num)
  190. setTimeout(() => {
  191. wx.showToast({
  192. title: '加入成功',
  193. icon: "none",
  194. icon: "none"
  195. });
  196. }, 200);
  197. });
  198. })
  199. },
  200. onShow() {
  201. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
  202. },
  203. })