recordPrize.js 3.6 KB

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