productdetails.js 1.6 KB

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