lin
2026-04-24 bea9e52d5a1f56d9ca26a30ea121122def824b3d
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
<template>
    <view>
        <view class="search">
            <view class="searchView">
                <image src="/static/imgs/search.png" mode=""></image>
                <input type="text" v-model="keyword" placeholder="搜索您想要的商品" @confirm="searchGoods" />
                <view class="searchBtn" @tap="searchGoods">搜索</view>
            </view>
        </view>
        <view class="catesMain">
            <view class="cates-left" :style="'height:' + scrollHeight + 'px'">
                <scroll-view scroll-y="true" class="scroll-Y">
                    <view :class="catesId == 0 ? 'active' : ''" @click="catesClick(0)">全部商品</view>
                    <view v-for="(item, index) in catesData" @click="catesClick(item)" :class="catesId == item.id ? 'active' : ''">{{item.title}}</view>
                </scroll-view>
            </view>
            <view class="cates-right" :style="'width:' + goodsWidth + 'px;height:' + (scrollHeight - 10) + 'px;margin-top: 20upx'" v-if="goodsData.length > 0">
                <scroll-view scroll-y="true" class="scroll-Y">
                    <view class="goods-list">
                        <view class="goods-item" v-for="(item, index) in goodsData" :style="'width:' + goodsItemWidth + 'px;'" @click="$util.goPages('/pages/ginfo/ginfo?id=' + item.id)">
                            <image class="goods-icon" :src="item.icon" mode=""></image>
                            <view class="goods-title">{{item.title}}</view>
                            <view class="goods-price">
                                <view>¥</view>
                                <view class="red">{{item.price}}</view>
                            </view>
                        </view>
                    </view>
                </scroll-view>
            </view>
            <view class="noData" v-else>
                <image src="/static/imgs/noData.png" style="margin-left: 50%;" mode=""></image>
                <view class="" style="margin-left: 120upx; width: auto;">没有商品信息</view>
            </view>
            
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                keyword: '',
                catesData: [],
                goodsData: [],
                scrollHeight: 0,
                goodsWidth: 0,
                goodsItemWidth: 0,
                catesId: 0,
                pageIndex: 1,
                pageSize: 200,
            }
        },
        onLoad() {
            this.getCatesData()
        },
        onReady() {
 
        },
        methods: {
            
            searchGoods () {
                this.getCatesGoods()
            },
            //获取分类数据
            getCatesData() {
                this.$util.post('Cates/getCates', {catesId: this.catesId, pageIndex: this.pageIndex, pageSize: this.pageSize}).then(res => {
                    if(res.code == 1) {
                        console.log('catesData',res)
                        this.catesData = res.data.list
                        this.getCatesGoods()
                    }
                })
            },
            //分类点击
            catesClick (e) {
                if(e == 0) {
                    this.catesId = e
                } else {
                    this.catesId = e.id
                }
                this.pageIndex = 1
                this.getCatesGoods()
            },
            //获取分类商品
            getCatesGoods(){
                this.$util.post('Goods/getCatesGoods', {keyword: this.keyword, catesId: this.catesId, pageIndex: this.pageIndex, pageSize: this.pageSize}).then(res => {
                    if(res.code == 1) {
                        this.goodsData = res.data.list
                    }
                })
            }        
        },
        // 计算swiper的高度
        mounted() {
            let t = this
            let headerSearchHeight = 0
            // 头部搜索height
            let headerSearchView = uni.createSelectorQuery().select('.search')
            headerSearchView
            .boundingClientRect((data) => {
                headerSearchHeight = data.height
            }).exec()
            
            // 左侧scroll宽度
            let catesWidth = 0
            let catesLeftView = uni.createSelectorQuery().select('.cates-left')
            catesLeftView
            .boundingClientRect((data) => {
                catesWidth = data.width
            }).exec()
            
            setTimeout(() => {
                // scroll-height
                uni.getSystemInfo({
                    success: (res) => {
                        t.scrollHeight = res.windowHeight - headerSearchHeight
                        t.goodsWidth = res.windowWidth - catesWidth
                        let mlW = res.windowWidth * 0.05
                        t.goodsItemWidth = (res.windowWidth - mlW - catesWidth) / 2
                    }
                })
            }, 300)
            
        }
    }
</script>
 
<style>
    @import url(/static/css/cates.css);
</style>