profile.js 5.5 KB

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