index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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" @querySearch="querySearch" @toReset="toClose" :shopList="shopList"></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 || '0' }}</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: outBill } = createNamespacedHelpers('outBill');
  35. const { mapActions: shop } = createNamespacedHelpers('shop');
  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. shopList: [],
  70. };
  71. },
  72. async created() {
  73. await this.search();
  74. await this.searchOther();
  75. },
  76. methods: {
  77. ...shop({ shopQuery: 'query' }),
  78. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  79. ...outBill({ outQuery: 'query', outCreate: 'create' }),
  80. // 查询
  81. async search({ skip = 0, limit = 10, ...info } = {}) {
  82. let condition = _.cloneDeep(this.searchForm);
  83. if (condition.buy_time && condition.shop) {
  84. condition[`start`] = _.head(condition.buy_time);
  85. condition[`end`] = _.last(condition.buy_time);
  86. delete condition.buy_time;
  87. let res = await this.query({ skip, limit, ...condition, ...info });
  88. if (this.$checkRes(res)) {
  89. this.$set(this, 'info', res.data);
  90. this.$set(this, 'afterSaleList', res.data.afterSaleList);
  91. this.$set(this, 'orderList', res.data.orderList);
  92. }
  93. } else {
  94. this.$message({ type: `warning`, message: `请选择查询信息` });
  95. }
  96. },
  97. // 重置
  98. toClose() {
  99. this.searchForm = {};
  100. this.search();
  101. },
  102. // 店铺名称远程查询
  103. async querySearch(value) {
  104. let res = await this.shopQuery({ name: value });
  105. if (this.$checkRes(res)) {
  106. this.$set(this, 'shopList', res.data);
  107. }
  108. },
  109. // 导出清单
  110. toFile() {
  111. const workbook = new ExcelJS.Workbook();
  112. let orderList = this.orderList;
  113. const worksheet_one = workbook.addWorksheet('订单');
  114. let data_one = [['订单号', '订单类型', '支付时间', '商品', '规格', '购买数量', '单价', '优惠金额', '总价']];
  115. for (const p1 of orderList) {
  116. let p2 = [[p1.no, p1.type, p1.pay_time, p1.goods, p1.spec, p1.buy_num, p1.price, p1.discount, p1.total]];
  117. data_one.push(...p2);
  118. }
  119. for (const val of data_one) {
  120. worksheet_one.addRow(val);
  121. }
  122. let afterSaleList = this.afterSaleList;
  123. const worksheet_two = workbook.addWorksheet('售后单');
  124. let data_two = [['订单号', '商品', '规格', '退款时间', '退款金额']];
  125. for (const p1 of afterSaleList) {
  126. let p2 = [[p1.no, p1.goods, p1.spec, p1.end_time, p1.money]];
  127. data_two.push(...p2);
  128. }
  129. for (const val of data_two) {
  130. worksheet_two.addRow(val);
  131. }
  132. worksheet_one.columns.forEach(function (column, i) {
  133. column.width = 20;
  134. });
  135. worksheet_two.columns.forEach(function (column, i) {
  136. column.width = 20;
  137. });
  138. workbook.xlsx.writeBuffer().then((buffer) => {
  139. FileSaver.saveAs(
  140. new Blob([buffer], {
  141. type: 'application/octet-stream',
  142. }),
  143. `对账单.xlsx`
  144. );
  145. });
  146. // this.$confirm('是否确认对账?', '提示', {
  147. // confirmButtonText: '确定',
  148. // cancelButtonText: '取消',
  149. // type: 'warning',
  150. // }).then(async () => {
  151. // let order = [];
  152. // for (const p1 of this.orderList) {
  153. // order.push(p1._id);
  154. // }
  155. // let afterSale = [];
  156. // for (const p1 of this.afterSaleList) {
  157. // afterSale.push(p1._id);
  158. // }
  159. // let res;
  160. // res = await this.outCreate({ order, afterSale });
  161. // if (this.$checkRes(res)) {
  162. // this.$message({ type: `success`, message: `对账成功` });
  163. // }
  164. // });
  165. },
  166. // 查询其他信息
  167. async searchOther() {},
  168. },
  169. computed: {
  170. ...mapState(['user']),
  171. },
  172. metaInfo() {
  173. return { title: this.$route.meta.title };
  174. },
  175. watch: {
  176. test: {
  177. deep: true,
  178. immediate: true,
  179. handler(val) {},
  180. },
  181. },
  182. };
  183. </script>
  184. <style lang="less" scoped>
  185. .one {
  186. margin: 0 0 10px 0;
  187. }
  188. .two {
  189. span {
  190. color: red;
  191. }
  192. }
  193. .title {
  194. text-align: center;
  195. }
  196. .el-col {
  197. margin: 10px 0;
  198. }
  199. </style>