123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import {
- getUserInfo,
- getVipInfo
- } from '~/api/user'
- import {
- getProducts,
- getTasks,
- submitTask
- } from '~/api/global'
- import {
- getOpenidNoLogin
- } from '~/utils/httpUtilNoLogin';
- import httpRequestApi from '~/utils/APIClient';
- let app = getApp()
- Page({
- data: {
- userInfo: {},
- vipTime: '',
- isIos: false,
- tasks: [],
- // isIos: app.globalData.isIOS,
- productNum: {},
- productVip: {}
- },
- onLoad() {
- this.getProducts()
- },
- async onShow() {
- let uid = wx.getStorageSync('uid') || ''
- // 没登陆先走静默登录,登录后直接获取用户信息
- if (!uid) {
- getOpenidNoLogin(async () => {
- this.setUserInfo()
- })
- } else {
- this.setUserInfo()
- }
- },
- // 设置用户信息及vip状态和任务完成情况
- async setUserInfo() {
- let userInfo = await getUserInfo()
- let vipTime = await getVipInfo()
- this.getTasks()
- this.setData({
- userInfo,
- vipTime,
- })
- console.log(userInfo);
- // 如果用户没有头像及昵称的话就提醒获取
- if (!userInfo.user.avatar && !userInfo.user.wechatName) {
- wx.navigateTo({
- url: `/pages/login/login`
- });
- }
- },
- async getTasks() {
- let tasks = await getTasks()
- this.setData({
- tasks
- })
- },
- async getProducts() {
- let products = await getProducts()
- let productVip = products.find(item => {
- return item.type == 1
- })
- let productNum = products.find(item => {
- return item.type == 2
- })
- console.log(productNum, productVip);
- this.setData({
- productNum,
- productVip
- })
- },
- // 支付
- toPay({
- currentTarget
- }) {
- let type = currentTarget.dataset.type
- },
- // 提交任务
- async submitTask({
- currentTarget
- }) {
- let id = currentTarget.dataset.type
- await submitTask({
- id
- })
- wx.showToast({
- title: id == '1' ? '签到成功!' : id == 3 ? "观看成功!" : "",
- icon: "none"
- })
- this.getTasks()
- },
- jump({
- currentTarget
- }) {
- let url = currentTarget.dataset.url
- wx.navigateTo({
- url: url
- });
- },
- goToService() {
- httpRequestApi.userEvent('SERVICE');
- },
- switcher({
- currentTarget
- }) {
- wx.reLaunch({
- url: `/pages/index/index?tabbarIndx=${currentTarget.dataset.index}`
- });
- },
- rewardedVideo() {
- if (this.data.tasks.length != 3 || this.data.tasks[2].completed) {
- return
- }
- this.selectComponent('#advert').rewardedVideo();
- }
- })
|