member.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. if (wx.getStorageSync('token')){
  51. // 获取用户折扣等级
  52. this.getLevel()
  53. this.getUser()
  54. this.getAmount()
  55. this.getCoin()
  56. }
  57. if (wx.getStorageSync('token') && this.data.needReqActivity) {
  58. this.getUserActivity()
  59. }
  60. this.setData({
  61. agree: wx.getStorageSync('agree') || false
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {},
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. if (this.timer_) {
  73. clearInterval(this.timer_)
  74. }
  75. },
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh: function () {},
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {},
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {},
  88. // 点击头像切换环境
  89. onAvatar() {
  90. this.data.sum++
  91. if (this.data.sum >= 10) {
  92. this.setData({
  93. visible: true,
  94. sum: 0
  95. })
  96. }
  97. },
  98. // 获取用户折扣等级
  99. getLevel() {
  100. get('/v2/api/user/discount_level', {}, (res) => {
  101. if (res.code == 200) {
  102. res.data = Number(res.data)
  103. let arr = [8, 9, 9.5, 9.8]
  104. let index = arr.findIndex(item => {
  105. return item == res.data
  106. })
  107. this.setData({
  108. imageIndex: index
  109. })
  110. if (res.data == 0) {
  111. this.setData({
  112. level: 0
  113. })
  114. return
  115. }
  116. this.setData({
  117. level: Number(res.data * 0.1)
  118. })
  119. }
  120. })
  121. },
  122. /**
  123. * 获取用户信息
  124. * api/user
  125. */
  126. getUser() {
  127. get('api/user', {}, (res) => {
  128. if (res.data) {
  129. this.setData({
  130. userInfo: res.data,
  131. goods_discount: res.data.goods_discount
  132. }, )
  133. wx.setStorageSync('userInfo', res.data)
  134. }
  135. })
  136. },
  137. /**
  138. * 获取我的储值
  139. * api/user
  140. */
  141. getAmount() {
  142. get('api/user/amount', {}, (res) => {
  143. if (res.data) {
  144. this.setData({
  145. inserllAmount: res.data.amount.split('.')[0],
  146. inserllAmountLittle: res.data.amount.split('.')[1],
  147. })
  148. }
  149. })
  150. },
  151. /**
  152. * 获取我的积分
  153. * api/user
  154. */
  155. getCoin() {
  156. get('api/user/coin', {}, (res) => {
  157. if (res.data) {
  158. this.setData({
  159. coin: res.data.coin_num
  160. })
  161. }
  162. })
  163. },
  164. /**
  165. * 跳转vip页面
  166. */
  167. goToVip() {
  168. console.log(this.data.userInfo)
  169. let nextDatas = JSON.stringify(this.data.userInfo)
  170. wx.navigateTo({
  171. url: `/pages/vip/vip?userInfo=${encodeURIComponent(nextDatas)}`
  172. // url: `/pages/vip/vip?userInfo=${JSON.stringify(this.data.userInfo)}`
  173. // url: '/pages/vip/vip?userInfo='+ JSON.stringify(this.data.userInfo),
  174. })
  175. },
  176. /**
  177. * 获取首次开卡优惠
  178. * api/user/activity
  179. */
  180. getUserActivity() {
  181. if (this.timer) {
  182. clearInterval(this.timer_)
  183. }
  184. get('api/user/activity', {}, (res) => {
  185. this.data.needReqActivity = false
  186. if (res.data) {
  187. res.data.currentTime = formatActivity(res.data.expire_time_seconds)
  188. this.setData({
  189. activity: res.data
  190. })
  191. this.timer_ = setInterval(() => {
  192. if (res.data.expire_time_seconds <= 0) {
  193. clearInterval(this.timer_)
  194. }
  195. res.data.expire_time_seconds--
  196. res.data.currentTime = formatActivity(res.data.expire_time_seconds)
  197. this.setData({
  198. activity: res.data
  199. })
  200. }, 1000)
  201. }
  202. })
  203. },
  204. // 获取是否拥有购买次卡后拥有的美妆折扣
  205. getCardDiscount() {
  206. get('', {}, (res) => {
  207. this.setData({
  208. CardDiscount: ''
  209. })
  210. })
  211. },
  212. // 跳转到个人档案
  213. goDossier() {
  214. wx.navigateTo({
  215. url: '/pages/dossier/dossier',
  216. })
  217. },
  218. // 打开我的二维码
  219. getQR() {
  220. this.setData({
  221. showQR: true
  222. })
  223. let userId = 'userid' + wx.getStorageSync('userInfo').uid
  224. toQrcode('qrcode', userId, 400, 400)
  225. },
  226. // 关闭我的二维码
  227. onCloseLandscape() {
  228. this.setData({
  229. showQR: false
  230. })
  231. }
  232. })