exchange.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // pages/integral/exchange.js
  2. import Integralinfo from '../../api/integralinfo'
  3. import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
  4. import { parseTime } from '../../utils/util'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tabStatus: 'a',
  11. cardList: [],
  12. row:{},
  13. listStatus:false
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. // this.data.row = JSON.parse(options.obj)
  20. },
  21. /**
  22. * 生命周期函数--监听页面初次渲染完成
  23. */
  24. onReady: function () {
  25. },
  26. /**
  27. * 生命周期函数--监听页面显示
  28. */
  29. onShow: function () {
  30. this.getList()
  31. },
  32. /**
  33. * 生命周期函数--监听页面隐藏
  34. */
  35. onHide: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面卸载
  39. */
  40. onUnload: function () {
  41. },
  42. /**
  43. * 页面相关事件处理函数--监听用户下拉动作
  44. */
  45. onPullDownRefresh: function () {
  46. },
  47. /**
  48. * 页面上拉触底事件的处理函数
  49. */
  50. onReachBottom: function () {
  51. },
  52. /**
  53. * 用户点击右上角分享
  54. */
  55. onShareAppMessage: function () {
  56. },
  57. // 排序
  58. cardsSortRule(pre, next) {
  59. if (!pre.order_status && pre.order_status === next.order_status) {
  60. // 一级分类内部的二级排序:没过期时,激活时间倒序
  61. return next.order_status - pre.order_status // -1
  62. } else {
  63. // 最外层一级大类排序:没过期排在过期前面
  64. if (pre.order_status && !next.order_status) {
  65. return 1
  66. } else {
  67. return -1
  68. }
  69. }
  70. },
  71. getList() {
  72. Integralinfo.getOrderList({
  73. channelid: '',
  74. shopid: '',
  75. storeid: '',
  76. mobile: getMobileCache()
  77. }).then(res => {
  78. const data = res.data
  79. data.forEach((v) => {
  80. let starttime = Math.round(new Date(v.starttime).getTime() / 1000)
  81. let endDate = Math.round(new Date(v.endtime).getTime() / 1000)
  82. let current = Math.round(new Date().getTime() / 1000)
  83. v.start = parseTime(starttime, '{y}-{m}-{d} {h}:{i}:{s}')
  84. v.end = parseTime(endDate, '{y}-{m}-{d} {h}:{i}:{s}')
  85. if (v.order_status === 0 && endDate < current) {
  86. v.order_status = 2
  87. }
  88. })
  89. data.sort(this.cardsSortRule)
  90. this.setData({
  91. cardList: data,
  92. listStatus: true
  93. })
  94. });
  95. },
  96. toInstructions(){
  97. wx.navigateTo({
  98. url: '../welfareMall/buyInfo/buyInfo'
  99. })
  100. }
  101. })