recordPrize.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. mobileTop: 'TONY WU',
  17. userDrawItemList: []
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. if (!options.activityId) {
  24. this.popMessage ('入参错误');
  25. wx.navigateTo({
  26. url: './index',
  27. })
  28. return
  29. }
  30. this.data.activityId = options.activityId
  31. this.setData({
  32. isLogin: getMobileCache() != ''
  33. })
  34. if(this.data.isLogin){
  35. this.getUserDrawRecord();
  36. }
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. },
  63. /**
  64. * 用户点击右上角分享
  65. */
  66. onShareAppMessage: function () {
  67. },
  68. getUserDrawRecord: function() {
  69. LuckDraw.getUserDrawRecord({
  70. page: this.data.page,
  71. pageSize: this.data.pageSize,
  72. mobile: getMobileCache(),
  73. activityId: this.data.activityId,
  74. }).then(res => {
  75. if (res.code == 200) {
  76. this.uaerPrizeListView(res.data)
  77. }
  78. this.data.lock = false
  79. }).catch(_ => {
  80. console.log(_)
  81. this.data.lock = false
  82. })
  83. },
  84. uaerPrizeListView: function(data) {
  85. if (!Array.isArray(data) || data.length == 0) {
  86. console.log("抽奖记录数据为空");
  87. if (this.data.page == 1) {
  88. this.setData({
  89. noResult: true
  90. })
  91. } else {
  92. this.setData({
  93. noMore: true
  94. })
  95. }
  96. return
  97. }
  98. data.forEach(v => {
  99. let beginTime = v.couponBeginTimestamp
  100. let endTime = v.couponEndTimestamp
  101. let createTime = v.createTime
  102. v.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  103. v.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  104. v.createTime = parseTime(createTime, "{y}.{m}.{d} {h}:{i}")
  105. })
  106. this.data.userDrawItemList = this.data.userDrawItemList.concat(...data)
  107. this.setData({
  108. userDrawItemList: this.data.userDrawItemList
  109. })
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. if (this.data.lock || this.data.noMore) {
  116. return
  117. }
  118. this.data.lock = true
  119. this.data.page++
  120. this.getUserDrawRecord()
  121. },
  122. toRecordPrize(e) {
  123. const url = "recordPrize?id=" + e.currentTarget.dataset.id
  124. wx.redirectTo({
  125. url
  126. })
  127. },
  128. turnPrize: function() {
  129. console.log("开始查看")
  130. if (this.isLock || !this.data.isLogin) {
  131. return
  132. }
  133. },
  134. // 授权手机号
  135. getPhoneNumber(e) {
  136. getPhoneNumberSync(e, _ => {
  137. this.setData({
  138. isLogin: true,
  139. mobileTop:getMobileCache(),
  140. })
  141. console.log(this.data.mobileTop)
  142. this.getUserDrawRecord()
  143. })
  144. },
  145. })