index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. paySuccess() {
  74. this.setUserInfo()
  75. this.selectComponent('#vipModal').open()
  76. },
  77. async getProducts() {
  78. let {
  79. productList: products,
  80. isPreferential
  81. } = await getProducts()
  82. console.log(products);
  83. this.setData({
  84. products,
  85. isPreferential
  86. })
  87. },
  88. activationCode() {
  89. wx.showModal({
  90. title: '请输入激活码',
  91. editable: true,
  92. success: async ({
  93. confirm,
  94. content
  95. }) => {
  96. if (confirm) {
  97. let regexp = /^[a-zA-Z0-9]{4}$/
  98. if (regexp.test(content)) {
  99. let activationRes = await getLearnCard({
  100. cardNo: content
  101. })
  102. if (activationRes.code == 200) {
  103. activationRes = {
  104. code: 200,
  105. message: '快去朗读挑战吧!'
  106. }
  107. }
  108. this.setUserInfo()
  109. if (typeof this.getTabBar === 'function') {
  110. this.getTabBar().setData({
  111. mask: true
  112. })
  113. }
  114. this.setData({
  115. activationModal: true,
  116. activationRes
  117. })
  118. } else {
  119. if (typeof this.getTabBar === 'function') {
  120. this.getTabBar().setData({
  121. mask: true
  122. })
  123. }
  124. this.setData({
  125. activationModal: true,
  126. activationRes: {
  127. code: 581,
  128. message: '请检查激活码输入是否正确'
  129. }
  130. })
  131. }
  132. }
  133. }
  134. })
  135. },
  136. toGzh() {
  137. this.selectComponent('#gzh').open()
  138. },
  139. openDonutBuy({
  140. currentTarget
  141. }) {
  142. let product = currentTarget.dataset.product
  143. console.log(product);
  144. this.selectComponent('#donutBuy').open(product)
  145. },
  146. jump({
  147. currentTarget
  148. }) {
  149. let url = currentTarget.dataset.url
  150. console.log(url);
  151. wx.navigateTo({
  152. url: url
  153. });
  154. },
  155. clipboar() {
  156. wx.setClipboardData({
  157. data: this.data.userInfo.user.eid,
  158. success: function (res) { //成功回调函数
  159. wx.showToast({
  160. title: '已复制',
  161. icon: "none"
  162. })
  163. }
  164. })
  165. },
  166. closeModal() {
  167. this.setData({
  168. activationModal: false
  169. })
  170. if (typeof this.getTabBar === 'function') {
  171. this.getTabBar().setData({
  172. mask: false
  173. })
  174. }
  175. },
  176. // 分享配置
  177. onShareAppMessage(res) {
  178. // #if MP
  179. return {
  180. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  181. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  182. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
  183. }
  184. // #elif ANDROID
  185. return {
  186. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  187. userName: 'gh_50f61361ad1d',
  188. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  189. imagePath: '/static/375-300-2.jpg',
  190. webpageUrl: 'http://www.efunbox.cn',
  191. withShareTicket: true,
  192. miniprogramType: 1,
  193. scene: 0,
  194. }
  195. // #endif
  196. },
  197. onShareTimeline: function () {
  198. return {
  199. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  200. query: `uid=${wx.getStorageSync('uid')}`,
  201. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  202. }
  203. },
  204. })