xuruiqian
2025-06-04 17ce21955b4e3402d3d5868b52e50bfdd55bc572
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<template>
    <view class="wh-full">
        <useNavbar title="分类"></useNavbar>
 
        <!-- 头部组件 -->
        <useHeader :fixed="headerFixed" :placeholder="headerPlaceholder" type="gray" :search-tip="searchTip"
                   :search-auto="searchAuto"></useHeader>
 
        <!-- 分类 -->
        <view class="category dflex-s h-full padding-top-big">
            <!-- 左侧一级分类 -->
            <view class="h-full left padding-tb-16">
                <scroll-view class="h-full" scroll-y="true" :scroll-top="scrollTop"
                             :scroll-with-animation="true">
                    <view v-for="(item,index) in fdatas" :key="index" class="item dflex-c"
                          :class="{'ac':active == index}">
                        <text @click="selectcategoryproduct(item,index)"> {{ item.name }}</text>
                    </view>
                </scroll-view>
            </view>
 
            <!-- 右侧 1二级分类 2商品列表 -->
            <scroll-view class="h-full right" scroll-with-animation scroll-y :scroll-top="top"
                         :style="{ height: scrollHeight, padding: 0 , width: '100%', backgroundColor: 'transparent'}"
                         @scroll="onScroll">
                <view v-for="(item,index) in children" :key="index" class="item dflex-c" style="width: 100%;"
                      :class="{'ac':active == index}">
                    <view class="limit-area use-area margin-lr-sm" style="width: 100%;">
                        <text style="font-size: 15px;font-weight: bold;">{{ item.name }}</text>
                        <u-row v-if="item.children.length>0">
                            <u-col span="6" v-for="(i,indexs) in item.children" @click="getproducts(i,indexs)">
                                <view style="text-align: center;">
                                    <image class="flex1" mode="heightFix" style="margin-top: 10px;width: 100%;"
                                           src="https://www.wisdomdeliver.com/d335a9db-464f-4123-9f2f-66e36e800489/others/20221022/d3de83ae-41b2-4ec3-bec5-38f0417cd196.jpg">
                                    </image>
                                </view>
                                <view style="text-align: center;">
                                    {{i.name}}
                                </view>
                            </u-col>
                        </u-row>
                        <u-empty v-else text="暂无更多数据!" mode="data"></u-empty>
                    </view>
                </view>
            </scroll-view>
 
            <!-- 置顶 -->
            <use-totop ref="usetop" type="tabbar" bottom="150" :top="10" :style="{ marginBottom: navHeight + 'px' }"
                       @to="totop"></use-totop>
        </view>
        <template>
            <view>
                <u-popup v-model="show" mode="bottom" width="50px" height="400px">
                    <view v-if="productformation">
                        <view style="margin-top: 80px;">
                            <u-row>
                                <u-col span="1">
                                    <view>
                                        <image :src="productformation.img" mode="aspectFill"
                                               style="height: 80px;width: 80px;">
                                        </image>
                                    </view>
                                </u-col>
                                <u-col span="8">
                                    <view style="margin-left: 150px;margin-top: -90px;">
                                        <view>名称:{{productformation.productname}}</view>
                                        <view>价格:{{productformation.price}}元</view>
                                    </view>
                                </u-col>
                            </u-row>
                        </view>
                        <!--     <view>颜色:</view> -->
                        <view style="margin-left: 20px;">
                            <u-row>
                                尺码:
                            </u-row>
                            <u-row>
                                <view>
                                    <u-radio-group v-model="value">
                                        <text @change="radioChange" v-for="(item, index) in chima" :name="item"
                                              style="width: 50px; border-radius: 30%; border-style:solid;text-align: center;margin-left: 20px;margin-top: 5px;">
                                            {{item}}
                                        </text>
                                    </u-radio-group>
 
                                </view>
                            </u-row>
                        </view>
                    </view>
                    <view style=": 1px;">
                        <button @click="addshoppbus">加入购物车</button>
                        <button>立即购买</button>
                    </view>
                </u-popup>
            </view>
        </template>
 
        <!-- 切换模式 1二级分类 2商品列表 -->
        <view class="fixed-top" :style="{ marginBottom: navHeight + 'px' }" @click="changeMode">
            <text class="iconfont iconpailie" v-if="mode == 1"></text>
            <text class="iconfont iconpailie02" v-if="mode == 2"></text>
        </view>
    </view>
