You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
6.0 KiB
170 lines
6.0 KiB
<template>
|
|
<div class="po-customer-field-auth">
|
|
<el-button v-if="!readonly" type="primary" :loading="saving" style="margin-bottom: 10px" @click="save">保存字段权限</el-button>
|
|
<div class="rq">
|
|
<el-table class="field-auth-table" :data="rows" border style="width: 100%" height="400">
|
|
<el-table-column prop="fieldCode" label="字段编码" min-width="160" />
|
|
<el-table-column prop="fieldLabel" label="字段名称" min-width="140" />
|
|
<el-table-column label="显示名称" min-width="180">
|
|
<template slot-scope="{ row }">
|
|
<el-input
|
|
v-model="row.displayLabel"
|
|
:disabled="readonly || !isExtField(row)"
|
|
clearable
|
|
placeholder="扩展字段可维护"
|
|
/>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="字典类型" min-width="160">
|
|
<template slot-scope="{ row }">
|
|
<el-input
|
|
v-model="row.dictType"
|
|
:disabled="readonly || !isDictTypeEditable(row)"
|
|
clearable
|
|
:placeholder="isExtDateField(row) ? '日期扩展字段不可填' : '留空=默认组件'"
|
|
/>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="可见" width="70">
|
|
<template slot-scope="{ row }">
|
|
<el-checkbox
|
|
v-model="row.visibleFlag"
|
|
true-label="Y"
|
|
false-label="N"
|
|
:disabled="readonly || isMandatoryField(row)"
|
|
@change="onVisibleChange(row)" />
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="必填" width="70">
|
|
<template slot-scope="{ row }">
|
|
<!-- 必填对标准/扩展字段均可维护;必录字段锁定为必填不可取消;只读或字段不可见时禁用(ship_via 已移出必录名单,可自由勾选) -->
|
|
<el-checkbox
|
|
v-model="row.requiredFlag"
|
|
true-label="Y"
|
|
false-label="N"
|
|
:disabled="readonly || isForceRequiredField(row) || row.visibleFlag !== 'Y'" />
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { listPoCustomerFieldAuth, savePoCustomerFieldAuth } from '@/api/order/poCustomer'
|
|
|
|
// 系统级必录字段:默认必填且不允许取消(与后端 PoFieldAuthSupport.FORCE_REQUIRED_FIELD_CODES 保持一致)
|
|
const FORCE_REQUIRED_FIELD_CODES = [
|
|
'po_no', 'buyer', 'supplier_name', 'destination', 'order_date',
|
|
'enquiry', 'part_no', 'qty', 'want_receive_date', 'price'
|
|
]
|
|
|
|
export default {
|
|
name: 'ComPoCustomerFieldAuth',
|
|
props: {
|
|
site: { type: String, required: true },
|
|
customerCode: { type: String, default: '' },
|
|
readonly: { type: Boolean, default: false }
|
|
},
|
|
data () {
|
|
return { rows: [], saving: false }
|
|
},
|
|
watch: {
|
|
customerCode: {
|
|
immediate: true,
|
|
handler () { this.load() }
|
|
}
|
|
},
|
|
methods: {
|
|
load () {
|
|
if (!this.customerCode) {
|
|
this.rows = []
|
|
return
|
|
}
|
|
listPoCustomerFieldAuth({ site: this.site, customerCode: this.customerCode }).then(({ data }) => {
|
|
this.rows = (data && data.code === 0 && data.rows) ? data.rows.map(r => ({
|
|
...r,
|
|
fieldLabel: r.fieldLabel || r.fieldCode,
|
|
mandatoryFlag: (r.mandatoryFlag || 'N').toUpperCase(),
|
|
displayLabel: r.displayLabel || r.fieldLabel || r.fieldCode,
|
|
dictType: this.isDictTypeEditable(r) ? (r.dictType || '') : '',
|
|
visibleFlag: ((r.mandatoryFlag || 'N').toUpperCase() === 'Y') ? 'Y' : (r.visibleFlag || 'Y'),
|
|
requiredFlag: this.isForceRequiredField(r) ? 'Y' : (r.requiredFlag || 'N')
|
|
})) : []
|
|
})
|
|
},
|
|
isExtField (row) {
|
|
const code = row && row.fieldCode ? String(row.fieldCode).toLowerCase() : ''
|
|
return code.indexOf('ext_') === 0
|
|
},
|
|
isExtDateField (row) {
|
|
const code = row && row.fieldCode ? String(row.fieldCode).toLowerCase() : ''
|
|
return /^ext_dt\d{2}$/.test(code)
|
|
},
|
|
isDictTypeEditable (row) {
|
|
return this.isExtField(row) && !this.isExtDateField(row)
|
|
},
|
|
isMandatoryField (row) {
|
|
return !!(row && String(row.mandatoryFlag || '').toUpperCase() === 'Y')
|
|
},
|
|
isForceRequiredField (row) {
|
|
const code = row && row.fieldCode ? String(row.fieldCode).trim().toLowerCase() : ''
|
|
return !!code && FORCE_REQUIRED_FIELD_CODES.indexOf(code) !== -1
|
|
},
|
|
onVisibleChange (row) {
|
|
if (this.isMandatoryField(row)) {
|
|
this.$set(row, 'visibleFlag', 'Y')
|
|
return
|
|
}
|
|
// 字段设为不可见时,必填无意义,自动取消勾选,避免出现「隐藏却必填」(必录字段除外,始终锁定为 Y)
|
|
if (row.visibleFlag !== 'Y' && !this.isForceRequiredField(row)) {
|
|
this.$set(row, 'requiredFlag', 'N')
|
|
}
|
|
},
|
|
normalizeNullable (value) {
|
|
if (value === null || value === undefined) return null
|
|
const text = String(value).trim()
|
|
return text ? text : null
|
|
},
|
|
normalizeDictTypeForSave (row) {
|
|
if (!this.isDictTypeEditable(row)) {
|
|
return null
|
|
}
|
|
return this.normalizeNullable(row && row.dictType)
|
|
},
|
|
save () {
|
|
if (!this.customerCode) return
|
|
this.saving = true
|
|
savePoCustomerFieldAuth({
|
|
site: this.site,
|
|
customerCode: this.customerCode,
|
|
rows: this.rows.map(r => ({
|
|
fieldCode: r.fieldCode,
|
|
visibleFlag: r.visibleFlag,
|
|
requiredFlag: r.requiredFlag,
|
|
displayLabel: this.normalizeNullable(r.displayLabel),
|
|
dictType: this.normalizeDictTypeForSave(r),
|
|
active: r.active || 'Y'
|
|
}))
|
|
}).then(({ data }) => {
|
|
this.saving = false
|
|
if (data && data.code === 0) {
|
|
this.$message.success('保存成功')
|
|
this.load()
|
|
} else {
|
|
this.$message.error((data && data.msg) || '保存失败')
|
|
}
|
|
}).catch(() => {
|
|
this.saving = false
|
|
this.$message.error('保存失败')
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.po-customer-field-auth .field-auth-table {
|
|
margin-bottom: 10px;
|
|
}
|
|
</style>
|