/*
 * @Descripttion: HJ
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2021-04-01 11:59:47
 * @LastEditors: HJ
 * @LastEditTime: 2021-04-20 14:09:45
 */
// 处理活动规则
export const computedActiveText = (active = {}) => {
  if (Object.keys(active).length < 1) return;

  const {
    discountInfo,
    overflowReduction = [],
    reduceDelivery,
    platformCouponInfo,
  } = active;
  const { summary } = discountInfo || {};
  const { upStatus, threshold, reduceFee, allReduceFlag, noThresholdFlag } =
    reduceDelivery || {};

  const overflowText = overflowReduction.map(
    (i) => `满${i.overflow}减${i.reduction}`
  );

  const deliveryText = upStatus
    ? `配送费${noThresholdFlag ? "" : "满" + threshold}${
        allReduceFlag ? "全免" : "减免" + reduceFee + "元"
      }`
    : "";

  const discountText = summary || "";

  // 平台券
  let { couponSummary, currMerchantId } = platformCouponInfo;
  couponSummary = couponSummary || {}
  const platformCouponText = couponSummary[currMerchantId] || couponSummary["ALL"] || '';
  let res = {};
  deliveryText && (res["配送"] = deliveryText);
  overflowText.length > 0 && (res["满减"] = overflowText);
  discountText && (res["折扣"] = discountText);
  platformCouponText && (res["通用"] = platformCouponText)
  return res;
};
