-
Notifications
You must be signed in to change notification settings - Fork 2
/
wepy-match-input.wpy
107 lines (92 loc) · 4.29 KB
/
wepy-match-input.wpy
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
<template>
<view class="wepy-match-input {{params.disabled?'disable':''}}">
<input disabled="{{params.disabled?'true':false}}" type="text" value="{{params.keyWord}}" bindinput="inputChange" bindfocus="inputFocus" bindblur="inputBlur" bindconfirm="inputConfirm" placeholder="{{params.placeholder}}" />
<view class="wepy-match-input-list" wx:if="{{params.matchList.length>0}}">
<view class="wepy-match-input-item" wx:for="{{params.matchList}}" catchtap="itemTap({{index}})">
{{item[params.keyName]}}
</view>
</view>
</view>
</template>
<script>
import wepy from 'wepy'
export default class MyPage extends wepy.component {
props = {
params:{
type:Object,
default:{
matchList:[],
keyWord:'',
keyName:'name',
disabled:false,
tapMatchListItemCallBackFunName:'wepyMatchInputTapCallBack',
tapInputFocusCallBackFunName:'wepyMatchInputFocusCallBack',
tapInputChangeCallBackFunName:'wepyMatchInputChangeCallBack',
tapInputBlurCallBackFunName:'wepyMatchInputBlurCallBack',
tapInputConfirmCallBackFunName:'wepyMatchInputConfirmCallBack',
placeholder:'',
},
twoWay: true
}
}
customData = {} // 自定义数据
customFunction() {
} // 自定义方法
onLoad() {
this.setDefaultValue(this.params)
} // 在Page和Component共用的生命周期函数
onShow() {
} // 只在Page中存在的页面生命周期函数
config = {}; // 只在Page实例中存在的配置数据,对应于原生的page.json文件
data = {}; // 页面所需数据均需在这里声明,可用于模板数据绑定
components = {}; // 声明页面中所引用的组件,或声明组件中所引用的子组件
mixins = []; // 声明页面所引用的Mixin实例
computed = {}; // 声明计算属性(详见后文介绍)
watch = {
params (newValue, oldValue) {
this.setDefaultValue(newValue);
}
}; // 声明数据watcher(详见后文介绍)
methods = {
itemTap:function (index) {
let data=this.params.matchList[index];
this.params.matchList=[];
this.$emit(this.params.tapMatchListItemCallBackFunName, data,index);
},
inputChange:function (e) {
let value=e.detail.value;
this.params.keyWord=value;
this.params.matchList=[];
this.$emit(this.params.tapInputChangeCallBackFunName,value);
},
inputFocus:function (e) {
let value=e.detail.value;
this.params.matchList=[];
this.$emit(this.params.tapInputFocusCallBackFunName,value);
},
inputBlur:function (e) {
let value=e.detail.value;
this.$emit(this.params.tapInputConfirmCallBackFunName,value);
},
bindconfirm:function (e) {
let value=e.detail.value;
this.params.matchList=[];
this.$emit(this.params.tapInputBlurCallBackFunName,value);
}
}; // 声明页面wxml中标签的事件处理函数。注意,此处只用于声明页面wxml中标签的bind、catch事件,自定义方法需以自定义方法的方式声明
events = {}; // 声明组件之间的事件处理函数
setDefaultValue(value){
value.matchList=value.matchList?value.matchList:[];
value.keyWord=value.keyWord?value.keyWord:'';
value.keyName=value.keyName?value.keyName:'name';
value.disabled=value.disabled?value.disabled:false;
value.tapMatchListItemCallBackFunName=value.tapMatchListItemCallBackFunName?value.tapMatchListItemCallBackFunName:'wepyMatchInputTapCallBack';
value.tapInputFocusCallBackFunName=value.tapInputFocusCallBackFunName?value.tapInputFocusCallBackFunName:'wepyMatchInputFocusCallBack';
value.tapInputChangeCallBackFunName=value.tapInputChangeCallBackFunName?value.tapInputChangeCallBackFunName:'wepyMatchInputChangeCallBack';
value.tapInputBlurCallBackFunName=value.tapInputBlurCallBackFunName?value.tapInputBlurCallBackFunName:'wepyMatchInputBlurCallBack';
value.tapInputConfirmCallBackFunName=value.tapInputConfirmCallBackFunName?value.tapInputConfirmCallBackFunName:'wepyMatchInputConfirmCallBack';
value.placeholder=value.placeholder?value.placeholder:'';
}
}
</script>
<style lang="scss" src="wepy-match-input.scss"></style>