Files
datie-bom/web_ui/templates/reconciliation.html
2026-06-22 18:08:34 +08:00

587 lines
38 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>绩效核查与 BOM 比对</title>
<!-- 引入 ElementUI 样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入 Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
<!-- 引入 ElementUI 组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!-- 引入 axios -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<style>
body { margin: 0; padding: 0; background-color: #f0f2f5; font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; }
.header { background-color: #fff; padding: 15px 30px; box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05); display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.header h2 { margin: 0; color: #303133; font-size: 20px; }
.main-container { padding: 0 30px; margin-bottom: 30px; }
.card-panel { background-color: #fff; border-radius: 4px; box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05); padding: 20px; margin-bottom: 20px; }
.filter-row { display: flex; gap: 15px; margin-bottom: 15px; align-items: center; }
.pagination-container { margin-top: 15px; display: flex; justify-content: flex-end; }
.el-table--small td, .el-table--small th { padding: 4px 0; }
.el-table__expand-icon { height: 16px !important; line-height: 16px !important; margin-right: 5px; }
.el-tag { font-weight: bold; }
</style>
</head>
<body>
<div id="app">
<div class="header">
<h2>🎯 绩效核查与 BOM 比对</h2>
<div style="display: flex; gap: 10px;">
<el-button type="primary" :icon="isSystemBusy ? 'el-icon-loading' : 'el-icon-refresh'" @click="syncAbnormalReport" :disabled="isSystemBusy" size="small">
<span v-text="isSystemBusy ? '抓取中...' : '同步BOM发料台账'"></span>
</el-button>
<el-button type="warning" :icon="isSystemBusy ? 'el-icon-loading' : 'el-icon-refresh'" @click="syncIssueReceipts" :disabled="isSystemBusy" size="small">
<span v-text="isSystemBusy ? '抓取中...' : '同步发料单明细'"></span>
</el-button>
<el-button type="info" plain icon="el-icon-back" @click="goBack" size="small">返回主控台</el-button>
</div>
</div>
<div class="main-container">
<div class="card-panel" style="display: flex; justify-content: space-between; align-items: center;">
<div>
<span style="font-size: 14px; color: #606266; margin-right: 15px;"><i class="el-icon-date"></i> 对账月份:</span>
<el-date-picker v-model="dateRangeSelect" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" size="small" style="width: 260px; margin-right: 15px;" @change="handleDateChange"></el-date-picker>
</div>
<el-button type="primary" icon="el-icon-magic-stick" @click="triggerMatch" :loading="matching">提取并匹配工单</el-button>
</div>
<el-tabs v-model="activeTab" type="border-card">
<!-- Tab 1: 工单发料明细 -->
<el-tab-pane label="工单发料明细" name="official">
<span slot="label"><i class="el-icon-document"></i> 工单发料明细</span>
<div class="filter-row">
<el-input v-model="officialSearch" placeholder="搜索工单号/物料名称/代码" style="width: 300px" clearable prefix-icon="el-icon-search"></el-input>
<el-radio-group v-model="officialStatusFilter" size="small" style="margin-left: 15px;">
<el-radio-button label="">全部 (<span v-text="officialStatusCounts['全部']"></span>)</el-radio-button>
<el-radio-button label="发料正常">发料正常 (<span v-text="officialStatusCounts['发料正常']"></span>)</el-radio-button>
<el-radio-button label="超领发料">超领发料 (<span v-text="officialStatusCounts['超领发料']"></span>)</el-radio-button>
<el-radio-button label="少领发料">少领发料 (<span v-text="officialStatusCounts['少领发料']"></span>)</el-radio-button>
<el-radio-button label="未发料">未发料 (<span v-text="officialStatusCounts['未发料']"></span>)</el-radio-button>
<el-radio-button label="BOM外发料">BOM外发料 (<span v-text="officialStatusCounts['BOM外发料']"></span>)</el-radio-button>
</el-radio-group>
<el-button type="success" icon="el-icon-download" @click="exportOfficialData" size="small" style="margin-left: auto;">导出 Excel</el-button>
</div>
<el-table :data="pagedOfficialData" v-loading="loadingOfficial" row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}" border style="width: 100%" stripe size="small" :header-cell-style="{background:'#f5f7fa',color:'#606266'}">
<el-table-column prop="sfc" label="工单号 (SFC)" width="150" sortable></el-table-column>
<el-table-column prop="order_date" label="工单时间" width="160" sortable></el-table-column>
<el-table-column prop="workshop" label="生产车间" width="120" show-overflow-tooltip></el-table-column>
<el-table-column prop="material_code" label="物料代码" width="120"></el-table-column>
<el-table-column prop="material_name" label="物料名称" min-width="180" show-overflow-tooltip></el-table-column>
<el-table-column label="物料项数" width="100" align="center">
<template slot-scope="scope">
<el-tag v-if="scope.row.id && scope.row.id.startsWith('sfc_')" size="mini" type="info" effect="plain" v-text="getMaterialCount(scope.row) + ' 项'"></el-tag>
</template>
</el-table-column>
<el-table-column label="发料对比" align="center">
<el-table-column prop="bom_qty" label="BOM 应发量" width="110" align="right">
<template slot-scope="scope">
<span v-if="scope.row.bom_qty !== ''" v-text="Number(scope.row.bom_qty).toFixed(4)"></span>
</template>
</el-table-column>
<el-table-column prop="actual_qty" label="实际发料量" width="110" align="right">
<template slot-scope="scope">
<span v-if="scope.row.actual_qty !== ''" style="font-weight: bold;" v-text="Number(scope.row.actual_qty).toFixed(4)"></span>
</template>
</el-table-column>
<el-table-column prop="diff_qty" label="差异数量 (实-应)" width="130" align="right">
<template slot-scope="scope">
<span v-if="scope.row.diff_qty !== ''" :style="{color: scope.row.diff_qty > 0 ? '#F56C6C' : (scope.row.diff_qty < 0 ? '#E6A23C' : '#67C23A'), fontWeight: 'bold'}" v-text="(scope.row.diff_qty > 0 ? '+' : '') + Number(scope.row.diff_qty).toFixed(4)"></span>
</template>
</el-table-column>
</el-table-column>
<el-table-column prop="status" label="状态" width="120" align="center" sortable>
<template slot-scope="scope">
<el-tag v-if="scope.row.status && scope.row.status !== '-'" :type="getStatusType(scope.row.status)" effect="dark" size="small" v-text="scope.row.status"></el-tag>
</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination @size-change="handleOfficialSizeChange" @current-change="handleOfficialCurrentChange" :current-page="officialPage" :page-sizes="[20, 50, 100, 500]" :page-size="officialPageSize" layout="total, sizes, prev, pager, next, jumper" :total="filteredOfficialData.length"></el-pagination>
</div>
</el-tab-pane>
<!-- Tab 2: 无工单发料明细 -->
<el-tab-pane label="无工单发料明细" name="unmatched">
<span slot="label"><i class="el-icon-warning-outline"></i> 无工单发料明细 <el-badge v-if="filteredUnmatchedData.length > 0" :value="filteredUnmatchedData.length" class="mark" type="warning"></el-badge></span>
<div class="filter-row">
<el-input v-model="unmatchedSearch" placeholder="搜索物料名称/代码/领料人" style="width: 300px" clearable prefix-icon="el-icon-search"></el-input>
</div>
<el-table :data="pagedUnmatchedData" v-loading="loadingUnmatched" border style="width: 100%" stripe size="small" :header-cell-style="{background:'#f5f7fa',color:'#606266'}">
<el-table-column type="index" label="序号" width="60" align="center"></el-table-column>
<el-table-column prop="execution_time" label="执行时间" width="160" sortable></el-table-column>
<el-table-column prop="issue_receipt_no" label="发料单号" width="150"></el-table-column>
<el-table-column prop="material_code" label="物料代码" width="120"></el-table-column>
<el-table-column prop="material_name" label="物料名称" min-width="150" show-overflow-tooltip></el-table-column>
<el-table-column prop="material_specification" label="规格" min-width="150" show-overflow-tooltip></el-table-column>
<el-table-column prop="issue_number" label="发料数量" width="90" align="right">
<template slot-scope="scope">
<span style="color: #F56C6C; font-weight: bold;" v-text="scope.row.issue_number"></span>
</template>
</el-table-column>
<el-table-column prop="executor_user_name" label="发料人" width="100" align="center"></el-table-column>
<el-table-column prop="warehouse_name" label="仓库" width="120" show-overflow-tooltip></el-table-column>
<el-table-column label="单据备注信息" min-width="200" show-overflow-tooltip>
<template slot-scope="scope">
<span v-if="scope.row.work_orders_remark" v-text="'【工单备注】' + scope.row.work_orders_remark + ' '"></span>
<span v-if="scope.row.detailed_remark" v-text="'【明细备注】' + scope.row.detailed_remark + ' '"></span>
<span v-if="scope.row.production_order_remark" v-text="'【生产单备注】' + scope.row.production_order_remark"></span>
</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination @size-change="handleUnmatchedSizeChange" @current-change="handleUnmatchedCurrentChange" :current-page="unmatchedPage" :page-sizes="[20, 50, 100, 500]" :page-size="unmatchedPageSize" layout="total, sizes, prev, pager, next, jumper" :total="filteredUnmatchedData.length"></el-pagination>
</div>
</el-tab-pane>
<!-- Tab 3: 从备注中提取的工单 -->
<el-tab-pane label="从备注中提取的工单" name="inferred">
<span slot="label"><i class="el-icon-magic-stick"></i> 从备注中提取的工单</span>
<div class="filter-row">
<el-input v-model="inferredSearch" placeholder="搜索工单号/物料名称/代码" style="width: 300px" clearable prefix-icon="el-icon-search"></el-input>
<el-radio-group v-model="inferredStatusFilter" size="small" style="margin-left: 15px;">
<el-radio-button label="">全部 (<span v-text="inferredStatusCounts['全部']"></span>)</el-radio-button>
<el-radio-button label="发料正常">发料正常 (<span v-text="inferredStatusCounts['发料正常']"></span>)</el-radio-button>
<el-radio-button label="超领发料">超领发料 (<span v-text="inferredStatusCounts['超领发料']"></span>)</el-radio-button>
<el-radio-button label="少领发料">少领发料 (<span v-text="inferredStatusCounts['少领发料']"></span>)</el-radio-button>
<el-radio-button label="未发料">未发料 (<span v-text="inferredStatusCounts['未发料']"></span>)</el-radio-button>
<el-radio-button label="BOM外发料">BOM外发料 (<span v-text="inferredStatusCounts['BOM外发料']"></span>)</el-radio-button>
</el-radio-group>
<el-button type="success" icon="el-icon-download" @click="exportInferredData" size="small" style="margin-left: auto;">导出 Excel</el-button>
</div>
<el-table :data="pagedInferredData" v-loading="loadingInferred" row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}" border style="width: 100%" stripe size="small" :header-cell-style="{background:'#f5f7fa',color:'#606266'}">
<el-table-column prop="sfc" label="提取的工单号" width="150" sortable></el-table-column>
<el-table-column prop="order_date" label="工单时间" width="160" sortable></el-table-column>
<el-table-column prop="workshop" label="生产车间" width="120" show-overflow-tooltip></el-table-column>
<el-table-column prop="material_code" label="物料代码" width="120"></el-table-column>
<el-table-column prop="material_name" label="物料名称" min-width="180" show-overflow-tooltip></el-table-column>
<el-table-column label="物料项数" width="100" align="center">
<template slot-scope="scope">
<el-tag v-if="scope.row.id && scope.row.id.startsWith('sfc_')" size="mini" type="info" effect="plain" v-text="getMaterialCount(scope.row) + ' 项'"></el-tag>
</template>
</el-table-column>
<el-table-column label="发料对比" align="center">
<el-table-column prop="bom_qty" label="BOM 应发量" width="110" align="right">
<template slot-scope="scope">
<span v-if="scope.row.bom_qty !== ''" v-text="Number(scope.row.bom_qty).toFixed(4)"></span>
</template>
</el-table-column>
<el-table-column prop="actual_qty" label="实际发料量" width="110" align="right">
<template slot-scope="scope">
<span v-if="scope.row.actual_qty !== ''" style="font-weight: bold;" v-text="Number(scope.row.actual_qty).toFixed(4)"></span>
</template>
</el-table-column>
<el-table-column prop="diff_qty" label="差异数量 (实-应)" width="130" align="right">
<template slot-scope="scope">
<span v-if="scope.row.diff_qty !== ''" :style="{color: scope.row.diff_qty > 0 ? '#F56C6C' : (scope.row.diff_qty < 0 ? '#E6A23C' : '#67C23A'), fontWeight: 'bold'}" v-text="(scope.row.diff_qty > 0 ? '+' : '') + Number(scope.row.diff_qty).toFixed(4)"></span>
</template>
</el-table-column>
</el-table-column>
<el-table-column prop="status" label="状态" width="120" align="center" sortable>
<template slot-scope="scope">
<el-tag v-if="scope.row.status && scope.row.status !== '-'" :type="getStatusType(scope.row.status)" effect="dark" size="small" v-text="scope.row.status"></el-tag>
</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination @size-change="handleInferredSizeChange" @current-change="handleInferredCurrentChange" :current-page="inferredPage" :page-sizes="[20, 50, 100, 500]" :page-size="inferredPageSize" layout="total, sizes, prev, pager, next, jumper" :total="filteredInferredData.length"></el-pagination>
</div>
</el-tab-pane>
</el-tabs>
</div>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
isSystemBusy: false,
activeTab: 'official',
matching: false,
dateRange: { start: '-', end: '-' },
dateRangeSelect: [],
loadingOfficial: false,
officialData: [],
officialSearch: '',
officialStatusFilter: '',
officialPage: 1,
officialPageSize: 50,
loadingUnmatched: false,
unmatchedData: [],
unmatchedSearch: '',
unmatchedPage: 1,
unmatchedPageSize: 50,
loadingInferred: false,
inferredData: [],
inferredSearch: '',
inferredStatusFilter: '',
inferredPage: 1,
inferredPageSize: 50,
};
},
computed: {
officialStatusCounts() {
const counts = { '全部': 0, '发料正常': 0, '超领发料': 0, '少领发料': 0, '未发料': 0, 'BOM外发料': 0 };
if (!this.officialData) return counts;
const checkStatus = (node, status) => {
if (node.status === status) return true;
if (node.children && node.children.length > 0) {
return node.children.some(child => checkStatus(child, status));
}
return false;
};
counts['全部'] = this.officialData.length;
['发料正常', '超领发料', '少领发料', '未发料', 'BOM外发料'].forEach(status => {
counts[status] = this.officialData.filter(row => checkStatus(row, status)).length;
});
return counts;
},
inferredStatusCounts() {
const counts = { '全部': 0, '发料正常': 0, '超领发料': 0, '少领发料': 0, '未发料': 0, 'BOM外发料': 0 };
if (!this.inferredData) return counts;
const checkStatus = (node, status) => {
if (node.status === status) return true;
if (node.children && node.children.length > 0) {
return node.children.some(child => checkStatus(child, status));
}
return false;
};
counts['全部'] = this.inferredData.length;
['发料正常', '超领发料', '少领发料', '未发料', 'BOM外发料'].forEach(status => {
counts[status] = this.inferredData.filter(row => checkStatus(row, status)).length;
});
return counts;
},
filteredUnmatchedData() {
let data = this.unmatchedData || [];
if (this.unmatchedSearch) {
const keyword = this.unmatchedSearch.toLowerCase();
data = data.filter(item =>
(item.issue_receipt_no && item.issue_receipt_no.toLowerCase().includes(keyword)) ||
(item.material_name && item.material_name.toLowerCase().includes(keyword)) ||
(item.material_code && item.material_code.toLowerCase().includes(keyword)) ||
(item.executor_user_name && item.executor_user_name.toLowerCase().includes(keyword))
);
}
return data;
},
pagedUnmatchedData() {
const start = (this.unmatchedPage - 1) * this.unmatchedPageSize;
const end = start + this.unmatchedPageSize;
return this.filteredUnmatchedData.slice(start, end);
},
filteredOfficialData() {
let result = this.officialData || [];
if (this.officialSearch || this.officialStatusFilter) {
const keyword = this.officialSearch ? this.officialSearch.toLowerCase() : '';
const statusFilter = this.officialStatusFilter;
const checkNode = (node, parentKeywordMatched = false) => {
let matchKeyword = parentKeywordMatched;
if (!matchKeyword && keyword) {
matchKeyword = (
(node.sfc && node.sfc.toLowerCase().includes(keyword)) ||
(node.material_code && node.material_code.toLowerCase().includes(keyword)) ||
(node.material_name && node.material_name.toLowerCase().includes(keyword))
);
} else if (!keyword) {
matchKeyword = true;
}
let matchStatus = true;
if (statusFilter) {
matchStatus = (node.status === statusFilter);
}
// 当前节点完全符合条件
if (matchKeyword && matchStatus) return true;
// 否则去检查子节点
// 传递 matchKeyword 给子节点:如果父节点搜索匹配了,子节点就不需要再匹配搜索框,只需匹配状态即可
if (node.children && node.children.length > 0) {
return node.children.some(child => checkNode(child, matchKeyword));
}
return false;
};
result = result.filter(row => checkNode(row));
}
return result;
},
pagedOfficialData() {
const start = (this.officialPage - 1) * this.officialPageSize;
const end = start + this.officialPageSize;
return this.filteredOfficialData.slice(start, end);
},
filteredInferredData() {
let result = this.inferredData || [];
if (this.inferredSearch || this.inferredStatusFilter) {
const keyword = this.inferredSearch ? this.inferredSearch.toLowerCase() : '';
const statusFilter = this.inferredStatusFilter;
const checkNode = (node, parentKeywordMatched = false) => {
let matchKeyword = parentKeywordMatched;
if (!matchKeyword && keyword) {
matchKeyword = (
(node.sfc && node.sfc.toLowerCase().includes(keyword)) ||
(node.material_code && node.material_code.toLowerCase().includes(keyword)) ||
(node.material_name && node.material_name.toLowerCase().includes(keyword))
);
} else if (!keyword) {
matchKeyword = true;
}
let matchStatus = true;
if (statusFilter) {
matchStatus = (node.status === statusFilter);
}
// 当前节点完全符合条件
if (matchKeyword && matchStatus) return true;
// 否则去检查子节点
// 传递 matchKeyword 给子节点:如果父节点搜索匹配了,子节点就不需要再匹配搜索框,只需匹配状态即可
if (node.children && node.children.length > 0) {
return node.children.some(child => checkNode(child, matchKeyword));
}
return false;
};
result = result.filter(row => checkNode(row));
}
return result;
},
pagedInferredData() {
const start = (this.inferredPage - 1) * this.inferredPageSize;
const end = start + this.inferredPageSize;
return this.filteredInferredData.slice(start, end);
}
},
watch: {
dateRangeSelect(newVal) {
if (newVal && newVal.length === 2) {
this.loadUnmatchedData();
this.loadOfficialData();
this.loadInferredData();
}
}
},
mounted() {
this.loadSummary();
this.loadUnmatchedData();
this.loadOfficialData();
this.loadInferredData();
this.timer = setInterval(this.checkTaskStatus, 2000);
},
beforeDestroy() {
if (this.timer) clearInterval(this.timer);
},
methods: {
syncAbnormalReport() {
this.$confirm('确定要抓取最新的 BOM 发料异常核对报表吗?该操作会在后台自动执行。', '提示', {
confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
}).then(() => {
this.isSystemBusy = true;
axios.post('/api/sync_abnormal_report').then(res => {
if (res.data.success) {
this.$message.success('已触发!' + res.data.message);
setTimeout(this.checkTaskStatus, 1000);
} else {
this.$message.error('触发失败:' + res.data.message);
}
}).catch(err => {
this.$message.error('请求失败');
this.isSystemBusy = false;
});
}).catch(() => {});
},
syncIssueReceipts() {
this.$confirm('确定要抓取最新的 发料单明细 吗?该操作会在后台自动执行。', '提示', {
confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
}).then(() => {
this.isSystemBusy = true;
axios.post('/api/sync_issue_receipts').then(res => {
if (res.data.success) {
this.$message.success('已触发!' + res.data.message);
setTimeout(this.checkTaskStatus, 1000);
} else {
this.$message.error('触发失败:' + res.data.message);
}
}).catch(err => {
this.$message.error('请求失败');
this.isSystemBusy = false;
});
}).catch(() => {});
},
checkTaskStatus() {
axios.get('/api/task_status').then(res => {
if (res.data.is_busy) {
this.isSystemBusy = true;
setTimeout(this.checkTaskStatus, 3000);
} else {
if (this.isSystemBusy) {
this.$message.success('数据抓取任务已完成!正在重新加载数据...');
this.loadSummary();
this.loadUnmatchedData();
this.loadOfficialData();
this.loadInferredData();
}
this.isSystemBusy = false;
}
});
},
getMaterialCount(row) {
if (!row.id || !row.id.startsWith('sfc_')) return '';
let count = 0;
const traverse = (nodes) => {
if (!nodes) return;
nodes.forEach(n => {
count++;
traverse(n.children);
});
};
traverse(row.children);
return count;
},
goBack() { window.location.href = '/'; },
handleDateChange(val) {
if (!val) this.dateRangeSelect = [this.dateRange.start, this.dateRange.end];
},
handleOfficialSizeChange(val) { this.officialPageSize = val; this.officialPage = 1; },
handleOfficialCurrentChange(val) { this.officialPage = val; },
handleUnmatchedSizeChange(val) { this.unmatchedPageSize = val; this.unmatchedPage = 1; },
handleUnmatchedCurrentChange(val) { this.unmatchedPage = val; },
handleInferredSizeChange(val) { this.inferredPageSize = val; this.inferredPage = 1; },
handleInferredCurrentChange(val) { this.inferredPage = val; },
getStatusType(status) {
if (status === '发料正常') return 'success';
if (status === '超领发料') return 'danger';
if (status === '少领发料') return 'warning';
if (status === '未发料') return 'info';
if (status === 'BOM外发料') return 'primary';
return 'info';
},
loadSummary() {
axios.get('/api/analysis/summary').then(res => {
this.dateRange = res.data;
if (!this.dateRangeSelect || this.dateRangeSelect.length === 0) {
this.dateRangeSelect = [this.dateRange.start, this.dateRange.end];
}
}).catch(err => console.error(err));
},
checkTaskStatus() {
axios.get('/api/task_status').then(res => {
if (res.data.is_busy && res.data.task_name.includes('自动清洗')) {
this.matching = true;
} else {
if (this.matching) {
this.matching = false;
this.loadUnmatchedData();
this.loadOfficialData();
this.loadInferredData();
}
}
}).catch(err => console.error('获取任务状态失败', err));
},
triggerMatch() {
this.matching = true;
axios.post('/api/analysis/match_work_orders')
.then(res => this.$message.success(res.data.message))
.catch(err => {
this.matching = false;
this.$message.error(err.response?.data?.message || '触发失败');
});
},
loadUnmatchedData() {
this.loadingUnmatched = true;
let url = '/api/analysis/unmatched_materials';
if (this.dateRangeSelect && this.dateRangeSelect.length === 2) {
url += `?start=${this.dateRangeSelect[0]}&end=${this.dateRangeSelect[1]}`;
}
axios.get(url).then(res => {
this.unmatchedData = res.data.rows || [];
this.unmatchedPage = 1;
}).catch(err => console.error(err)).finally(() => { this.loadingUnmatched = false; });
},
loadOfficialData() {
this.loadingOfficial = true;
let url = '/api/analysis/bom_reconciliation?match_type=official';
if (this.dateRangeSelect && this.dateRangeSelect.length === 2) {
url += `&start=${this.dateRangeSelect[0]}&end=${this.dateRangeSelect[1]}`;
}
axios.get(url).then(res => {
this.officialData = res.data.rows || [];
this.officialPage = 1;
}).catch(err => console.error(err)).finally(() => { this.loadingOfficial = false; });
},
loadInferredData() {
this.loadingInferred = true;
let url = '/api/analysis/bom_reconciliation?match_type=inferred';
if (this.dateRangeSelect && this.dateRangeSelect.length === 2) {
url += `&start=${this.dateRangeSelect[0]}&end=${this.dateRangeSelect[1]}`;
}
axios.get(url).then(res => {
this.inferredData = res.data.rows || [];
this.inferredPage = 1;
}).catch(err => console.error(err)).finally(() => { this.loadingInferred = false; });
},
exportOfficialData() {
const headers = ['层级', '工单号(SFC)', '物料代码', '物料名称', 'BOM应发量', '实际发料量', '差异数量', '状态'];
let csvContent = "data:text/csv;charset=utf-8,\uFEFF" + headers.join(",") + "\n";
const processRow = (node, level = 0) => {
const indent = " ".repeat(level);
const rowData = [
level, node.sfc || '', node.material_code || '', `"${indent}${node.material_name || ''}"`,
node.bom_qty !== '' ? node.bom_qty : '', node.actual_qty !== '' ? node.actual_qty : '',
node.diff_qty !== '' ? node.diff_qty : '', node.status || ''
];
csvContent += rowData.join(",") + "\n";
if (node.children && node.children.length > 0) {
node.children.forEach(child => processRow(child, level + 1));
}
};
this.filteredOfficialData.forEach(row => processRow(row, 0));
const link = document.createElement("a");
link.setAttribute("href", encodeURI(csvContent));
link.setAttribute("download", "工单发料对账单.csv");
document.body.appendChild(link); link.click(); document.body.removeChild(link);
},
exportInferredData() {
const headers = ['层级', '工单号(SFC)', '物料代码', '物料名称', 'BOM应发量', '实际发料量', '差异数量', '状态'];
let csvContent = "data:text/csv;charset=utf-8,\uFEFF" + headers.join(",") + "\n";
const processRow = (node, level = 0) => {
const indent = " ".repeat(level);
const rowData = [
level, node.sfc || '', node.material_code || '', `"${indent}${node.material_name || ''}"`,
node.bom_qty !== '' ? node.bom_qty : '', node.actual_qty !== '' ? node.actual_qty : '',
node.diff_qty !== '' ? node.diff_qty : '', node.status || ''
];
csvContent += rowData.join(",") + "\n";
if (node.children && node.children.length > 0) {
node.children.forEach(child => processRow(child, level + 1));
}
};
this.filteredInferredData.forEach(row => processRow(row, 0));
const link = document.createElement("a");
link.setAttribute("href", encodeURI(csvContent));
link.setAttribute("download", "备注提取工单对账单.csv");
document.body.appendChild(link); link.click(); document.body.removeChild(link);
}
}
});
</script>
{% include "global_log.html" %}
</body>
</html>