迁移电池追溯模块

This commit is contained in:
sheng
2026-06-22 17:36:22 +08:00
parent 15526ca6e4
commit a1716b0069
7 changed files with 355 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
import { request } from '@/api/_service'
const BASE = 'planning_production/produce/traceability/'
function apiParams (method, data = {}) {
return { method, platform: 'background', ...data }
}
export function getBatteryTraceList (data) {
return request({
url: BASE + 'battery',
method: 'get',
params: apiParams('planning_production_produce_traceability_battery', data)
})
}
export function getBatteryProcessData (data) {
return request({
url: BASE + 'batteryProcess',
method: 'get',
params: apiParams('planning_production_produce_traceability_batteryProcess', data)
})
}
export function cancelBatteryActive (data) {
return request({
url: BASE + 'batteryactive',
method: 'get',
params: apiParams('planning_production_produce_traceability_batteryactive', data)
})
}

View File

@@ -1304,6 +1304,37 @@
"grade": "Grade",
"please_select_at_least_one_battery": "Select at least one battery",
"cancel_success": "Cancel active successfully"
},
"battery": {
"query": "Search",
"reset": "Reset",
"battery_code": "Battery Barcode",
"enter_battery_code": "Enter battery barcode",
"login_batch": "Login Batch",
"tray_no": "Tray No.",
"lot": "LOT",
"is_active": "Active",
"activated": "Activated",
"stopped": "Stopped",
"good_or_ng": "GOOD/NG",
"grade": "Grade",
"ng_info": "NG Info",
"current_process_code": "Current Process Code",
"battery_detail": "Battery Detail",
"cancel_activation": "Cancel Active",
"reinvestment_activation": "Rework Activation",
"no_data": "No data",
"title": "Battery [{battery_id}] Traceability Detail",
"process_label": "Process",
"process_data": "Process Data",
"item_name": "Item Name",
"content": "Content",
"search_item_name": "Search item name",
"prompt": "Prompt",
"cancel_active_confirm": "Cancel activation for this battery?",
"activation_confirm": "Execute rework activation?",
"cancel_success": "Cancel active successfully",
"activation_success": "Rework activation successfully"
}
}
}

View File

@@ -1304,6 +1304,37 @@
"grade": "等级",
"please_select_at_least_one_battery": "请至少选择一个电池",
"cancel_success": "取消激活成功"
},
"battery": {
"query": "查询",
"reset": "重置",
"battery_code": "电池条码",
"enter_battery_code": "请输入电池条码",
"login_batch": "登录批次",
"tray_no": "托盘号",
"lot": "LOT",
"is_active": "是否激活",
"activated": "已激活",
"stopped": "已停止",
"good_or_ng": "良品/不良",
"grade": "等级",
"ng_info": "不良信息",
"current_process_code": "当前工序编码",
"battery_detail": "电池详情",
"cancel_activation": "取消激活",
"reinvestment_activation": "复投激活",
"no_data": "暂无数据",
"title": "电池【{battery_id}】追溯详情",
"process_label": "工序",
"process_data": "工序数据",
"item_name": "项目名称",
"content": "内容",
"search_item_name": "搜索项目名称",
"prompt": "提示",
"cancel_active_confirm": "确认取消该电池激活?",
"activation_confirm": "确认执行复投激活?",
"cancel_success": "取消激活成功",
"activation_success": "复投激活成功"
}
}
}

View File

@@ -37,6 +37,12 @@ export default {
name: `${pre}traceability-tray`,
meta: { ...meta, cache: true, title: '托盘追溯' },
component: _import('data-platform/traceability/tray')
},
{
path: 'produce/traceability/battery',
name: `${pre}traceability-battery`,
meta: { ...meta, cache: true, title: '电池追溯' },
component: _import('data-platform/traceability/battery')
}
])('data_middleground-')
}

View File

