unionShare.js 6.23 KB
import { API_HOST, SERVICE_HOST } from '../../../../libs/config';
import { GET, POST } from '../../../../libs/request';
import {
  logEvent,
  YB_PAGE_OPEN_L,
  YB_SHARE_PROMOTION_C,
  YB_SHARE_RESULT_L,
} from '../../../../libs/analytics.js'

let app = getApp();
let PV_ID = new Date().getTime() + '';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShowSnapshoot: false,
    from_page_name: '',
    from_page_param: '',
    current_page_name: 'unionShare',
    current_page_param: '',


    sourceType: 'product_union',

    snapshootShareData: {},
    shareCommand: '',
    content: '',
    shortUrl: '',
    rebateContent: '',
    contentSwitch: true,
    contentShow: false,
    user_union_type_imageUrl: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let timestamp = options.timestamp;
    let from_page_name = options.page_name;
    let from_page_param = options.page_param;
    let sourceType = 'product_union';
    let value = wx.getStorageSync(timestamp);
    try {
      wx.setStorageSync(timestamp, null);//清除内存
    } catch (e) {
    }

    if (from_page_name == 'productDetail') {
      sourceType = 'product_union'
    } else if (from_page_name == 'goodsList' || from_page_name == 'search') {
      sourceType = 'list_union'
    } else if (from_page_name == 'webview') {
      sourceType = 'h5_union'
    }
    let user_union_type_imageUrl = app.globalData.user_union_type_imageUrl;

    this.setData({
      from_page_name,
      from_page_param,
      sourceType,
      snapshootShareData: value,
      user_union_type_imageUrl,
    })
    console.log(this.data.snapshootShareData);

    this.getShareCodeInfo();

    var pages = getCurrentPages()
    var currentPage = pages[pages.length - 1]
    var url = currentPage.route

    let params = {
      PAGE_NAME: this.data.current_page_name,
      PAGE_PARAM: this.data.current_page_param,
      FROM_PAGE_NAME: this.data.from_page_name,
      FROM_PAGE_PARAM: this.data.from_page_param,
      PV_ID: PV_ID,
      PAGE_PATH: url
    };
    logEvent(YB_PAGE_OPEN_L, params);
  },

  onShareAppMessage: function (res) {

    let params = {
      PAGE_PATH: this.data.snapshootShareData.sharePath,
      SHARE_TYPE: 1,
    };
    logEvent(YB_SHARE_PROMOTION_C, params);


    let param = {
      FROM: res.from,
      SHARE_RESUIL: 0,
      TITLE: '创建推广',
      DESC: this.data.snapshootShareData.content,
      PATH: this.data.snapshootShareData.sharePath,
      SHARE_TYPE: 1,
    }

    return {
      title: this.data.snapshootShareData.title, // 分享标题
      imageUrl: this.data.snapshootShareData.default_image,
      desc: this.data.snapshootShareData.content, // 分享描述
      path: this.data.snapshootShareData.sharePath, // 分享路径
      success: function (res) {
        param.SHARE_RESUIL = 1
        logEvent(YB_SHARE_RESULT_L, param);
      },
      fail: function (res) {
        param.SHARE_RESUIL = 2
        logEvent(YB_SHARE_RESULT_L, param);
      }
    }
  },

  getShareCodeInfo: function(){
    let gender = app.globalData.selectedChannel == 'boy' ? '1,3' : '2,3';
    let type = 1;
    if (this.data.from_page_name == 'productDetail') {
      type = 1;
    } else if (this.data.from_page_name == 'webview') {
      type = 2;
    } else if (this.data.from_page_name == 'goodsList' || this.data.from_page_name == 'search') {
      type = 3;
    }

    let param = {
      method: 'app.union.shareOrder.getShareCodeInfo',
      unionType: app.globalData.user_union_type,
      type,
      skn: type == 1 && this.data.snapshootShareData && this.data.snapshootShareData.product_skn? this.data.snapshootShareData.product_skn: '',
      shareId: type == 2 && this.data.snapshootShareData && this.data.snapshootShareData.shareId  ? this.data.snapshootShareData.shareId : '',
      msort: type == 3 && this.data.snapshootShareData && this.data.snapshootShareData.msort ? this.data.snapshootShareData.msort : '',
      misort: type == 3 && this.data.snapshootShareData && this.data.snapshootShareData.misort ? this.data.snapshootShareData.misort : '',
      gender,
      query: type == 3 && this.data.snapshootShareData && this.data.snapshootShareData.query ? this.data.snapshootShareData.query : '',
      title: this.data.snapshootShareData ? this.data.snapshootShareData.title: '',
    }
    if (this.data.from_page_name == 'goodsList'){
      param.actiontype = 1;
      param.title = this.data.snapshootShareData.goodListName;
    } else if (this.data.from_page_name == 'search') {
      param.title = this.data.snapshootShareData.keyword;
    }
    if (this.data.from_page_name == 'goodsList' && this.data.snapshootShareData.sort) {
      param.sort = this.data.snapshootShareData.sort;
    }
    let that = this;
    GET(API_HOST, param)
      .then(data => {
        if (data.code == 200) {
          let shareCommand = data.data.shareCommand ? data.data.shareCommand : '';
          let content = data.data.content ? data.data.content : '';
          let shortUrl = data.data.shortUrl;
          let rebateContent = data.data.rebateContent;
          let contentSwitch = data.data.contentSwitch;
          that.setData({
            shareCommand,     
            content,
            shortUrl,
            rebateContent,
            contentSwitch,
            contentShow: true,
          });
        }
      })
      .catch(error => {
        // console.log(error)
      });
  },

  sharePicture: function () {
    this.setData({
      isShowSnapshoot: true,
    });

    let params = {
      PAGE_PATH: this.data.snapshootShareData.sharePath,
      SHARE_TYPE: 2,
    };
    logEvent(YB_SHARE_PROMOTION_C, params);
  },

  save: function() {
    wx.setClipboardData({
      data: this.data.content,
      success: function (res) {
      },
    }) 
    let params = {
      PAGE_PATH: this.data.snapshootShareData.sharePath,
      SHARE_TYPE: 3,
    };
    logEvent(YB_SHARE_PROMOTION_C, params);
  },

  lookDetail: function () {
    wx.navigateTo({
      url: '../../../../pages/webview/webview?url=' + 'https://activity.yoho.cn/feature/2213.html?title=说明详情',
    })
  },
  
  bindInput: function(e){
    let value = e.detail.value;
    this.setData({
      content: value
    })
  },

  hiddenSheet: function(){
    this.setData({
      isShowSnapshoot: false
    })
  },

})