setProduct.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import Vue from 'vue';
  2. //改变数量
  3. export function changeCount(row, countObj,noDiscountSingle) {
  4. let total = row[countObj.countKey] || 0;
  5. let data = row;
  6. let endIndex = row.packageDispositionList.findIndex(
  7. (ite) => row[countObj.unitIdKey] == ite.id
  8. );
  9. for (; 0 < endIndex; endIndex--) {
  10. total = Vue.prototype.$math.format(
  11. row.packageDispositionList[endIndex].packageCell * total,
  12. 14
  13. );
  14. }
  15. data['totalCount'] = total;
  16. data['discountSinglePrice'] = !noDiscountSingle
  17. ? data.singlePrice
  18. : data.discountSinglePrice;
  19. setWeight(data);
  20. if (row.totalCount && row.singlePrice) {
  21. data['totalPrice'] = row.totalCount * row.singlePrice;
  22. data['discountTotalPrice'] = !noDiscountSingle
  23. ? data.totalPrice
  24. : data.discountTotalPrice;
  25. }
  26. // getNotaxSinglePrice(data);
  27. return data;
  28. // if (row) {
  29. // singleWeightChange(row, index);
  30. // }
  31. // return getNumTotalPrice(arr, noDiscountSingle);
  32. }
  33. function setWeight(row) {
  34. if (row.weightUnit == row.measuringUnit) {
  35. row['totalWeight'] = row.totalCount;
  36. } else if (row.totalCount && row.singleWeight) {
  37. row['totalWeight'] = row.totalCount * row.singleWeight;
  38. } else {
  39. row['totalWeight'] = 0;
  40. }
  41. }
  42. export function getAllPrice(arr){
  43. let sum = 0;
  44. arr.forEach(item=>{
  45. if(item.totalPrice){
  46. sum+=Number(item.totalPrice)
  47. }
  48. })
  49. return sum
  50. }
  51. // //计算不含税单价
  52. // function getNotaxSinglePrice(row) {
  53. // if (row.singlePrice && row.taxRate) {
  54. // row['notaxSinglePrice'] = parseFloat(
  55. // (row.singlePrice / (1 + row.taxRate / 100)).toFixed(2)
  56. // );
  57. // } else {
  58. // row['notaxSinglePrice'] = '';
  59. // }
  60. // }
  61. // //计算总金额
  62. // function getNumTotalPrice(arr, noDiscountSingle) {
  63. // let sum = 0;
  64. // arr.forEach((r, index) => {
  65. // // if (r.singlePrice) {
  66. // // r.notaxSinglePrice=r.taxRate?r.singlePrice/(1-(r.taxRate/100)):r.singlePrice
  67. // // }
  68. // if (r.singlePrice && r.totalCount) {
  69. // Vue.set(
  70. // arr[index],
  71. // 'discountSinglePrice',
  72. // !noDiscountSingle ? r.singlePrice : r.discountSinglePrice
  73. // );
  74. // Vue.set(arr[index], 'totalPrice', getAllPrice(r));
  75. // Vue.set(
  76. // arr[index],
  77. // 'discountTotalPrice',
  78. // !noDiscountSingle ? r.totalPrice : r.discountTotalPrice
  79. // );
  80. // sum += Number(r.totalPrice);
  81. // } else {
  82. // Vue.set(arr[index], 'totalPrice', 0);
  83. // Vue.set(arr[index], 'discountTotalPrice',0);
  84. // }
  85. // });
  86. // return { allPrice: isNaN(sum) ? 0 : sum.toFixed(2), arr };
  87. // }
  88. // //获取合计
  89. // function getAllPrice(row) {
  90. // let num = 0;
  91. // if (row.pricingWay == 1) {
  92. // //按数量计价计算总金额
  93. // num = Number(row.singlePrice) * Number(row.totalCount);
  94. // }
  95. // if (row.pricingWay == 2) {
  96. // //按重量计价计算总金额
  97. // num =
  98. // Number(row.singlePrice) *
  99. // Number(row.totalCount) *
  100. // Number(row.singleWeight);
  101. // }
  102. // return isNaN(num) ? '' : num.toFixed(2);
  103. // }
  104. // function singleWeightChange(row) {
  105. // console.log(row, 'row');
  106. // if (row && row.singleWeight && row.totalCount) {
  107. // row.totalWeight = (row.singleWeight * row.totalCount).toFixed(2) || 0;
  108. // } else {
  109. // row.totalWeight = '';
  110. // }
  111. // }