@@ -0,0 +1,222 @@
<template>
<d2-container>
<template #header>
<div class="search-bar">
<el-form ref="searchForm" :inline="true" :model="search" size="mini">
<el-form-item :label="$t(key('battery_code'))" prop="battery_id">
<el-input v-model.trim="search.battery_id" :placeholder="$t(key('enter_battery_code'))" clearable style="width:240px" @keyup.enter.native="fetchData" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" :disabled="loading" @click="fetchData">{{ $t(key('query')) }}</el-button>
<el-button icon="el-icon-refresh" :disabled="loading" @click="resetSearch">{{ $t(key('reset')) }}</el-button>
</el-form-item>
</el-form>
</div>
</template>
<page-table
:columns="columns"
:data="tableData"
:loading="loading"
:toolbar-buttons="[]"
:row-buttons="rowButtons"
:pagination="pagination"
:table-attrs="{ size: 'mini', rowKey: 'battery_id', highlightCurrentRow: true }"
auto-height
@page-change="onPageChange"
>
<template #col-active="{ row }">
<el-tag :type="Number(row.active) === 1 ? 'success' : 'warning'" size="mini">{{ Number(row.active) === 1 ? $t(key('activated')) : $t(key('stopped')) }}</el-tag>
</template>
<template #col-class="{ row }">
<el-tag v-if="row.class === 'GOOD'" type="success" size="mini">GOOD</el-tag>
<el-tag v-else-if="row.class === 'NG'" type="warning" size="mini">NG</el-tag>
<span v-else>{{ row.class || '-' }}</span>
</template>
<template #empty>
<el-empty :description="$t(key('no_data'))" :image-size="80" />
</template>
</page-table>
<el-dialog :visible.sync="detailVisible" :show-close="false" fullscreen append-to-body>
<div slot="title">
<el-page-header @back="closeDetail" :content="detailTitle" />
</div>
<div class="detail-layout">
<aside class="process-list">
<el-card shadow="never">
<div slot="header">{{ $t(key('process_label')) }}</div>
<el-button
v-for="(item, index) in processList"
:key="index"
class="process-button"
:type="activeProcessIndex === index ? 'primary' : 'default'"
@click="selectProcess(index)"
>
{{ item.process_name || item.process_code || '-' }}
</el-button>
</el-card>
</aside>
<main class="process-detail">
<el-card shadow="never">
<div slot="header">{{ activeProcessName }}{{ $t(key('process_data')) }}</div>
<el-input v-model.trim="detailKeyword" size="mini" clearable :placeholder="$t(key('search_item_name'))" class="detail-search" />
<el-table :data="filteredGridData" border size="mini" height="calc(100vh - 230px)">
<el-table-column type="index" width="60" />
<el-table-column prop="name" :label="$t(key('item_name'))" min-width="180" show-overflow-tooltip />
<el-table-column prop="content" :label="$t(key('content'))" min-width="220" show-overflow-tooltip />
</el-table>
</el-card>
</main>
</div>
</el-dialog>
</d2-container>
</template>
<script>
import { useTableColumns } from '@/composables/useTableColumns'
import { i18nMixin } from '@/composables/useI18n'
import PageTable from '@/components/page-table'
import { sendWorkerman } from '@/api/production-master-data/workerman'
import { cancelBatteryActive, getBatteryProcessData, getBatteryTraceList } from '@/api/data-platform/traceability/battery'
export default {
name: 'data-platform-traceability-battery',
components: { PageTable },
mixins: [i18nMixin('page.data_platform.traceability.battery')],
data () {
return {
loading: false,
search: { battery_id: this.$route.query.battery_id || '' },
tableData: [],
pagination: { current: 1, size: 10, total: 0 },
detailVisible: false,
activeBattery: {},
processList: [],
activeProcessIndex: -1,
gridData: [],
detailKeyword: ''
}
},
computed: {
columns () {
return useTableColumns([
{ prop: 'battery_id', label: this.key('battery_code'), minWidth: 180, showOverflowTooltip: true },
{ prop: 'batch', label: this.key('login_batch'), minWidth: 140, showOverflowTooltip: true },
{ prop: 'tray', label: this.key('tray_no'), minWidth: 130, showOverflowTooltip: true },
{ prop: 'lot', label: this.key('lot'), minWidth: 120, showOverflowTooltip: true },
{ prop: 'active', label: this.key('is_active'), minWidth: 110, slot: 'active' },
{ prop: 'class', label: this.key('good_or_ng'), minWidth: 110, slot: 'class' },
{ prop: 'classname', label: this.key('grade'), minWidth: 120, showOverflowTooltip: true },
{ prop: 'explain', label: this.key('ng_info'), minWidth: 160, showOverflowTooltip: true },
{ prop: 'next_process_code', label: this.key('current_process_code'), minWidth: 160, showOverflowTooltip: true }
], { selectionWidth: 0, indexWidth: 55, operationWidth: 260 })
},
rowButtons () {
return [
{ key: 'detail', label: this.key('battery_detail'), type: 'primary', icon: 'el-icon-document', size: 'mini', onClick: this.openDetail },
{ key: 'cancel', label: this.key('cancel_activation'), type: 'warning', icon: 'el-icon-close', size: 'mini', visible: row => Number(row.active) === 1, onClick: this.cancelActive },
{ key: 'rebatch', label: this.key('reinvestment_activation'), type: 'success', icon: 'el-icon-refresh-right', size: 'mini', visible: row => Number(row.active) === 0 && row.class === 'NG', onClick: this.reinvestmentActivation }
]
},
detailTitle () {
return this.$t(this.key('title'), { battery_id: this.activeBattery.battery_id || '' })
},
activeProcessName () {
const item = this.processList[this.activeProcessIndex] || {}
return item.process_name || item.process_code || '-'
},
filteredGridData () {
const keyword = String(this.detailKeyword || '').toLowerCase()
return this.gridData.filter(item => !keyword || String(item.name || '').toLowerCase().includes(keyword))
}
},
watch: {
'$route.query.battery_id' (value) {
if (value) {
this.search.battery_id = value
this.fetchData()
}
}
},
mounted () {
if (this.search.battery_id) this.fetchData()
},
methods: {
responseData (res) { return res && res.data !== undefined ? res.data : res },
async fetchData () {
this.loading = true
try {
const res = await getBatteryTraceList({ ...this.search, action: 'battery_traceability_search', page_no: this.pagination.current, page_size: this.pagination.size })
const data = this.responseData(res)
this.tableData = Array.isArray(data) ? data : []
this.pagination.total = Number(data && data.count) || this.tableData.length
} finally {
this.loading = false
}
},
resetSearch () {
this.search.battery_id = ''
this.tableData = []
this.pagination.current = 1
this.pagination.total = 0
},
onPageChange (page) {
this.pagination = { ...this.pagination, ...page }
this.fetchData()
},
openDetail (row) {
this.activeBattery = row
this.processList = Array.isArray(row.process) ? row.process : []
this.activeProcessIndex = -1
this.gridData = []
this.detailKeyword = ''
this.detailVisible = true
if (this.processList.length) this.selectProcess(0)
},
closeDetail () {
this.detailVisible = false
},
async selectProcess (index) {
const process = this.processList[index]
if (!process) return
this.activeProcessIndex = index
const res = await getBatteryProcessData({
process_code: process.process_code,
process_id: process.process_id,
batch: this.activeBattery.batch,
battery_id: this.activeBattery.battery_id,
tray: this.activeBattery.tray,
lot: this.activeBattery.lot,
action: 'get_one_battery_data'
})
const data = this.responseData(res)
this.gridData = Array.isArray(data) ? data : []
},
async cancelActive (row) {
await this.$confirm(this.$t(this.key('cancel_active_confirm')), this.$t(this.key('prompt')), { type: 'warning' })
const batterData = [{ batch: row.batch, tray: row.tray, lot: row.lot, battery_id: row.battery_id }]
await cancelBatteryActive({ batterData: JSON.stringify(batterData) })
row.active = 0
this.$message.success(this.$t(this.key('cancel_success')))
},
async reinvestmentActivation (row) {
await this.$confirm(this.$t(this.key('activation_confirm')), this.$t(this.key('prompt')), { type: 'warning' })
const sendData = { action: 'set_battery_rebatch', param: { battery_ids: [row.battery_id] } }
await sendWorkerman({ sendData })
this.$message.success(this.$t(this.key('activation_success')))
this.search.battery_id = row.battery_id
this.fetchData()
}
}
}
</script>
<style lang="scss" scoped>
.search-bar { margin-bottom: -18px; }
.detail-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; }
.process-list { max-height: calc(100vh - 150px); overflow: auto; }
.process-button { display: block; width: 100%; margin: 0 0 10px; }
.process-detail { min-width: 0; }
.detail-search { width: 260px; margin-bottom: 12px; }
</style>