profile.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // pages/luckDraw/profile.js
  2. import LuckDraw from '../../api/luck-draw'
  3. import { parseTime } from '../../utils/util'
  4. import {getMobileCache, getPhoneNumberNew 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: true,
  17. hidden2: true,
  18. noCoupon: false,
  19. noPrize: false,
  20. mobileTop: 'TONY WU',
  21. couponNum: 0,
  22. productNum: 0,
  23. thirdPrizeNum: 0,
  24. goodsType: 1,
  25. goodsItemList: [],
  26. showCustomPreview: false
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. this.setData({
  33. isLogin: getMobileCache() != '',
  34. mobileTop:getMobileCache(),
  35. })
  36. if(this.data.isLogin){
  37. this.setData({
  38. hidden1: false,
  39. hidden2: true,
  40. noCoupon: true,
  41. noPrize: false,
  42. })
  43. this.getUserPrizeList();
  44. }
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload: function () {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh: function () {
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. },
  76. getUserPrizeList: function() {
  77. LuckDraw.getUserPrizeList({
  78. page: this.data.page,
  79. pageSize: this.data.pageSize,
  80. mobile: getMobileCache(),
  81. goodsType: this.data.goodsType
  82. }).then(res => {
  83. if (res.code == 200) {
  84. this.uaerPrizeListView(res.data)
  85. }
  86. this.data.lock = false
  87. }).catch(_ => {
  88. console.log(_)
  89. this.data.lock = false
  90. })
  91. },
  92. uaerPrizeListView: function(data) {
  93. if (!Array.isArray(data.goodsItemList) || data.goodsItemList.length == 0) {
  94. console.log("数据为空");
  95. if (this.data.page == 1) {
  96. this.setData({
  97. mobileTop:getMobileCache(),
  98. couponNum: data.couponNum,
  99. productNum: data.productNum,
  100. thirdPrizeNum: data.thirdPrizeNum,
  101. noResult: true
  102. })
  103. } else {
  104. this.setData({
  105. mobileTop:getMobileCache(),
  106. noMore: true
  107. })
  108. }
  109. return
  110. }
  111. data.goodsItemList.forEach(v => {
  112. let createTime = v.createTime
  113. v.couponStartTime = v.couponBeginTimestamp
  114. v.couponEndTime = v.couponEndTimestamp
  115. v.isSn = true
  116. v.couponBeginTimestamp = parseTime(v.couponBeginTimestamp, "{y}.{m}.{d}")
  117. v.couponEndTimestamp = parseTime(v.couponEndTimestamp, "{y}.{m}.{d}")
  118. v.createTime = parseTime(createTime, "{y}.{m}.{d} {h}:{i}")
  119. })
  120. if (this.data.page == 1) {
  121. this.setData({
  122. couponNum: data.couponNum,
  123. productNum: data.productNum,
  124. thirdPrizeNum: data.thirdPrizeNum,
  125. })
  126. }
  127. this.data.goodsItemList = this.data.goodsItemList.concat(...data.goodsItemList)
  128. this.setData({
  129. mobileTop:getMobileCache(),
  130. goodsItemList: this.data.goodsItemList
  131. })
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom: function () {
  137. if (this.data.lock || this.data.noMore) {
  138. return
  139. }
  140. this.data.lock = true
  141. this.data.page++
  142. this.getUserPrizeList()
  143. },
  144. toPrize(e) {
  145. const url = "prize?id=" + e.currentTarget.dataset.id
  146. wx.redirectTo({
  147. url
  148. })
  149. },
  150. getProfile(e) {
  151. this.setData({
  152. hidden1: false,
  153. hidden2: true,
  154. page: 1,
  155. goodsType: 1,
  156. noMore: false,
  157. noResult: false,
  158. noCoupon: true,
  159. noPrize: false,
  160. goodsItemList: [],
  161. })
  162. this.getUserPrizeList()
  163. },
  164. getPrize(e) {
  165. this.setData({
  166. hidden1: true,
  167. hidden2: false,
  168. page: 1,
  169. goodsType: 3,
  170. noMore: false,
  171. noResult: false,
  172. noCoupon: false,
  173. noPrize: true,
  174. goodsItemList: [],
  175. })
  176. this.getUserPrizeList()
  177. },
  178. turnPrize: function() {
  179. console.log("开始查看")
  180. if (this.lock || !this.data.isLogin) {
  181. return
  182. }
  183. this.lock = true
  184. },
  185. // 授权手机号
  186. getPhoneNumber(e) {
  187. getPhoneNumberSync(e, _ => {
  188. this.setData({
  189. isLogin: true,
  190. mobileTop: getMobileCache(),
  191. hidden1: false,
  192. hidden2: true,
  193. noCoupon: true,
  194. noPrize: false,
  195. })
  196. this.getUserPrizeList()
  197. })
  198. },
  199. toRecordPrize(e) {
  200. const url = "recordPrize?id=" + e.currentTarget.dataset.id
  201. wx.redirectTo({
  202. url
  203. })
  204. },
  205. toLookHitPhoto(e) {
  206. console.log(e)
  207. let url = e.currentTarget.dataset.src;
  208. this.setData({
  209. showCustomPreview: true,
  210. previewImgSrc: url,
  211. })
  212. // url = 'https://ks3-cn-shanghai.ksyun.com/pb001/web/hsay/publicPath/a2623624-caf1-4877-99d0-c9355984e964.jpg';
  213. // // url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp05%2F19100120461512E-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642243223&t=d67f73c97f32e30932e5ee49bbce6dbd'
  214. // wx.previewImage({
  215. // current: url, // 当前显示图片的http链接
  216. // urls: [url] // 需要预览的图片http链接列表
  217. // })
  218. },
  219. closePreviewImage() {
  220. this.setData({
  221. showCustomPreview: false
  222. })
  223. }
  224. })