excel.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <el-container>
  3. <basic-container class="mt-10 content">
  4. <div class="full-width white-bg" style="width: 100vw">
  5. <div class="flex flex-center flex-justify-start">
  6. <el-button type="primary" plain @click="back">返回</el-button>
  7. <el-button type="primary" @click="exportExcel">导出表格</el-button>
  8. </div>
  9. <span class="red full-width text-left flex flex-justify-start mt-10"
  10. >注:左右滑动,查看更多内容</span
  11. >
  12. </div>
  13. <div class="content mt-10">
  14. <div class="header flex flex-center flex-justify-start full-width">
  15. <div
  16. class="flex flex-center"
  17. style="background-color: #5acafa"
  18. v-for="(item, index) in header"
  19. :key="item.id"
  20. >
  21. <div
  22. class="item flex flex-center"
  23. :class="index === 0 ? 'item' : 'sub'"
  24. >
  25. {{ item }}
  26. </div>
  27. </div>
  28. </div>
  29. <div class="flex flex-center flex-justify-start flex-col">
  30. <div
  31. class="flex flex-center full-width"
  32. v-for="item in list"
  33. :key="item.id"
  34. >
  35. <div class="flex flex-center flex-justify-start full-width">
  36. <div class="flex flex-center">
  37. <div
  38. v-for="(sub, index) in item"
  39. :key="sub.id"
  40. class="item flex flex-center overflow-hide"
  41. :class="index === 0 ? 'item' : 'sub'"
  42. >
  43. <el-tooltip :content="sub" placement="top">
  44. {{ sub }}
  45. </el-tooltip>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </basic-container>
  53. </el-container>
  54. </template>
  55. <route>
  56. {
  57. name: '导出预览'
  58. }
  59. </route>
  60. <script>
  61. import BasicContainer from '@/components/basic-container/main.vue'
  62. export default {
  63. name: 'excel',
  64. components: { BasicContainer },
  65. data() {
  66. return {
  67. header: [],
  68. list: [],
  69. query: null
  70. }
  71. },
  72. created() {
  73. this.query = this.$route.query
  74. console.log(this.query)
  75. this.getList()
  76. },
  77. methods: {
  78. back() {
  79. this.$router.back()
  80. },
  81. getList() {
  82. this.$api.params.preview(this.query).then(res => {
  83. if (res.code === 200) {
  84. this.header = res.data.header
  85. this.list = res.data.list
  86. } else {
  87. this.$message.error(res.msg)
  88. }
  89. })
  90. },
  91. exportExcel() {
  92. if (this.query.previewType === '1') {
  93. this.$api.params.exportResult(this.query).then(res => {
  94. if (res.hasOwnProperty('code')) {
  95. this.$message.error(res.msg)
  96. return
  97. }
  98. this.download(res)
  99. })
  100. } else {
  101. this.$api.params.summaryExport(this.query).then(res => {
  102. if (res.hasOwnProperty('code')) {
  103. this.$message.error(res.msg)
  104. return
  105. }
  106. this.download(res)
  107. })
  108. }
  109. },
  110. download(res) {
  111. const url = window.URL.createObjectURL(
  112. new Blob([res], { type: 'application/vnd.ms-excel' })
  113. )
  114. const link = document.createElement('a')
  115. link.style.display = 'none'
  116. link.href = url
  117. const excelName = new Date().getTime() + '.xlsx'
  118. link.setAttribute('download', excelName)
  119. document.body.appendChild(link)
  120. link.click()
  121. link.remove()
  122. this.diaType = -1
  123. this.$message.success('导出成功')
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .content {
  130. white-space: nowrap;
  131. overflow-x: scroll;
  132. }
  133. .header {
  134. background-color: #5acafa;
  135. border-top: #1a1a1a solid 1px;
  136. }
  137. .item {
  138. width: 80px;
  139. text-wrap: normal;
  140. height: 50px;
  141. border-collapse: collapse;
  142. border: #1a1a1a solid 1px;
  143. margin-right: -1px;
  144. margin-top: -1px;
  145. padding: 5px;
  146. white-space: pre-wrap;
  147. }
  148. .top {
  149. position: static;
  150. top: 0;
  151. z-index: 3;
  152. left: 0;
  153. }
  154. .sub {
  155. width: 200px;
  156. height: 50px;
  157. text-wrap: normal;
  158. }
  159. </style>