liveroomProductJumpRecord.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div>
  3. <BaseTable :columns='columns' :condition='condition' :queryFunction='queryFunction' ref="table"
  4. paginationSize="mini"
  5. :paginationText="{ currentPage: 'pageCurrent', total: 'countTotal', totalPage: 'pageCount', data: 'orderList' }"
  6. size="small" :span="12">
  7. <template slot="append-btn">
  8. <el-button type="success" size="small" @click="exportFunction">导出</el-button>
  9. </template>
  10. </BaseTable>
  11. </div>
  12. </template>
  13. <script>
  14. import * as tableConfig from '@/components/base-table/config.js'
  15. import BaseTable from "@/components/base-table/base-table.vue"
  16. import moment from "moment";
  17. export default {
  18. data() {
  19. return {
  20. columns: tableConfig.liveroomProductJumpRecord.columns,
  21. condition: tableConfig.liveroomProductJumpRecord.condition,
  22. queryParam: {},
  23. total: 0,
  24. queryFunction: params => new Promise((resolve, reject) => {
  25. let url = '/room/records'
  26. let formatParams = {
  27. "roomId": parseInt(this.$route.params.id), //直播间 ID
  28. "page": params.pageCurrent, //当前第几页
  29. "limit": 10 //页面的大小
  30. }
  31. if (params.query.time) {
  32. url = '/room/search'
  33. formatParams.start = params.query.time[0]
  34. formatParams.end = params.query.time[1]
  35. }
  36. return this.$http({
  37. url,
  38. method: 'post',
  39. data: formatParams,
  40. params: formatParams
  41. }).then(
  42. ({ data }) => {
  43. const formatData = {
  44. pageCurrent: params.pageCurrent,
  45. countTotal: data.total,
  46. pageCount: Math.ceil(data.total / 10),
  47. orderList: data.maiDiansList || []
  48. }
  49. url == '/room/records' && (this.total = data.total)
  50. resolve(formatData)
  51. }
  52. ).catch(e => reject(e))
  53. }),
  54. }
  55. },
  56. components: { BaseTable, },
  57. mounted() {
  58. },
  59. methods: {
  60. exportFunction() {
  61. console.log(this.$route);
  62. let formatParams = {
  63. "roomId": parseInt(this.$route.params.id), //直播间 ID
  64. "page": 1, //当前第几页
  65. "limit": this.total //页面的大小
  66. }
  67. this.$http({
  68. url: '/room/records',
  69. method: 'post',
  70. data: formatParams,
  71. params: formatParams
  72. }).then(
  73. ({ data }) => {
  74. this.exportToCSVFile(data.maiDiansList)
  75. }
  76. )
  77. },
  78. exportToCSVFile(list) {
  79. let header = '用户,商品名称,商品链接,点击时间\n';
  80. let datas = list.map(ele => {
  81. return `${ele.phone},${ele.name},${ele.linkInfo},${moment(ele.createAt).format("yyyy-MM-DD HH:mm:ss")}\n`;
  82. });
  83. let dataStrs = [header, ...datas].join('');
  84. // 创建一个 Blob 对象
  85. const blob = new Blob(['\uFEFF' + dataStrs], {
  86. type: 'text/plain;charset=utf-8',
  87. });
  88. // 创建一个 a 标签
  89. const link = document.createElement("a");
  90. // 一个 URL,可以是任意协议的,不只是 HTTP 协议
  91. // 这里创建了一个 Blob URL
  92. // blob:http://localhost:1234/9b3be48e-9948-496d-8a2b-18d437eb46e0
  93. link.href = URL.createObjectURL(blob);
  94. console.log(link.href);
  95. // 此属性表示用户下载文件而不是进行导航到 URL,这里指的为文件名
  96. link.download = `商品跳转记录-${this.$route.query.title}直播间(苏州掌银客户专享).csv`;
  97. link.click();
  98. // 需要释放 URL
  99. URL.revokeObjectURL(link.href);
  100. },
  101. exportList(list, title) {
  102. //表格表头,导出表头
  103. let tableHeader = [['#', '资产编号', '资产名称', '资产类别', '资产型号', "资产单价", "资产金额",
  104. "生产厂家", "生产日期", "购买日期", "购买人", "状态", "库存数量"]]
  105. list.forEach((item, index) => {
  106. let rowData = []
  107. //导出内容的字段
  108. rowData = [
  109. index + 1,
  110. item.zcbh,
  111. item.zcmc,
  112. item.name,
  113. item.zcxh,
  114. item.zcdj,
  115. item.zcje,
  116. item.sccj,
  117. currencyFormatDate(item.scrq),
  118. currencyFormatDate(item.gmrq),
  119. item.gmr,
  120. item.sts,
  121. item.kcsl,
  122. ]
  123. tableHeader.push(rowData)
  124. })
  125. let wb = XLSX.utils.book_new()
  126. let ws = XLSX.utils.aoa_to_sheet(tableHeader)
  127. XLSX.utils.book_append_sheet(wb, ws, '资产设备基本信息') // 工作簿名称
  128. XLSX.writeFile(wb, '商品跳转记录-老字号直播间(苏州掌银客户专享).xlsx') // 保存的文件名
  129. }
  130. }
  131. }
  132. </script>
  133. <style></style>