detail.js 6.6 KB

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