profile.js 5.8 KB

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