detail.js 4.7 KB

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