Files
dvcp_v2_wxcp_app/components/AiSelect/AiSelect.vue

99 lines
2.0 KiB
Vue
Raw Normal View History

2021-11-15 10:29:05 +08:00
<template>
<section class="AiSelect">
<div class="display" v-if="$slots.default" @tap="handleShowOptions">
<slot/>
</div>
<div v-else class="display" @tap="handleShowOptions">
<div class="selectedLabel" v-if="selectedLabel">{{ selectedLabel }}</div>
<i v-else>{{ placeholder }}</i>
<u-icon name="arrow-right" color="#ddd"/>
</div>
2023-03-08 11:23:20 +08:00
<u-select v-model="show" :list="options" :mode="mode" @confirm="handleConfirm" z-index="202303081123"/>
2021-11-15 10:29:05 +08:00
</section>
</template>
<script>
export default {
name: "AiSelect",
2022-01-13 16:47:34 +08:00
model: {
event: "input",
prop: "value"
},
2021-11-15 10:29:05 +08:00
props: {
value: String,
placeholder: {default: "请选择"},
list: {default: () => []},
2022-01-13 16:47:34 +08:00
mode: {default: "single-column"},
2021-11-15 10:29:05 +08:00
dict: {default: ""},
2022-01-13 16:47:34 +08:00
disabled: Boolean
2021-11-15 10:29:05 +08:00
},
computed: {
selectedLabel() {
let label = this.options.find(e => e.value == this.value)?.label
return this.selected?.map(e => e.label)?.join(",") || label
},
options() {
2022-01-13 16:47:34 +08:00
return this.dictKey ? this.$dict.getDict(this.dict).map(e => ({
2021-11-15 10:29:05 +08:00
value: e.dictValue,
label: e.dictName
})) : this.list
}
},
data() {
return {
show: false,
2022-01-13 16:47:34 +08:00
dictKey: '',
2021-11-15 10:29:05 +08:00
selected: []
}
},
2022-01-13 16:47:34 +08:00
2023-03-08 11:23:20 +08:00
mounted() {
2022-01-13 16:47:34 +08:00
this.$dict.load(this.dict).then(() => {
this.dictKey = this.dict
})
},
2021-11-15 10:29:05 +08:00
methods: {
handleConfirm(v) {
this.selected = v
this.$emit("data", this.selected)
2022-01-13 16:47:34 +08:00
this.$emit("input", v[0].value)
2021-11-15 10:29:05 +08:00
this.$forceUpdate()
},
handleShowOptions() {
if (!this.disabled) this.show = true
}
}
}
</script>
<style lang="scss" scoped>
.AiSelect {
max-width: 100%;
::v-deep .u-icon {
margin-left: 8px;
}
.display {
display: flex;
align-items: center;
.selectedLabel {
flex: 1;
2022-01-14 09:21:24 +08:00
max-width: 450px;
2021-11-15 10:29:05 +08:00
overflow: hidden;
text-overflow: ellipsis;
2022-01-13 16:47:34 +08:00
font-size: 30px;
color: #333;
2021-11-15 10:29:05 +08:00
white-space: nowrap;
}
}
i {
font-style: normal;
2022-01-13 16:47:34 +08:00
font-size: 30px;
2021-11-15 10:29:05 +08:00
color: $uni-text-color-grey;
}
}
</style>