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
| /**
| * CFilterInput - 筛选项目,单选
| * @author Tevin
| */
|
| <template>
| <view
| class="c-filter-input"
| :class="['type-'+place, focusing?'':'off']"
| >
| <view class="label">{{label}}</view>
| <input
| class="input"
| type="text"
| :placeholder="'请输入' + label"
| :value="value"
| @input="evt => handleChange(evt.target.value)"
| @focus="evt => handleFocus()"
| @blur="evt => handleBlur(evt.target.value)"
| />
| </view>
| </template>
|
| <script>
| import Taro from '@tarojs/taro';
| import { AtInput } from 'taro-ui-vue';
| import './cFilterInput.scss';
|
| export default {
| name: 'CFilterInput',
| components: {
| AtInput,
| },
| props: {
| // 位置类型,bar、item
| place: String,
| // 项名称
| label: String,
| // 项键名
| name: String,
| // 项值
| value: String,
| // 变化回调
| onChange: Function,
| },
| data() {
| return {
| focusing: false,
| };
| },
| methods: {
| handleChange(value) {
| // 横条时,不响应变化
| if (this.place === 'bar') {
| return;
| }
| this.onChange({
| place: this.place,
| name: this.name,
| value: value || undefined,
| });
| },
| handleFocus() {
| this.focusing = true;
| },
| handleBlur(value, act) {
| this.focusing = !!value;
| // 展开项时,不响应失去焦点
| if (this.place === 'item') {
| return;
| }
| // 未改变值时,不触发
| if (this.value === value) {
| return;
| }
| this.onChange({
| place: this.place,
| name: this.name,
| value: value || undefined,
| });
| },
| },
| mounted() {
| this.focusing = !!this.value;
| },
| };
| </script>
|
|