import { Picker as VanPicker, CheckboxGroup as VanCheckboxGroup, Checkbox as VanCheckbox, CellGroup as VanCellGroup, Cell as VanCell } from 'vant' import { computed, ref, onBeforeUpdate } from 'vue' import { useOptions } from '@cip/components/hooks/form-input' import { formInputProps } from '../../form-input-props' export default { props: { ...formInputProps, customFieldName: {}, columns: {} }, emits: ['confirm', 'cancel'], setup (props, { emit }) { // 是否多选 const multiple = computed(() => { return props.config?.multiple ?? false }) const { options, getValue } = useOptions(props, multiple) const confirm = (value) => { if (multiple.value) { emit('confirm', checked.value) } else { if (props.customFieldName.children) { value = value[value.length - 1] } emit('confirm', value) } } const cancel = (val) => { if (multiple.value) { checked.value = getValue(props.modelValue) } emit('cancel', val) } // 多选 console.log('init', getValue(props.modelValue), props.modelValue) const checked = ref(getValue(props.modelValue)) const checkboxRefs = ref([]) const toggle = (index) => { checkboxRefs.value[index]?.toggle() } onBeforeUpdate(() => { checkboxRefs.value = [] }) const Buttons = () =>
{props.config.label}
const CellSlot = (item, index) => {{ 'right-icon': () => { checkboxRefs[index] = el }} /> }} const CellSlots = () => options.value.map((v, idx) => CellSlot(v, idx)) const Checkbox = () => {Buttons()} {CellSlots()} // 单选 const Picker = () => return () => multiple.value ? Checkbox() : Picker() } }