productdetails.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. Page({
  2. data: {
  3. item: {},
  4. selectedSpec: '基础款(50粒)',
  5. quantity: 1,
  6. showimg: '',
  7. gouwucimg: '',
  8. gaoliao: 0,
  9. },
  10. onLoad(options) {
  11. console.log('进了');
  12. const itemData = decodeURIComponent(options.data);
  13. const item = JSON.parse(itemData);
  14. this.setData({
  15. item: item
  16. });
  17. const fileIDs = [
  18. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show.png',
  19. // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/gouwuc_img.png'
  20. ];
  21. // 并发下载多个 fileID
  22. Promise.all(
  23. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  24. ).then(results => {
  25. // 每个 result 对应一个下载结果
  26. const tempFilePaths = results.map(r => r.tempFilePath);
  27. console.log('全部下载成功:', tempFilePaths);
  28. this.setData({
  29. showimg: tempFilePaths[0],
  30. // gouwucimg: tempFilePaths[1]
  31. });
  32. }).catch(err => {
  33. console.error('有文件下载失败:', err);
  34. });
  35. },
  36. handleSpecSelect(e) {
  37. const spec = e.currentTarget.dataset.spec;
  38. this.setData({ selectedSpec: spec });
  39. },
  40. handleQuantityChange(e) {
  41. const action = e.currentTarget.dataset.action;
  42. let quantity = this.data.quantity;
  43. if (action === 'plus') {
  44. quantity++;
  45. } else if (action === 'minus' && quantity > 1) {
  46. quantity--;
  47. }
  48. this.setData({ quantity });
  49. },
  50. addToCart() {
  51. // 加入购物车逻辑
  52. console.log('加入购物车');
  53. },
  54. buyNow() {
  55. // 立即购买逻辑
  56. console.log('立即购买');
  57. }
  58. });