1
0

order.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. Page({
  4. data: {
  5. order_status: '',
  6. evaluate_status: '',
  7. orderList: [],
  8. page: 1,
  9. size: 10,
  10. tabList: ['全部', '待付款', '待收货', '待评价'],
  11. tabIndex: 0
  12. // markers: [{
  13. // iconPath: "/static/images/rider.png",
  14. // id: 0,
  15. // latitude: 31.834082,
  16. // longitude: 117.232939,
  17. // width: 40,
  18. // height: 40,
  19. // callout: {
  20. // content: '距离你2.77km',
  21. // color: '#fe7200',
  22. // display: 'ALWAYS',
  23. // padding: 10,
  24. // borderRadius: 30
  25. // }
  26. // }]
  27. },
  28. toggleTab(e) {
  29. this.setData({
  30. tabIndex: e.currentTarget.dataset.index,
  31. orderList: [],
  32. page: 1,
  33. });
  34. this.switchOrderType(e.currentTarget.dataset.index);
  35. },
  36. swiperChange(e) {
  37. this.setData({
  38. tabIndex: e.detail.current
  39. });
  40. this.switchOrderType(e.detail.current);
  41. },
  42. onLoad: function (options) {
  43. // 页面初始化 options为页面跳转所带来的参数
  44. if (options.tabIndex) {
  45. this.setData({
  46. tabIndex: options.tabIndex
  47. });
  48. }
  49. },
  50. getOrderList() {
  51. let that = this;
  52. util.request(api.OrderList,
  53. {
  54. order_status: that.data.order_status,
  55. evaluate_status: that.data.evaluate_status,
  56. page: that.data.page,
  57. size: that.data.size
  58. }).then(function (res) {
  59. if (res.errno === 0) {
  60. let orderList = res.data.data;
  61. that.setData({
  62. orderList: orderList
  63. });
  64. //获取待付款倒计时
  65. that.data.orderList.forEach((item, num) => {
  66. if (item.pay_status == 0 || item.pay_status == 1) {
  67. util.countdown(that, that.data.orderList, 'orderList', num)
  68. }
  69. })
  70. }
  71. });
  72. },
  73. payOrder(event) {
  74. wx.redirectTo({
  75. url: '/pages/pay/pay?orderId=' + event.target.dataset.orderId
  76. + '&actualPrice=' + event.target.dataset.actualPrice
  77. })
  78. },
  79. againBuy(event) {
  80. let orderId = event.target.dataset.orderId;
  81. util.request(api.CartAddByOrder, {orderId: orderId}).then(function (res) {
  82. if (res.errno === 0) {
  83. wx.switchTab({
  84. url: '/pages/cart/cart',
  85. });
  86. } else if (res.errno === 0) {
  87. wx.showToast({
  88. title: res.errmsg,
  89. image: '/static/images/icon_error.png',
  90. duration: 2000
  91. });
  92. }
  93. });
  94. },
  95. switchOrderType(tabIndex) {
  96. let that = this;
  97. if (tabIndex == 0) {
  98. that.setData({
  99. order_status: '',
  100. evaluate_status: '',
  101. });
  102. } else if (tabIndex == 1) {
  103. that.setData({
  104. order_status: 0,
  105. evaluate_status: '',
  106. });
  107. } else if (tabIndex == 2) {
  108. that.setData({
  109. order_status: 300,
  110. evaluate_status: '',
  111. });
  112. } else if (tabIndex == 3) {
  113. that.setData({
  114. order_status: 301,
  115. evaluate_status: 0,
  116. });
  117. }
  118. that.getOrderList();
  119. },
  120. onReady: function () {
  121. // 页面渲染完成
  122. },
  123. onShow: function () {
  124. // 页面显示
  125. let that = this;
  126. that.switchOrderType(that.data.tabIndex);
  127. },
  128. onHide: function () {
  129. // 页面隐藏
  130. },
  131. onUnload: function () {
  132. // 页面关闭
  133. },
  134. onReachBottom() {
  135. var that = this;
  136. that.setData({
  137. page: that.data.page + 1,
  138. });
  139. that.getOrderList();
  140. }
  141. })