checkout.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. this.getCheckoutInfo();
  37. },
  38. getCheckoutInfo: function () {
  39. let that = this;
  40. util.request(api.CartCheckout, { addressId: that.data.addressId, couponId: that.data.couponId}).then(function (res) {
  41. if (res.errno === 0) {
  42. console.log(res.data);
  43. that.setData({
  44. checkedGoodsList: res.data.checkedGoodsList,
  45. checkedAddress: res.data.checkedAddress,
  46. actualPrice: res.data.actualPrice,
  47. checkedCoupon: res.data.checkedCoupon,
  48. couponList: res.data.couponList,
  49. couponPrice: res.data.couponPrice,
  50. freightPrice: res.data.freightPrice,
  51. goodsTotalPrice: res.data.goodsTotalPrice,
  52. orderTotalPrice: res.data.orderTotalPrice
  53. });
  54. }
  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. },
  73. onHide:function(){
  74. // 页面隐藏
  75. },
  76. onUnload:function(){
  77. // 页面关闭
  78. },
  79. submitOrder: function(){
  80. if (this.data.addressId <=0) {
  81. util.showErrorToast('请选择收货地址');
  82. return false;
  83. }
  84. let that = this;
  85. util.request(api.OrderSubmit, { addressId: that.data.addressId, couponId: that.data.couponId }, 'POST').then(function (res) {
  86. if (res.errno === 0) {
  87. wx.navigateTo({
  88. url: '/pages/pay/pay'
  89. })
  90. } else {
  91. util.showErrorToast(res.data.errmsg);
  92. }
  93. });
  94. }
  95. })