Files
klp-oa/klp-ui/src/views/wms/processSpec/index.vue

602 lines
19 KiB
Vue
Raw Normal View History

<template>
2026-04-27 20:37:59 +08:00
<div class="spec-page">
<!-- 规程类型 -->
<div class="dict-toolbar-row">
<div class="type-tab-bar">
<span
v-for="t in specTypeTab"
:key="'stype-' + (t.value === '' ? 'all' : t.value)"
:class="['type-tab', { active: activeSpecType === t.value }]"
@click="switchSpecType(t.value)"
>{{ t.label }}</span>
</div>
<dict-select
toolbar-only
:kisv="false"
:editable="true"
:refresh="false"
:dict-type="DICT_SPEC_TYPE"
panel-title="规程工艺类型字典"
@dict-updated="loadSpecTypeDict"
/>
2026-04-27 20:37:59 +08:00
</div>
<!-- 产线 -->
<div class="dict-toolbar-row line-row">
<div class="line-tab-bar">
<span
:class="['line-tab', { active: activeLineId === '' }]"
@click="switchLine('')"
>全部</span>
<span
v-for="line in lineOptions"
:key="'ln-' + line.lineId"
:class="['line-tab', { active: lineTabActive(line) }]"
@click="switchLine(line.lineId)"
>{{ line.lineName }}</span>
</div>
<dict-select
toolbar-only
:kisv="false"
:editable="true"
:refresh="false"
:dict-type="DICT_LINE"
panel-title="规程产线筛选项(字典值为产线 line_id"
@dict-updated="loadLineOptions"
/>
2026-04-27 20:37:59 +08:00
</div>
2026-04-27 20:37:59 +08:00
<!-- 工具栏 -->
<div class="toolbar">
<div class="toolbar-left">
<el-button type="primary" size="mini" icon="el-icon-plus" @click="handleAdd">新增</el-button>
<el-button size="mini" icon="el-icon-edit" :disabled="single" @click="handleUpdate()">修改</el-button>
<el-button size="mini" icon="el-icon-delete" :disabled="multiple" @click="handleDelete()">删除</el-button>
</div>
<div class="toolbar-right">
<el-input
v-model="queryParams.specName"
size="small"
placeholder="规程名称"
clearable
style="width:180px; margin-right:8px"
@keyup.enter.native="handleQuery"
/>
<el-button size="mini" type="primary" @click="handleQuery">查询</el-button>
<el-button size="mini" @click="resetQuery">重置</el-button>
</div>
</div>
<!-- 列表 -->
<el-table
v-loading="loading"
:data="dataList"
size="small"
highlight-current-row
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" />
<el-table-column label="规程编号" prop="specCode" show-overflow-tooltip />
<el-table-column label="规程名称" prop="specName" show-overflow-tooltip />
<el-table-column label="产品类型" prop="productType" show-overflow-tooltip />
<el-table-column label="创建时间" prop="createTime" />
<el-table-column label="启用" align="center">
<template slot-scope="{ row }">
<el-switch
:value="row.isEnabled === 1"
active-color="#5F7BA0"
@change="toggleEnabled(row, $event)"
/>
</template>
</el-table-column>
2026-04-27 20:37:59 +08:00
<el-table-column label="操作" align="right">
<template slot-scope="{ row }">
<el-button type="text" size="mini" @click="goVersionManage(row)">版本与方案</el-button>
<el-button type="text" size="mini" @click="handleUpdate(row)">修改</el-button>
<el-button type="text" size="mini" class="btn-danger" @click="handleDelete(row)">删除</el-button>
</template>
</el-table-column>
2026-04-27 20:37:59 +08:00
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
2026-04-27 20:37:59 +08:00
<!-- 新增/修改 -->
<el-dialog :title="dialogTitle" :visible.sync="open" width="520px" append-to-body @close="reset">
<el-form ref="form" :model="form" :rules="rules" label-width="88px" size="small">
<el-form-item label="规程编号" prop="specCode">
<el-input v-model="form.specCode" placeholder="唯一编号" maxlength="64" show-word-limit />
</el-form-item>
<el-form-item label="规程名称" prop="specName">
2026-04-27 20:37:59 +08:00
<el-input v-model="form.specName" maxlength="200" show-word-limit />
</el-form-item>
<el-form-item label="规程类型" prop="specType">
2026-04-27 20:37:59 +08:00
<el-select v-model="form.specType" style="width:100%">
<el-option
v-for="t in specTypeOptionsForForm"
:key="t.dictValue"
:label="t.dictLabel"
:value="t.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item label="产线" prop="lineId">
2026-04-27 20:37:59 +08:00
<el-select v-model="form.lineId" filterable placeholder="请选择" style="width:100%">
<el-option
v-for="line in lineOptionsForForm"
:key="line.lineId"
:label="lineOptLabel(line)"
:value="line.lineId"
/>
</el-select>
</el-form-item>
<el-form-item label="产品类型" prop="productType">
2026-04-27 20:37:59 +08:00
<el-input v-model="form.productType" maxlength="100" />
</el-form-item>
<el-form-item label="是否启用" prop="isEnabled">
2026-04-27 20:37:59 +08:00
<el-switch v-model="form.isEnabled" :active-value="1" :inactive-value="0" />
</el-form-item>
<el-form-item label="备注" prop="remark">
2026-04-27 20:37:59 +08:00
<el-input v-model="form.remark" type="textarea" rows="2" maxlength="500" show-word-limit />
</el-form-item>
</el-form>
2026-04-27 20:37:59 +08:00
<div slot="footer">
<el-button size="small" @click="open = false">取消</el-button>
<el-button size="small" type="primary" :loading="btnLoading" @click="submitForm">确定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { getDicts } from '@/api/system/dict/data'
import { listProcessSpec, getProcessSpec, delProcessSpec, updateProcessSpec, addProcessSpec } from '@/api/wms/processSpec'
import { listProductionLine } from '@/api/wms/productionLine'
const DICT_SPEC_TYPE = 'wms_process_spec_type'
const DICT_LINE = 'wms_process_spec_line'
const DEFAULT_SPEC_TYPES = [
2026-04-27 20:37:59 +08:00
]
export default {
name: 'ProcessSpec',
data() {
return {
DICT_SPEC_TYPE,
DICT_LINE,
2026-04-27 20:37:59 +08:00
loading: false,
btnLoading: false,
total: 0,
dataList: [],
ids: [],
single: true,
multiple: true,
open: false,
2026-04-27 20:37:59 +08:00
dialogTitle: '',
specTypeRows: [],
lineOptions: [],
2026-04-27 20:37:59 +08:00
activeSpecType: '',
activeLineId: '',
queryParams: {
pageNum: 1,
pageSize: 20,
specName: undefined,
specType: undefined,
2026-04-27 20:37:59 +08:00
lineId: undefined
},
form: {},
rules: {
specCode: [{ required: true, message: '规程编号不能为空', trigger: 'blur' }],
specName: [{ required: true, message: '规程名称不能为空', trigger: 'blur' }],
2026-04-27 20:37:59 +08:00
specType: [{ required: true, message: '请选择规程类型', trigger: 'change' }],
lineId: [{ required: true, message: '请选择产线', trigger: 'change' }]
}
}
},
computed: {
specTypeTab() {
const rows = this.mergeSpecTypeRowsWithDefaults()
const sorted = [...rows].sort((a, b) => (Number(a.dictSort) || 0) - (Number(b.dictSort) || 0))
return [{ label: '全部', value: '' }, ...sorted.map(r => ({ label: r.dictLabel, value: r.dictValue }))]
},
specTypeOptionsForForm() {
const rows = this.mergeSpecTypeRowsWithDefaults()
return [...rows].sort((a, b) => (Number(a.dictSort) || 0) - (Number(b.dictSort) || 0))
},
lineOptionsForForm() {
return this.lineOptions
}
},
created() {
Promise.all([this.loadSpecTypeDict(), this.loadLineOptions()]).finally(() => {
this.getList()
2026-04-27 20:37:59 +08:00
})
},
methods: {
/**
* 工艺类型默认 PROCESS/STANDARD 与字典合并若仅有字典中存在的新项仍可保留两行基础兜底 dict_value 以字典为准可改名 sort
*/
mergeSpecTypeRowsWithDefaults() {
const byVal = new Map()
DEFAULT_SPEC_TYPES.forEach(row => {
byVal.set(row.dictValue, { ...row })
})
for (const row of this.specTypeRows || []) {
if (!row || row.dictValue === undefined || row.dictValue === null || row.dictValue === '') continue
const v = String(row.dictValue)
const prev = byVal.get(v)
const sort = row.dictSort != null && row.dictSort !== ''
? Number(row.dictSort)
: (prev && prev.dictSort != null ? prev.dictSort : 999)
const label = (row.dictLabel != null && String(row.dictLabel).trim() !== '')
? row.dictLabel
: (prev && prev.dictLabel)
byVal.set(v, {
dictLabel: label,
dictValue: v,
dictSort: sort
})
}
return Array.from(byVal.values())
},
/**
* 产线 ID 与字典值用数字字符串避免超过 Number.MAX_SAFE_INTEGER 时精度丢失雪花 id
*/
normalizeLineIdString(value) {
if (value === undefined || value === null || value === '') return ''
const s = String(value).trim()
return /^\d+$/.test(s) ? s : ''
},
/** Tab 高亮:雪花 id 一律按字符串比较 */
lineTabActive(line) {
if (this.activeLineId === '' || this.activeLineId === undefined) return false
return String(this.activeLineId) === String(line.lineId)
},
parseDictRows(res) {
const rows = (res.data || []).filter(d => d.status === '0' || d.status === undefined)
rows.sort((a, b) => (Number(a.dictSort) || 0) - (Number(b.dictSort) || 0))
return rows
},
async loadSpecTypeDict() {
try {
const res = await getDicts(DICT_SPEC_TYPE)
this.specTypeRows = this.parseDictRows(res)
} catch (err) {
console.error('规程工艺类型字典加载失败', err)
this.specTypeRows = []
}
},
/**
* 产线 Tab产线主表 字典中合法数字 line_id字典独有也会显示 Tab
* line_id 全程用数字字符串避免超过 Number.MAX_SAFE_INTEGER 时精度丢失字典值须为数字 line_id
*/
async loadLineOptions() {
const previousOptions = Array.isArray(this.lineOptions) && this.lineOptions.length
? this.lineOptions.map(o => ({ ...o }))
: []
let dictRows = []
try {
const res = await getDicts(DICT_LINE)
dictRows = this.parseDictRows(res)
} catch (err) {
console.error('规程产线字典加载失败', err)
}
const dictMeta = new Map()
for (const d of dictRows) {
const idStr = this.normalizeLineIdString(d.dictValue)
if (!idStr) continue
const sort = Number(d.dictSort) || 0
const label = (d.dictLabel != null && String(d.dictLabel).trim() !== '')
? String(d.dictLabel).trim()
: idStr
dictMeta.set(idStr, { label, sort })
}
let tableLines = []
// try {
// const res = await listProductionLine({ pageNum: 1, pageSize: 500 })
// tableLines = (res.rows || []).map(p => {
// const idStr = this.normalizeLineIdString(p.lineId) || (p.lineId != null ? String(p.lineId).trim() : '')
// return {
// lineId: idStr,
// lineName: p.lineName,
// lineCode: p.lineCode
// }
// }).filter(p => p.lineId)
// } catch (e2) {
// console.error('产线列表加载失败', e2)
// }
const tableIdSet = new Set(tableLines.map(l => String(l.lineId)))
const next = []
for (const line of tableLines) {
const idStr = String(line.lineId)
const dm = dictMeta.get(idStr)
next.push({
lineId: idStr,
lineName: dm ? dm.label : line.lineName,
lineCode: line.lineCode
})
}
const dictOnly = []
for (const [idStr, meta] of dictMeta) {
if (!tableIdSet.has(idStr)) {
dictOnly.push({ lineId: idStr, lineName: meta.label, lineCode: undefined, _sort: meta.sort })
}
}
dictOnly.sort((a, b) => a._sort - b._sort)
dictOnly.forEach(d => {
const { _sort, ...rest } = d
next.push(rest)
})
if (next.length === 0 && previousOptions.length > 0) {
console.warn('[规程产线] 本次未解析出有效筛选项(可能字典值非数字或产线接口异常),保留上一版 Tab')
return
}
this.lineOptions = next
},
lineOptLabel(line) {
if (line.lineCode) {
return `${line.lineName}${line.lineCode}`
}
return line.lineName
},
getList() {
this.loading = true
2026-04-27 20:37:59 +08:00
listProcessSpec(this.queryParams).then(res => {
this.dataList = res.rows || []
this.total = res.total || 0
}).finally(() => { this.loading = false })
},
2026-04-27 20:37:59 +08:00
switchSpecType(val) {
this.activeSpecType = val
this.queryParams.specType = val || undefined
this.queryParams.pageNum = 1
this.getList()
},
2026-04-27 20:37:59 +08:00
switchLine(lineId) {
if (lineId === '' || lineId === undefined || lineId === null) {
this.activeLineId = ''
} else {
const s = this.normalizeLineIdString(lineId)
this.activeLineId = s || String(lineId).trim()
}
this.queryParams.lineId = this.activeLineId === '' ? undefined : this.activeLineId
2026-04-27 20:37:59 +08:00
this.queryParams.pageNum = 1
this.getList()
},
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
resetQuery() {
2026-04-27 20:37:59 +08:00
this.queryParams.specName = undefined
this.handleQuery()
},
2026-04-27 20:37:59 +08:00
handleSelectionChange(sel) {
this.ids = sel.map(r => r.specId)
this.single = sel.length !== 1
this.multiple = !sel.length
},
defaultSpecType() {
const first = this.specTypeOptionsForForm[0]
return first ? first.dictValue : 'PROCESS'
},
2026-04-27 20:37:59 +08:00
reset() {
this.form = {
specId: undefined,
specCode: undefined,
specName: undefined,
specType: this.defaultSpecType(),
lineId: undefined,
productType: undefined,
isEnabled: 1,
remark: undefined
}
2026-04-27 20:37:59 +08:00
this.$refs.form && this.$refs.form.clearValidate()
},
handleAdd() {
this.reset()
2026-04-27 20:37:59 +08:00
this.dialogTitle = '新增规程'
this.open = true
},
handleUpdate(row) {
this.reset()
2026-04-27 20:37:59 +08:00
const specId = row ? row.specId : this.ids[0]
getProcessSpec(specId).then(res => {
this.form = res.data || {}
if (this.form.lineId != null && this.form.lineId !== '') {
const sid = this.normalizeLineIdString(this.form.lineId)
this.form.lineId = sid || String(this.form.lineId).trim()
}
2026-04-27 20:37:59 +08:00
this.dialogTitle = '修改规程'
this.open = true
})
},
submitForm() {
2026-04-27 20:37:59 +08:00
this.$refs.form.validate(valid => {
if (!valid) return
this.btnLoading = true
const req = this.form.specId ? updateProcessSpec(this.form) : addProcessSpec(this.form)
req.then(() => {
2026-04-27 20:37:59 +08:00
this.$modal.msgSuccess('保存成功')
this.open = false
this.getList()
2026-04-27 20:37:59 +08:00
}).finally(() => { this.btnLoading = false })
})
},
handleDelete(row) {
2026-04-27 20:37:59 +08:00
const ids = row ? row.specId : this.ids
this.$modal.confirm('确认删除所选规程?').then(() => {
this.loading = true
2026-04-27 20:37:59 +08:00
return delProcessSpec(ids)
}).then(() => {
this.$modal.msgSuccess('删除成功')
2026-04-27 20:37:59 +08:00
this.getList()
}).catch(() => {}).finally(() => { this.loading = false })
},
2026-04-27 20:37:59 +08:00
toggleEnabled(row, val) {
const updated = { ...row, isEnabled: val ? 1 : 0 }
updateProcessSpec(updated).then(() => {
row.isEnabled = updated.isEnabled
}).catch(() => {})
},
goVersionManage(row) {
const pathCurrent = this.$route.path.replace(/\/$/, '')
const m = pathCurrent.match(/^(.*\/processSpec)(?:\/.*)?$/)
const base = m ? m[1] : pathCurrent
2026-04-27 20:37:59 +08:00
this.$router.push({ path: `${base}/version`, query: { specId: String(row.specId) } })
}
}
}
</script>
2026-04-27 20:37:59 +08:00
<style scoped>
.spec-page {
padding: 16px 20px;
min-height: 100%;
}
/* ── 双色主题:默认=白底灰边,激活/主操作=深藏青 #5F7BA0 ── */
.dict-toolbar-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px 10px;
margin-bottom: 6px;
}
.dict-toolbar-row.line-row {
margin-bottom: 12px;
}
2026-04-27 20:37:59 +08:00
.type-tab-bar {
display: flex;
flex: 0 1 auto;
flex-wrap: wrap;
2026-04-27 20:37:59 +08:00
gap: 0;
border-radius: 4px;
overflow: hidden;
border: 1px solid #dcdfe6;
}
.type-tab {
padding: 5px 14px;
font-size: 12px;
cursor: pointer;
color: #606266;
background: #fff;
border: none;
border-right: 1px solid #dcdfe6;
transition: color .15s, background .15s;
user-select: none;
line-height: 1;
}
.type-tab:last-child { border-right: none; }
.type-tab:hover { color: #5F7BA0; }
.type-tab.active {
color: #fff;
background: #5F7BA0;
}
.line-tab-bar {
display: flex;
flex-wrap: wrap;
flex: 0 1 auto;
align-items: center;
2026-04-27 20:37:59 +08:00
gap: 6px;
padding: 10px 0;
min-width: 0;
2026-04-27 20:37:59 +08:00
}
.line-tab {
padding: 4px 12px;
border-radius: 4px;
font-size: 12px;
cursor: pointer;
color: #606266;
background: #fff;
border: 1px solid #dcdfe6;
transition: color .15s, background .15s, border-color .15s;
user-select: none;
line-height: 1;
}
.line-tab:hover { color: #5F7BA0; border-color: #5F7BA0; }
.line-tab.active {
color: #fff;
background: #5F7BA0;
border-color: #5F7BA0;
}
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.toolbar-left,
.toolbar-right {
display: flex;
align-items: center;
gap: 6px;
}
.el-table {
border-radius: 4px;
overflow: hidden;
}
/* el-button主操作类 → 深藏青;默认类 → 白底灰边 */
::v-deep .el-button--primary {
color: #fff !important;
background: #5F7BA0 !important;
border-color: #5F7BA0 !important;
}
::v-deep .el-button--primary:hover,
::v-deep .el-button--primary:focus {
background: #4d6a8e !important;
border-color: #4d6a8e !important;
}
::v-deep .el-button--primary:active { background: #4a6585 !important; border-color: #4a6585 !important; }
::v-deep .el-button--primary.is-disabled { opacity: .5; }
::v-deep .el-button:not(.el-button--primary):not(.el-button--text):not(.el-button--danger):not(.el-button--info) {
color: #606266 !important;
background: #fff !important;
border-color: #dcdfe6 !important;
}
::v-deep .el-button:not(.el-button--primary):not(.el-button--text):not(.el-button--danger):not(.el-button--info):hover {
color: #5F7BA0 !important;
border-color: #5F7BA0 !important;
}
::v-deep .el-button:not(.el-button--primary):not(.el-button--text):not(.el-button--danger):not(.el-button--info).is-disabled { opacity: .5; }
::v-deep .el-button--text { background: transparent !important; border-color: transparent !important; }
::v-deep .el-button--text.btn-danger { color: #f56c6c !important; }
.btn-danger { color: #f56c6c; }
/* 与 Tab 同一行时,将齿轮框配色贴近规程主题 */
::v-deep .dict-toolbar-row .el-icon-setting {
color: #5F7BA0;
}
2026-04-27 20:37:59 +08:00
</style>