|
@@ -1,22 +1,26 @@
|
|
|
<template>
|
|
|
<el-select
|
|
|
- v-model="modelObj"
|
|
|
+ :model-value="props.modelValue[props.name[0]]"
|
|
|
+ @update:model-value="
|
|
|
+ value => {
|
|
|
+ changeStaff(value);
|
|
|
+ }
|
|
|
+ "
|
|
|
:clearable="props.clearable"
|
|
|
:remote="props.remote"
|
|
|
:id="props.id"
|
|
|
:remote-method="xcMethod"
|
|
|
- :style="{ width: props.width + 'px' }"
|
|
|
+ :style="{ width: XEUtils.addUnit(props.width) }"
|
|
|
ref="selectRef"
|
|
|
filterable
|
|
|
- @change="el => changeStaff(el)"
|
|
|
@clear="clear"
|
|
|
@focus="getFocus"
|
|
|
>
|
|
|
<el-option
|
|
|
v-for="(item, index) in props.data"
|
|
|
- :key="item.index"
|
|
|
- :label="item.name"
|
|
|
- :value="item.code"
|
|
|
+ :key="`${uuid + index}`"
|
|
|
+ :value="item[props.keys[0]]"
|
|
|
+ :label="item[props.keys[1]]"
|
|
|
>
|
|
|
<template
|
|
|
v-for="(opitem, index) in optionList"
|
|
@@ -26,9 +30,9 @@
|
|
|
<span :style="opitem.style">{{ item[opitem.label] }}</span>
|
|
|
</template>
|
|
|
<template v-else>
|
|
|
- <span>{{ item.code }}</span>
|
|
|
+ <span>{{ item[props.keys[0]] }}</span>
|
|
|
<el-divider direction="vertical"></el-divider>
|
|
|
- <span>{{ item.name }}</span>
|
|
|
+ <span>{{ item[props.keys[1]] }}</span>
|
|
|
</template>
|
|
|
</el-option>
|
|
|
</el-select>
|
|
@@ -37,9 +41,10 @@
|
|
|
<script setup>
|
|
|
import { debounce } from "@/utils/debounce";
|
|
|
import { stringNotBlank } from "@/utils/blank-utils";
|
|
|
-import { onMounted, watch } from "vue";
|
|
|
+import { onMounted, watch, useId } from "vue";
|
|
|
import useCompRef from "@/utils/useCompRef";
|
|
|
import { ElSelect } from "element-plus";
|
|
|
+import XEUtils from "xe-utils";
|
|
|
|
|
|
const props = defineProps({
|
|
|
modelValue: {
|
|
@@ -50,7 +55,7 @@ const props = defineProps({
|
|
|
default: ["code", "name"],
|
|
|
},
|
|
|
width: {
|
|
|
- type: Number,
|
|
|
+ type: [Number, String],
|
|
|
default: 120,
|
|
|
},
|
|
|
data: {
|
|
@@ -68,10 +73,15 @@ const props = defineProps({
|
|
|
id: {
|
|
|
type: String,
|
|
|
},
|
|
|
+ keys: {
|
|
|
+ type: Array,
|
|
|
+ default: ["code", "name"],
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
const emit = defineEmits(["method", "change", "focus"]);
|
|
|
|
|
|
+const uuid = useId();
|
|
|
const modelObj = ref(null);
|
|
|
const selectRef = useCompRef(ElSelect);
|
|
|
const optionList = ref([]);
|
|
@@ -83,20 +93,14 @@ const colorList = {
|
|
|
warning: "#E6A23C",
|
|
|
};
|
|
|
|
|
|
-const changeStaff = el => {
|
|
|
- nextTick(() => {
|
|
|
- props.modelValue[props.name[0]] = el;
|
|
|
- props.modelValue[props.name[1]] =
|
|
|
- selectRef.value?.states.selected?.currentLabel;
|
|
|
- });
|
|
|
- emit(
|
|
|
- "change",
|
|
|
- props.data.find(i => i.code === modelObj.value)
|
|
|
- );
|
|
|
+const changeStaff = value => {
|
|
|
+ const find = props.data.find(i => i.code === value);
|
|
|
+ props.modelValue[props.name[0]] = find[props.keys[0]];
|
|
|
+ props.modelValue[props.name[1]] = find[props.keys[1]];
|
|
|
+ emit("change", find);
|
|
|
};
|
|
|
|
|
|
const clear = () => {
|
|
|
- modelObj.value = null;
|
|
|
props.modelValue[props.name[0]] = null;
|
|
|
props.modelValue[props.name[1]] = null;
|
|
|
};
|
|
@@ -150,10 +154,9 @@ const blur = () => {
|
|
|
defineExpose({ focus, blur });
|
|
|
|
|
|
onMounted(() => {
|
|
|
- nextTick(() => {
|
|
|
- modelObj.value = props.modelValue[props.name[0]];
|
|
|
- });
|
|
|
-
|
|
|
+ // nextTick(() => {
|
|
|
+ // modelObj.value = props.modelValue[props.name[0]];
|
|
|
+ // });
|
|
|
// 判断组件是否使用了 slot
|
|
|
if (!!useSlots().default) {
|
|
|
// 判断 slot 有没有想要的值
|
|
@@ -179,5 +182,3 @@ onMounted(() => {
|
|
|
}
|
|
|
});
|
|
|
</script>
|
|
|
-
|
|
|
-<style scoped></style>
|