修复工厂模型产线和区域功能问题
Some checks failed
Release pipeline / publish (push) Has been cancelled
Release pipeline / Always run job (push) Has been cancelled

This commit is contained in:
sheng
2026-06-24 14:57:27 +08:00
parent 4455b90854
commit 3b801a270e
6 changed files with 322 additions and 263 deletions

View File

@@ -49,3 +49,11 @@ export function deleteFactoryArea (data) {
data: apiParams('delete', data) data: apiParams('delete', data)
}) })
} }
export function exportFactoryAreaTask (data) {
return request({
url: BASE + 'export',
method: 'post',
data: apiParams('export', data)
})
}

View File

@@ -41,3 +41,11 @@ export function deleteProductionLine (data) {
data: apiParams('delete', data) data: apiParams('delete', data)
}) })
} }
export function exportProductionLineTask (data) {
return request({
url: BASE + 'export',
method: 'post',
data: apiParams('export', data)
})
}

View File

@@ -44,7 +44,20 @@
"tip": "Tip", "tip": "Tip",
"confirm_delete": "Are you sure to delete?", "confirm_delete": "Are you sure to delete?",
"validation_fail": "Validation failed", "validation_fail": "Validation failed",
"please_enter": "Please enter {name}" "please_enter": "Please enter {name}",
"parent_area": "Parent Area",
"select_parent_area": "Please select parent area",
"status": "Status",
"select_status": "Please select status",
"enabled": "Enabled",
"disabled": "Disabled",
"add_child": "Add Subarea",
"add_child_title": "Add Subarea",
"export": "Export",
"confirm_export": "Create export task?",
"length_1_100": "Length should be 1 to 100 characters",
"remark_max_500": "Remark cannot exceed 500 characters",
"parent_cycle_error": "Parent area cannot be itself or a child area"
}, },
"production_line": { "production_line": {
"search": "Search", "search": "Search",
@@ -71,7 +84,15 @@
"confirm": "Confirm", "confirm": "Confirm",
"tip": "Tip", "tip": "Tip",
"confirm_delete": "Are you sure to delete?", "confirm_delete": "Are you sure to delete?",
"validation_fail": "Validation failed" "validation_fail": "Validation failed",
"status": "Status",
"select_status": "Please select status",
"enabled": "Enabled",
"disabled": "Disabled",
"export": "Export",
"confirm_export": "Create export task?",
"length_1_100": "Length should be 1 to 100 characters",
"remark_max_500": "Remark cannot exceed 500 characters"
} }
}, },
"process_model": { "process_model": {

View File

@@ -44,7 +44,20 @@
"tip": "提示", "tip": "提示",
"confirm_delete": "确定要执行该操作吗?", "confirm_delete": "确定要执行该操作吗?",
"validation_fail": "校验失败", "validation_fail": "校验失败",
"please_enter": "请输入{name}" "please_enter": "请输入{name}",
"parent_area": "上级区域",
"select_parent_area": "请选择上级区域",
"status": "状态",
"select_status": "请选择状态",
"enabled": "启用",
"disabled": "禁用",
"add_child": "新增子区域",
"add_child_title": "新增子区域",
"export": "导出",
"confirm_export": "确认创建导出任务?",
"length_1_100": "长度在 1 到 100 个字符",
"remark_max_500": "备注不能超过 500 个字符",
"parent_cycle_error": "上级区域不能选择自身或下级区域"
}, },
"production_line": { "production_line": {
"search": "查询", "search": "查询",
@@ -71,7 +84,15 @@
"confirm": "确定", "confirm": "确定",
"tip": "提示", "tip": "提示",
"confirm_delete": "确定要执行该操作吗?", "confirm_delete": "确定要执行该操作吗?",
"validation_fail": "校验失败" "validation_fail": "校验失败",
"status": "状态",
"select_status": "请选择状态",
"enabled": "启用",
"disabled": "禁用",
"export": "导出",
"confirm_export": "确认创建导出任务?",
"length_1_100": "长度在 1 到 100 个字符",
"remark_max_500": "备注不能超过 500 个字符"
} }
}, },
"process_model": { "process_model": {

View File

@@ -4,30 +4,20 @@
<div class="search-bar"> <div class="search-bar">
<el-form :inline="true" size="mini"> <el-form :inline="true" size="mini">
<el-form-item :label="$t(key('code'))"> <el-form-item :label="$t(key('code'))">
<el-input <el-input v-model="search.code" :placeholder="$t(key('enter_code'))" clearable style="width:200px" @keyup.enter.native="onSearch" />
v-model="search.code"
:placeholder="$t(key('enter_code'))"
clearable
style="width:200px"
@keyup.enter.native="onSearch"
/>
</el-form-item> </el-form-item>
<el-form-item :label="$t(key('name'))"> <el-form-item :label="$t(key('name'))">
<el-input <el-input v-model="search.name" :placeholder="$t(key('enter_name'))" clearable style="width:200px" @keyup.enter.native="onSearch" />
v-model="search.name" </el-form-item>
:placeholder="$t(key('enter_name'))" <el-form-item :label="$t(key('status'))">
clearable <el-select v-model="search.status" :placeholder="$t(key('select_status'))" clearable style="width:140px" @change="onSearch">
style="width:200px" <el-option value="1" :label="$t(key('enabled'))" />
@keyup.enter.native="onSearch" <el-option value="0" :label="$t(key('disabled'))" />
/> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" @click="onSearch"> <el-button type="primary" icon="el-icon-search" @click="onSearch">{{ $t(key('search')) }}</el-button>
{{ $t(key('search')) }} <el-button icon="el-icon-refresh" @click="onReset">{{ $t(key('reset')) }}</el-button>
</el-button>
<el-button icon="el-icon-refresh" @click="onReset">
{{ $t(key('reset')) }}
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
@@ -35,25 +25,31 @@
<page-table <page-table
ref="pageTable" ref="pageTable"
row-key="id"
:columns="columns" :columns="columns"
:data="tableData" :data="tableData"
:loading="loading" :loading="loading"
:toolbar-buttons="toolbarButtons" :toolbar-buttons="toolbarButtons"
:row-buttons="rowButtons" :row-buttons="rowButtons"
:pagination="pagination" :pagination="null"
:table-attrs="tableAttrs"
help-url="/help/factory-area" help-url="/help/factory-area"
:help-text="$t(ckey('help'))" :help-text="$t(ckey('help'))"
auto-height auto-height
@page-change="onPageChange"
@selection-change="onSelect" @selection-change="onSelect"
/> >
<template #col-status="{ row }">
<span v-if="String(row.status) === '1'" class="status-on"><i class="el-icon-circle-check" /> {{ $t(key('enabled')) }}</span>
<span v-else class="status-off"><i class="el-icon-circle-close" /> {{ $t(key('disabled')) }}</span>
</template>
</page-table>
<page-dialog-form <page-dialog-form
ref="dialogForm" ref="dialogForm"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
:title="dialogTitle" :title="dialogTitle"
:width="'35%'" :width="'35%'"
:form-cols="formCols" :form-cols="dialogFormCols"
:form-data="formData" :form-data="formData"
:rules="rules" :rules="rules"
:label-width="'100px'" :label-width="'100px'"
@@ -70,12 +66,12 @@
import { useTableColumns } from '@/composables/useTableColumns' import { useTableColumns } from '@/composables/useTableColumns'
import { useTableButtons } from '@/composables/useTableButtons' import { useTableButtons } from '@/composables/useTableButtons'
import { i18nMixin } from '@/composables/useI18n' import { i18nMixin } from '@/composables/useI18n'
import { confirmMixin } from '@/composables/useConfirmHandle'
import { import {
getFactoryAreaList, getFactoryAreaList,
createFactoryArea, createFactoryArea,
editFactoryArea, editFactoryArea,
deleteFactoryArea deleteFactoryArea,
exportFactoryAreaTask
} from '@/api/production-master-data/factory-area' } from '@/api/production-master-data/factory-area'
import PageTable from '@/components/page-table' import PageTable from '@/components/page-table'
import PageDialogForm from '@/components/page-dialog-form' import PageDialogForm from '@/components/page-dialog-form'
@@ -83,104 +79,81 @@ import PageDialogForm from '@/components/page-dialog-form'
export default { export default {
name: 'production-master-data-factory-area', name: 'production-master-data-factory-area',
components: { PageTable, PageDialogForm }, components: { PageTable, PageDialogForm },
mixins: [i18nMixin('page.production_master_data.factory_model.factory_area'), confirmMixin], mixins: [i18nMixin('page.production_master_data.factory_model.factory_area')],
data () { data () {
return { return {
loading: false, loading: false,
submitting: false, submitting: false,
tableData: [], tableData: [],
rawAreaData: [],
selectedRows: [], selectedRows: [],
dialogVisible: false, dialogVisible: false,
dialogTitle: '', dialogTitle: '',
editId: '', editId: '',
handleType: 'create', handleType: 'create',
search: { code: '', name: '' }, search: { code: '', name: '', status: '' },
pagination: { current: 1, size: 10, total: 0 }, tableAttrs: { defaultExpandAll: true, treeProps: { children: 'children', hasChildren: 'hasChildren' } },
formData: { code: '', name: '', remark: '' }, statusOptions: [
{ value: '1', label: this.$t(this.key('enabled')) },
{ value: '0', label: this.$t(this.key('disabled')) }
],
formData: { code: '', name: '', parent_id: '', status: '1', remark: '' },
rules: { rules: {
code: [ code: [
{ required: true, message: this.key('enter_code'), trigger: 'blur' }, { required: true, message: this.key('enter_code'), trigger: 'blur' },
{ min: 1, max: 100, message: this.key('remark_length'), trigger: 'blur' } { min: 1, max: 100, message: this.key('length_1_100'), trigger: 'blur' }
], ],
name: [ name: [
{ required: true, message: this.key('enter_name'), trigger: 'blur' }, { required: true, message: this.key('enter_name'), trigger: 'blur' },
{ min: 1, max: 100, message: this.key('remark_length'), trigger: 'blur' } { min: 1, max: 100, message: this.key('length_1_100'), trigger: 'blur' }
] ],
status: [{ required: true, message: this.key('select_status'), trigger: 'change' }],
remark: [{ max: 500, message: this.key('remark_max_500'), trigger: 'blur' }]
}, },
columns: [], columns: [],
toolbarButtons: [], toolbarButtons: [],
rowButtons: [], rowButtons: [],
formCols: [ baseFormCols: [
[ [{ type: 'input', prop: 'code', label: this.key('code'), placeholder: this.key('enter_code'), clearable: true, style: { width: '90%' } }],
{ [{ type: 'input', prop: 'name', label: this.key('name'), placeholder: this.key('enter_name'), clearable: true, style: { width: '90%' } }],
type: 'input', [{ type: 'select', prop: 'parent_id', label: this.key('parent_area'), placeholder: this.key('select_parent_area'), clearable: true, filterable: true, style: { width: '90%' }, options: [] }],
prop: 'code', [{ type: 'select', prop: 'status', label: this.key('status'), placeholder: this.key('select_status'), clearable: false, style: { width: '90%' }, options: [] }],
label: this.key('code'), [{ type: 'input', prop: 'remark', inputType: 'textarea', autosize: { minRows: 2, maxRows: 6 }, label: this.key('remark'), placeholder: this.key('remark_required'), clearable: true, style: { width: '90%' } }]
placeholder: this.key('enter_code'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'name',
label: this.key('name'),
placeholder: this.key('enter_name'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'remark',
inputType: 'textarea',
autosize: { minRows: 2, maxRows: 6 },
label: this.key('remark'),
placeholder: this.key('remark_required'),
clearable: true,
style: { width: '90%' }
}
]
] ]
} }
}, },
computed: {
dialogFormCols () {
const cols = JSON.parse(JSON.stringify(this.baseFormCols))
cols[2][0].options = this.parentAreaOptions
cols[3][0].options = this.statusOptions
return cols
},
parentAreaOptions () {
const disabledIds = this.handleType === 'edit' ? new Set([String(this.editId), ...this.collectDescendantIds(this.editId)]) : new Set()
return this.flattenTree(this.tableData)
.filter(item => !disabledIds.has(String(this.getId(item))))
.map(item => ({ value: this.getId(item), label: item._treeLabel || item.name }))
}
},
created () { created () {
this.columns = useTableColumns([ this.columns = useTableColumns([
{ prop: 'sort', label: this.key('sort'), width: 80 }, { prop: 'sort', label: this.key('sort'), width: 80 },
{ prop: 'code', label: this.key('code'), minWidth: 120 }, { prop: 'code', label: this.key('code'), minWidth: 140 },
{ prop: 'name', label: this.key('name'), minWidth: 120 }, { prop: 'name', label: this.key('name'), minWidth: 160 },
{ prop: 'status', label: this.key('status'), slot: 'status', width: 110 },
{ prop: 'remark', label: this.key('remark') }, { prop: 'remark', label: this.key('remark') },
{ prop: '_actions', label: this.key('operation'), width: 160, fixed: 'right' } { prop: '_actions', label: this.key('operation'), width: 230, fixed: 'right' }
]) ])
const btns = useTableButtons({ const btns = useTableButtons({
toolbar: [ toolbar: [
{ { key: 'add', label: this.key('add'), icon: 'el-icon-plus', type: 'primary', auth: '/production_configuration/factory_model/factory_area/create', onClick: this.openAdd },
key: 'add', { key: 'export', label: this.key('export'), icon: 'el-icon-download', auth: '/production_configuration/factory_model/factory_area/export', onClick: this.handleExport }
label: this.key('add'),
icon: 'el-icon-plus',
type: 'primary',
auth: '/production_configuration/factory_model/factory_area/create',
onClick: this.openAdd
}
], ],
row: [ row: [
{ { key: 'addChild', label: this.key('add_child'), icon: 'el-icon-plus', auth: '/production_configuration/factory_model/factory_area/create', onClick: this.openAddChild },
key: 'edit', { key: 'edit', label: this.key('edit'), icon: 'el-icon-edit', auth: '/production_configuration/factory_model/factory_area/edit', onClick: this.openEdit },
label: this.key('edit'), { key: 'delete', label: this.key('delete'), icon: 'el-icon-delete', color: 'danger', auth: '/production_configuration/factory_model/factory_area/delete', onClick: this.handleDelete }
icon: 'el-icon-edit',
auth: '/production_configuration/factory_model/factory_area/edit',
onClick: this.openEdit
},
{
key: 'delete',
label: this.key('delete'),
icon: 'el-icon-delete',
color: 'danger',
auth: '/production_configuration/factory_model/factory_area/delete',
onClick: this.handleDelete
}
] ]
}, this.$permission) }, this.$permission)
this.toolbarButtons = btns.toolbarButtons this.toolbarButtons = btns.toolbarButtons
@@ -188,41 +161,89 @@ export default {
this.fetchData() this.fetchData()
}, },
methods: { methods: {
getId (row) {
return row && (row.id !== undefined ? row.id : row.area_id)
},
getParentId (row) {
if (!row) return ''
if (row.parent_id !== undefined) return row.parent_id || ''
if (row.pid !== undefined) return row.pid || ''
if (row.parentId !== undefined) return row.parentId || ''
return ''
},
normalizeResponse (res) {
const data = res && res.data !== undefined ? res.data : res
if (Array.isArray(data)) return { list: data, total: data.length }
if (data && Array.isArray(data.list)) return { list: data.list, total: Number(data.count || data.total || data.list.length) }
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(data.count || data.total || data.data.length) }
if (data && data.data && Array.isArray(data.data.data)) return { list: data.data.data, total: Number(data.data.count || data.data.total || data.data.data.length) }
return { list: [], total: 0 }
},
normalizeNode (row, level = 0) {
const children = Array.isArray(row.children) ? row.children.map(item => this.normalizeNode(item, level + 1)) : []
const node = { ...row, id: this.getId(row), parent_id: this.getParentId(row), children }
node._treeLabel = `${' '.repeat(level)}${node.name || ''}`
if (!node.children.length) delete node.children
return node
},
buildTree (list) {
if (list.some(item => Array.isArray(item.children))) return list.map(item => this.normalizeNode(item))
const map = new Map()
const roots = []
list.forEach(item => {
const node = this.normalizeNode(item)
node.children = []
map.set(String(node.id), node)
})
map.forEach(node => {
const parentId = this.getParentId(node)
const parent = parentId !== '' ? map.get(String(parentId)) : null
if (parent && String(parent.id) !== String(node.id)) parent.children.push(node)
else roots.push(node)
})
const mark = (nodes, level = 0) => nodes.map(node => {
node._treeLabel = `${' '.repeat(level)}${node.name || ''}`
if (node.children.length) node.children = mark(node.children, level + 1)
else delete node.children
return node
})
return mark(roots)
},
flattenTree (tree, result = []) {
tree.forEach(item => {
result.push(item)
if (Array.isArray(item.children)) this.flattenTree(item.children, result)
})
return result
},
collectDescendantIds (id) {
const current = this.flattenTree(this.tableData).find(item => String(this.getId(item)) === String(id))
if (!current || !Array.isArray(current.children)) return []
return this.flattenTree(current.children).map(item => String(this.getId(item)))
},
async fetchData () { async fetchData () {
this.loading = true this.loading = true
try { try {
const res = await getFactoryAreaList({ const res = await getFactoryAreaList({ ...this.search, page_no: 1, page_size: 10000 })
...this.search, const data = this.normalizeResponse(res)
page_no: this.pagination.current, this.rawAreaData = data.list
page_size: this.pagination.size this.tableData = this.buildTree(data.list)
})
const list = Array.isArray(res) ? res : (res.data || [])
const total = Array.isArray(res) ? res.length : (res.count || 0)
this.tableData = list
this.pagination.total = total
} finally { } finally {
this.loading = false this.loading = false
} }
}, },
onSearch () { onSearch () {
this.pagination.current = 1
this.fetchData() this.fetchData()
}, },
onReset () { onReset () {
this.search = { code: '', name: '' } this.search = { code: '', name: '', status: '' }
this.pagination.current = 1
this.fetchData()
},
onPageChange (page) {
this.pagination.current = page.current
this.pagination.size = page.size
this.fetchData() this.fetchData()
}, },
onSelect (rows) { onSelect (rows) {
this.selectedRows = rows this.selectedRows = rows
}, },
resetForm () { resetForm () {
this.formData = { code: '', name: '', remark: '' } this.formData = { code: '', name: '', parent_id: '', status: '1', remark: '' }
this.editId = '' this.editId = ''
}, },
openAdd () { openAdd () {
@@ -234,25 +255,38 @@ export default {
this.dialogVisible = true this.dialogVisible = true
}) })
}, },
openAddChild (row) {
this.handleType = 'create'
this.dialogTitle = this.key('add_child_title')
this.$nextTick(() => {
this.$refs.dialogForm && this.$refs.dialogForm.reset()
this.resetForm()
this.formData.parent_id = this.getId(row)
this.dialogVisible = true
})
},
openEdit (row) { openEdit (row) {
this.handleType = 'edit' this.handleType = 'edit'
this.dialogTitle = this.key('edit_title') this.dialogTitle = this.key('edit_title')
this.editId = row.id this.editId = this.getId(row)
this.formData = { this.formData = { code: row.code, name: row.name, parent_id: this.getParentId(row), status: row.status !== undefined ? String(row.status) : '1', remark: row.remark || '' }
code: row.code,
name: row.name,
remark: row.remark || ''
}
this.dialogVisible = true this.dialogVisible = true
}, },
validateHierarchy () {
if (this.handleType !== 'edit' || this.formData.parent_id === '') return true
const parentId = String(this.formData.parent_id)
if (parentId === String(this.editId) || this.collectDescendantIds(this.editId).includes(parentId)) {
this.$message.warning(this.$t(this.key('parent_cycle_error')))
return false
}
return true
},
async onDialogSubmit () { async onDialogSubmit () {
if (!this.validateHierarchy()) return
this.submitting = true this.submitting = true
try { try {
if (this.handleType === 'create') { if (this.handleType === 'create') await createFactoryArea(this.formData)
await createFactoryArea(this.formData) else await editFactoryArea({ ...this.formData, id: this.editId })
} else {
await editFactoryArea({ ...this.formData, id: this.editId })
}
this.$message.success(this.$t(this.key('operation_success'))) this.$message.success(this.$t(this.key('operation_success')))
this.dialogVisible = false this.dialogVisible = false
this.fetchData() this.fetchData()
@@ -263,31 +297,32 @@ export default {
onDialogClose () { onDialogClose () {
this.resetForm() this.resetForm()
}, },
async confirmAction (message, action) {
try {
await this.$confirm(this.$t(message), this.$t(this.key('tip')), { type: 'warning' })
} catch {
return false
}
await action()
return true
},
async handleDelete (row) { async handleDelete (row) {
const cancelled = await this.$confirmAction( const ok = await this.confirmAction(this.key('confirm_delete'), () => deleteFactoryArea({ id: [this.getId(row)] }))
{ if (!ok) return
message: this.key('confirm_delete'),
title: this.key('tip')
},
() => deleteFactoryArea({ id: [row.id] })
)
if (cancelled) return
this.$message.success(this.$t(this.key('operation_success'))) this.$message.success(this.$t(this.key('operation_success')))
this.pagination.current = Math.min(
this.pagination.current,
Math.ceil((this.pagination.total - 1) / this.pagination.size) || 1
)
this.fetchData() this.fetchData()
},
async handleExport () {
const ok = await this.confirmAction(this.key('confirm_export'), () => exportFactoryAreaTask({ ...this.search }))
if (ok) this.$message.success(this.$t(this.key('operation_success')))
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
.search-bar { .search-bar { padding: 10px 0; }
padding: 10px 0; .status-on { color: #67C23A; }
} .status-off { color: #909399; }
/deep/ .el-form-item--mini.el-form-item { /deep/ .el-form-item--mini.el-form-item { margin-bottom: 4px; }
margin-bottom: 4px;
}
</style> </style>

View File

@@ -28,6 +28,7 @@
clearable clearable
filterable filterable
style="width:200px" style="width:200px"
@change="onSearch"
> >
<el-option <el-option
v-for="item in areaOptions" v-for="item in areaOptions"
@@ -37,6 +38,18 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item :label="$t(key('status'))">
<el-select
v-model="search.status"
:placeholder="$t(key('select_status'))"
clearable
style="width:140px"
@change="onSearch"
>
<el-option value="1" :label="$t(key('enabled'))" />
<el-option value="0" :label="$t(key('disabled'))" />
</el-select>
</el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" @click="onSearch"> <el-button type="primary" icon="el-icon-search" @click="onSearch">
{{ $t(key('search')) }} {{ $t(key('search')) }}
@@ -62,7 +75,12 @@
auto-height auto-height
@page-change="onPageChange" @page-change="onPageChange"
@selection-change="onSelect" @selection-change="onSelect"
/> >
<template #col-status="{ row }">
<span v-if="String(row.status) === '1'" class="status-on"><i class="el-icon-circle-check" /> {{ $t(key('enabled')) }}</span>
<span v-else class="status-off"><i class="el-icon-circle-close" /> {{ $t(key('disabled')) }}</span>
</template>
</page-table>
<page-dialog-form <page-dialog-form
ref="dialogForm" ref="dialogForm"
@@ -86,12 +104,12 @@
import { useTableColumns } from '@/composables/useTableColumns' import { useTableColumns } from '@/composables/useTableColumns'
import { useTableButtons } from '@/composables/useTableButtons' import { useTableButtons } from '@/composables/useTableButtons'
import { i18nMixin } from '@/composables/useI18n' import { i18nMixin } from '@/composables/useI18n'
import { confirmMixin } from '@/composables/useConfirmHandle'
import { import {
getProductionLineList, getProductionLineList,
createProductionLine, createProductionLine,
editProductionLine, editProductionLine,
deleteProductionLine deleteProductionLine,
exportProductionLineTask
} from '@/api/production-master-data/production-line' } from '@/api/production-master-data/production-line'
import { getFactoryAreaALL } from '@/api/production-master-data/factory-area' import { getFactoryAreaALL } from '@/api/production-master-data/factory-area'
import PageTable from '@/components/page-table' import PageTable from '@/components/page-table'
@@ -100,7 +118,7 @@ import PageDialogForm from '@/components/page-dialog-form'
export default { export default {
name: 'production-master-data-production-line', name: 'production-master-data-production-line',
components: { PageTable, PageDialogForm }, components: { PageTable, PageDialogForm },
mixins: [i18nMixin('page.production_master_data.factory_model.production_line'), confirmMixin], mixins: [i18nMixin('page.production_master_data.factory_model.production_line')],
data () { data () {
return { return {
loading: false, loading: false,
@@ -111,81 +129,50 @@ export default {
dialogTitle: '', dialogTitle: '',
editId: '', editId: '',
handleType: 'create', handleType: 'create',
search: { code: '', name: '', area_id: '' }, search: { code: '', name: '', area_id: '', status: '' },
pagination: { current: 1, size: 10, total: 0 }, pagination: { current: 1, size: 10, total: 0 },
areaOptions: [], areaOptions: [],
formData: { code: '', name: '', area_id: '', remark: '' }, statusOptions: [
{ value: '1', label: this.$t(this.key('enabled')) },
{ value: '0', label: this.$t(this.key('disabled')) }
],
formData: { code: '', name: '', area_id: '', status: '1', remark: '' },
rules: { rules: {
code: [ code: [
{ required: true, message: this.key('enter_code'), trigger: 'blur' }, { required: true, message: this.key('enter_code'), trigger: 'blur' },
{ min: 1, max: 100, message: this.key('remark_length'), trigger: 'blur' } { min: 1, max: 100, message: this.key('length_1_100'), trigger: 'blur' }
], ],
name: [ name: [
{ required: true, message: this.key('enter_name'), trigger: 'blur' }, { required: true, message: this.key('enter_name'), trigger: 'blur' },
{ min: 1, max: 100, message: this.key('remark_length'), trigger: 'blur' } { min: 1, max: 100, message: this.key('length_1_100'), trigger: 'blur' }
], ],
area_id: [ area_id: [
{ required: true, message: this.key('select_area'), trigger: 'change' } { required: true, message: this.key('select_area'), trigger: 'change' }
],
status: [
{ required: true, message: this.key('select_status'), trigger: 'change' }
],
remark: [
{ max: 500, message: this.key('remark_max_500'), trigger: 'blur' }
] ]
}, },
columns: [], columns: [],
toolbarButtons: [], toolbarButtons: [],
rowButtons: [], rowButtons: [],
baseFormCols: [ baseFormCols: [
[ [{ type: 'input', prop: 'code', label: this.key('code'), placeholder: this.key('enter_code'), clearable: true, style: { width: '90%' } }],
{ [{ type: 'input', prop: 'name', label: this.key('name'), placeholder: this.key('enter_name'), clearable: true, style: { width: '90%' } }],
type: 'input', [{ type: 'select', prop: 'area_id', label: this.key('area'), placeholder: this.key('select_area'), clearable: true, filterable: true, style: { width: '90%' }, options: [] }],
prop: 'code', [{ type: 'select', prop: 'status', label: this.key('status'), placeholder: this.key('select_status'), clearable: false, style: { width: '90%' }, options: [] }],
label: this.key('code'), [{ type: 'input', prop: 'remark', inputType: 'textarea', autosize: { minRows: 2, maxRows: 6 }, label: this.key('remark'), placeholder: this.key('enter_remark'), clearable: true, style: { width: '90%' } }]
placeholder: this.key('enter_code'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'name',
label: this.key('name'),
placeholder: this.key('enter_name'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'select',
prop: 'area_id',
label: this.key('area'),
placeholder: this.key('select_area'),
clearable: true,
filterable: true,
style: { width: '90%' },
options: []
}
],
[
{
type: 'input',
prop: 'remark',
inputType: 'textarea',
autosize: { minRows: 2, maxRows: 6 },
label: this.key('remark'),
placeholder: this.key('enter_remark'),
clearable: true,
style: { width: '90%' }
}
]
] ]
} }
}, },
computed: { computed: {
dialogFormCols () { dialogFormCols () {
const idx = 2
const cols = JSON.parse(JSON.stringify(this.baseFormCols)) const cols = JSON.parse(JSON.stringify(this.baseFormCols))
if (cols[idx] && cols[idx][0]) { cols[2][0].options = this.areaOptions
cols[idx][0].options = this.areaOptions cols[3][0].options = this.statusOptions
}
return cols return cols
} }
}, },
@@ -196,36 +183,18 @@ export default {
{ prop: 'code', label: this.key('code'), minWidth: 120 }, { prop: 'code', label: this.key('code'), minWidth: 120 },
{ prop: 'name', label: this.key('name'), minWidth: 120 }, { prop: 'name', label: this.key('name'), minWidth: 120 },
{ prop: 'area_name', label: this.key('area_name'), minWidth: 120 }, { prop: 'area_name', label: this.key('area_name'), minWidth: 120 },
{ prop: 'status', label: this.key('status'), slot: 'status', width: 110 },
{ prop: 'remark', label: this.key('remark') }, { prop: 'remark', label: this.key('remark') },
{ prop: '_actions', label: this.key('operation'), width: 160, fixed: 'right' } { prop: '_actions', label: this.key('operation'), width: 160, fixed: 'right' }
]) ])
const btns = useTableButtons({ const btns = useTableButtons({
toolbar: [ toolbar: [
{ { key: 'add', label: this.key('add'), icon: 'el-icon-plus', type: 'primary', auth: '/production_configuration/factory_model/factory_line/create', onClick: this.openAdd },
key: 'add', { key: 'export', label: this.key('export'), icon: 'el-icon-download', auth: '/production_configuration/factory_model/factory_line/export', onClick: this.handleExport }
label: this.key('add'),
icon: 'el-icon-plus',
type: 'primary',
auth: '/production_configuration/factory_model/factory_line/create',
onClick: this.openAdd
}
], ],
row: [ row: [
{ { key: 'edit', label: this.key('edit'), icon: 'el-icon-edit', auth: '/production_configuration/factory_model/factory_line/edit', onClick: this.openEdit },
key: 'edit', { key: 'delete', label: this.key('delete'), icon: 'el-icon-delete', color: 'danger', auth: '/production_configuration/factory_model/factory_line/delete', onClick: this.handleDelete }
label: this.key('edit'),
icon: 'el-icon-edit',
auth: '/production_configuration/factory_model/factory_line/edit',
onClick: this.openEdit
},
{
key: 'delete',
label: this.key('delete'),
icon: 'el-icon-delete',
color: 'danger',
auth: '/production_configuration/factory_model/factory_line/delete',
onClick: this.handleDelete
}
] ]
}, this.$permission) }, this.$permission)
this.toolbarButtons = btns.toolbarButtons this.toolbarButtons = btns.toolbarButtons
@@ -233,25 +202,28 @@ export default {
this.fetchData() this.fetchData()
}, },
methods: { methods: {
normalizeResponse (res) {
const data = res && res.data !== undefined ? res.data : res
if (Array.isArray(data)) return { list: data, total: data.length }
if (data && Array.isArray(data.list)) return { list: data.list, total: Number(data.count || data.total || data.list.length) }
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(data.count || data.total || data.data.length) }
if (data && data.data && Array.isArray(data.data.data)) return { list: data.data.data, total: Number(data.data.count || data.data.total || data.data.data.length) }
return { list: [], total: 0 }
},
async initAreaOptions () { async initAreaOptions () {
try { try {
const res = await getFactoryAreaALL() const res = await getFactoryAreaALL()
const data = Array.isArray(res) ? res : (res.data || []) const data = this.normalizeResponse(res).list
this.areaOptions = data.map(item => ({ value: item.area_id || item.id, label: item.name })) this.areaOptions = data.map(item => ({ value: item.area_id || item.id, label: item.name }))
} catch { /* 忽略加载失败 */ } } catch { /* 忽略加载失败 */ }
}, },
async fetchData () { async fetchData () {
this.loading = true this.loading = true
try { try {
const res = await getProductionLineList({ const res = await getProductionLineList({ ...this.search, page_no: this.pagination.current, page_size: this.pagination.size })
...this.search, const data = this.normalizeResponse(res)
page_no: this.pagination.current, this.tableData = data.list
page_size: this.pagination.size this.pagination.total = data.total
})
const list = Array.isArray(res) ? res : (res.data || [])
const total = Array.isArray(res) ? res.length : (res.count || 0)
this.tableData = list
this.pagination.total = total
} finally { } finally {
this.loading = false this.loading = false
} }
@@ -261,7 +233,7 @@ export default {
this.fetchData() this.fetchData()
}, },
onReset () { onReset () {
this.search = { code: '', name: '', area_id: '' } this.search = { code: '', name: '', area_id: '', status: '' }
this.pagination.current = 1 this.pagination.current = 1
this.fetchData() this.fetchData()
}, },
@@ -274,7 +246,7 @@ export default {
this.selectedRows = rows this.selectedRows = rows
}, },
resetForm () { resetForm () {
this.formData = { code: '', name: '', area_id: '', remark: '' } this.formData = { code: '', name: '', area_id: '', status: '1', remark: '' }
this.editId = '' this.editId = ''
}, },
openAdd () { openAdd () {
@@ -290,22 +262,14 @@ export default {
this.handleType = 'edit' this.handleType = 'edit'
this.dialogTitle = this.key('edit_title') this.dialogTitle = this.key('edit_title')
this.editId = row.id this.editId = row.id
this.formData = { this.formData = { code: row.code, name: row.name, area_id: row.area_id, status: row.status !== undefined ? String(row.status) : '1', remark: row.remark || '' }
code: row.code,
name: row.name,
area_id: row.area_id,
remark: row.remark || ''
}
this.dialogVisible = true this.dialogVisible = true
}, },
async onDialogSubmit () { async onDialogSubmit () {
this.submitting = true this.submitting = true
try { try {
if (this.handleType === 'create') { if (this.handleType === 'create') await createProductionLine(this.formData)
await createProductionLine(this.formData) else await editProductionLine({ ...this.formData, id: this.editId })
} else {
await editProductionLine({ ...this.formData, id: this.editId })
}
this.$message.success(this.$t(this.key('operation_success'))) this.$message.success(this.$t(this.key('operation_success')))
this.dialogVisible = false this.dialogVisible = false
this.fetchData() this.fetchData()
@@ -316,31 +280,33 @@ export default {
onDialogClose () { onDialogClose () {
this.resetForm() this.resetForm()
}, },
async confirmAction (message, action) {
try {
await this.$confirm(this.$t(message), this.$t(this.key('tip')), { type: 'warning' })
} catch {
return false
}
await action()
return true
},
async handleDelete (row) { async handleDelete (row) {
const cancelled = await this.$confirmAction( const ok = await this.confirmAction(this.key('confirm_delete'), () => deleteProductionLine({ id: [row.id] }))
{ if (!ok) return
message: this.key('confirm_delete'),
title: this.key('tip')
},
() => deleteProductionLine({ id: [row.id] })
)
if (cancelled) return
this.$message.success(this.$t(this.key('operation_success'))) this.$message.success(this.$t(this.key('operation_success')))
this.pagination.current = Math.min( this.pagination.current = Math.min(this.pagination.current, Math.ceil((this.pagination.total - 1) / this.pagination.size) || 1)
this.pagination.current,
Math.ceil((this.pagination.total - 1) / this.pagination.size) || 1
)
this.fetchData() this.fetchData()
},
async handleExport () {
const ok = await this.confirmAction(this.key('confirm_export'), () => exportProductionLineTask({ ...this.search }))
if (ok) this.$message.success(this.$t(this.key('operation_success')))
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
.search-bar { .search-bar { padding: 10px 0; }
padding: 10px 0; .status-on { color: #67C23A; }
} .status-off { color: #909399; }
/deep/ .el-form-item--mini.el-form-item { /deep/ .el-form-item--mini.el-form-item { margin-bottom: 4px; }
margin-bottom: 4px;
}
</style> </style>