profile.js 4.3 KB

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