evaluationReportTable.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="reportTItem">
  3. <el-dialog title="考评报告详情" v-model="editEvaluaVisible" :fullscreen="true" :close-on-click-modal="false">
  4. <div class="reportTAll">
  5. <div class="reportTBtn">
  6. <div class="PeriodBtn">
  7. <!-- <p style="font-size: 14px">{{rowevalradio.evaluateReportName}}</p> -->
  8. <el-row :gutter="10" style="padding-left: 10px;position: relative;right: -39vw;">
  9. <el-col :span="1.5">
  10. <el-button
  11. type="warning"
  12. icon="Download"
  13. size="mini"
  14. @click="handleExport"
  15. >导出</el-button>
  16. </el-col>
  17. </el-row>
  18. </div>
  19. <div class="reportTTableData">
  20. <el-table :data="reportTableData.body" ref="report-table" style="width: 100%">
  21. <el-table-column :label="rowevalradio.des" align="center">
  22. <el-table-column label="序号" type="index" width="50" align="center" />
  23. <el-table-column :label="item.nameZh" :prop="item.nameEh" v-for="item in reportTableData.title" :key="item" />
  24. </el-table-column>
  25. </el-table>
  26. </div>
  27. </div>
  28. </div>
  29. </el-dialog>
  30. </div>
  31. </template>
  32. <script>
  33. import ExcelJS from 'exceljs'
  34. import fileSave from 'file-saver'
  35. import {apiGetEvalReportinfoList} from '../../api/api'
  36. export default {
  37. data() {
  38. return {
  39. editEvaluaVisible: false,
  40. reportTableData: [],
  41. rowevalradio: {},
  42. }
  43. },
  44. methods: {
  45. init(row) {
  46. this.editEvaluaVisible = true
  47. this.reportTableData = []
  48. this.rowevalradio = row
  49. this.getreportTableData(row)
  50. },
  51. // 查询规则详情数据
  52. getreportTableData(row) {
  53. let that = this
  54. let params = {
  55. evaluateReportId: row.id
  56. }
  57. apiGetEvalReportinfoList(params).then(datas =>{
  58. if (datas && datas.data) {
  59. that.reportTableData = datas.data
  60. }
  61. })
  62. },
  63. handleExport() {
  64. let dataHeader = this.reportTableData.title //接口返回表格头
  65. let dataMsg = this.reportTableData.body //接口返回数据
  66. let adb = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'G', 'K', 'L', 'M', 'N']
  67. let col = [{name: '序号'}]
  68. let colEn = []
  69. dataHeader.forEach(item =>{
  70. let objzh = {
  71. name: item.nameZh
  72. }
  73. col.push(objzh)
  74. colEn.push(item.nameEh)
  75. })
  76. let rowData = []
  77. for(let i =0; i<dataMsg.length; i++) {
  78. let item = dataMsg[i]
  79. let arr = []
  80. for(let j =0; j<colEn.length; j++) {
  81. let it = colEn[j]
  82. arr[0] = i+1
  83. arr.push(item[it])
  84. }
  85. rowData.push(arr)
  86. }
  87. const workbook = new ExcelJS.Workbook()
  88. const worksheet = workbook.addWorksheet('Sheet1')
  89. worksheet.properties.defaultColWidth = 15; // 默认列宽
  90. //定义表格标题
  91. const Targetrow = worksheet.getRow(1);
  92. Targetrow.height = 30;
  93. const Targetcell = worksheet.getCell(`A1`);
  94. worksheet.mergeCells(`A1:${adb[col.length-1]}1`);
  95. Targetcell.value = this.rowevalradio.des;
  96. Targetcell.font = { name: "微软雅黑", family: 4, size: 11, bold: false }; // 字体
  97. Targetcell.alignment = { vertical: "middle", horizontal: "center" }; //对齐
  98. worksheet.addTable({
  99. name: 'MyTable',
  100. ref: 'A2',
  101. headerRow: true,
  102. columns: col,
  103. rows: rowData,
  104. });
  105. workbook.xlsx.writeBuffer().then(buffer => {
  106. //这里为type
  107. const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' })
  108. fileSave(blob, `数据导出.xlsx`)
  109. })
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="less">
  115. .reportTItem{
  116. .el-overlay{
  117. .el-dialog{
  118. // margin-top: 5vh !important;
  119. .el-dialog__body{
  120. padding: 0 20px 30px 20px !important;
  121. .reportTAll{
  122. .el-select, .el-input{
  123. width: 100%;
  124. }
  125. .reportTBtn{
  126. padding: 10px 20px 0 20px;
  127. .PeriodBtn{
  128. display: flex;
  129. justify-content: center;
  130. padding: 20px 0;
  131. .el-button{
  132. height: 30px;
  133. padding: 0 30px ;
  134. span{
  135. margin:0;
  136. }
  137. }
  138. .is-disabled{
  139. opacity: 0.5;
  140. }
  141. }
  142. }
  143. .reportTTableData{
  144. .el-table{
  145. .el-table__body-wrapper{
  146. height: 65vh !important;
  147. }
  148. .el-input__inner{
  149. height: 30px !important;
  150. }
  151. .el-radio__label{
  152. display: none;
  153. }
  154. }
  155. .el-pagination{
  156. margin-top: 20px;
  157. text-align: end;
  158. position: relative;
  159. }
  160. }
  161. .onlyDialog{
  162. .el-overlay{
  163. .el-dialog{
  164. margin-top: 10vh !important;
  165. }
  166. }
  167. }
  168. }
  169. }
  170. .el-dialog__footer{
  171. .dialog-footer{
  172. display: flex;
  173. justify-content: center;
  174. .el-button{
  175. width: 180px !important;
  176. height: 40px !important;
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. </style>