index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. vipTime: '',
  24. tasks: [],
  25. isIos: app.globalData.isIOS,
  26. qrCode: '',
  27. activationModal: false,
  28. activationRes: {},
  29. products: [],
  30. isPreferential: false
  31. },
  32. async onLoad() {
  33. // 手工绑定
  34. this.storeBindings = createStoreBindings(this, {
  35. store,
  36. actions: {
  37. setUser: 'setUser'
  38. }
  39. })
  40. if (this.data.isIos) {
  41. let qrCode = await getWxQrcode()
  42. this.setData({
  43. qrCode: qrCode.ticketUrl
  44. })
  45. }
  46. },
  47. async onShow() {
  48. if (typeof this.getTabBar === 'function') {
  49. this.getTabBar().setData({
  50. selected: 4
  51. })
  52. }
  53. let uid = wx.getStorageSync('uid') || ''
  54. if (!uid) {
  55. getApp().callBack = (res) => {
  56. this.setUserInfo()
  57. }
  58. } else {
  59. this.setUserInfo()
  60. }
  61. },
  62. // 设置用户信息及vip状态
  63. async setUserInfo() {
  64. let userInfo = await getMyInfo()
  65. let vipTime = await getVipInfo()
  66. this.setUser(userInfo.user)
  67. this.getProducts()
  68. this.setData({
  69. userInfo,
  70. vipTime,
  71. })
  72. },
  73. async getProducts() {
  74. let {
  75. productList: products,
  76. isPreferential
  77. } = await getProducts()
  78. console.log(products);
  79. this.setData({
  80. products,
  81. isPreferential
  82. })
  83. },
  84. activationCode() {
  85. wx.showModal({
  86. title: '请输入激活码',
  87. editable: true,
  88. success: async ({
  89. confirm,
  90. content
  91. }) => {
  92. if (confirm) {
  93. let regexp = /^[a-zA-Z0-9]{4}$/
  94. if (regexp.test(content)) {
  95. let activationRes = await getLearnCard({
  96. cardNo: content
  97. })
  98. if (activationRes.code == 200) {
  99. activationRes = {
  100. code: 200,
  101. message: '快去朗读挑战吧!'
  102. }
  103. }
  104. this.setUserInfo()
  105. if (typeof this.getTabBar === 'function') {
  106. this.getTabBar().setData({
  107. mask: true
  108. })
  109. }
  110. this.setData({
  111. activationModal: true,
  112. activationRes
  113. })
  114. } else {
  115. if (typeof this.getTabBar === 'function') {
  116. this.getTabBar().setData({
  117. mask: true
  118. })
  119. }
  120. this.setData({
  121. activationModal: true,
  122. activationRes: {
  123. code: 581,
  124. message: '请检查激活码输入是否正确'
  125. }
  126. })
  127. }
  128. }
  129. }
  130. })
  131. },
  132. toGzh() {
  133. this.selectComponent('#gzh').open()
  134. },
  135. openDonutBuy({
  136. currentTarget
  137. }) {
  138. let product = currentTarget.dataset.product
  139. console.log(product);
  140. this.selectComponent('#donutBuy').open(product)
  141. },
  142. jump({
  143. currentTarget
  144. }) {
  145. let url = currentTarget.dataset.url
  146. console.log(url);
  147. wx.navigateTo({
  148. url: url
  149. });
  150. },
  151. clipboar() {
  152. wx.setClipboardData({
  153. data: this.data.userInfo.user.eid,
  154. success: function (res) { //成功回调函数
  155. wx.showToast({
  156. title: '已复制',
  157. icon: "none"
  158. })
  159. }
  160. })
  161. },
  162. closeModal() {
  163. this.setData({
  164. activationModal: false
  165. })
  166. if (typeof this.getTabBar === 'function') {
  167. this.getTabBar().setData({
  168. mask: false
  169. })
  170. }
  171. },
  172. // 分享配置
  173. onShareAppMessage(res) {
  174. // #if MP
  175. return {
  176. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  177. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  178. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
  179. }
  180. // #elif ANDROID
  181. return {
  182. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  183. userName: 'gh_50f61361ad1d',
  184. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  185. imagePath: '/static/375-300-2.jpg',
  186. webpageUrl: 'http://www.efunbox.cn',
  187. withShareTicket: true,
  188. miniprogramType: 1,
  189. scene: 0,
  190. }
  191. // #endif
  192. },
  193. onShareTimeline: function () {
  194. return {
  195. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  196. query: `uid=${wx.getStorageSync('uid')}`,
  197. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  198. }
  199. },
  200. })