2026-01-19 18:52:18 +08:00
|
|
|
|
<template>
|
2026-01-21 15:27:18 +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;
|
|
|
|
|
|
})
|
|
|
|
|
|
const value = computed(() => {
|
|
|
|
|
|
if (!props.form || !props.form[props.title]) return '';
|
|
|
|
|
|
|
|
|
|
|
|
const currentValue = props.form[props.title];
|
|
|
|
|
|
// 如果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-21 15:27:18 +08:00
|
|
|
|
value: selectedValue
|
2026-01-19 18:52:18 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style>
|
|
|
|
|
|
@import '../cell-style.css';
|
|
|
|
|
|
</style>
|