76 lines
1.9 KiB
Vue
Raw Normal View History

2026-01-19 18:52:18 +08:00
<template>
2026-01-23 14:36:28 +08:00
<picker mode="selector" :range="displayRange" :disabled="disableChange" @change="change($event)">
2026-01-19 18:52:18 +08:00
<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 || ''}`)
2026-01-21 15:27:18 +08:00
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;
})
2026-01-23 14:36:28 +08:00
2026-01-21 15:27:18 +08:00
const value = computed(() => {
if (!props.form) return '';
2026-01-21 15:27:18 +08:00
const currentValue = props.form[props.title];
if (currentValue === undefined || currentValue === null || currentValue === '') return '';
2026-01-21 15:27:18 +08:00
// 如果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;
})
2026-01-19 18:52:18 +08:00
function change(e) {
2026-01-21 15:27:18 +08:00
const selectedValue = props.range[e.detail.value];
2026-01-19 18:52:18 +08:00
emits('change', {
title: props.title,
2026-01-23 14:36:28 +08:00
value: typeof selectedValue === 'object' ? selectedValue.value : selectedValue
2026-01-19 18:52:18 +08:00
})
}
</script>
<style>
@import '../cell-style.css';
</style>