forked from kouchao/vue-layui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.vue
More file actions
115 lines (113 loc) · 2.41 KB
/
select.vue
File metadata and controls
115 lines (113 loc) · 2.41 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
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
<template>
<div :class="$parent.block ? 'layui-input-block' : 'layui-input-inline'">
<div
class="layui-unselect layui-form-select"
:class="{ 'layui-form-selected layui-form-selectup': isOpen }"
@click="handleClick"
>
<div class="layui-select-title">
<input
v-model="selectText"
type="text"
:placeholder="placeholder"
readonly=""
class="layui-input layui-unselect"
:class="{
'layui-disabled': disabled
}"
>
<i class="layui-edge" />
</div>
<dl
class="layui-anim layui-anim-upbit"
:class="{
'layui-select-group': group
}"
style=""
>
<dd
lay-value=""
class="layui-select-tips"
>
{{ placeholder }}
</dd>
<span
v-for="g in datas"
:key="g.title"
>
<dt v-if="group">{{ g.title }}</dt>
<dd
v-for="item in g.data"
:key="item.lable"
:value="item[prop.value || 'value']"
:class="item[prop.value || 'value'] == value ? 'layui-this' : ''"
@click.stop="selectOption(item)"
>
{{ item[prop.lable || "lable"] }}
</dd>
</span>
</dl>
</div>
</div>
</template>
<script>
export default {
name: 'LaySelect',
props: {
disabled: Boolean,
value: {
type: [String, Number],
default: ''
},
data: {
type: Array,
default: () => []
},
prop: {
type: Object,
default: () => {}
},
placeholder: {
type: String,
default: ''
},
group: Boolean
},
data: function () {
return {
isOpen: false,
selected: false,
selectText: ''
};
},
created: function () {
if (!this.group) {
this.datas = [
{
data: this.data
}
];
} else {
this.datas = this.data;
}
},
methods: {
handleClick: function () {
if (!this.disabled) {
this.isOpen = !this.isOpen;
} else {
this.isOpen = false;
}
},
selectOption: function (item) {
if (!this.disabled) {
this.selectText = item[this.prop.lable];
this.$emit('input', item[this.prop.value]);
this.$emit('change', this.value);
}
this.handleClick();
}
}
};
</script>
<style></style>