删除工厂区域上级区域表单项
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
:visible.sync="dialogVisible"
|
||||
:title="dialogTitle"
|
||||
:width="'35%'"
|
||||
:form-cols="dialogFormCols"
|
||||
:form-cols="baseFormCols"
|
||||
:form-data="formData"
|
||||
:rules="rules"
|
||||
:label-width="'100px'"
|
||||
@@ -101,24 +101,10 @@ export default {
|
||||
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: 'select', prop: 'parent_id', label: this.key('parent_area'), placeholder: this.key('select_parent_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('remark_required'), clearable: true, style: { width: '90%' } }]
|
||||
]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
dialogFormCols () {
|
||||
const cols = JSON.parse(JSON.stringify(this.baseFormCols))
|
||||
cols[2][0].options = this.parentAreaOptions
|
||||
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 () {
|
||||
this.columns = useTableColumns([
|
||||
{ prop: 'sort', label: this.key('sort'), width: 80 },
|
||||
@@ -197,11 +183,6 @@ export default {
|
||||
})
|
||||
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 () {
|
||||
this.loading = true
|
||||
try {
|
||||
@@ -243,17 +224,7 @@ export default {
|
||||
this.formData = { code: row.code, name: row.name, parent_id: this.getParentId(row), remark: row.remark || '' }
|
||||
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 () {
|
||||
if (!this.validateHierarchy()) return
|
||||
this.submitting = true
|
||||
try {
|
||||
if (this.handleType === 'create') await createFactoryArea(this.formData)
|
||||
|
||||
Reference in New Issue
Block a user