profile.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. hidden1: false,
  17. hidden2: false,
  18. mobileTop: 'TONY WU',
  19. couponNum: 0,
  20. productNum: 0,
  21. goodsType: 1,
  22. goodsItemList: []
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. this.setData({
  29. isLogin: getMobileCache() != ''
  30. })
  31. if(this.data.isLogin){
  32. this.setData({
  33. hidden1: false,
  34. hidden2: true,
  35. })
  36. this.getUserPrizeList();
  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. getUserPrizeList: function() {
  70. LuckDraw.getUserPrizeList({
  71. page: this.data.page,
  72. pageSize: this.data.pageSize,
  73. mobile: getMobileCache(),
  74. goodsType: this.data.goodsType
  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.goodsItemList) || data.goodsItemList.length == 0) {
  87. console.log("数据为空");
  88. if (this.data.page == 1) {
  89. this.setData({
  90. mobileTop:getMobileCache(),
  91. couponNum: data.couponNum,
  92. productNum: data.productNum,
  93. noResult: true
  94. })
  95. } else {
  96. this.setData({
  97. mobileTop:getMobileCache(),
  98. noMore: true
  99. })
  100. }
  101. return
  102. }
  103. data.goodsItemList.forEach(v => {
  104. let beginTime = v.couponBeginTimestamp
  105. let endTime = v.couponEndTimestamp
  106. v.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  107. v.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  108. if(v.couponType == 'D' && v.discount >0){
  109. v.discount /= 10
  110. }
  111. if(v.couponType == 'C' && v.discount >0){
  112. v.reduceCost /= 100
  113. }
  114. })
  115. if (this.data.page == 1) {
  116. this.setData({
  117. couponNum: data.couponNum,
  118. productNum: data.productNum
  119. })
  120. }
  121. this.data.goodsItemList = this.data.goodsItemList.concat(...data.goodsItemList)
  122. this.setData({
  123. mobileTop:getMobileCache(),
  124. goodsItemList: this.data.goodsItemList
  125. })
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function () {
  131. if (this.data.lock || this.data.noMore) {
  132. return
  133. }
  134. this.data.lock = true
  135. this.data.page++
  136. this.getUserPrizeList()
  137. },
  138. toPrize(e) {
  139. const url = "prize?id=" + e.currentTarget.dataset.id
  140. wx.redirectTo({
  141. url
  142. })
  143. },
  144. getProfile(e) {
  145. this.setData({
  146. hidden1: false,
  147. hidden2: true,
  148. page: 1,
  149. goodsType: 1,
  150. noMore: false,
  151. noResult: false
  152. })
  153. this.data.goodsItemList = [];
  154. this.getUserPrizeList()
  155. },
  156. getPrize(e) {
  157. this.setData({
  158. hidden1: true,
  159. hidden2: false,
  160. page: 1,
  161. goodsType: 2,
  162. noMore: false,
  163. noResult: false
  164. })
  165. this.data.goodsItemList = [];
  166. this.getUserPrizeList()
  167. },
  168. turnPrize: function() {
  169. console.log("开始查看")
  170. if (this.lock || !this.data.isLogin) {
  171. return
  172. }
  173. this.lock = true
  174. },
  175. // 授权手机号
  176. getPhoneNumber(e) {
  177. getPhoneNumberSync(e, _ => {
  178. this.setData({
  179. isLogin: true,
  180. mobileTop: getMobileCache(),
  181. hidden1: false,
  182. hidden2: true,
  183. })
  184. this.getUserPrizeList()
  185. })
  186. },
  187. toRecordPrize(e) {
  188. const url = "recordPrize?id=" + e.currentTarget.dataset.id
  189. wx.redirectTo({
  190. url
  191. })
  192. },
  193. })