member.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {
  2. get,
  3. post
  4. } from '../../utils/http'
  5. import {
  6. formatActivity
  7. } from '../../utils/time'
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. userInfo: {},
  14. agree: false,
  15. visible: false,
  16. sum: 0,
  17. activity: {},
  18. needReqActivity: true,
  19. inserllAmount: 0,
  20. inserllAmountLittle: '00',
  21. CardDiscount: '', //是否购买次卡拥有美妆折扣
  22. goods_discount: '', //是否存在商品权益,1是,0否
  23. level: '', //用户折扣等级 (0是未拥有等级)
  24. levelList: {
  25. 1: '0.98',
  26. 4: '0.95',
  27. 7: '0.90',
  28. }, //折扣列表
  29. levelImage: ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%205%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%202%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%207%402x.png']
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady: function () {},
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow: function () {
  44. // 获取用户折扣等级
  45. this.getLevel()
  46. this.getUser()
  47. this.getAmount()
  48. this.getCoin()
  49. if (wx.getStorageSync('token') && this.data.needReqActivity) {
  50. this.getUserActivity()
  51. }
  52. this.setData({
  53. agree: wx.getStorageSync('agree') || false
  54. })
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide: function () {},
  60. /**
  61. * 生命周期函数--监听页面卸载
  62. */
  63. onUnload: function () {
  64. if (this.timer_) {
  65. clearInterval(this.timer_)
  66. }
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {},
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom: function () {},
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {},
  80. // 点击头像切换环境
  81. onAvatar() {
  82. this.data.sum++
  83. if (this.data.sum >= 10) {
  84. this.setData({
  85. visible: true,
  86. sum: 0
  87. })
  88. }
  89. },
  90. // 获取用户折扣等级
  91. getLevel() {
  92. get('/v2/api/user/discount_level', {}, (res) => {
  93. let arr = [1,4,7]
  94. let index = arr.findIndex(item=>{
  95. return item==res.data
  96. })
  97. this.setData({
  98. imageIndex:index
  99. })
  100. if (res.code == 200) {
  101. if (res.data == 0) {
  102. this.setData({
  103. level: 0
  104. })
  105. return
  106. }
  107. let getValue = (item, val) => {
  108. return item[val]
  109. }
  110. this.setData({
  111. level: Number(getValue(this.data.levelList, res.data))
  112. })
  113. }
  114. })
  115. },
  116. /**
  117. * 获取用户信息
  118. * api/user
  119. */
  120. getUser() {
  121. get('api/user', {}, (res) => {
  122. if (res.data) {
  123. this.setData({
  124. userInfo: res.data,
  125. goods_discount: res.data.goods_discount
  126. }, )
  127. wx.setStorageSync('userInfo', res.data)
  128. }
  129. })
  130. },
  131. /**
  132. * 获取我的储值
  133. * api/user
  134. */
  135. getAmount() {
  136. get('api/user/amount', {}, (res) => {
  137. if (res.data) {
  138. this.setData({
  139. inserllAmount: res.data.amount.split('.')[0],
  140. inserllAmountLittle: res.data.amount.split('.')[1],
  141. })
  142. }
  143. })
  144. },
  145. /**
  146. * 获取我的积分
  147. * api/user
  148. */
  149. getCoin() {
  150. get('api/user/coin', {}, (res) => {
  151. if (res.data) {
  152. this.setData({
  153. coin: res.data.coin_num
  154. })
  155. }
  156. })
  157. },
  158. /**
  159. * 跳转vip页面
  160. */
  161. goToVip() {
  162. console.log(this.data.userInfo)
  163. let nextDatas = JSON.stringify(this.data.userInfo)
  164. wx.navigateTo({
  165. url: `/pages/vip/vip?userInfo=${encodeURIComponent(nextDatas)}`
  166. // url: `/pages/vip/vip?userInfo=${JSON.stringify(this.data.userInfo)}`
  167. // url: '/pages/vip/vip?userInfo='+ JSON.stringify(this.data.userInfo),
  168. })
  169. },
  170. /**
  171. * 获取首次开卡优惠
  172. * api/user/activity
  173. */
  174. getUserActivity() {
  175. if (this.timer) {
  176. clearInterval(this.timer_)
  177. }
  178. get('api/user/activity', {}, (res) => {
  179. this.data.needReqActivity = false
  180. if (res.data) {
  181. res.data.currentTime = formatActivity(res.data.expire_time_seconds)
  182. this.setData({
  183. activity: res.data
  184. })
  185. this.timer_ = setInterval(() => {
  186. if (res.data.expire_time_seconds <= 0) {
  187. clearInterval(this.timer_)
  188. }
  189. res.data.expire_time_seconds--
  190. res.data.currentTime = formatActivity(res.data.expire_time_seconds)
  191. this.setData({
  192. activity: res.data
  193. })
  194. }, 1000)
  195. }
  196. })
  197. },
  198. // 获取是否拥有购买次卡后拥有的美妆折扣
  199. getCardDiscount() {
  200. get('', {}, (res) => {
  201. this.setData({
  202. CardDiscount: ''
  203. })
  204. })
  205. }
  206. })