76 lines
1.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<picker mode="selector" :range="displayRange" :disabled="disableChange" @change="change($event)">
<common-cell :name="name" :required="required">
<view class="form-content__wrapper">
<view class="flex-main-content truncate" :class="value ? '' : 'form__placeholder'">
{{ value || placeholder }}
</view>
<uni-icons class="form-arrow" type="arrowright"></uni-icons>
</view>
</common-cell>
</picker>
</template>
<script setup>
import { computed } from 'vue';
import commonCell from '../common-cell.vue';
const emits = defineEmits(['change']);
const props = defineProps({
form: {
type: Object,
default: () => ({})
},
name: {
default: ''
},
range: {
type: Array,
default: () => []
},
required: {
type: Boolean,
default: false
},
disableChange: {
type: Boolean,
default: false
},
title: {
default: ''
}
})
const placeholder = computed(() => `请输入${props.name || ''}`)
const displayRange = computed(() => {
// 如果range是对象数组提取label作为显示文本
if (Array.isArray(props.range) && props.range.length > 0 && typeof props.range[0] === 'object') {
return props.range.map(item => item.label);
}
return props.range;
})
const value = computed(() => {
if (!props.form) return '';
const currentValue = props.form[props.title];
if (currentValue === undefined || currentValue === null || currentValue === '') return '';
// 如果range是对象数组找到对应的label显示
if (Array.isArray(props.range) && props.range.length > 0 && typeof props.range[0] === 'object') {
const option = props.range.find(item => item.value === currentValue);
return option ? option.label : currentValue;
}
return currentValue;
})
function change(e) {
const selectedValue = props.range[e.detail.value];
emits('change', {
title: props.title,
value: typeof selectedValue === 'object' ? selectedValue.value : selectedValue
})
}
</script>
<style>
@import '../cell-style.css';
</style>