/**
 * 计算 减法
 */
const calcNumber = (a = 0, b = 0, type = 'add') => {
  const tempA = a || 0;
  const tempB = b || 0;
  return type === 'add'
    ? Math.floor(tempA * 100 + tempB * 100) / 100
    : Math.floor(tempA * 100 - tempB * 100) / 100;
};

const calcNumberThird = (a, b, c, type = 'add') => {
  const tempA = a || 0;
  const tempB = b || 0;
  const tempC = c || 0;
  return type === 'add'
    ? Math.floor(tempA * 100 + tempB * 100 + tempC * 100) / 100
    : Math.floor(tempA * 100 - tempB * 100) / 100;
};
// 获取会员价等级价格
const getMemberLevelPrice = (priceSetting = [], level = '') => {
  if (priceSetting.length === 1) {
    // 统一会员价
    return priceSetting[0].membershipPrice;
  }
  if (level === 'NONE') {
    return priceSetting[0] ? priceSetting[0].membershipPrice : '';
  }
  const item = priceSetting.filter(v => v.level === level);
  return item[0] ? item[0].membershipPrice : '';
};

export default { calcNumber, calcNumberThird, getMemberLevelPrice };
