feat: 增加工时报表导出并调整质量菜单
This commit is contained in:
@@ -63,6 +63,15 @@
|
||||
<span class="show-text">任务ID:</span>
|
||||
<el-input v-model="searchForm.did" clearable size="small" style="width: 90px; margin-right: 8px" />
|
||||
<el-button :loading="loading" icon="el-icon-search" plain size="small" type="primary" @click="searchTable">查询</el-button>
|
||||
<el-button
|
||||
:disabled="loading || tableData.length === 0"
|
||||
:loading="exporting"
|
||||
icon="el-icon-download"
|
||||
plain
|
||||
size="small"
|
||||
type="success"
|
||||
@click="exportToExcel"
|
||||
>导出</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
@@ -110,11 +119,14 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as XLSX from 'xlsx'
|
||||
|
||||
export default {
|
||||
name: 'DesignReportHoursReport',
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
exporting: false,
|
||||
tableData: [],
|
||||
projectOptions: [],
|
||||
materialOptions: [],
|
||||
@@ -176,6 +188,86 @@ export default {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
exportToExcel() {
|
||||
if (this.tableData.length === 0) {
|
||||
this.$message.warning('没有数据可导出')
|
||||
return
|
||||
}
|
||||
|
||||
this.exporting = true
|
||||
try {
|
||||
const rows = this.flattenTree(this.tableData)
|
||||
const exportData = rows.map(row => ({
|
||||
层级: row.Level === 1 ? '操作人汇总' : (row.Level === 2 ? '日期汇总' : '任务明细'),
|
||||
'操作人 / 日期 / 任务': `${' '.repeat(Math.max((row.Level || 1) - 1, 0))}${this.getTreeTitle(row)}`,
|
||||
工作日期: this.getExportValue(row.工作日期),
|
||||
RID: this.getExportValue(row.RID),
|
||||
DID: this.getExportValue(row.DID),
|
||||
项目号: this.getExportValue(row.项目号),
|
||||
物料编码: this.getExportValue(row.物料编码),
|
||||
物料名称: this.getExportValue(row.物料名称),
|
||||
图号: this.getExportValue(row.图号),
|
||||
类别: this.getExportValue(row.类别),
|
||||
报工次数: this.getExportValue(row.报工次数),
|
||||
'工时(h)': this.formatHours(row.工时小时),
|
||||
开始时间: this.getExportValue(row.开始时间),
|
||||
结束时间: this.getExportValue(row.结束时间),
|
||||
校验状态: this.getExportValue(row.校验状态),
|
||||
进度说明: this.getExportValue(row.进度说明),
|
||||
备注: this.getExportValue(row.备注)
|
||||
}))
|
||||
const workbook = XLSX.utils.book_new()
|
||||
const worksheet = XLSX.utils.json_to_sheet(exportData)
|
||||
worksheet['!cols'] = [
|
||||
{ wch: 12 },
|
||||
{ wch: 32 },
|
||||
{ wch: 14 },
|
||||
{ wch: 10 },
|
||||
{ wch: 10 },
|
||||
{ wch: 16 },
|
||||
{ wch: 22 },
|
||||
{ wch: 24 },
|
||||
{ wch: 16 },
|
||||
{ wch: 16 },
|
||||
{ wch: 12 },
|
||||
{ wch: 12 },
|
||||
{ wch: 20 },
|
||||
{ wch: 20 },
|
||||
{ wch: 14 },
|
||||
{ wch: 30 },
|
||||
{ wch: 30 }
|
||||
]
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, '设计工时报表')
|
||||
XLSX.writeFile(workbook, `设计工时报表_${this.formatDateForFileName(new Date())}.xlsx`)
|
||||
this.$message.success('导出成功')
|
||||
} catch (error) {
|
||||
console.error('设计工时报表导出失败:', error)
|
||||
this.$message.error('导出失败')
|
||||
} finally {
|
||||
this.exporting = false
|
||||
}
|
||||
},
|
||||
flattenTree(rows) {
|
||||
return rows.reduce((result, row) => {
|
||||
result.push(row)
|
||||
if (row.children && row.children.length > 0) {
|
||||
result.push(...this.flattenTree(row.children))
|
||||
}
|
||||
return result
|
||||
}, [])
|
||||
},
|
||||
getExportValue(value) {
|
||||
return value === null || value === undefined ? '' : value
|
||||
},
|
||||
formatDateForFileName(date) {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||
return `${year}${month}${day}_${hours}${minutes}${seconds}`
|
||||
},
|
||||
async queryProjects(query) {
|
||||
const data = this.CreateData('11', '设计报工_项目查询', [['过滤', query || '']])
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user