member.js 5.4 KB

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