quanwei
2025-10-31 7a27a1d4d0038abe2115adb1753f897f56d66323
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
<template>
    <view class="search-wrap">
 
        <!-- 搜索框 -->
        <view class="index-search-box d-b-c" id="searchBox">
            <view class="index-search t-c flex-1">
                <span class="icon iconfont icon-sousuo"></span>
                <input type="text" v-model="form.keyWord" class="flex-1 ml10 f30 gray3" value="" placeholder-class="f24 gray6"
                 placeholder="输入你要的商品" confirm-type="search" @confirm="search()"/>
            </view>
            <!--<button class="btn ml10" @click="search()" type="default">搜索</button>-->
        </view>
 
        <!-- <view class="p-0-20 bg-white">
            <view class="group-hd">
                <view class="left"><text class="min-name">最近搜索</text></view>
                <view class="right">
                    <span class="icon iconfont icon-lajitong" @click='clearStorage'></span>
                </view>
            </view>
            <view class="before-search">
                <text class="item" v-for="(item,index) in arr" :key="index" @click="search(arr[index])">{{arr[index]}}</text>
            </view>
        </view> -->
 
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                form: {
                     
                },
                arr:[],
                shop_supplier_id: ''
            }
        },
        mounted() {
            /*获取缓存数据*/
            this.getData();
        },
        onLoad(option) {
            let self = this;
            self.GetStatusBarHeight();
            self.shop_supplier_id = option.shop_supplier_id;
        },
        methods: {
            /*获取缓存里的搜索历史*/
            getData(){
                let self=this;
                /*获取搜索记录*/
                uni.getStorage({
                    key: 'search_list',
                    success: function (res) {
                        if(res!=null&&res.data!=null){
                            self.arr = res.data;
                        }
                    }
                });
 
            },
            /*搜索*/
            search(str) {
                let self = this;
                let search=null;
                if(str!=null){
                    search=str;
                }else{
                    search= this.form.keyWord;
                    let arrs=this.arr;
                    if(typeof search != "undefined" && search!=null && search!=''){
                        arrs.push(search);
                    }else{
                        uni.showToast({
                            title: '请输入搜索的关键字',
                            icon: 'none',
                            duration: 2000
                        });
                        return false;
                    }
                    /*设置搜索记录*/
                    uni.setStorage({
                        key: 'search_list',
                        data: arrs,
                        success: function () {
                            console.log('success');
                        }
                    });
                }
                let category_id = 0;
                let sortType = 'all';
                
                self.gotoPage('/pages/product/list/list?search=' + search + '&category_id=' + category_id + '&sortType=' + sortType + '&shop_supplier_id=' + self.supplier_id);
                
            },
            /*清楚缓存*/
            clearStorage(){
                let self=this;
                uni.removeStorage({
                    key: 'search_list',
                    success: function (res) {
                        self.arr=[];
                    }
                });
            }
        }
    }
</script>
 
<style>
    .search-wrap .index-search-box .search-box {
            padding: 0 20rpx;
            height: 64rpx;
            line-height: 64rpx;
            background: #f7f7f7;
            border-radius: 50rpx;
            overflow: hidden;
            font-size: 28rpx;
            color: #999;
            box-sizing: border-box;
        }
        .search-wrap .index-search-box button{ height: 78rpx; line-height: 78rpx; border:solid 1rpx #CCCCCC; color:#333333; background: #FFFFFF;}
    
        .before-search {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            flex-flow: wrap;
        }
    
        .before-search .item {
            padding: 16rpx;
            margin-right: 16rpx;
            margin-bottom: 16rpx;
            border-radius: 8rpx;
            color: #686868;
            background: #f0f2f5;
            font-size: 24rpx;
        }
</style>