| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- var _request = require('../../utils/request.js')
- var version = getApp().globalData.version
- var channel // 渠道二维码信息
- var scene // 渠道二维码id
- var url = '' // 分享或模板落地页
- var invite = 0 //邀请id
- var poster = []
- var project = []
- Page({
- data: {
- animationData: {},
- popup: false
- },
- onLoad: function (options) {
- console.log('options',options)
- url = 0
- if (options.scene) {
- scene = decodeURIComponent(options.scene)
- if (scene.indexOf('invite_wx_') > -1) {
- invite = scene.slice(10)
- } else if (scene.indexOf('poster') > -1) {
- this.getPoster(scene)
- } else if (scene.indexOf('project') > -1) {
- this.getPosterProject(scene)
- } else {
- this.getScene(scene)
- }
- } else if (options.url) {
- this.urlHandle(options)
- }
- if (options.invite) {
- invite = options.invite
- }
- var that = this
-
-
- //2020
- wx.setStorageSync('invite', invite) //存入邀请
- this.getAnimation(2000);
- return false;
-
- wx.getSetting({
- success: res => {
- var auth = res.authSetting
- if (!auth['scope.userInfo']) {
- that.setData({
- popup: true
- })
- } else {
- this.getVersion(2000)
- }
- }
- })
- },
- getPoster: function (val) {
- poster = val.split('$')
- if (poster.length > 0) {
- invite = poster[2]
- }
- },
- getPosterProject: function (val) {
- project = val.split('$')
- if (project.length > 0) {
- invite = project[2]
- }
- },
- urlHandle: function (val) {
- if (val.url) {
- url = val.url + '?'
- for (var i in val) {
- if (i !== 'url') {
- url += i + '=' + val[i] + '&'
- }
- }
- }
- },
- getScene: function () {
- var that = this
- var url = 'v1/xcx/channel/info/' + scene
- var params = {}
- var success = function (res) {
- channel = res.data
- }
- _request.$get(url, params, success)
- },
- sceneCount: function () {
- var that = this
- var url = 'v1/xcx/channel/figure/' + channel.parent_id
- var params = {}
- var success = function (res) {
- }
- _request.$post(url, params, success)
- },
- getAnimation: function (val) {
- var animation = wx.createAnimation({
- duration: 500,
- timingFunction: 'linear'
- })
- setTimeout(function() {
- animation.translateY(-150).opacity(0).step()
- this.setData({
- animationData:animation.export()
- })
- }.bind(this), val)
- setTimeout(function() {
- console.log(channel)
- if (channel) {
- this.sceneCount()
- }
- if (channel && channel.channel_url) {
- this.urlType(channel.channel_url)
- } else if (url) {
- this.urlType(url)
- } else if (poster.length > 0) {
- this.scanPoster()
- wx.redirectTo({
- url: '/pages/helpfarm/helpfarm-detail/helpfarm-detail?id=' + poster[1]
- })
- } else if (project.length > 0) {
- this.scanPoster()
- wx.redirectTo({
- url: '/pages/projects/project-detail/project-detail?id=' + project[1]
- })
- } else {
- wx.switchTab({
- url: '/pages/home/home'
- })
- }
- }.bind(this), val + 1000)
- },
- scanPoster: function (val, type) {
- var that = this
- var url = 'v1/poster/scan'
- var params = {
- params: scene
- }
- var success = function (res) {
- }
- _request.$get(url, params, success)
- },
- urlType: function (val) {
- let type = [
- 'pages/projects/projects?',
- 'pages/helpfarm/helpfarm?',
- 'pages/customservice/customservice?',
- 'pages/user/all/all?',
- ]
- let i = -1
- for (let a in type) {
- if (type[a].indexOf(val) > -1) {
- i = a
- let str = type[i]
- wx.switchTab({
- url: '/' + str.substring(0, str.length - 1)
- })
- break
- }
- }
- if (i <= -1) {
- wx.redirectTo({
- url: '/' + val
- })
- }
- },
- getUserInfo: function (val) {
- var channel_id = 0
- if (channel && Number(channel.parent_id) > 0) {
- channel_id = Number(channel.parent_id)
- }
- var that = this
- if (val.detail.errMsg === 'getUserInfo:ok') {
- wx.showLoading({
- title: '加载中'
- })
- _request.sendInfo(val, channel_id, invite, that)
- }
- },
- getVersion: function (val) {
- this.check()
- this.getAnimation(val)
- // var that = this
- // var url = 'v1/xcx/version/' + version
- // var params = {}
- // var success = function (res) {
- // if (res.data && res.data.state === 0) {
- // getApp().globalData.vershow = false
- // }
- // that.check()
- // that.getAnimation(val)
- // }
- // _request.$get(url, params, success)
- },
- check: function () {
- var that = this
- var url = 'v1/user/check'
- var params = {
- }
- var success = function (res) {
- getApp().globalData.wx_id = res.data.wx_user_id
- }
- _request.$get(url, params, success)
- }
- })
|