profile.js 6.7 KB

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