index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div id="card-1">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <search-1 :form="searchForm" @onSubmit="search" @toReset="toClose"></search-1>
  7. </el-col>
  8. <el-col>
  9. <el-button type="primary" @click="toFile()">对账</el-button>
  10. </el-col>
  11. <el-col :span="24" class="two">
  12. 净销售额:<span>{{ info.total || '暂无' }}</span> 元
  13. </el-col>
  14. <el-col :span="24">
  15. <el-tabs type="border-card">
  16. <el-tab-pane label="订单">
  17. <data-table :fields="orderfields" @query="search" :data="orderList" :usePage="false"> </data-table>
  18. </el-tab-pane>
  19. <el-tab-pane label="售后单">
  20. <data-table :fields="afterSalefields" @query="search" :data="afterSaleList" :usePage="false"> </data-table>
  21. </el-tab-pane>
  22. </el-tabs>
  23. </el-col>
  24. </el-col>
  25. </el-row>
  26. </div>
  27. </template>
  28. <script>
  29. const _ = require('lodash');
  30. import FileSaver from 'file-saver';
  31. const ExcelJS = require('exceljs');
  32. import { mapState, createNamespacedHelpers } from 'vuex';
  33. const { mapActions } = createNamespacedHelpers('getBill');
  34. const { mapActions: selfShop } = createNamespacedHelpers('selfShop');
  35. export default {
  36. name: 'card-1',
  37. props: {},
  38. components: { search1: () => import('./parts/search-1.vue') },
  39. data: function () {
  40. return {
  41. searchForm: {},
  42. info: {},
  43. afterSaleList: [],
  44. orderList: [],
  45. orderfields: [
  46. { label: '订单号', model: 'no' },
  47. { label: '订单类型', model: 'type' },
  48. { label: '支付时间', model: 'pay_time' },
  49. { label: '商品', model: 'goods' },
  50. { label: '规格', model: 'spec' },
  51. { label: '购买数量', model: 'buy_num' },
  52. { label: '单价', model: 'price' },
  53. { label: '优惠金额', model: 'discount' },
  54. { label: '总价', model: 'total' },
  55. ],
  56. afterSalefields: [
  57. { label: '订单号', model: 'no' },
  58. { label: '商品', model: 'goods' },
  59. { label: '规格', model: 'spec' },
  60. { label: '退款时间', model: 'end_time' },
  61. { label: '退款金额', model: 'money' },
  62. ],
  63. // 多选值
  64. selected: [],
  65. // 自营店铺信息
  66. shop: {},
  67. };
  68. },
  69. async created() {
  70. await this.search();
  71. await this.searchOther();
  72. },
  73. methods: {
  74. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  75. ...selfShop(['getInfo']),
  76. // 查询
  77. async search({ skip = 0, limit = 10, ...info } = {}) {
  78. let condition = _.cloneDeep(this.searchForm);
  79. if (condition.buy_time) {
  80. condition[`start`] = _.head(condition.buy_time);
  81. condition[`end`] = _.last(condition.buy_time);
  82. delete condition.buy_time;
  83. let res = await this.query({ skip, limit, ...condition, ...info, shop: _.get(this.shop, '_id') });
  84. if (this.$checkRes(res)) {
  85. this.$set(this, 'info', res.data);
  86. this.$set(this, 'afterSaleList', res.data.afterSaleList);
  87. this.$set(this, 'orderList', res.data.orderList);
  88. }
  89. }
  90. },
  91. toClose() {
  92. this.searchForm = {};
  93. this.search();
  94. },
  95. // 导出清单
  96. toFile() {
  97. const workbook = new ExcelJS.Workbook();
  98. let orderList = this.orderList;
  99. const worksheet_one = workbook.addWorksheet('订单');
  100. let data_one = [['订单号', '订单类型', '支付时间', '商品', '规格', '购买数量', '单价', '优惠金额', '总价']];
  101. for (const p1 of orderList) {
  102. let p2 = [[p1.no, p1.type, p1.pay_time, p1.goods, p1.spec, p1.buy_num, p1.price, p1.discount, p1.total]];
  103. data_one.push(...p2);
  104. }
  105. for (const val of data_one) {
  106. worksheet_one.addRow(val);
  107. }
  108. let afterSaleList = this.afterSaleList;
  109. const worksheet_two = workbook.addWorksheet('售后单');
  110. let data_two = [['订单号', '商品', '规格', '退款时间', '退款金额']];
  111. for (const p1 of afterSaleList) {
  112. let p2 = [[p1.no, p1.goods, p1.spec, p1.end_time, p1.money]];
  113. data_two.push(...p2);
  114. }
  115. for (const val of data_two) {
  116. worksheet_two.addRow(val);
  117. }
  118. worksheet_one.columns.forEach(function (column, i) {
  119. column.width = 20;
  120. });
  121. worksheet_two.columns.forEach(function (column, i) {
  122. column.width = 20;
  123. });
  124. workbook.xlsx.writeBuffer().then((buffer) => {
  125. FileSaver.saveAs(
  126. new Blob([buffer], {
  127. type: 'application/octet-stream',
  128. }),
  129. `对账单.xlsx`
  130. );
  131. });
  132. },
  133. // 查询其他信息
  134. async searchOther() {
  135. let res;
  136. res = await this.getInfo();
  137. if (this.$checkRes(res)) this.$set(this, `shop`, res.data);
  138. },
  139. },
  140. computed: {
  141. ...mapState(['user']),
  142. },
  143. metaInfo() {
  144. return { title: this.$route.meta.title };
  145. },
  146. watch: {
  147. test: {
  148. deep: true,
  149. immediate: true,
  150. handler(val) {},
  151. },
  152. },
  153. };
  154. </script>
  155. <style lang="less" scoped>
  156. .one {
  157. margin: 0 0 10px 0;
  158. }
  159. .two {
  160. span {
  161. color: red;
  162. }
  163. }
  164. .title {
  165. text-align: center;
  166. }
  167. .el-col {
  168. margin: 10px 0;
  169. }
  170. </style>