recordPrize.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/luckDraw/recordPrize.js
  2. import LuckDraw from '../../api/luck-draw'
  3. import { parseTime } from '../../utils/util'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. page: 1,
  11. pageSize: 10,
  12. lock: false,
  13. noResult: false,
  14. noMore: false,
  15. isLogin: false,
  16. userDrawItemList: []
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. this.setData({
  23. isLogin: getMobileCache() != ''
  24. })
  25. this.getUserDrawRecord();
  26. },
  27. /**
  28. * 生命周期函数--监听页面初次渲染完成
  29. */
  30. onReady: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面隐藏
  39. */
  40. onHide: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面卸载
  44. */
  45. onUnload: function () {
  46. },
  47. /**
  48. * 页面相关事件处理函数--监听用户下拉动作
  49. */
  50. onPullDownRefresh: function () {
  51. },
  52. /**
  53. * 用户点击右上角分享
  54. */
  55. onShareAppMessage: function () {
  56. },
  57. getUserDrawRecord: function() {
  58. LuckDraw.getUserDrawRecord({
  59. page: this.data.page,
  60. pageSize: this.data.pageSize,
  61. mobile: getMobileCache(),
  62. goodsType: 1
  63. }).then(res => {
  64. if (res.code == 200) {
  65. this.uaerPrizeListView(res.data)
  66. }
  67. this.data.lock = false
  68. }).catch(_ => {
  69. console.log(_)
  70. this.data.lock = false
  71. })
  72. },
  73. uaerPrizeListView: function(data) {
  74. if (!Array.isArray(data) || data.length == 0) {
  75. console.log("没有获取到数据");
  76. this.setData({
  77. noResult: true
  78. })
  79. return
  80. }
  81. data.forEach(v => {
  82. let beginTime = v.couponBeginTimestamp
  83. let endTime = v.couponEndTimestamp
  84. let createTime = v.createTime
  85. v.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  86. v.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  87. v.createTime = parseTime(createTime, "{y}.{m}.{d} {h}:{s}")
  88. })
  89. this.data.userDrawItemList = this.data.userDrawItemList.concat(...data)
  90. this.setData({
  91. userDrawItemList: this.data.userDrawItemList
  92. })
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. onReachBottom: function () {
  97. if (this.data.lock || this.data.noMore) {
  98. return
  99. }
  100. this.data.lock = true
  101. this.data.page++
  102. this.getUserPrizeList()
  103. },
  104. */
  105. toRecordPrize(e) {
  106. const url = "recordPrize?id=" + e.currentTarget.dataset.id
  107. wx.redirectTo({
  108. url
  109. })
  110. },
  111. turnPrize: function() {
  112. console.log("开始查看")
  113. if (this.isLock || !this.data.isLogin) {
  114. return
  115. }
  116. },
  117. // 授权手机号
  118. getPhoneNumber(e) {
  119. getPhoneNumberSync(e, _ => {
  120. this.getUserDrawRecord()
  121. })
  122. },
  123. })