|
|
@ -11,7 +11,7 @@ |
|
|
</div> |
|
|
</div> |
|
|
</template> |
|
|
</template> |
|
|
<script> |
|
|
<script> |
|
|
import {selectDictDataList} from "../../../api/dict"; |
|
|
|
|
|
|
|
|
import {selectDictDataList, selectDictTypeList} from "../../../api/dict"; |
|
|
export default { |
|
|
export default { |
|
|
name:'dictDataSelect', |
|
|
name:'dictDataSelect', |
|
|
model:{ |
|
|
model:{ |
|
|
@ -33,6 +33,10 @@ export default { |
|
|
type:Boolean, |
|
|
type:Boolean, |
|
|
default:true, |
|
|
default:true, |
|
|
}, |
|
|
}, |
|
|
|
|
|
useTypeMultiDefaultValue: { |
|
|
|
|
|
type: Boolean, |
|
|
|
|
|
default: false, |
|
|
|
|
|
}, |
|
|
useSite:{ |
|
|
useSite:{ |
|
|
type:Boolean, |
|
|
type:Boolean, |
|
|
default:true, |
|
|
default:true, |
|
|
@ -48,20 +52,91 @@ export default { |
|
|
}, |
|
|
}, |
|
|
data () { |
|
|
data () { |
|
|
return { |
|
|
return { |
|
|
options: [] |
|
|
|
|
|
|
|
|
options: [], |
|
|
|
|
|
dictTypeMultiDefaultValue: '' |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
created () { |
|
|
created () { |
|
|
this.initOption() |
|
|
this.initOption() |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
|
|
|
hasCurrentValue () { |
|
|
|
|
|
if (Array.isArray(this.value)) { |
|
|
|
|
|
return this.value.length > 0 |
|
|
|
|
|
} |
|
|
|
|
|
return this.value !== null && this.value !== undefined && String(this.value).trim() !== '' |
|
|
|
|
|
}, |
|
|
|
|
|
isMultipleMode () { |
|
|
|
|
|
if (Array.isArray(this.value)) { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
const multiple = this.$attrs ? this.$attrs.multiple : false |
|
|
|
|
|
if (multiple === '' || multiple === true || multiple === 'multiple') { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
if (typeof multiple === 'string') { |
|
|
|
|
|
return multiple !== 'false' |
|
|
|
|
|
} |
|
|
|
|
|
return !!multiple |
|
|
|
|
|
}, |
|
|
|
|
|
parseMultiDefaultValue (value) { |
|
|
|
|
|
if (value === null || value === undefined) { |
|
|
|
|
|
return [] |
|
|
|
|
|
} |
|
|
|
|
|
const cache = new Set() |
|
|
|
|
|
return String(value) |
|
|
|
|
|
.split(/[;,\n]/) |
|
|
|
|
|
.map(item => String(item || '').trim()) |
|
|
|
|
|
.filter(item => { |
|
|
|
|
|
if (!item || cache.has(item)) { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
cache.add(item) |
|
|
|
|
|
return true |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
async loadDictTypeMultiDefaultValue () { |
|
|
|
|
|
this.dictTypeMultiDefaultValue = '' |
|
|
|
|
|
const currentDictType = String(this.dictType || '').trim() |
|
|
|
|
|
if (!this.useTypeMultiDefaultValue || !currentDictType) { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
const site = this.site ? this.site : (this.useSite ? this.$store.state.user.site : '*') |
|
|
|
|
|
if (!site) { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
let {data} = await selectDictTypeList({ site, dictType: currentDictType }) |
|
|
|
|
|
if (data && data.code === 0 && Array.isArray(data.rows)) { |
|
|
|
|
|
const matched = data.rows.find(item => String(item.dictType || '').trim() === currentDictType) |
|
|
|
|
|
this.dictTypeMultiDefaultValue = matched ? String(matched.multiDefaultValue || '').trim() : '' |
|
|
|
|
|
} |
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
}, |
|
|
dictDefaultValue(){ |
|
|
dictDefaultValue(){ |
|
|
// 当value值不存在 并且查询的下拉框存在默认值列,将value赋值为默认 |
|
|
// 当value值不存在 并且查询的下拉框存在默认值列,将value赋值为默认 |
|
|
if (!this.value && this.options.length > 0){ |
|
|
|
|
|
let find = this.options.find(item=>item.isDefault === 'Y'); |
|
|
|
|
|
if (find && find.status === 'Y'){ |
|
|
|
|
|
this.$emit("change",find.dictValue); |
|
|
|
|
|
|
|
|
if (this.hasCurrentValue() || this.options.length === 0){ |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if (this.isMultipleMode()) { |
|
|
|
|
|
const enabledValueSet = new Set( |
|
|
|
|
|
this.options.filter(item => item.status === 'Y').map(item => item.dictValue) |
|
|
|
|
|
) |
|
|
|
|
|
let defaultValues = this.parseMultiDefaultValue(this.dictTypeMultiDefaultValue) |
|
|
|
|
|
.filter(item => enabledValueSet.has(item)) |
|
|
|
|
|
if (defaultValues.length === 0) { |
|
|
|
|
|
defaultValues = this.options |
|
|
|
|
|
.filter(item => item.isDefault === 'Y' && item.status === 'Y') |
|
|
|
|
|
.map(item => item.dictValue) |
|
|
} |
|
|
} |
|
|
|
|
|
if (defaultValues.length > 0) { |
|
|
|
|
|
this.$emit("change", defaultValues) |
|
|
|
|
|
} |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
let find = this.options.find(item=>item.isDefault === 'Y'); |
|
|
|
|
|
if (find && find.status === 'Y'){ |
|
|
|
|
|
this.$emit("change",find.dictValue); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
//初始化options |
|
|
//初始化options |
|
|
@ -83,9 +158,10 @@ export default { |
|
|
if (data && data.code === 0){ |
|
|
if (data && data.code === 0){ |
|
|
this.options = data.rows; |
|
|
this.options = data.rows; |
|
|
if (this.options.length === 0){ |
|
|
if (this.options.length === 0){ |
|
|
this.$emit("change",'') |
|
|
|
|
|
|
|
|
this.$emit("change", this.isMultipleMode() ? [] : '') |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
await this.loadDictTypeMultiDefaultValue() |
|
|
if (this.useDefaultValue){ |
|
|
if (this.useDefaultValue){ |
|
|
this.dictDefaultValue(); |
|
|
this.dictDefaultValue(); |
|
|
} |
|
|
} |
|
|
|