<template> <!-- 临时考核问题清单报表 --> <div class="LSresultsPublicity"> <div class="searchox"> <n-space> <n-radio-group v-model:value="orgValue" name="radiogroup" @update:value="handleUpdateValue"> <n-space> <n-radio v-for="org in organ" :key="org.value" :value="org.value"> {{ org.label }} </n-radio> </n-space> </n-radio-group> <n-date-picker v-model:value="selectyear" size="tiny" type="year" @update:value="handleUpdateValue" /> </n-space> <n-button type="primary" style="margin: 0 10px" @click="exportData">导出 </n-button> </div> <div class="tabBox"> <LSResultsTable :data="tableData" :tableLoading="tableLoading" /> </div> </div> </template> <script> import { ref, reactive, toRefs, onMounted } from 'vue'; import LSResultsTable from './components/LSResultsTable.vue'; import { tempPerformQuestionStatisticList } from '@/services'; import axios from 'axios'; import { downloadBlob } from '@/utils/util'; import { formatDate } from '@/utils/util'; import { useMessage } from 'naive-ui'; export default { name: 'resultsPublicity', components: { LSResultsTable }, setup() { const message = useMessage(); const state = reactive({ tableData: [], selectyear: Date.now(), tableLoading: true, orgValue: 1, organ: [ { label: '项目公司考评', value: 0 }, { label: '水务局考评', value: 1 }, ], }); // 获取表格数据 const getTableData = async () => { state.tableLoading = true; let pramas = { type: state.orgValue, year: formatDate(state.selectyear, 'YYYY'), }; let res = await tempPerformQuestionStatisticList(pramas); if (res.code === 200) { state.tableLoading = false; if (res.data == null) return; state.tableData = res.data; } }; // 导出数据 const token = localStorage.getItem('tokenXF'); async function exportData() { if (state.tableData.length == 0) { message.error('表格数据为空,无法导出'); return; } axios .get(`/api/perform/performCount/tempPerformQuestionStatisticExcel`, { headers: { token: token, }, responseType: 'blob', params: { type: state.orgValue, year: formatDate(state.selectyear, 'YYYY'), }, }) .then(function (res) { console.log(res, 'res'); downloadBlob(res.data, decodeURIComponent(res.headers['content-disposition'].split('filename=')[1])); }); } // 切换tab/年份/考评公司 const handleUpdateValue = (value) => { getTableData(); }; onMounted(() => { getTableData(); }); return { ...toRefs(state), getTableData, exportData, handleUpdateValue, }; }, }; </script> <style lang="less"> .LSresultsPublicity { width: 1739px; height: 927px; .tabBox { width: 100%; height: 850px; padding: 10px; overflow: auto; tbody, tfoot, thead, tr, th, td { vertical-align: middle; } } .searchox { display: flex; align-items: center; justify-content: space-between; padding: 10px; } .question { position: absolute; top: 50px; left: 2.5%; width: 95%; height: calc(100% - 50px); display: flex; justify-content: center; } } </style>