UNPKG

1.73 kBPlain TextView Raw
1<template>
2 <div class="box">
3 <van-field
4 readonly
5 clickable
6 :value="value"
7 placeholder="请选择"
8 :label="label"
9 v-bind="$attrs"
10 @click="onClick"
11 />
12 <div class="info">
13 <slot></slot>
14 </div>
15 <yn-pop v-model="showPicker">
16 <van-picker
17 show-toolbar
18 v-bind="$attrs"
19 :columns="options"
20 @confirm="confirm"
21 @cancel="showPicker=false"
22 />
23 </yn-pop>
24 </div>
25</template>
26<script>
27/**
28 * ----------------------------------------
29 * 下拉选择
30 * @param {String} label - 标签
31 * @param {String} val - 设置选中
32 * @param {Array<String>} options - 选项
33 * @param {Function} change({value,index}) - 点击回调
34 * ----------------------------------------
35 */
36export default {
37 props: {
38 val: {
39 type: String,
40 default: "",
41 },
42 options: {
43 type: Array,
44 default: () => [],
45 },
46 label: {
47 type: String,
48 default: "",
49 },
50 disabled: {
51 type: Boolean,
52 default: false,
53 },
54 },
55 watch: {
56 val(v) {
57 v && (this.value = v);
58 },
59 },
60 data() {
61 return {
62 showPicker: false,
63 value: "",
64 };
65 },
66 methods: {
67 onClick() {
68 if (this.disabled) {
69 this.$emit("disabled");
70 return;
71 }
72 this.showPicker = true;
73 },
74 confirm(value, index) {
75 this.showPicker = false;
76 this.value = value;
77 this.$emit("change", { value, index });
78 },
79 setValue(v) {
80 this.value = v;
81 },
82 },
83};
84</script>
85<style lang="scss" scoped>
86.box {
87 display: flex;
88 background: white;
89 align-items: center;
90}
91.info {
92 flex-shrink: 0;
93 font-size: 13px;
94 padding-right: 15px;
95}
96</style>