class.vue
3.4 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
<template>
<view class="container flexJ">
<!-- 左边索引 -->
<view class="rightBox">
<view class="rightItem flexC" :class="data.cur == item.id ? 'check' : ''" v-for="(item, index) in data.firstClass" :key="item.id" @click="bindToView(item, index)">{{ item.name }}</view>
</view>
<!-- 右边内容 -->
<scroll-view :enable-flex="true" class="scroller" scroll-y="true" scroll-with-animation="true">
<view class="left" v-for="item in data.titleList">
<view class="title">{{ item.name }}</view>
<view class="shopBpx">
<view class="shop flexV" v-for="it in item.three" :key="it.id" @click="toThreeClassHandler(it.id)">
<image :src="it.image_text" mode=""></image>
<view class="name">{{ it.name }}</view>
</view>
</view>
</view>
</scroll-view>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onShow, onLoad, onHide } from '@dcloudio/uni-app'
import { getTwoClassification } from '@/api/'
let data = reactive({
cur: 0,
firstClass: [], //一级分类
titleList: [] //二级分类名称
})
onShow(() => {
getClassifications()
})
onHide(() => {
console.log(11222)
uni.removeStorage({ key: 'classId' })
data.cur = 0
})
// 左边一级分类点击
const bindToView = (item, index) => {
data.cur = item.id
data.titleList = item.two
}
// 一级分类
const getClassifications = async () => {
try {
const res = await getTwoClassification()
console.log(res, '三级分类')
data.cur = uni.getStorageSync('classId') || 0
data.firstClass = res
if (data.cur === 0) {
data.cur = res[0].id
data.titleList = res[0].two
} else {
data.titleList = res.find(item => item.id === data.cur).two
}
console.log('getClassification', res)
// 保存数据
} catch (err) {
uni.showToast({ title: err, icon: 'none' })
console.log('getClassification', err)
}
}
// 三级分类跳转
const toThreeClassHandler = pid => uni.navigateTo({ url: `/pages/class/classList?pid=${pid}` })
</script>
<style lang="scss">
.container {
width: 100vw;
height: 100vh;
.rightBox {
width: 160rpx;
height: 100vh;
background: #f5f5f5ff;
.rightItem {
width: 160rpx;
height: 104rpx;
background: #f5f5f5ff;
border: 0 solid #979797ff;
}
.check {
width: 160rpx;
height: 104rpx;
border-radius: 32rpx 0 0 32rpx;
opacity: 1;
color: #f43736ff;
font-size: 28rpx;
font-weight: 700;
// border: 0 solid #979797ff;
background: #ffffffff;
}
}
.scroller {
height: 100vh;
width: 100%;
padding: 0 32rpx 0 24rpx;
box-sizing: border-box;
.left {
width: 100%;
padding: 24rpx 24rpx 40rpx;
box-sizing: border-box;
opacity: 1;
background: #ffffffff;
margin-bottom: 24rpx;
.title {
color: #323233ff;
font-size: 28rpx;
font-weight: 700;
margin-bottom: 22rpx;
}
.shopBpx {
width: 100%;
display: flex;
flex-wrap: wrap;
.shop {
width: 162rpx;
margin-bottom: 24rpx;
display: inline-grid;
.name {
color: #646566ff;
font-size: 24rpx;
text-align: center;
}
image {
width: 128rpx;
height: 128rpx;
margin-bottom: 8rpx;
}
}
}
}
}
}
</style>