detail.js 6.8 KB

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