recordPrize.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. this.setData({
  80. noResult: true,
  81. userDrawItemList:[]
  82. })
  83. return
  84. }
  85. data.forEach(v => {
  86. let beginTime = v.couponBeginTimestamp
  87. let endTime = v.couponEndTimestamp
  88. let createTime = v.createTime
  89. v.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  90. v.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  91. v.createTime = parseTime(createTime, "{y}.{m}.{d} {h}:{s}")
  92. })
  93. this.data.userDrawItemList = this.data.userDrawItemList.concat(...data)
  94. this.setData({
  95. userDrawItemList: this.data.userDrawItemList
  96. })
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. onReachBottom: function () {
  102. if (this.data.lock || this.data.noResult) {
  103. return
  104. }
  105. this.data.lock = true
  106. this.data.page++
  107. this.getUserDrawRecord()
  108. },
  109. toRecordPrize(e) {
  110. const url = "recordPrize?id=" + e.currentTarget.dataset.id
  111. wx.redirectTo({
  112. url
  113. })
  114. },
  115. turnPrize: function() {
  116. console.log("开始查看")
  117. if (this.isLock || !this.data.isLogin) {
  118. return
  119. }
  120. },
  121. // 授权手机号
  122. getPhoneNumber(e) {
  123. getPhoneNumberSync(e, _ => {
  124. this.setData({
  125. isLogin: true,
  126. mobileTop:getMobileCache(),
  127. })
  128. console.log(this.data.mobileTop)
  129. this.getUserDrawRecord()
  130. })
  131. },
  132. })