index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <ele-page flex-table>
  3. <page-search @search="reload" />
  4. <common-table
  5. ref="pageRef"
  6. :pageConfig="pageConfig"
  7. :columns="columns"
  8. :tools="false"
  9. show-summary
  10. :summary-method="getSummaries"
  11. :flex-table="false"
  12. >
  13. <template #toolbar="{ row }">
  14. <div>
  15. <el-button
  16. type="success"
  17. plain
  18. v-permission="'statistic:recycleOrder:export'"
  19. @click="handleExportExcel(row)"
  20. >
  21. 导出EXCEL
  22. </el-button>
  23. </div>
  24. </template>
  25. </common-table>
  26. </ele-page>
  27. </template>
  28. <script setup>
  29. import { ref, reactive } from 'vue';
  30. import CommonTable from '@/components/CommonPage/CommonTable.vue';
  31. import pageSearch from './components/page-search.vue';
  32. defineOptions({ name: 'RecycleOrder' });
  33. /** 表格列配置 */
  34. const columns = ref([
  35. { type: 'index', label: '#', align: 'center', width: 80 },
  36. { label: '日期', prop: 'statisticDate', align: 'center' },
  37. { label: '仓库', prop: 'godownName', align: 'center' },
  38. { label: '回收订单数', prop: 'orderNum', align: 'center' },
  39. { label: '回收本数', prop: 'bookNum', align: 'center' },
  40. { label: '订单预估金额', prop: 'recycleTotalMoney', align: 'center' },
  41. { label: '回收平均价格', prop: 'recycleAveragePrice', align: 'center' },
  42. { label: '审核订单数', prop: 'auditNum', align: 'center' },
  43. { label: '审核总本数', prop: 'auditGoodNum', align: 'center' },
  44. { label: '审核金额', prop: 'auditMoney', align: 'center' },
  45. { label: '审核订单预估金额', prop: 'auditTotalMoney', align: 'center' },
  46. { label: '审核平均单本价', prop: 'auditAverageMoney', align: 'center' },
  47. { label: '库存周转率', prop: 'stockWeekTurnoverRate', align: 'center' },
  48. { label: '平均库存', prop: 'averageStock', align: 'center' },
  49. ]);
  50. /** 页面组件实例 */
  51. const pageRef = ref(null);
  52. const pageConfig = reactive({
  53. pageUrl: '/order/recycleOrderStatistic/pagelist',
  54. exportUrl: '/order/recycleOrderStatistic/export',
  55. fileName: '回收订单统计',
  56. cacheKey: 'recycleOrderStatisticTable'
  57. });
  58. /**
  59. * 自定义表格汇总计算方法
  60. * @param {Object} param0 - 表格数据和列信息
  61. * @returns {Array} - 汇总行显示的数据
  62. */
  63. function getSummaries({ columns, data }) {
  64. const sums = [];
  65. columns.forEach((column, index) => {
  66. if (index === 0) {
  67. sums[index] = '合计';
  68. return;
  69. }
  70. const values = data.map((item) => Number(item[column.property]));
  71. if (!values.length) {
  72. sums[index] = 'N/A';
  73. return;
  74. }
  75. switch (column.property) {
  76. case 'auditAverageMoney':
  77. case 'recycleAveragePrice': {
  78. // 只计算有值的数据的平均值
  79. const validValues = values.filter(
  80. (value) => value && !isNaN(value)
  81. );
  82. if (validValues.length > 0) {
  83. const sum = validValues.reduce(
  84. (prev, curr) => prev + curr,
  85. 0
  86. );
  87. sums[index] = (sum / validValues.length).toFixed(2);
  88. } else {
  89. sums[index] = '';
  90. }
  91. break;
  92. }
  93. case 'auditGoodNum':
  94. case 'orderNum':
  95. case 'bookNum':
  96. case 'auditNum': {
  97. // 求和
  98. const sum = values.reduce((prev, curr) => {
  99. const value = Number(curr);
  100. if (!isNaN(value)) {
  101. return prev + value;
  102. } else {
  103. return prev;
  104. }
  105. }, 0);
  106. sums[index] = sum;
  107. break;
  108. }
  109. case 'auditMoney':
  110. case 'recycleTotalMoney':
  111. case 'auditTotalMoney': {
  112. // 求和,保留两位小数
  113. const sum = values.reduce((prev, curr) => {
  114. const value = Number(curr);
  115. if (!isNaN(value)) {
  116. return prev + value;
  117. } else {
  118. return prev;
  119. }
  120. }, 0);
  121. sums[index] = sum.toFixed(2);
  122. break;
  123. }
  124. default:
  125. sums[index] = '';
  126. }
  127. });
  128. return sums;
  129. }
  130. //刷新表格
  131. function reload(where) {
  132. pageRef.value?.reload(where);
  133. }
  134. //导出excel
  135. function handleExportExcel() {
  136. pageRef.value?.exportData('回收订单统计', 'GET');
  137. }
  138. </script>