setProduct.js 4.2 KB

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