index.vue
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!--
* @Date: 2022-08-30 13:46:51
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-02-01 09:12:24
* @FilePath: /data-table/src/components/PickerField/index.vue
* @Description: 单列选择器组件
-->
<template>
<div v-if="HideShow" class="picker-field-page">
<div class="label">
{{ item.component_props.label
}}<span v-if="item.component_props.required"> *</span>
</div>
<van-field
v-model="item.value"
is-link
readonly
:name="item.key"
:required="item.component_props.required"
:placeholder="item.component_props.placeholder"
:rules="item.rules"
@click="showPicker = true"
:border="false"
/>
<!-- <van-field v-if="has_add_info" :name="add_info_name" v-model="add_info" label="" placeholder="请输入补充信息" :border="false" style="border: 1px solid #eaeaea;border-radius: 0.25rem; padding: 0.25rem 0.5rem; margin-top: 0.25rem;" /> -->
<van-popup v-model:show="showPicker" position="bottom">
<van-picker
:columns="item.component_props.options"
@confirm="onConfirm"
@cancel="showPicker = false"
/>
</van-popup>
</div>
</template>
<script setup>
const props = defineProps({
item: Object,
});
// TEST: 测试新功能:选择其他选项时,下方出现输入框,如果其他项被选中,输入框值为最终录入值。
// 绑定值发生变化时回调,处理选项为其他时的输入项录入
// const has_add_info = ref(false); // TODO: 文字不一定是其他,后续可能需要字段绑定一个值,标识是否有其他输入框进行判断
// const add_info = ref('');
// const add_info_name = ref(props.item.key + '#');
// const add_info_key = ref('其他'); // TODO: 以后动态获取
onMounted(() => {
// add_info_name.value = `${props.item.key}#${add_info_key.value}`
// props.item.component_props.options = props.item.component_props.options.map((opt) => {
// return {
// text: opt,
// value: opt,
// };
// });
});
const selectedValues = ref("");
const showPicker = ref(false);
const onConfirm = ({ selectedOptions }) => {
props.item.value = selectedOptions[0]?.value;
showPicker.value = false;
if (add_info_key.value === props.item.value) {
has_add_info.value = true;
}
};
// 隐藏显示
const HideShow = computed(() => {
return !props.item.component_props.disabled
})
</script>
<style lang="less" scoped>
.picker-field-page {
margin: 1rem;
.label {
// padding: 1rem 1rem 0 0;
font-size: 0.9rem;
font-weight: bold;
span {
color: red;
}
}
}
:deep(.van-cell--clickable) {
border: 1px solid #eaeaea;
border-radius: 0.25rem;
padding: 0.25rem 0.5rem;
margin-top: 0.5rem;
}
</style>