2022-11-14 03:59:26 +00:00
|
|
|
import { w as withInstall } from "../badge/index2.js";
|
|
|
|
import { defineComponent, inject, ref, computed, withDirectives, openBlock, createElementBlock, normalizeClass, unref, createBlock, isRef, createCommentVNode, renderSlot, createTextVNode, toDisplayString, vShow } from "vue";
|
2023-11-03 03:48:11 +00:00
|
|
|
import { _ as _sfc_main$1 } from "../checkbox/index2.js";
|
2022-11-14 03:59:26 +00:00
|
|
|
const __default__ = {
|
|
|
|
name: "LaySelectOption"
|
|
|
|
};
|
|
|
|
const _sfc_main = defineComponent({
|
|
|
|
...__default__,
|
|
|
|
props: {
|
|
|
|
label: { default: "" },
|
|
|
|
value: null,
|
|
|
|
disabled: { type: Boolean, default: false },
|
|
|
|
keyword: { default: "" }
|
|
|
|
},
|
|
|
|
setup(__props) {
|
|
|
|
const props = __props;
|
|
|
|
const searchValue = inject("searchValue");
|
|
|
|
const selectRef = inject("selectRef");
|
2022-12-12 01:08:28 +00:00
|
|
|
const searchMethod = inject("searchMethod");
|
2024-09-24 09:04:44 +00:00
|
|
|
const selectedValue = inject(
|
|
|
|
"selectedValue"
|
|
|
|
);
|
2022-11-14 03:59:26 +00:00
|
|
|
const multiple = inject("multiple");
|
|
|
|
const checkboxRef = ref();
|
|
|
|
const handleSelect = () => {
|
|
|
|
var _a;
|
|
|
|
if (multiple.value) {
|
|
|
|
if (!props.disabled) {
|
|
|
|
(_a = checkboxRef.value) == null ? void 0 : _a.toggle();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!props.disabled) {
|
|
|
|
selectRef.value.hide();
|
|
|
|
selectedValue.value = props.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const selected = computed(() => {
|
|
|
|
if (multiple.value) {
|
|
|
|
return selectedValue.value.indexOf(props.value) != -1;
|
|
|
|
} else {
|
|
|
|
return selectedValue.value === props.value;
|
|
|
|
}
|
|
|
|
});
|
2022-12-12 01:08:28 +00:00
|
|
|
const first = ref(true);
|
2022-11-14 03:59:26 +00:00
|
|
|
const display = computed(() => {
|
|
|
|
var _a, _b;
|
2022-12-12 01:08:28 +00:00
|
|
|
if (searchMethod && !first.value) {
|
|
|
|
return searchMethod(searchValue.value, props);
|
|
|
|
}
|
|
|
|
first.value = false;
|
2022-11-14 03:59:26 +00:00
|
|
|
return ((_a = props.keyword) == null ? void 0 : _a.toString().indexOf(searchValue.value)) > -1 || ((_b = props.label) == null ? void 0 : _b.toString().indexOf(searchValue.value)) > -1;
|
|
|
|
});
|
|
|
|
const classes = computed(() => {
|
|
|
|
return [
|
|
|
|
"layui-select-option",
|
|
|
|
{
|
|
|
|
"layui-this": selected.value,
|
|
|
|
"layui-disabled": props.disabled
|
|
|
|
}
|
|
|
|
];
|
|
|
|
});
|
|
|
|
return (_ctx, _cache) => {
|
|
|
|
return withDirectives((openBlock(), createElementBlock("dd", {
|
|
|
|
class: normalizeClass(unref(classes)),
|
|
|
|
onClick: handleSelect
|
|
|
|
}, [
|
|
|
|
unref(multiple) ? (openBlock(), createBlock(_sfc_main$1, {
|
|
|
|
key: 0,
|
|
|
|
skin: "primary",
|
|
|
|
ref_key: "checkboxRef",
|
|
|
|
ref: checkboxRef,
|
|
|
|
modelValue: unref(selectedValue),
|
|
|
|
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(selectedValue) ? selectedValue.value = $event : null),
|
|
|
|
disabled: __props.disabled,
|
|
|
|
value: __props.value
|
|
|
|
}, null, 8, ["modelValue", "disabled", "value"])) : createCommentVNode("", true),
|
|
|
|
renderSlot(_ctx.$slots, "default", {}, () => [
|
|
|
|
createTextVNode(toDisplayString(__props.label), 1)
|
|
|
|
])
|
|
|
|
], 2)), [
|
|
|
|
[vShow, unref(display)]
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const component = withInstall(_sfc_main);
|
|
|
|
export { _sfc_main as _, component as c };
|