detail.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. const _Http = getApp().globalData.http;
  2. let sa_brandid = null,
  3. sys_enterpriseid = null;
  4. import {
  5. getLabelList
  6. } from "../../utils/customItemType";
  7. import {
  8. fileList
  9. } from "../../utils/FormatTheAttachment";
  10. import currency from "../../utils/currency";
  11. Page({
  12. data: {
  13. labelList: getLabelList(),
  14. hidePrice: wx.getStorageSync('hidePrice'),
  15. badge: getApp().globalData.collectCount,
  16. favoriteCount: getApp().globalData.favoriteCount,
  17. loading: true,
  18. content: {
  19. sa_itemgroupid: null,
  20. spec: "", //规格
  21. color: "", //颜色
  22. material: "", //材质
  23. cheek: "" //边框
  24. },
  25. detail: {
  26. spec: ""
  27. },
  28. },
  29. onLoad(options) {
  30. let data = JSON.parse(options.params);
  31. sa_brandid = data.sa_brandid;
  32. if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = data.sys_enterpriseid
  33. this.data.content.sa_itemgroupid = data.sa_itemgroupid;
  34. this.setData({
  35. userrole: wx.getStorageSync('userrole')
  36. })
  37. this.getDetail(true);
  38. },
  39. /* 获取详情 */
  40. getDetail(init = false) {
  41. let content = this.data.content;
  42. if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
  43. _Http.basic({
  44. "id": "20221223165503",
  45. content
  46. }).then(res => {
  47. wx.hideLoading();
  48. console.log("商品详情", res)
  49. if (res.msg != '成功') return wx.showToast({
  50. title: res.msg,
  51. icon: "none"
  52. })
  53. if (res.data.item.length == 0) return wx.showToast({
  54. title: '未查询到商品',
  55. icon: "none",
  56. mask: true
  57. })
  58. const item = res.data.item[0];
  59. this.handleFiles(item.attinfos)
  60. const CNY = sum => currency(sum, {
  61. symbol: "¥",
  62. precision: 2
  63. }).format();
  64. item.gradeprice = CNY(item.gradeprice);
  65. item.marketprice = CNY(item.marketprice);
  66. this.setData({
  67. content,
  68. detail: item,
  69. specRows: res.data.specRows.reverse(),
  70. cheekRows: res.data.cheekRows,
  71. materialRows: res.data.materialRows,
  72. colorRows: res.data.colorRows,
  73. loading: false
  74. });
  75. //是否定制
  76. if (init && item.iscustomsize == 1) this.selectComponent("#customMade").init(item);
  77. })
  78. },
  79. /* 预览媒体 */
  80. viewMedias(e) {
  81. const {
  82. index,
  83. type
  84. } = e.currentTarget.dataset;
  85. wx.previewMedia({
  86. current: index,
  87. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  88. })
  89. },
  90. /* 处理附件 */
  91. handleFiles(arr) {
  92. let files = {
  93. images: [],
  94. viewImages: [],
  95. videos: [],
  96. viewVideos: [],
  97. files: []
  98. },
  99. list = fileList(arr);
  100. list.forEach(v => {
  101. switch (v.fileType) {
  102. case "video":
  103. files.videos.push(v)
  104. files.viewVideos.push({
  105. url: v.url,
  106. type: "video",
  107. poster: v.subfiles[0].url
  108. })
  109. break;
  110. case "image":
  111. files.images.push(v)
  112. files.viewImages.push({
  113. url: v.url,
  114. type: "image"
  115. })
  116. break;
  117. default:
  118. files.files.push(v)
  119. break;
  120. }
  121. });
  122. this.setData({
  123. files
  124. })
  125. },
  126. /* 切换产品 */
  127. changeItemno(e) {
  128. const {
  129. value,
  130. valuename
  131. } = e.currentTarget.dataset,
  132. content = this.data.content;
  133. if (!value.flag) return;
  134. wx.showLoading({
  135. title: '加载中...',
  136. mask: true
  137. })
  138. content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
  139. this.getDetail(valuename == "spec")
  140. },
  141. clickBut() {
  142. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  143. title: '请选择加入产品领域',
  144. icon: "none",
  145. duration: 3000
  146. }) : this.handleStorage(0);
  147. },
  148. /* 打开文档 */
  149. openDocument(e) {
  150. const {
  151. item
  152. } = e.currentTarget.dataset;
  153. console.log(item)
  154. wx.showLoading({
  155. title: '加载中...',
  156. mask: true,
  157. })
  158. wx.downloadFile({
  159. url: item.url,
  160. success: function (res) {
  161. const filePath = res.tempFilePath
  162. wx.openDocument({
  163. filePath: filePath,
  164. showMenu: true,
  165. fileType: item.postfix,
  166. success: function (res) {
  167. wx.hideLoading();
  168. console.log('打开文档成功')
  169. },
  170. fail(e) {
  171. console.log(e)
  172. wx.showToast({
  173. title: '打开失败',
  174. icon: "error",
  175. mask: true
  176. })
  177. }
  178. })
  179. },
  180. fail(e) {
  181. console.log(e)
  182. wx.showToast({
  183. title: '打开失败',
  184. icon: "error",
  185. mask: true
  186. })
  187. }
  188. })
  189. },
  190. clickBut(e) {
  191. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  192. title: '请选择加入产品领域',
  193. icon: "none",
  194. duration: 3000
  195. }) : this[e.target.id](0);
  196. },
  197. /* 选择领域 */
  198. storage(e) {
  199. this.addToShoppingCart(e.detail.value)
  200. },
  201. /* 加入购物车 */
  202. addToShoppingCart(index) {
  203. let detail = this.data.detail,
  204. custom = {
  205. length: 0,
  206. width: 0
  207. };
  208. //是否为定制项
  209. if (detail.iscustomsize == 1) custom = this.selectComponent("#customMade").getResult(true);
  210. if (typeof custom == "boolean") return;
  211. let content = Object.assign(this.data.content, {
  212. sa_brandid,
  213. itemid: detail.itemid, //货品id
  214. qty: detail.orderminqty, //数量
  215. itemno: detail.itemno, //货品编号
  216. tradefield: detail.tradefield[index].tradefield,
  217. }, custom);
  218. _Http.basic({
  219. "id": 20220924095102,
  220. content,
  221. }).then(res => {
  222. console.log("加入购物车", res)
  223. wx.showToast({
  224. title: res.msg == '成功' ? '加入成功' : res.msg,
  225. icon: "none"
  226. });
  227. if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
  228. badge
  229. }))
  230. })
  231. },
  232. /* 加入收藏夹 */
  233. addToFavorites() {
  234. let detail = this.data.detail,
  235. content = this.data.content,
  236. iscollection = this.data.detail.iscollection == 1 ? false : true
  237. if (iscollection && detail.iscustomsize == 1) {
  238. if (detail.widthschemeid != 0 && content.dwidth == 0) return wx.showToast({
  239. title: '请完成定制宽选项',
  240. icon: "none"
  241. })
  242. if (detail.lengthschemeid != 0 && content.dlength == 0) return wx.showToast({
  243. title: '请完成定制长选项',
  244. icon: "none"
  245. })
  246. }
  247. _Http.basic({
  248. "id": 20231121143403,
  249. "content": {
  250. "itemid": this.data.detail.itemid, //货品id
  251. "qty": detail.orderminqty, //数量
  252. width: content.dwidth || 0,
  253. length: content.dlength || 0,
  254. iscollection
  255. },
  256. }).then(res => {
  257. console.log(iscollection + "收藏夹", res)
  258. wx.showToast({
  259. title: res.msg == '成功' ? iscollection ? '收藏成功' : "已取消收藏" : res.msg,
  260. icon: "none"
  261. });
  262. if (res.msg == '成功') {
  263. getApp().globalData.getFavoriteCount().then(num => {
  264. this.setData({
  265. favoriteCount: num
  266. })
  267. })
  268. this.setData({
  269. "detail.iscollection": iscollection ? 1 : 0
  270. })
  271. }
  272. })
  273. },
  274. /* 前往购物车 */
  275. toCollect(e) {
  276. getApp().globalData.changeBar({
  277. detail: "Collect"
  278. })
  279. wx.navigateBack();
  280. }
  281. })