liveroomInvite-stats.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <avue-crud ref="crud" :page="page" :data="dataList" :option="tableOption" @on-load="getDataList">
  3. <template slot="menuLeft">
  4. <el-button type="success" icon="el-icon-download" size="small" @click="exportToCSVFile">导出结果至Excel</el-button>
  5. </template>
  6. </avue-crud>
  7. </template>
  8. <script lang="ts">
  9. import Vue from 'vue'
  10. import { IPage } from '@/utils/vo'
  11. import httpx from '@/utils/httpx'
  12. import { tableOption } from "@/avue/crud/liveroomInviteStats"
  13. import datasheet2csv from "@/utils/datasheet2csv"
  14. import { download_blob } from "@/utils/index"
  15. import { datetime_format } from '@/utils/formatters'
  16. const getPages = (count: number) => {
  17. return {
  18. total: count,
  19. currentPage: 1,
  20. pageSize: count,
  21. pageSizes: [count],
  22. layout: '', //隐藏分页
  23. }
  24. }
  25. export default Vue.extend({
  26. props: {
  27. daterange: { type: Array, }, // string[]
  28. roomId: { type: Number },
  29. roomInfo: { type: Object }
  30. },
  31. data() {
  32. return {
  33. dataListLoading: false,
  34. page: getPages(10),
  35. dataList: [] as {
  36. manager_info: string,
  37. count: number,
  38. }[],
  39. }
  40. },
  41. methods: {
  42. getDataList(page?: IPage, query?: never, done?: Function) {
  43. if (this.roomId <= 0) {
  44. return
  45. } else if (this.daterange.length !== 2) {
  46. this.dataList = []
  47. return
  48. }
  49. const [start, end] = this.daterange
  50. this.dataListLoading = true
  51. httpx.post(httpx.makeurl('/rooms/invitesCountList'), {
  52. startTime: start,
  53. endTime: end,
  54. roomId: this.roomId,
  55. }).then(({ data }) => {
  56. this.dataList = data.invitesList
  57. this.dataListLoading = false
  58. this.page = getPages(data.invitesList.length)
  59. if (done) {
  60. done()
  61. }
  62. })
  63. },
  64. exportToCSVFile() {
  65. const blob = datasheet2csv(
  66. this.dataList,
  67. (v) => [v.manager_info, v.count],
  68. ['客户经理信息', '有效邀约数量']
  69. )
  70. const start = (this.daterange[0] as string).replaceAll(':', "-")
  71. const end = (this.daterange[1] as string).replaceAll(':', "-")
  72. download_blob(blob, `客户邀约记录_${this.roomInfo.title}_${start}至${end}.csv`)
  73. },
  74. },
  75. watch: {
  76. daterange() {
  77. this.getDataList()
  78. }
  79. },
  80. computed: {
  81. tableOption() { return tableOption }
  82. },
  83. })
  84. </script>