filter.vue
4.1 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
<div>
<div class="bg" v-if="show">
<div class="content show">
<div style="height: 3.1rem;">
<Scroll
class="postscroll"
ref="scroll"
:listenScroll="true"
:probeType="3" >
<div class="posts display-flex">
<div @click="typeClick(item, index)" :class="current==index?'active':''" v-for="(item,index) in posts" :key="index" class="post_item">{{item.name}}</div>
</div>
</Scroll>
</div>
<div class="over" @click="complete">完成</div>
</div>
</div>
</div>
</template>
<script>
import Scroll from '@/components/scroll.vue'
export default {
name: 'fil',
props: {
show: {
type: Boolean,
default: false
}
},
components: {
Scroll
},
data () {
return {
posts: [],
current: 0,
infoType: '', // 选择工种
itemId: '' // 工种id
}
},
mounted () {
this.pos()
},
methods: {
fontNumber (date) {
const length = date.length
if (length > 6) {
var str = ''
str = date.substring(0, 6) + '...'
return str
} else {
return date
}
},
// 工种列表接口
async pos () {
const that = this
that.isShow = !that.isShow
const reslist = await that.api.pos()
if (reslist.code === 1) {
that.posts = reslist.data.list
if (localStorage.getItem('pId')) {
that.posts.forEach((item, index) => {
item.name = this.fontNumber(item.name)
if (item.id === localStorage.getItem('pId')) {
that.current = index
}
})
}
} else {
that.$toast(reslist.msg)
}
},
typeClick (item, index) { // 点击选择工种
this.infoType = item.name
this.current = index
this.itemId = item.id
localStorage.removeItem('postname')
localStorage.removeItem('pId')
localStorage.setItem('postname', item.name)
localStorage.setItem('pId', item.id)
console.log(localStorage.getItem('postname'))
},
complete () { // 点击完成
if (this.infoType === '') {
this.infoType = this.posts[this.current].name
this.itemId = this.posts[this.current].id
}
this.$emit('infoType', this.infoType, this.itemId)
}
}
}
</script>
<style scoped lang="scss">
.bg{
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
position: fixed;
bottom: 0;
left: 0;
z-index: 9;
top: 0.8rem;
}
.content{
width: 100%;
height:5.04rem;
background-color: #fff;
padding: 0.32rem;
box-sizing: border-box;
overflow: hidden;
}
.show{
animation: show 0.3s ease-in;
}
@keyframes show{
0%{
opacity: 0;
height: 0;
}
50%{
opacity: 0.5;
height: 2.5rem;
}
100%{
opacity: 1;
height:5.04rem;
}
}
.postscroll{
height: 100%;
overflow: hidden;
}
.posts{
height:auto;
flex-wrap: wrap;
}
.post_item{
width: 2.1rem;
height: 0.8rem;
border-radius: 0.08rem;
opacity: 1;
background: rgba(239,242,246,1);
color: rgba(7,29,17,1);
font-size: 0.28rem;
font-weight: 400;
text-align: center;
line-height: 0.8rem;
margin:0 0.26rem 0.26rem 0;
}
.post_item:nth-child(3n){
margin-right: 0;
}
.active{
color: #fff;
background: rgba(37.19,124.31,255,1)
}
.over{
width: 100%;
height: 0.88rem;
opacity: 1;
background: rgba(37.19,124.31,255,1);
text-align: center;
color: #fff;
font-size: 0.32rem;
line-height: 0.88rem;
margin-top: 0.36rem;
}
</style>