//改变数量
export function changeCount(row, index, arr, noDiscountSingle) {
  if (row) {
    singleWeightChange(row, index);
  }
  return getNumTotalPrice(arr, noDiscountSingle);
}

//计算总金额
function getNumTotalPrice(arr, noDiscountSingle) {
  let sum = 0;
  arr.forEach((r, index) => {
    // if (r.singlePrice) {
    //   r.notaxSinglePrice=r.taxRate?r.singlePrice/(1-(r.taxRate/100)):r.singlePrice
    // }
    if (r.singlePrice && r.totalCount) {
      r.discountSinglePrice = !noDiscountSingle
        ? r.singlePrice
        : r.discountSinglePrice;
      r.totalPrice = getAllPrice(r);

      r.discountTotalPrice = !noDiscountSingle
        ? r.totalPrice
        : r.discountTotalPrice;
      sum += Number(r.totalPrice);
    } else {
      r.totalPrice = 0;
      r.discountTotalPrice = 0;
    }
  });
  return { allPrice: isNaN(sum) ? 0 : sum.toFixed(2), arr };
}

//获取合计
function getAllPrice(row) {
  let num = 0;
  if (row.pricingWay == 1) {
    //按数量计价计算总金额
    num = Number(row.singlePrice) * Number(row.totalCount);
  }
  if (row.pricingWay == 2) {
    //按重量计价计算总金额
    num =
      Number(row.singlePrice) *
      Number(row.totalCount) *
      Number(row.singleWeight);
  }
  return isNaN(num) ? '' : num.toFixed(2);
}
function singleWeightChange(row) {
  console.log(row, 'row');
  if (row && row.singleWeight && row.totalCount) {
    row.totalWeight = (row.singleWeight * row.totalCount).toFixed(2) || 0;
  } else {
    row.totalWeight = '';
  }
}
