submitorder.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Page({
  2. data: {
  3. products: [],
  4. totalAmount: 0,
  5. dingweiimg: '',
  6. youjiantouimg: '',
  7. },
  8. onLoad() {
  9. const selectedItems = wx.getStorageSync('checkoutItems') || [];
  10. // 标准化 quantity 字段
  11. const products = selectedItems.map(item => ({
  12. ...item,
  13. quantity: item.num
  14. }));
  15. console.log(123123);
  16. this.setData({ products }, () => {
  17. this.calculateTotal();
  18. });
  19. const fileIDs = [
  20. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/dingwei.png',
  21. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/youjiantou.png',
  22. ];
  23. // 并发下载多个 fileID
  24. Promise.all(
  25. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  26. ).then(results => {
  27. // 每个 result 对应一个下载结果
  28. const tempFilePaths = results.map(r => r.tempFilePath);
  29. console.log('全部下载成功:', tempFilePaths);
  30. this.setData({
  31. dingweiimg: tempFilePaths[0],
  32. youjiantouimg: tempFilePaths[1],
  33. });
  34. }).catch(err => {
  35. console.error('有文件下载失败:', err);
  36. });
  37. },
  38. decreaseQuantity(e) {
  39. const index = e.currentTarget.dataset.index;
  40. let products = this.data.products;
  41. if (products[index].quantity > 1) {
  42. products[index].quantity--;
  43. this.setData({ products });
  44. this.calculateTotal();
  45. }
  46. },
  47. increaseQuantity(e) {
  48. const index = e.currentTarget.dataset.index;
  49. let products = this.data.products;
  50. products[index].quantity++;
  51. this.setData({ products });
  52. this.calculateTotal();
  53. },
  54. onChange(e) {
  55. const { id } = e.currentTarget.dataset;
  56. const { detail } = e;
  57. const products = this.data.products.map(item => {
  58. if (item._id === id) {
  59. return { ...item, quantity: detail };
  60. }
  61. return item;
  62. });
  63. this.setData({ products }, () => {
  64. this.calculateTotal();
  65. });
  66. },
  67. calculateTotal() {
  68. let totalAmount = 0;
  69. this.data.products.forEach(item => {
  70. totalAmount += item.price * item.quantity;
  71. });
  72. this.setData({ totalAmount });
  73. },
  74. handlePay() {
  75. // 处理支付逻辑
  76. },
  77. setGridView() {
  78. wx.navigateTo({
  79. url: '/subpackages/addresslist/addresslist'
  80. });
  81. }
  82. });