checkout.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data:{
  6. checkedGoodsList: [],
  7. checkedAddress: {},
  8. checkedCoupon: [],
  9. couponList: [],
  10. goodsTotalPrice: 0.00, //商品总价
  11. freightPrice: 0.00, //快递费
  12. couponPrice: 0.00, //优惠券的价格
  13. orderTotalPrice: 0.00, //订单总价
  14. actualPrice: 0.00, //实际需要支付的总价
  15. addressId: 0,
  16. couponId: 0
  17. },
  18. onLoad:function(options){
  19. // 页面初始化 options为页面跳转所带来的参数
  20. try {
  21. var addressId = wx.getStorageSync('addressId');
  22. if (addressId) {
  23. this.setData({
  24. 'addressId': addressId
  25. });
  26. }
  27. var couponId = wx.getStorageSync('couponId');
  28. if (couponId) {
  29. this.setData({
  30. 'couponId': couponId
  31. });
  32. }
  33. } catch (e) {
  34. // Do something when catch error
  35. }
  36. },
  37. getCheckoutInfo: function () {
  38. let that = this;
  39. util.request(api.CartCheckout, { addressId: that.data.addressId, couponId: that.data.couponId}).then(function (res) {
  40. if (res.errno === 0) {
  41. console.log(res.data);
  42. that.setData({
  43. checkedGoodsList: res.data.checkedGoodsList,
  44. checkedAddress: res.data.checkedAddress,
  45. actualPrice: res.data.actualPrice,
  46. checkedCoupon: res.data.checkedCoupon,
  47. couponList: res.data.couponList,
  48. couponPrice: res.data.couponPrice,
  49. freightPrice: res.data.freightPrice,
  50. goodsTotalPrice: res.data.goodsTotalPrice,
  51. orderTotalPrice: res.data.orderTotalPrice
  52. });
  53. }
  54. wx.hideLoading();
  55. });
  56. },
  57. selectAddress(){
  58. wx.navigateTo({
  59. url: '/pages/shopping/address/address',
  60. })
  61. },
  62. addAddress() {
  63. wx.navigateTo({
  64. url: '/pages/shopping/addressAdd/addressAdd',
  65. })
  66. },
  67. onReady:function(){
  68. // 页面渲染完成
  69. },
  70. onShow:function(){
  71. // 页面显示
  72. wx.showLoading({
  73. title: '加载中...',
  74. })
  75. this.getCheckoutInfo();
  76. },
  77. onHide:function(){
  78. // 页面隐藏
  79. },
  80. onUnload:function(){
  81. // 页面关闭
  82. },
  83. submitOrder: function(){
  84. if (this.data.addressId <=0) {
  85. util.showErrorToast('请选择收货地址');
  86. return false;
  87. }
  88. let that = this;
  89. util.request(api.OrderSubmit, { addressId: that.data.addressId, couponId: that.data.couponId }, 'POST').then(function (res) {
  90. if (res.errno === 0) {
  91. wx.navigateTo({
  92. url: '/pages/pay/pay'
  93. })
  94. } else {
  95. util.showErrorToast(res.data.errmsg);
  96. }
  97. });
  98. }
  99. })