MyComponent.vue
2.31 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
<!--
* @Date: 2023-03-28 15:38:09
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-03-28 16:10:58
* @FilePath: /data-table/src/components/AppointmentField/MyComponent.vue
* @Description: 自定义组件
-->
<template>
<div style="width: 100%;">
<van-row v-for="(opt, index) in props.component_props.options" :key="index">
<van-col span="7">
<div style="font-size: 1rem; line-height: 3;">{{ opt.title }}</div>
</van-col>
<van-col span="17">
<van-field
v-model="opt.value"
is-link
readonly
:placeholder="opt.placeholder"
@click="onClick(index, opt)"
:border="false"
/>
</van-col>
</van-row>
</div>
<van-popup v-model:show="showPicker" position="bottom">
<van-picker
:title="props.component_props.appointment_title"
:columns="columns"
@confirm="onConfirm"
@cancel="showPicker = false"
/>
</van-popup>
</template>
<script setup>
import { inject, ref } from 'vue'
import { useCustomFieldValue } from '@vant/use';
import { styleColor } from "@/constant.js";
import { showDialog } from 'vant';
// 获取父组件传值
const props = inject('props');
const showPicker = ref(false);
const picker_value = ref('');
const columns = ref([]);
const current_index = ref(0);
const onClick = (index, opt) => {
if (opt.disabled) {
showDialog({
title: '温馨提示',
message: '暂时不能预约!',
theme: 'round-button',
width: '320px',
confirmButtonColor: styleColor.baseColor
}).then(() => {
// on close
});
return false;
}
current_index.value = index;
columns.value = props.component_props.options[index]['columns'];
showPicker.value = true;
}
const onConfirm = ({ selectedOptions }) => {
props.component_props.options.forEach(item => {
item.value = ''
})
props.component_props.options[current_index.value]['value'] = selectedOptions[0]?.text;
picker_value.value = selectedOptions[0]?.value;
showPicker.value = false;
};
// 此处传入的值会替代 Field 组件内部的 value
useCustomFieldValue(() => picker_value.value);
</script>
<style lang="less" scoped>
:deep(.van-cell--clickable) {
border: 1px solid #eaeaea;
border-radius: 0.25rem;
padding: 0.25rem 0.5rem;
margin-top: 0.5rem;
}
</style>