profile.js 5.1 KB

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