setProduct.js 3.4 KB

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