profile.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. 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 beginTime = v.couponBeginTimestamp
  113. let endTime = v.couponEndTimestamp
  114. v.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  115. v.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  116. if(v.couponType == 'D' && v.discount >0){
  117. v.discount /= 10
  118. }
  119. if(v.couponType == 'C' && v.discount >0){
  120. v.reduceCost /= 100
  121. }
  122. })
  123. if (this.data.page == 1) {
  124. this.setData({
  125. couponNum: data.couponNum,
  126. productNum: data.productNum,
  127. thirdPrizeNum: data.thirdPrizeNum,
  128. })
  129. }
  130. this.data.goodsItemList = this.data.goodsItemList.concat(...data.goodsItemList)
  131. this.setData({
  132. mobileTop:getMobileCache(),
  133. goodsItemList: this.data.goodsItemList
  134. })
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function () {
  140. if (this.data.lock || this.data.noMore) {
  141. return
  142. }
  143. this.data.lock = true
  144. this.data.page++
  145. this.getUserPrizeList()
  146. },
  147. toPrize(e) {
  148. const url = "prize?id=" + e.currentTarget.dataset.id
  149. wx.redirectTo({
  150. url
  151. })
  152. },
  153. getProfile(e) {
  154. this.setData({
  155. hidden1: false,
  156. hidden2: true,
  157. page: 1,
  158. goodsType: 1,
  159. noMore: false,
  160. noResult: false,
  161. noCoupon: true,
  162. noPrize: false,
  163. })
  164. this.data.goodsItemList = [];
  165. this.getUserPrizeList()
  166. },
  167. getPrize(e) {
  168. this.setData({
  169. hidden1: true,
  170. hidden2: false,
  171. page: 1,
  172. goodsType: 3,
  173. noMore: false,
  174. noResult: false,
  175. noCoupon: false,
  176. noPrize: true,
  177. })
  178. this.data.goodsItemList = [];
  179. this.getUserPrizeList()
  180. },
  181. turnPrize: function() {
  182. console.log("开始查看")
  183. if (this.lock || !this.data.isLogin) {
  184. return
  185. }
  186. this.lock = true
  187. },
  188. // 授权手机号
  189. getPhoneNumber(e) {
  190. getPhoneNumberSync(e, _ => {
  191. this.setData({
  192. isLogin: true,
  193. mobileTop: getMobileCache(),
  194. hidden1: false,
  195. hidden2: true,
  196. noCoupon: true,
  197. noPrize: false,
  198. })
  199. this.getUserPrizeList()
  200. })
  201. },
  202. toRecordPrize(e) {
  203. const url = "recordPrize?id=" + e.currentTarget.dataset.id
  204. wx.redirectTo({
  205. url
  206. })
  207. },
  208. toLookHitPhoto(e) {
  209. console.log(e)
  210. let url = e.currentTarget.dataset.src;
  211. this.setData({
  212. showCustomPreview: true,
  213. previewImgSrc: url,
  214. })
  215. // url = 'https://ks3-cn-shanghai.ksyun.com/pb001/web/hsay/publicPath/a2623624-caf1-4877-99d0-c9355984e964.jpg';
  216. // // 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'
  217. // wx.previewImage({
  218. // current: url, // 当前显示图片的http链接
  219. // urls: [url] // 需要预览的图片http链接列表
  220. // })
  221. },
  222. closePreviewImage() {
  223. this.setData({
  224. showCustomPreview: false
  225. })
  226. }
  227. })