submitorder.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Page({
  2. data: {
  3. products: [
  4. {
  5. id: 1,
  6. image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
  7. name: '幼儿启蒙绘本10册套装',
  8. desc: '适合3-6岁儿童,培养创造力',
  9. price: 134.00,
  10. quantity: 1
  11. },
  12. {
  13. id: 1,
  14. image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
  15. name: '幼儿启蒙绘本10册套装',
  16. desc: '适合3-6岁儿童,培养创造力',
  17. price: 134.00,
  18. quantity: 1
  19. }
  20. ],
  21. totalAmount: 134.00,
  22. dingweiimg: '',
  23. youjiantouimg: '',
  24. },
  25. onLoad(options) {
  26. // const title = options.title ? decodeURIComponent(options.title) : '商品列表';
  27. // this.setData({ title });
  28. // wx.setNavigationBarTitle({ title });
  29. const fileIDs = [
  30. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/dingwei.png',
  31. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/youjiantou.png',
  32. ];
  33. // 并发下载多个 fileID
  34. Promise.all(
  35. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  36. ).then(results => {
  37. // 每个 result 对应一个下载结果
  38. const tempFilePaths = results.map(r => r.tempFilePath);
  39. console.log('全部下载成功:', tempFilePaths);
  40. this.setData({
  41. dingweiimg: tempFilePaths[0],
  42. youjiantouimg: tempFilePaths[1],
  43. });
  44. }).catch(err => {
  45. console.error('有文件下载失败:', err);
  46. });
  47. },
  48. decreaseQuantity(e) {
  49. const index = e.currentTarget.dataset.index;
  50. let products = this.data.products;
  51. if (products[index].quantity > 1) {
  52. products[index].quantity--;
  53. this.setData({ products });
  54. this.calculateTotal();
  55. }
  56. },
  57. increaseQuantity(e) {
  58. const index = e.currentTarget.dataset.index;
  59. let products = this.data.products;
  60. products[index].quantity++;
  61. this.setData({ products });
  62. this.calculateTotal();
  63. },
  64. calculateTotal() {
  65. let totalAmount = 0;
  66. this.data.products.forEach(item => {
  67. totalAmount += item.price * item.quantity;
  68. });
  69. this.setData({ totalAmount });
  70. },
  71. handlePay() {
  72. // 处理支付逻辑
  73. },
  74. setGridView() {
  75. wx.navigateTo({
  76. url: '/subpackages/addresslist/addresslist'
  77. });
  78. }
  79. });