index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 :span="24" v-if="afterSaleList.length != '0' || orderList.length != '0'">
  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. const { mapActions: outBill } = createNamespacedHelpers('outBill');
  36. export default {
  37. name: 'card-1',
  38. props: {},
  39. components: { search1: () => import('./parts/search-1.vue') },
  40. data: function () {
  41. return {
  42. searchForm: {},
  43. info: {},
  44. afterSaleList: [],
  45. orderList: [],
  46. orderfields: [
  47. { label: '订单号', model: 'no' },
  48. { label: '订单类型', model: 'type' },
  49. { label: '支付时间', model: 'pay_time' },
  50. { label: '商品', model: 'goods' },
  51. { label: '规格', model: 'spec' },
  52. { label: '购买数量', model: 'buy_num' },
  53. { label: '单价', model: 'price' },
  54. { label: '优惠金额', model: 'discount' },
  55. { label: '总价', model: 'total' },
  56. ],
  57. afterSalefields: [
  58. { label: '订单号', model: 'no' },
  59. { label: '商品', model: 'goods' },
  60. { label: '规格', model: 'spec' },
  61. { label: '退款时间', model: 'end_time' },
  62. { label: '退款金额', model: 'money' },
  63. ],
  64. // 多选值
  65. selected: [],
  66. // 自营店铺信息
  67. shop: {},
  68. };
  69. },
  70. async created() {
  71. await this.search();
  72. await this.searchOther();
  73. },
  74. methods: {
  75. ...selfShop(['getInfo']),
  76. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  77. ...outBill({ outQuery: 'query', outCreate: 'create' }),
  78. // 查询
  79. async search({ skip = 0, limit = 10, ...info } = {}) {
  80. let condition = _.cloneDeep(this.searchForm);
  81. if (condition.buy_time) {
  82. condition[`start`] = _.head(condition.buy_time);
  83. condition[`end`] = _.last(condition.buy_time);
  84. delete condition.buy_time;
  85. let res = await this.query({ skip, limit, ...condition, ...info, shop: _.get(this.shop, '_id') });
  86. if (this.$checkRes(res)) {
  87. this.$set(this, 'info', res.data);
  88. this.$set(this, 'afterSaleList', res.data.afterSaleList);
  89. this.$set(this, 'orderList', res.data.orderList);
  90. }
  91. }
  92. },
  93. toClose() {
  94. this.searchForm = {};
  95. this.search();
  96. },
  97. // 导出清单
  98. toFile() {
  99. const workbook = new ExcelJS.Workbook();
  100. let orderList = this.orderList;
  101. const worksheet_one = workbook.addWorksheet('订单');
  102. let data_one = [['订单号', '订单类型', '支付时间', '商品', '规格', '购买数量', '单价', '优惠金额', '总价']];
  103. for (const p1 of orderList) {
  104. let p2 = [[p1.no, p1.type, p1.pay_time, p1.goods, p1.spec, p1.buy_num, p1.price, p1.discount, p1.total]];
  105. data_one.push(...p2);
  106. }
  107. for (const val of data_one) {
  108. worksheet_one.addRow(val);
  109. }
  110. let afterSaleList = this.afterSaleList;
  111. const worksheet_two = workbook.addWorksheet('售后单');
  112. let data_two = [['订单号', '商品', '规格', '退款时间', '退款金额']];
  113. for (const p1 of afterSaleList) {
  114. let p2 = [[p1.no, p1.goods, p1.spec, p1.end_time, p1.money]];
  115. data_two.push(...p2);
  116. }
  117. for (const val of data_two) {
  118. worksheet_two.addRow(val);
  119. }
  120. worksheet_one.columns.forEach(function (column, i) {
  121. column.width = 20;
  122. });
  123. worksheet_two.columns.forEach(function (column, i) {
  124. column.width = 20;
  125. });
  126. workbook.xlsx.writeBuffer().then((buffer) => {
  127. FileSaver.saveAs(
  128. new Blob([buffer], {
  129. type: 'application/octet-stream',
  130. }),
  131. `对账单.xlsx`
  132. );
  133. });
  134. this.$confirm('是否确认对账?', '提示', {
  135. confirmButtonText: '确定',
  136. cancelButtonText: '取消',
  137. type: 'warning',
  138. }).then(async () => {
  139. let order = [];
  140. for (const p1 of this.orderList) {
  141. order.push(p1._id);
  142. }
  143. let afterSale = [];
  144. for (const p1 of this.afterSaleList) {
  145. afterSale.push(p1._id);
  146. }
  147. let res;
  148. res = await this.outCreate({ order, afterSale });
  149. if (this.$checkRes(res)) {
  150. this.$message({ type: `success`, message: `对账成功` });
  151. }
  152. });
  153. },
  154. // 查询其他信息
  155. async searchOther() {
  156. let res;
  157. res = await this.getInfo();
  158. if (this.$checkRes(res)) this.$set(this, `shop`, res.data);
  159. },
  160. },
  161. computed: {
  162. ...mapState(['user']),
  163. },
  164. metaInfo() {
  165. return { title: this.$route.meta.title };
  166. },
  167. watch: {
  168. test: {
  169. deep: true,
  170. immediate: true,
  171. handler(val) {},
  172. },
  173. },
  174. };
  175. </script>
  176. <style lang="less" scoped>
  177. .one {
  178. margin: 0 0 10px 0;
  179. }
  180. .two {
  181. span {
  182. color: red;
  183. }
  184. }
  185. .title {
  186. text-align: center;
  187. }
  188. .el-col {
  189. margin: 10px 0;
  190. }
  191. </style>