detail.js 7.1 KB

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