recordPrize.js 4.1 KB

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