2 changed files with 408 additions and 0 deletions
-
3src/api/shopOrder/productionReport.js
-
405src/views/modules/shopOrder/productionReport/orderDowntimeReport.vue
@ -0,0 +1,405 @@ |
|||||
|
<template> |
||||
|
<div class="mod-config"> |
||||
|
<el-card :class="['search-card', { 'collapsed': !searchExpanded }]" shadow="hover"> |
||||
|
<div slot="header" class="search-header"> |
||||
|
<div class="header-left"> |
||||
|
<i class="el-icon-search"></i> |
||||
|
<span class="header-title">查询条件</span> |
||||
|
</div> |
||||
|
<div class="header-right"> |
||||
|
<el-button type="text" size="small" @click="toggleSearchExpand" class="collapse-btn"> |
||||
|
<span>{{ searchExpanded ? '收起' : '展开' }}</span> |
||||
|
<i :class="searchExpanded ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i> |
||||
|
</el-button> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<el-form |
||||
|
:inline="true" |
||||
|
label-position="top" |
||||
|
:model="searchData" |
||||
|
class="search-form" |
||||
|
@keyup.enter.native="getData"> |
||||
|
<template v-if="searchExpanded"> |
||||
|
<el-row :gutter="16"> |
||||
|
<el-col :span="4"> |
||||
|
<el-form-item label="工单号"> |
||||
|
<el-input v-model="searchData.orderNo" placeholder="请输入" clearable></el-input> |
||||
|
</el-form-item> |
||||
|
</el-col> |
||||
|
<el-col :span="4"> |
||||
|
<el-form-item label="加工中心名称"> |
||||
|
<el-input v-model="searchData.workCenter" placeholder="请输入" clearable></el-input> |
||||
|
</el-form-item> |
||||
|
</el-col> |
||||
|
<el-col :span="4"> |
||||
|
<el-form-item label="生产机台"> |
||||
|
<el-input v-model="searchData.resource" placeholder="请输入" clearable></el-input> |
||||
|
</el-form-item> |
||||
|
</el-col> |
||||
|
<el-col :span="8"> |
||||
|
<el-form-item label="创建日期"> |
||||
|
<div class="date-range"> |
||||
|
<el-date-picker |
||||
|
v-model="searchData.startDate" |
||||
|
type="date" |
||||
|
value-format="yyyy-MM-dd" |
||||
|
placeholder="开始日期"> |
||||
|
</el-date-picker> |
||||
|
<span class="date-split">~</span> |
||||
|
<el-date-picker |
||||
|
v-model="searchData.endDate" |
||||
|
type="date" |
||||
|
value-format="yyyy-MM-dd" |
||||
|
placeholder="结束日期"> |
||||
|
</el-date-picker> |
||||
|
</div> |
||||
|
</el-form-item> |
||||
|
</el-col> |
||||
|
</el-row> |
||||
|
</template> |
||||
|
|
||||
|
<el-row :gutter="16"> |
||||
|
<el-col :span="24"> |
||||
|
<div class="search-actions"> |
||||
|
<el-button type="primary" icon="el-icon-search" :loading="searchLoading" @click="getData">查询</el-button> |
||||
|
<el-button icon="el-icon-refresh" @click="resetSearch">重置</el-button> |
||||
|
<el-button type="primary" icon="el-icon-download" :loading="exportLoading" @click="exportData">导出</el-button> |
||||
|
<div class="summary-bar"> |
||||
|
<span class="summary-item-inline"> |
||||
|
<span class="summary-label-inline">记录数:</span> |
||||
|
<span class="summary-value-inline">{{ totalCount }}</span> |
||||
|
</span> |
||||
|
</div> |
||||
|
</div> |
||||
|
</el-col> |
||||
|
</el-row> |
||||
|
</el-form> |
||||
|
</el-card> |
||||
|
|
||||
|
<el-table |
||||
|
:key="tableKey" |
||||
|
:height="tableHeight" |
||||
|
:data="pageList" |
||||
|
border |
||||
|
v-loading="dataListLoading" |
||||
|
style="width: 100%;"> |
||||
|
<el-table-column |
||||
|
v-for="item in columnList" |
||||
|
:key="item.columnProp" |
||||
|
:prop="item.columnProp" |
||||
|
:label="item.columnLabel" |
||||
|
:min-width="item.columnWidth" |
||||
|
:align="item.align" |
||||
|
header-align="center" |
||||
|
show-overflow-tooltip> |
||||
|
</el-table-column> |
||||
|
</el-table> |
||||
|
<el-pagination |
||||
|
style="margin-top: 0px" |
||||
|
@size-change="sizeChangeHandle" |
||||
|
@current-change="currentChangeHandle" |
||||
|
:current-page="pageIndex" |
||||
|
:page-sizes="[20, 50, 100, 200, 500]" |
||||
|
:page-size="pageSize" |
||||
|
:total="totalCount" |
||||
|
layout="total, sizes, prev, pager, next, jumper"> |
||||
|
</el-pagination> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import {getOrderDowntimeReport} from "@/api/shopOrder/productionReport.js" |
||||
|
import XLSX from "xlsx" |
||||
|
|
||||
|
const FIXED_COLUMNS = ["创建日期", "工单号", "加工中心编码", "加工中心名称", "生产机台", "总时长"] |
||||
|
|
||||
|
export default { |
||||
|
name: "orderDowntimeReport", |
||||
|
data() { |
||||
|
return { |
||||
|
searchExpanded: true, |
||||
|
searchLoading: false, |
||||
|
dataListLoading: false, |
||||
|
exportLoading: false, |
||||
|
searchData: this.emptySearch(), |
||||
|
dataList: [], |
||||
|
columnList: this.buildColumns(FIXED_COLUMNS), |
||||
|
pageIndex: 1, |
||||
|
pageSize: 50, |
||||
|
tableHeight: 400, |
||||
|
tableKey: 0 |
||||
|
} |
||||
|
}, |
||||
|
computed: { |
||||
|
totalCount() { |
||||
|
return this.dataList.length |
||||
|
}, |
||||
|
pageList() { |
||||
|
const start = (this.pageIndex - 1) * this.pageSize |
||||
|
return this.dataList.slice(start, start + this.pageSize) |
||||
|
} |
||||
|
}, |
||||
|
created() { |
||||
|
this.setDefaultDates() |
||||
|
this.calculateTableHeight() |
||||
|
window.addEventListener("resize", this.calculateTableHeight) |
||||
|
}, |
||||
|
beforeDestroy() { |
||||
|
window.removeEventListener("resize", this.calculateTableHeight) |
||||
|
}, |
||||
|
methods: { |
||||
|
emptySearch() { |
||||
|
return { |
||||
|
site: this.$store.state.user.site ? String(this.$store.state.user.site) : "", |
||||
|
orderNo: "", |
||||
|
workCenter: "", |
||||
|
resource: "", |
||||
|
startDate: "", |
||||
|
endDate: "" |
||||
|
} |
||||
|
}, |
||||
|
setDefaultDates() { |
||||
|
const now = new Date() |
||||
|
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1) |
||||
|
const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0) |
||||
|
this.searchData.startDate = this.formatDate(firstDay) |
||||
|
this.searchData.endDate = this.formatDate(lastDay) |
||||
|
}, |
||||
|
formatDate(date) { |
||||
|
const month = String(date.getMonth() + 1).padStart(2, "0") |
||||
|
const day = String(date.getDate()).padStart(2, "0") |
||||
|
return date.getFullYear() + "-" + month + "-" + day |
||||
|
}, |
||||
|
calculateTableHeight() { |
||||
|
this.$nextTick(() => { |
||||
|
const headerHeight = this.searchExpanded ? 220 : 150 |
||||
|
this.tableHeight = window.innerHeight - headerHeight - 105 |
||||
|
}) |
||||
|
}, |
||||
|
toggleSearchExpand() { |
||||
|
this.searchExpanded = !this.searchExpanded |
||||
|
this.calculateTableHeight() |
||||
|
}, |
||||
|
buildColumns(names) { |
||||
|
return names.map((name, index) => ({ |
||||
|
columnProp: name, |
||||
|
columnLabel: name, |
||||
|
columnWidth: this.columnWidth(name, index), |
||||
|
align: index >= FIXED_COLUMNS.length || name === "总时长" ? "right" : (name === "创建日期" ? "center" : "left") |
||||
|
})) |
||||
|
}, |
||||
|
columnWidth(name, index) { |
||||
|
if (name === "创建日期") return 140 |
||||
|
if (name === "工单号") return 180 |
||||
|
if (index >= FIXED_COLUMNS.length) return 120 |
||||
|
return 140 |
||||
|
}, |
||||
|
getData() { |
||||
|
if (!this.searchData.site) { |
||||
|
this.$message.warning("未获取到当前工厂,请重新登录") |
||||
|
return |
||||
|
} |
||||
|
if (!this.searchData.startDate || !this.searchData.endDate) { |
||||
|
this.$message.warning("请选择创建日期") |
||||
|
return |
||||
|
} |
||||
|
this.searchLoading = true |
||||
|
this.dataListLoading = true |
||||
|
getOrderDowntimeReport({ |
||||
|
site: this.searchData.site, |
||||
|
orderNo: this.searchData.orderNo, |
||||
|
seqNo: "", |
||||
|
workCenter: this.searchData.workCenter, |
||||
|
resource: this.searchData.resource, |
||||
|
startDate: this.searchData.startDate, |
||||
|
endDate: this.searchData.endDate |
||||
|
}).then(({data}) => { |
||||
|
if (data && data.success === false) { |
||||
|
this.dataList = [] |
||||
|
this.columnList = this.buildColumns(FIXED_COLUMNS) |
||||
|
this.$message.error(data.msg || "查询失败") |
||||
|
return |
||||
|
} |
||||
|
const rows = (data && data.rows) || [] |
||||
|
const columns = (data && data.columns && data.columns.length) ? data.columns : FIXED_COLUMNS |
||||
|
this.columnList = this.buildColumns(columns) |
||||
|
this.dataList = rows |
||||
|
this.pageIndex = 1 |
||||
|
this.tableKey += 1 |
||||
|
}).catch(error => { |
||||
|
this.dataList = [] |
||||
|
this.$message.error("查询失败: " + (error.message || "未知错误")) |
||||
|
}).finally(() => { |
||||
|
this.searchLoading = false |
||||
|
this.dataListLoading = false |
||||
|
}) |
||||
|
}, |
||||
|
resetSearch() { |
||||
|
this.searchData = this.emptySearch() |
||||
|
this.setDefaultDates() |
||||
|
this.pageIndex = 1 |
||||
|
}, |
||||
|
sizeChangeHandle(val) { |
||||
|
this.pageSize = val |
||||
|
this.pageIndex = 1 |
||||
|
}, |
||||
|
currentChangeHandle(val) { |
||||
|
this.pageIndex = val |
||||
|
}, |
||||
|
exportData() { |
||||
|
if (this.dataList.length === 0) { |
||||
|
this.$message.warning("没有数据可导出,请先查询") |
||||
|
return |
||||
|
} |
||||
|
this.exportLoading = true |
||||
|
try { |
||||
|
const header = this.columnList.map(item => item.columnLabel) |
||||
|
const body = this.dataList.map(row => this.columnList.map(item => { |
||||
|
const value = row[item.columnProp] |
||||
|
return value === null || value === undefined ? "" : value |
||||
|
})) |
||||
|
const sheet = XLSX.utils.aoa_to_sheet([header].concat(body)) |
||||
|
const book = XLSX.utils.book_new() |
||||
|
XLSX.utils.book_append_sheet(book, sheet, "停机明细") |
||||
|
XLSX.writeFile(book, "停机明细" + this.dayjs().format("YYYYMMDDHHmmss") + ".xlsx") |
||||
|
} finally { |
||||
|
this.exportLoading = false |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style scoped> |
||||
|
.search-card { |
||||
|
margin-bottom: 16px; |
||||
|
border-radius: 8px; |
||||
|
overflow: hidden; |
||||
|
transition: all 0.3s ease; |
||||
|
} |
||||
|
|
||||
|
.search-card:hover { |
||||
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08); |
||||
|
} |
||||
|
|
||||
|
.search-card /deep/ .el-card__header { |
||||
|
padding: 5px 20px; |
||||
|
background: linear-gradient(135deg, #9ac3d0 20%, #b6c7dd 80%); |
||||
|
border-bottom: none; |
||||
|
} |
||||
|
|
||||
|
.search-header { |
||||
|
display: flex; |
||||
|
justify-content: space-between; |
||||
|
align-items: center; |
||||
|
} |
||||
|
|
||||
|
.header-left { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
color: #fff; |
||||
|
} |
||||
|
|
||||
|
.header-left i { |
||||
|
font-size: 16px; |
||||
|
margin-right: 8px; |
||||
|
} |
||||
|
|
||||
|
.header-title { |
||||
|
font-size: 14px; |
||||
|
font-weight: 600; |
||||
|
} |
||||
|
|
||||
|
.collapse-btn { |
||||
|
color: #fff !important; |
||||
|
font-size: 13px; |
||||
|
padding: 4px 8px; |
||||
|
} |
||||
|
|
||||
|
.collapse-btn:hover { |
||||
|
background: rgba(255, 255, 255, 0.2); |
||||
|
} |
||||
|
|
||||
|
.collapse-btn i { |
||||
|
margin-left: 4px; |
||||
|
} |
||||
|
|
||||
|
.search-form { |
||||
|
padding: 6px 0; |
||||
|
} |
||||
|
|
||||
|
.search-card /deep/ .el-card__body { |
||||
|
padding: 10px; |
||||
|
} |
||||
|
|
||||
|
.search-card.collapsed /deep/ .el-card__body { |
||||
|
padding: 10px 20px; |
||||
|
} |
||||
|
|
||||
|
.search-form /deep/ .el-form-item { |
||||
|
margin-bottom: 12px; |
||||
|
width: 100%; |
||||
|
} |
||||
|
|
||||
|
.search-form /deep/ .el-form-item__label { |
||||
|
font-weight: 500; |
||||
|
color: #606266; |
||||
|
padding-bottom: 4px; |
||||
|
} |
||||
|
|
||||
|
.search-form /deep/ .el-input__inner { |
||||
|
border-radius: 6px; |
||||
|
} |
||||
|
|
||||
|
.search-form /deep/ .el-date-editor.el-input { |
||||
|
width: 100%; |
||||
|
} |
||||
|
|
||||
|
.date-range { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
} |
||||
|
|
||||
|
.date-range .el-date-editor { |
||||
|
flex: 1; |
||||
|
} |
||||
|
|
||||
|
.date-split { |
||||
|
margin: 0 8px; |
||||
|
color: #DCDFE6; |
||||
|
} |
||||
|
|
||||
|
.search-actions { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
padding: 8px 0 2px 0; |
||||
|
gap: 8px; |
||||
|
} |
||||
|
|
||||
|
.search-card:not(.collapsed) .search-actions { |
||||
|
border-top: 1px solid #f0f0f0; |
||||
|
margin-top: 6px; |
||||
|
} |
||||
|
|
||||
|
.summary-bar { |
||||
|
margin-left: auto; |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
background: #f2f6fa; |
||||
|
border: 1px solid #c8dff0; |
||||
|
border-radius: 6px; |
||||
|
padding: 5px 14px; |
||||
|
font-size: 13px; |
||||
|
} |
||||
|
|
||||
|
.summary-label-inline { |
||||
|
color: #5a7a8f; |
||||
|
font-weight: 500; |
||||
|
} |
||||
|
|
||||
|
.summary-value-inline { |
||||
|
color: #3a7ba8; |
||||
|
font-weight: bold; |
||||
|
} |
||||
|
</style> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue