category.vue
3.3 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
<template>
<view class="cateGory">
<view class="top">
<image src="../../static/ic-back-false.png" mode="" @click="back"></image>
<view class="search">
<view class="tosear">
<input type="text" value="" placeholder="搜索"
placeholder-style="text-align: center;font-size: 28rpx; color: rgba(194,194,194,1);"
v-model="keyword" @confirm="gosourch" />
<image src="../../static/icon-search.png" mode="" v-if="!keyword"></image>
</view>
</view>
</view>
<view style="margin-top: 100rpx;">
<u-index-list :index-list="indexList">
<template v-for="(item, index) in itemArr">
<!-- #ifdef APP-NVUE -->
<u-index-anchor :text="indexList[index]"></u-index-anchor>
<!-- #endif -->
<u-index-item>
<!-- #ifndef APP-NVUE -->
<u-index-anchor :text="indexList[index]"></u-index-anchor>
<!-- #endif -->
<view class="list-cell" v-for="(cell, index) in item" @click="tolist(cell.id)">
<image :src="cell.image_preview" mode=""></image>
{{cell.name}}
</view>
</u-index-item>
</template>
</u-index-list>
</view>
</view>
</template>
<script>
import {
sort_all
} from '@/api/index.js'
export default {
data() {
return {
indexList: [],
itemArr: [],
keyword: '',
}
},
onLoad() {
this.sort_all()
},
methods: {
//返回
back() {
uni.redirectTo({
url: "/pages/index/index"
})
},
//搜索
gosourch() {
this.itemArr = []
this.sort_all()
},
//跳转列表
tolist(e) {
uni.navigateTo({
url: "/pages/index/product?sort_id="+e
})
},
//分类列表
async sort_all() {
try {
const res = await sort_all(this.keyword)
console.log('sort_all', res)
this.indexList = res.word
let list = res.list
list.forEach((item, index) => {
this.itemArr.push(item.sort_list)
})
// 保存数据
} catch (err) {
uni.showToast({
title: err,
icon: 'none'
})
console.log('sort_all', err)
}
},
}
}
</script>
<style lang="scss" scoped>
.cateGory {
.top {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 99;
height: 96rpx;
opacity: 1;
background: rgba(255, 255, 255, 1);
padding: 16rpx 32rpx;
display: flex;
box-sizing: border-box;
align-items: center;
image {
margin-right: 32rpx;
width: 48rpx;
height: 48rpx;
}
.search {
flex: 1;
display: flex;
align-items: center;
.tosear {
position: relative;
width: 522rpx;
height: 64rpx;
border-radius: 38rpx;
opacity: 1;
border: 0 solid rgba(0.5920000076293945, 0.5920000076293945, 0.5920000076293945, 1);
background: rgba(245, 245, 245, 1);
padding: 0 32rpx;
input {
text-align: center;
width: 100%;
height: 100%;
}
image {
position: absolute;
left: 280rpx;
top: 50%;
left: 36%;
transform: translateY(-50%);
width: 32rpx;
height: 32rpx;
}
}
}
}
.list-cell {
display: flex;
align-items: center;
box-sizing: border-box;
width: 100%;
padding: 10px 24rpx;
overflow: hidden;
color: #323233;
font-size: 14px;
line-height: 24px;
background-color: #fff;
image {
margin-right: 16rpx;
width: 80rpx;
height: 80rpx;
}
}
}
</style>