detail.js 4.6 KB

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