commonShareUtils.js 4.61 KB
'use strict';

// union_type  CPS 用户都要携带
// miniQrType=4 拼团详情 √
// miniQrType=7 商品详情 √
// miniQrType=9 h5 √
// miniQrType=15 拼团列表 √
// miniQrType=18 逛

// miniQrType=15

let host = 'http://api.yoho.cn';
const shareGroupPurchaseList = (shareInfo) => {
  let {
    activityId,
    shareCodeInfo
  } = shareInfo;

  let param = {
    activityId,
  }
  let qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + encodeURIComponent(JSON.stringify(param)) + '&miniQrType=24' + '&miniapp_type=60';
  let miniProgramPath = `/pages/group/list?activityId=${activityId}`;
  let fromPage = 'GroupPurchase';
  let businessId = 'collage';

  let shareParam = {
    title: shareCodeInfo.content ? shareCodeInfo.content : '',
    content: shareCodeInfo.content ? shareCodeInfo.content : '',
    image: shareCodeInfo.pic,
    bigImage: shareCodeInfo.bigImage,
    url: shareCodeInfo.url,
    miniProgramPath,
    miniProgramQCodeUrl: qrCode,
    from: fromPage,
    businessId
  };
  return shareParam;
};

// miniQrType=17
const shareGroupPurchaseDetail = (shareInfo) => {
  const productSkn = shareInfo.productInfo.productSkn;

  let {
    activityId,
    productInfo,
    union_type
  } = shareInfo;

  let miniProgramPath = `pages/group/detail?productSkn=${productSkn}&activityId=${activityId}&union_type=${union_type}`
  let param = {
    productSkn,
    activityId,
    union_type
  };
  let qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + encodeURIComponent(JSON.stringify(param)) + '&miniQrType=24' + '&miniapp_type=60';

  let shareParam = {
    title: productInfo.productName ? productInfo.productName : '',
    content: productInfo.productName ? productInfo.productName : '',
    image: productInfo.colorImage,
    url: productInfo.productUrl,
    miniProgramPath: miniProgramPath,
    miniProgramQCodeUrl: qrCode,
    product_name: productInfo.productName ? productInfo.productName : '',
    sales_price: `¥${productInfo.marketPrice}`,
    original_sales_price: `¥${productInfo.originalSalesPrice}`,
    productDefaultImage: productInfo.colorImage,
    fromType: 'productDetail',
  };
  return shareParam;
};

// miniQrType=7
const shareGoodsDetail = (shareInfo) => {
  let {
    productInfo,
    union_type
  } = shareInfo;
  let qrCode;

  let productSkn = productInfo.productSkn;
  let params = {
    productSkn,
    union_type,
  }

  let paramsString = encodeURIComponent(JSON.stringify(params));
  qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + paramsString + '&miniQrType=7';

  let shareParam = {
    title: productInfo.productName ? productInfo.productName : '',
    content: productInfo.productName ? productInfo.productName : '',
    image: productInfo.colorImage,
    url: productInfo.productUrl,
    miniProgramPath: 'pages/goodsDetail/goodsDetail?productSkn=' + productSkn,
    miniProgramQCodeUrl: qrCode,
    product_name: productInfo.productName ? productInfo.productName : '',
    sales_price: `¥${productInfo.originalSalesPrice}`,
    productDefaultImage: productInfo.colorImage,
    product_skn: productSkn + '',
    fromType: 'productDetail',
  };
  return shareParam;
};

// miniQrType=18
const shareStrollDetail = (shareInfo) => {
  let {
    url,
    title,
    content,
    pic,
    minSortName,
    wechatShareImgUrl,
    union_type
  } = shareInfo;

  let params = {
    id: shareInfo.someKey,
    union_type
  }
  let paramsString = encodeURIComponent(JSON.stringify(params));
  let qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + paramsString + '&miniQrType=18';
  let miniProgramPath = `page/subPackage/pages/guang/detail?id=${shareInfo.someKey}`;
  let shareParam = {
    title: title ? title : '',
    content: content ? content : '',
    pic: pic,
    image: pic,
    bigImage: wechatShareImgUrl,
    url: url,
    minSortName,
    miniProgramQCodeUrl: qrCode,
    miniProgramPath,
  };
  return shareParam;
}

// miniQrType=9
const shareH5 = (shareInfo) => {
  // 请求web数据
  let { someKey, url, data, isCatch } = shareInfo;
  let param = {
    shareId: someKey,
    url: data.shareUrl
  }
  let qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + encodeURIComponent(JSON.stringify(param)) + '&miniQrType=9';
  let miniProgramPath = `pages/webview/webview?url=${url}&title=${data.content}`;
  let shareParam = {
    title: data.content ? data.content : '',
    content: data.content ? data.content : '',
    image: data.pic,
    bigImage: data.bigImage,
    url: url,
    miniProgramPath,
    miniProgramQCodeUrl: qrCode,
    from: 'h5',
    isCatch,
  };
  return shareParam;
}

export {
  shareGroupPurchaseList,
  shareGroupPurchaseDetail,
  shareGoodsDetail,
  shareStrollDetail,
  shareH5,
};