index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {
  2. getMyInfo,
  3. getVipInfo,
  4. getWxQrcode,
  5. getLearnCard
  6. } from '~/api/user'
  7. import event from '~/mixins/event'
  8. import {
  9. getProducts,
  10. userEvent
  11. } from '~/api/global'
  12. import {
  13. createStoreBindings
  14. } from 'mobx-miniprogram-bindings'
  15. import {
  16. store
  17. } from '~/store/index'
  18. const app = getApp()
  19. Page({
  20. behaviors: [event],
  21. data: {
  22. userInfo: {},
  23. products: [],
  24. },
  25. async onLoad() {
  26. // 手工绑定
  27. this.storeBindings = createStoreBindings(this, {
  28. store,
  29. actions: {
  30. setUser: 'setUser'
  31. }
  32. })
  33. if (this.data.isIos) {
  34. let qrCode = await getWxQrcode()
  35. this.setData({
  36. qrCode: qrCode.ticketUrl
  37. })
  38. }
  39. },
  40. async onShow() {
  41. if (typeof this.getTabBar === 'function') {
  42. this.getTabBar().setData({
  43. selected: 4
  44. })
  45. }
  46. let uid = wx.getStorageSync('uid') || ''
  47. if (!uid) {
  48. getApp().callBack = (res) => {
  49. this.setUserInfo()
  50. }
  51. } else {
  52. this.setUserInfo()
  53. }
  54. },
  55. // 设置用户信息及vip状态
  56. async setUserInfo() {
  57. let userInfo = await getMyInfo()
  58. let vipTime = await getVipInfo()
  59. this.setUser(userInfo.user)
  60. this.getProducts()
  61. this.setData({
  62. userInfo,
  63. vipTime,
  64. })
  65. },
  66. paySuccess() {
  67. this.setUserInfo()
  68. this.selectComponent('#vipModal').open()
  69. },
  70. async getProducts() {
  71. let {
  72. productList: products,
  73. } = await getProducts()
  74. this.setData({
  75. products,
  76. })
  77. },
  78. openDonutBuy({
  79. currentTarget
  80. }) {
  81. let product = currentTarget.dataset.product
  82. this.selectComponent('#donutBuy').open(product)
  83. },
  84. jump({
  85. currentTarget
  86. }) {
  87. let url = currentTarget.dataset.url
  88. console.log(url);
  89. wx.navigateTo({
  90. url: url
  91. });
  92. },
  93. clipboar() {
  94. wx.setClipboardData({
  95. data: this.data.userInfo.user.eid,
  96. success: function (res) { //成功回调函数
  97. wx.showToast({
  98. title: '已复制',
  99. icon: "none"
  100. })
  101. }
  102. })
  103. },
  104. })