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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<template>
<view class="pubPicker">
<template v-if="type=='select'">
<picker @change="bindPickerChange" :value="index" :range="range" range-key="label" :disabled="readonly">
<view class="flex flex-between">
<view class="uni-input">{{showText}}</view>
<uni-icons type="right" size="18" style="margin-left: 10rpx;"></uni-icons>
</view>
</picker>
</template>
<template v-if="type == 'date'">
<picker mode="date" :value="pickerValue" :start="startDate" :end="endDate" @change="bindDateChange"
:disabled="readonly" fields="day">
<view class="flex flex-between">
<view class="uni-input">{{showTextDate}}</view>
<uni-icons type="right" size="18" style="margin-left: 10rpx;"></uni-icons>
</view>
</picker>
</template>
<template v-if="type == 'tagSelect'">
<view class="tags">
<view class="tag flex-center" :class="item.value == pickerValue ? 'active' :''"
v-for="(item,index) in range" @click="selectTag(item)">{{item.label}}</view>
</view>
</template>
</view>
</template>
<script>
export default {
name: "PubPicker",
props: {
range: {
type: Array,
default: () => []
},
value: {
type: [String, Number],
default: () => ''
},
placeholder: {
type: String,
default: () => '請選擇'
},
type: {
type: String,
default: () => 'select'
},
readonly: {
type: Boolean,
default: () => false
},
},
computed: {
pickerValue: {
get() {
return this.value;
},
set(newValue) {
this.$emit('input', newValue);
this.$emit('change', this.pickerItem);
},
},
showText() {
let findItem = this.range.find(item => item.value == this.pickerValue)
if (findItem) {
return findItem.label
}
return this.placeholder || ''
},
showTextDate() {
return this.pickerValue || '請選擇日期'
},
},
data() {
return {
index: 0,
startDate: '',
endDate: '',
pickerItem: ''
};
},
methods: {
bindPickerChange(val) {
// console.log(val.detail.value);
this.index = val.detail.value
this.pickerItem = this.range[this.index]
this.pickerValue = this.range[this.index]?.value
},
bindDateChange(e) {
this.pickerValue = e.detail.value
},
selectTag(e) {
if (this.readonly) {
return
}
this.pickerItem = e
this.pickerValue = e.value
},
}
}
</script>
<style lang="less" scoped>
@import url('@/style/index.less');
.pubPicker {
display: inline-block;
}
.tags {
width: 100%;
display: flex;
flex-wrap: wrap;
.tag {
width: 182rpx;
height: 80rpx;
border-radius: 8rpx;
background: #FFFFFF;
border: 2rpx solid #E5E5E5;
margin-right: 20rpx;
margin-bottom: 23rpx;
&:nth-child(3n) {
margin-right: 0;
}
&.active {
border: 2rpx solid #32BAEC;
color: #32BAEC;
}
}
}
</style>