lin
2026-05-25 9e8dc1c9e3ac624bd3b71d991f7b3a7d7ccb2ec9
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
<template>
    <view>
        <view class="search">
            <view class="searchView">
                <span class="back" @tap="$util.goSwitch('/pages/index/index')">返回</span>
                <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="searchKey" v-if="goodsData.length == 0">
            <view class="">
                <view class="title">搜索历史</view>
                <view class="item" v-if="keywordData.length > 0">
                    <view class="" v-for="(item, index) in keywordData" v-if="index <= 19" @tap="keywordSearch(item)">{{item}}</view>
                </view>
                <view class="noData" v-else>
                    <image src="/static/imgs/noData.png" mode="" style="margin-top: 200upx;"></image>
                    <view class="">没有搜索记录</view>
                </view>
            </view>
        </view>
        <view class="goodsData" v-else>
            <view class="goods-list">
                <view class="goods-item" v-for="(itm, idx) in goodsData" @click="$util.goPages('/pages/ginfo/ginfo?id=' + itm.id)">
                    <image lazy-load class="goods-icon" :src="itm.icon" mode="widthFix"></image>
                    <view class="goods-title">{{itm.title}}</view>
                    <view class="goods-price">
                        <view>¥</view>
                        <view class="red">{{itm.price}}</view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                keyword: '',
                catesId: 0,
                pageIndex: 1,
                pageSize: 200,
                goodsData: [],
                keywordData: uni.getStorageSync('keyword') ? JSON.parse(uni.getStorageSync('keyword')) : [],
            }
        },
        onLoad() {
        },
        methods: {    
            keywordSearch (e){
                this.keyword = e
                this.searchGoods()
            },
            //获取分类商品
            searchGoods(){
                if(this.keyword != ''){
                    if(this.keywordData.indexOf(this.keyword) < 0){
                        this.keywordData.unshift(this.keyword)
                        uni.setStorageSync('keyword', JSON.stringify(this.keywordData))
                    }
                    this.$util.post('Goods/getCatesGoods', {keyword: this.keyword, pageIndex: this.pageIndex, pageSize: this.pageSize}).then(res => {
                        if(res.code == 1) {
                            this.goodsData = res.data.list
                        }
                    })
                } else {
                    this.goodsData = []
                }
            }    
        }
    }
</script>
 
<style>
    @import url(/static/css/search.css);
</style>