profile.js 6.6 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, getColor} 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. prizeImgList: [],
  28. config: {},
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: async function (options) {
  34. this.setData({
  35. isLogin: getMobileCache() != '',
  36. mobileTop:getMobileCache(),
  37. })
  38. if(this.data.isLogin){
  39. this.setData({
  40. hidden1: false,
  41. hidden2: true,
  42. noCoupon: true,
  43. noPrize: false,
  44. })
  45. this.getUserPrizeList();
  46. }
  47. let info = await getColor();
  48. this.setData({
  49. prizeImgList:info.prizeImgList,
  50. config:info.config,
  51. })
  52. console.log(info.prizeImgList)
  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. })