setProduct.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import Vue from 'vue';
  2. //改变数量
  3. export function changeCount(row, countObj, noDiscountSingle, weightType) {
  4. // console.log('changeCount~~', row, countObj, noDiscountSingle);
  5. let data = JSON.parse(JSON.stringify(row));
  6. let total = data[countObj.countKey] || 0;
  7. let _endIndex = 0; //计算单重需要
  8. if (data.packageDispositionList) {
  9. let endIndex = data.packageDispositionList.findIndex(
  10. (ite) => data[countObj.unitIdKey] == ite.id
  11. );
  12. _endIndex = endIndex;
  13. let packageData = data.packageDispositionList.find(
  14. (ite) => data[countObj.unitIdKey] == ite.id
  15. );
  16. data[countObj.unitKey] = packageData.conversionUnit;
  17. if (data.weightUnit == data.measuringUnit && data.singleWeight) {
  18. data.packageDispositionList[1].packageCell = data.singleWeight;
  19. }
  20. for (; 0 < endIndex; endIndex--) {
  21. total = Vue.prototype.$math.format(
  22. data.packageDispositionList[endIndex].packageCell * total,
  23. 14
  24. );
  25. }
  26. }
  27. data['totalCount'] = total;
  28. data['discountSinglePrice'] = !noDiscountSingle
  29. ? data.singlePrice
  30. : data.discountSinglePrice;
  31. if (weightType == 'totalWeight') {
  32. console.log('weightType~~', 1);
  33. setSingleWeight(data, countObj, _endIndex);
  34. } else {
  35. console.log('weightType~~', 2);
  36. setWeight(data, countObj);
  37. }
  38. data['totalPrice'] = 0;
  39. data['discountTotalPrice'] = 0;
  40. if (data.pricingWay == 2 || data.pricingWay == 3) {
  41. if (data.totalWeight && data.singlePrice) {
  42. data['totalPrice'] = (data.totalWeight * data.singlePrice).toFixed(2);
  43. }
  44. } else {
  45. if (data[countObj.countKey] && data.singlePrice) {
  46. data['totalPrice'] = (data[countObj.countKey] * data.singlePrice).toFixed(
  47. 2
  48. );
  49. }
  50. }
  51. data['discountTotalPrice'] = !noDiscountSingle
  52. ? data.totalPrice
  53. : data.discountTotalPrice;
  54. return data;
  55. }
  56. // 计算总重
  57. function setWeight(row, countObj) {
  58. // return
  59. if (row.weightUnit == row.measuringUnit) {
  60. row['totalWeight'] = row.totalCount;
  61. } else if (row.totalCount && row.singleWeight) {
  62. row['totalWeight'] = Number((row.totalCount * row.singleWeight).toFixed(2));
  63. } else {
  64. row['totalWeight'] = 0;
  65. }
  66. // if (row.weightUnit == row[countObj.unitKey]) {
  67. // row['totalWeight'] = row.totalCount;
  68. // } else if (row[countObj.countKey] && row.singleWeight) {
  69. // row['totalWeight'] = (row[countObj.countKey] * row.singleWeight).toFixed(2);
  70. // } else {
  71. // row['totalWeight'] = 0;
  72. // }
  73. // if (row.weightUnit == row.measuringUnit) {
  74. // row['totalCount'] = row.totalWeight;
  75. // }
  76. console.log(row['totalCount'], 'dsds');
  77. }
  78. // 计算单重
  79. function setSingleWeight(row, countObj, endIndex) {
  80. console.log('setSingleWeight~~', row);
  81. // if (row.totalWeight && row[countObj.countKey]) {
  82. // row['singleWeight'] = (row.totalWeight / row[countObj.countKey]).toFixed(2);
  83. // console.log('singleWeight~~', row['singleWeight']);
  84. // } else {
  85. // row['singleWeight'] = 0;
  86. // }
  87. // console.log(endIndex, 'endIndex');
  88. if (row.weightUnit == row.measuringUnit) {
  89. let totalWeight = row['totalWeight'];
  90. for (; 1 < endIndex; endIndex--) {
  91. totalWeight = Vue.prototype.$math.format(
  92. totalWeight / row.packageDispositionList[endIndex].packageCell,
  93. 14
  94. );
  95. }
  96. // console.log(totalWeight, 'totalWeight');
  97. row['singleWeight'] = Number(totalWeight / row[countObj.countKey]).toFixed(
  98. 2
  99. );
  100. } else if (row.totalWeight && row.totalCount) {
  101. row['singleWeight'] = Number((row.totalWeight / row.totalCount).toFixed(2));
  102. } else {
  103. row['singleWeight'] = 0;
  104. }
  105. if (row.weightUnit == row.measuringUnit) {
  106. row['totalCount'] = row.totalWeight;
  107. }
  108. if (row.weightUnit == row[countObj.unitKey]) {
  109. row[countObj.countKey] = row.totalWeight;
  110. }
  111. }
  112. export function getAllPrice(arr) {
  113. let sum = 0;
  114. arr.forEach((item) => {
  115. if (item.totalPrice) {
  116. sum += Number(item.totalPrice);
  117. }
  118. });
  119. return isNaN(sum) ? 0 : sum.toFixed(2);
  120. }
  121. // //计算不含税单价
  122. // function getNotaxSinglePrice(row) {
  123. // if (row.singlePrice && row.taxRate) {
  124. // row['notaxSinglePrice'] = parseFloat(
  125. // (row.singlePrice / (1 + row.taxRate / 100)).toFixed(2)
  126. // );
  127. // } else {
  128. // row['notaxSinglePrice'] = '';
  129. // }
  130. // }
  131. // //计算总金额
  132. // function getNumTotalPrice(arr, noDiscountSingle) {
  133. // let sum = 0;
  134. // arr.forEach((r, index) => {
  135. // // if (r.singlePrice) {
  136. // // r.notaxSinglePrice=r.taxRate?r.singlePrice/(1-(r.taxRate/100)):r.singlePrice
  137. // // }
  138. // if (r.singlePrice && r.totalCount) {
  139. // Vue.set(
  140. // arr[index],
  141. // 'discountSinglePrice',
  142. // !noDiscountSingle ? r.singlePrice : r.discountSinglePrice
  143. // );
  144. // Vue.set(arr[index], 'totalPrice', getAllPrice(r));
  145. // Vue.set(
  146. // arr[index],
  147. // 'discountTotalPrice',
  148. // !noDiscountSingle ? r.totalPrice : r.discountTotalPrice
  149. // );
  150. // sum += Number(r.totalPrice);
  151. // } else {
  152. // Vue.set(arr[index], 'totalPrice', 0);
  153. // Vue.set(arr[index], 'discountTotalPrice',0);
  154. // }
  155. // });
  156. // return { allPrice: isNaN(sum) ? 0 : sum.toFixed(2), arr };
  157. // }
  158. // //获取合计
  159. // function getAllPrice(row) {
  160. // let num = 0;
  161. // if (row.pricingWay == 1) {
  162. // //按数量计价计算总金额
  163. // num = Number(row.singlePrice) * Number(row.totalCount);
  164. // }
  165. // if (row.pricingWay == 2) {
  166. // //按重量计价计算总金额
  167. // num =
  168. // Number(row.singlePrice) *
  169. // Number(row.totalCount) *
  170. // Number(row.singleWeight);
  171. // }
  172. // return isNaN(num) ? '' : num.toFixed(2);
  173. // }
  174. // function singleWeightChange(row) {
  175. // console.log(row, 'row');
  176. // if (row && row.singleWeight && row.totalCount) {
  177. // row.totalWeight = (row.singleWeight * row.totalCount).toFixed(2) || 0;
  178. // } else {
  179. // row.totalWeight = '';
  180. // }
  181. // }