detail.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. hidePrice: wx.getStorageSync('hidePrice'),
  11. badge: getApp().globalData.collectCount,
  12. favoriteCount: getApp().globalData.favoriteCount,
  13. loading: true,
  14. content: {
  15. sa_itemgroupid: null,
  16. spec: "", //规格
  17. color: "", //颜色
  18. material: "", //材质
  19. cheek: "", //边框
  20. dwidth: 0,
  21. dlength: 0,
  22. },
  23. detail: {
  24. spec: ""
  25. },
  26. cWidth: null, //宽定制方案
  27. cLength: null, //长定制方案
  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) {
  77. if (item.iscustomsize == 1) {
  78. let cWidth = null,
  79. cLength = null;
  80. Promise.all([{
  81. "id": "20230707091603",
  82. "version": 1,
  83. "content": {
  84. "sa_sizecustomizedschemeid": item.lengthschemeid,
  85. date: Date.now() + 1
  86. }
  87. }, {
  88. "id": "20230707091603",
  89. "version": 1,
  90. "content": {
  91. "sa_sizecustomizedschemeid": item.widthschemeid,
  92. date: Date.now() + 2
  93. }
  94. }].map(v => _Http.basic(v))).then(s => {
  95. if (s.some(c => c.msg != '成功')) return wx.showToast({
  96. title: '定制方案获取失败',
  97. icon: "none"
  98. })
  99. if (item.lengthschemeid) cLength = s[0].data;
  100. if (item.widthschemeid) cWidth = s[1].data;
  101. this.setData({
  102. cWidth,
  103. cLength,
  104. "content.dwidth": cWidth.min || 0,
  105. "content.dlength": cLength.min || 0,
  106. });
  107. })
  108. } else {
  109. this.setData({
  110. cWidth: null,
  111. cLength: null,
  112. "content.dwidth": 0,
  113. "content.dlength": 0,
  114. });
  115. }
  116. }
  117. })
  118. },
  119. /* 预览媒体 */
  120. viewMedias(e) {
  121. const {
  122. index,
  123. type
  124. } = e.currentTarget.dataset;
  125. wx.previewMedia({
  126. current: index,
  127. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  128. })
  129. },
  130. /* 处理附件 */
  131. handleFiles(arr) {
  132. let files = {
  133. images: [],
  134. viewImages: [],
  135. videos: [],
  136. viewVideos: [],
  137. files: []
  138. },
  139. list = fileList(arr);
  140. list.forEach(v => {
  141. switch (v.fileType) {
  142. case "video":
  143. files.videos.push(v)
  144. files.viewVideos.push({
  145. url: v.url,
  146. type: "video",
  147. poster: v.subfiles[0].url
  148. })
  149. break;
  150. case "image":
  151. files.images.push(v)
  152. files.viewImages.push({
  153. url: v.url,
  154. type: "image"
  155. })
  156. break;
  157. default:
  158. files.files.push(v)
  159. break;
  160. }
  161. });
  162. this.setData({
  163. files
  164. })
  165. },
  166. /* 切换产品 */
  167. changeItemno(e) {
  168. const {
  169. value,
  170. valuename
  171. } = e.currentTarget.dataset,
  172. content = this.data.content;
  173. if (!value.flag) return;
  174. wx.showLoading({
  175. title: '加载中...',
  176. mask: true
  177. })
  178. content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
  179. this.getDetail(valuename == "spec")
  180. },
  181. /* 定制选项 */
  182. customParameter(e) {
  183. let {
  184. value,
  185. valuename
  186. } = e.currentTarget.dataset;
  187. this.data.content[valuename] = value;
  188. this.setData({
  189. content: this.data.content
  190. })
  191. },
  192. /* 定制步进器 */
  193. cahngeStepper(e) {
  194. const name = e.currentTarget.dataset.name,
  195. name2 = name == 'cWidth' ? "dwidth" : "dlength",
  196. content = this.data.content;
  197. if (e.type == 'plus') {
  198. content[name2] += 1
  199. } else if (e.type == 'minus') {
  200. content[name2] -= 1
  201. } else {
  202. const data = this.data[name];
  203. content[name2] = (e.detail.value - 0).toFixed(data.decimalplaces);
  204. }
  205. let item = this.data[name];
  206. if (content[name2] > item.max) content[name2] = item.max;
  207. if (content[name2] < item.min) content[name2] = item.min;
  208. this.setData({
  209. content
  210. })
  211. },
  212. /* 打开文档 */
  213. openDocument(e) {
  214. const {
  215. item
  216. } = e.currentTarget.dataset;
  217. console.log(item)
  218. wx.showLoading({
  219. title: '加载中...',
  220. mask: true,
  221. })
  222. wx.downloadFile({
  223. url: item.url,
  224. success: function (res) {
  225. const filePath = res.tempFilePath
  226. wx.openDocument({
  227. filePath: filePath,
  228. showMenu: true,
  229. fileType: item.postfix,
  230. success: function (res) {
  231. wx.hideLoading();
  232. console.log('打开文档成功')
  233. },
  234. fail(e) {
  235. console.log(e)
  236. wx.showToast({
  237. title: '打开失败',
  238. icon: "error",
  239. mask: true
  240. })
  241. }
  242. })
  243. },
  244. fail(e) {
  245. console.log(e)
  246. wx.showToast({
  247. title: '打开失败',
  248. icon: "error",
  249. mask: true
  250. })
  251. }
  252. })
  253. },
  254. clickBut(e) {
  255. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  256. title: '请选择加入产品领域',
  257. icon: "none",
  258. duration: 3000
  259. }) : this[e.target.id](0);
  260. },
  261. /* 选择领域 */
  262. storage(e) {
  263. this.addToShoppingCart(e.detail.value)
  264. },
  265. /* 加入购物车 */
  266. addToShoppingCart(index) {
  267. let detail = this.data.detail,
  268. content = this.data.content;
  269. if (detail.iscustomsize == 1) {
  270. if (detail.widthschemeid != 0 && content.dwidth == 0) return wx.showToast({
  271. title: '请完成定制宽选项',
  272. icon: "none"
  273. })
  274. if (detail.lengthschemeid != 0 && content.dlength == 0) return wx.showToast({
  275. title: '请完成定制长选项',
  276. icon: "none"
  277. })
  278. }
  279. _Http.basic({
  280. "id": 20220924095102,
  281. "content": {
  282. sa_brandid,
  283. "itemid": detail.itemid, //货品id
  284. "qty": detail.orderminqty, //数量
  285. itemno: detail.itemno, //货品编号
  286. tradefield: detail.tradefield[index].tradefield,
  287. width: content.dwidth,
  288. length: content.dlength
  289. },
  290. }).then(res => {
  291. console.log("加入购物车", res)
  292. wx.showToast({
  293. title: res.msg == '成功' ? '加入成功' : res.msg,
  294. icon: "none"
  295. });
  296. if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
  297. badge
  298. }))
  299. })
  300. },
  301. /* 加入收藏夹 */
  302. addToFavorites() {
  303. let detail = this.data.detail,
  304. content = this.data.content,
  305. iscollection = this.data.detail.iscollection == 1 ? false : true
  306. if (iscollection && detail.iscustomsize == 1) {
  307. if (detail.widthschemeid != 0 && content.dwidth == 0) return wx.showToast({
  308. title: '请完成定制宽选项',
  309. icon: "none"
  310. })
  311. if (detail.lengthschemeid != 0 && content.dlength == 0) return wx.showToast({
  312. title: '请完成定制长选项',
  313. icon: "none"
  314. })
  315. }
  316. _Http.basic({
  317. "id": 20231121143403,
  318. "content": {
  319. "itemid": this.data.detail.itemid, //货品id
  320. "qty": detail.orderminqty, //数量
  321. width: content.dwidth || 0,
  322. length: content.dlength || 0,
  323. iscollection
  324. },
  325. }).then(res => {
  326. console.log(iscollection + "收藏夹", res)
  327. wx.showToast({
  328. title: res.msg == '成功' ? iscollection ? '收藏成功' : "已取消收藏" : res.msg,
  329. icon: "none"
  330. });
  331. if (res.msg == '成功') {
  332. getApp().globalData.getFavoriteCount().then(num => {
  333. this.setData({
  334. favoriteCount: num
  335. })
  336. })
  337. this.setData({
  338. "detail.iscollection": iscollection ? 1 : 0
  339. })
  340. }
  341. })
  342. },
  343. /* 前往购物车 */
  344. toCollect(e) {
  345. getApp().globalData.changeBar({
  346. detail: "Collect"
  347. })
  348. wx.navigateBack();
  349. }
  350. })