</template>
 
<script>
    import {ref, reactive, toRefs, onMounted, getCurrentInstance} from "vue";
    import {onShow} from "@dcloudio/uni-app";
    import {useBasicInfoStore} from "../../store/basicInfo";
    import {GetProductCategoryListByParentName, GetProductListByCategoryId} from '../../apis/api';
    import {useNavbar} from "../../components/use-navbar/use-navbar.vue";
    import {useHeader} from "../../components/use-header/use-header.vue";
 
    export default {
        components: {useNavbar, useHeader},
        setup() {
            const userStore = useBasicInfoStore()
            const {proxy} = getCurrentInstance();
            const state = reactive({
                categories: [],
                category: userStore.category,
                products: [],
                // 1分类列表 2商品列表
                mode: 2,
                // 兼容支付宝 height 显示 bug
                scrollHeight: '100%',
                active: 0,
                scrollTop: 0,
                height: 0,
                // 头部参数
                headerPlaceholder: 0,
                headerFixed: !0,
                searchAuto: !0,
                searchTip: '请输入搜索关键字',
                // 当前选中分类ID
                value: 1,
                needcount: "",
                cid: 0,
                cname: '',
                categoryids: [],
                // 一级数据
                fdatas: [],
                // 二级数据
                children: [],
                secchildren: [],
                categoryDatas: [],
                categoryEmpty: false,
                show: false,
                needpayproducts: [],
                // 商品列表
                goodsDatas: [],
                chima: ["39", "40", "41", "42", "43",],
                empty: false,
                hasmore: 0,
                productformation: [],
                loadmoreType: 'nomore',
                // 商品请求数据
                reqdata: {
                    rows: 20,
                    page: 1
                },
 
                top: 0,
                navHeight: 0
            })
 
            onMounted(() => {
                Init();
                loadProductCategories();
            });
 
            onShow((option) => {
                console.log(option); // 获取url中query部分的参数
            })
 
            const Init = () => {
 
            }
 
            const loadProductCategories = () => {
                state.categories = [];
 
                GetProductCategoryListByParentName("家政服务").then(resp => {
                    if (resp.data) {
                        state.categories = resp.data;
                        if (state.categories) {
                            if (!state.category) {
                                state.category = state.categories.shift();
                                console.log(state.category);
                            }
 
                            loadProductListByCategoryId(state.category.id);
                        }
                    }
                }).catch(err => {
                    console.error(err);
                });
            }
 
            const loadProductListByCategoryId = (categoryid) => {
                state.products = [];
 
                GetProductListByCategoryId(categoryid).then(resp => {
                    if (resp.data) {
                        state.products = resp.data;
                    }
                }).catch(err => {
                    console.error(err);
                });
            }
 
            const onProductClick = (product) => {
                let params = {
                    id: product.id
                }
 
                uni.navigateTo({
                    url: `/pages/product/index?data=${encodeURIComponent(JSON.stringify(params))}`,
                });
 
                // proxy.$refs.uToast.success(`点击了${product.name}`)
            }
 
            return {...toRefs(state), userStore, onProductClick}
        }
    }
</script>
 
<style scoped lang="scss">
    page {
        height: 100%;
        background-color: $page-color-base;
    }
 
    .category {
        overflow: hidden;
 
        .left {
            width: 180 rpx;
            background-color: $page-color-base;
 
            .item {
                font-size: 28 rpx;
                height: 100 rpx;
                color: $font-color-base;
                position: relative;
 
                &.active {
                    color: $uni-color-primary;
                    font-size: 38 rpx;
                    font-weight: 580;
                }
            }
        }
 
        .addbutton {
            height: 28px;
            width: 20px;
            background-color: red;
            margin-left: 150px;
            border-radius: 50%;
            margin-top: 25px;
            line-height: 28px;
 
 
        }
 
        .right {
            flex: 1;
            overflow: hidden;
            display: block;
 
            .item {
                flex-shrink: 0;
                width: 33.33%;
                font-size: $font-sm + 2upx;
                color: #666;
 
                image {
                    width: 130 rpx;
                    height: 130 rpx;
                }
            }
        }
    }
 
    .goods {
        display: flex;
 
        .goods-left {
            image {
                width: 120 rpx;
                height: 120 rpx;
            }
        }
 
        .price-box {
            bottom: 0;
        }
    }
</style>