yohoJump.js 2.59 KB
import queryString from '../vendors/query-stringify';

const GO_LIST = 'go.list';
const GO_PRODUCT_POOL = 'go.poollist';
const GO_SHOP = 'go.shop';
const GO_BRAND = 'go.brand';
const GO_CATEGORY = 'go.category';
const GO_DETAIL = 'go.productDetail';
const GO_COUPON = 'go.coupon';
const GO_MINE = 'go.mine';
const GO_NEW = 'go.new';
const GO_SHOP_CART = 'go.shopcart';
const GO_H5 = 'go.h5';
const GO_ACTIVITY = 'go.activitytemplate';

export default function jumpYohoUrl(jumpUrl, pageName) {
  if (!jumpUrl) {
    return;
  }

  let url = '';
  let startIndex = jumpUrl.indexOf('openby:yohobuy=');

  if (startIndex < 0) {
    return;
  }

  let jsonRule = jumpUrl.substring(startIndex + 'openby:yohobuy='.length);
  let json = JSON.parse(jsonRule);
  let action = json.action;

  let path = '';

  if (GO_LIST === action) {
    let actionType = +json.params.actiontype;

    if (actionType === 1 || !actionType) {
      path = '/pages/goodsList/goodsList';
    } else if (actionType === 2) {

      // 模式1不支持优惠活动详情
      path = '/pages/goodsList/activtyDetail';
    }
  } else if (GO_BRAND === action) {

    // 模式1暂不支持品牌
    path = '/pages/goodsList/brand';
  } else if (GO_PRODUCT_POOL === action) {
    path = '/pages/goodsList/productPool';
  } else if (GO_SHOP === action) {

    // 模式1不支持
    path = '/pages/goodsList/brandStore';
  } else if (GO_DETAIL === action) {
    path = '/pages/goodsDetail/goodsDetail';
  } else if (GO_COUPON === action) {

    // 模式1不支持优惠券列表
    path = '/pages/page/subPackage/pages/couponList/couponList';
  } else if (GO_NEW === action) {

    // 模式1暂不支持新品到着
    path = '/pages/goodsList/newArrival';
  } else if (GO_SHOP_CART === action) {
    wx.switchTab({
      url: '/pages/cart/cart'
    });
    return;
  } else if (GO_CATEGORY === action) {
    wx.switchTab({
      url: '/pages/shop/category/category'
    });
    return;
  } else if (GO_MINE === action) {
    wx.switchTab({
      url: '/pages/home/home'
    });
    return;
  } else if (GO_H5 === action) {
    path = '/pages/webview/webview';
  } else if (GO_ACTIVITY === action) {
    let actionType = +json.params.type;

    if (actionType === 2) {

      // 模式1不支持团购
      path = '/pages/groupPurchase/groupPurchase';
    } else if (actionType === 3) {

      // 模式1不支持助力
      path = '/pages/assist/assist';
    }
  }

  if (!path) {
    return;
  }

  let params = queryString.stringify(json.params, {encode: false});

  url = path + '?page_name=' + pageName + '&' + params;

  if (url) {
    wx.navigateTo({
      url
    });
  }
}