orders_index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // page/component/orders/orders.js
  2. Page({
  3. data: {
  4. address: {},
  5. hasAddress: false,
  6. total: 0,
  7. orders: [
  8. { id: 1, title: '新鲜芹菜 半斤', image: '/image/s5.png', num: 4, price: 0.01 },
  9. { id: 2, title: '素米 500g', image: '/image/s6.png', num: 1, price: 0.03 }
  10. ]
  11. },
  12. onReady() {
  13. this.getTotalPrice();
  14. },
  15. onShow: function () {
  16. const self = this;
  17. wx.getStorage({
  18. key: 'address',
  19. success(res) {
  20. self.setData({
  21. address: res.data,
  22. hasAddress: true
  23. })
  24. }
  25. })
  26. },
  27. /**
  28. * 计算总价
  29. */
  30. getTotalPrice() {
  31. let orders = this.data.orders;
  32. let total = 0;
  33. for (let i = 0; i < orders.length; i++) {
  34. total += orders[i].num * orders[i].price;
  35. }
  36. this.setData({
  37. total: total
  38. })
  39. },
  40. toPay() {
  41. wx.showModal({
  42. title: '提示',
  43. content: '本系统只做演示,支付系统已屏蔽',
  44. complete() {
  45. wx.switchTab({
  46. url: '/page/component/user/user'
  47. })
  48. }
  49. })
  50. }
  51. })