const isCheckedAll = (carList = []) => {
  return carList.every(v => {
    if (v.status === 'N') {
      return true;
    }
    return v.checkedState === 'Y';
  });
};

/**
 * 计算 选中了多少类物品
 * @param carList
 * return number
 */
const getCheckedNum = (carList = []) => {
  if (!carList.length) return 0;
  return carList.reduce((checkedNum, item) => {
    return item.checkedState === 'Y' ? checkedNum + 1 : checkedNum;
  }, 0);
};

/**
 * 计算 选中每类的物品总量
 * @param carList
 * return number
 */
const checkedGoodsNum = (carList = []) => {
  let num = 0;
  carList.forEach(v => {
    if (v.checkedState === 'Y') num += +v.quantity;
  });
  return num;
};

const isShowAuto = (car = {}) => {
  const { carts = [] } = car;
  if (carts.length) {
    if (carts.length === 1) {
      return false;
    }
    return !carts.every((v, index) => {
      if (
        index < carts.length - 1 &&
        v.deliverType !== carts[index + 1].deliverType
      ) {
        return false;
      }
      return true;
    });
  }
  return false;
};
export default {
  isShowAuto,
  isCheckedAll,
  checkedGoodsNum,
  getCheckedNum,
};
