setProduct.js 3.5 KB

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