orders.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. text:'center',
  45. complete() {
  46. wx.switchTab({
  47. url: '/page/component/user/user'
  48. })
  49. }
  50. })
  51. }
  52. })