移动系统liao
2024-05-15 d7c7a6e9d05eec7b38b41b8ae39f373f650ca891
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
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="搜索" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <view class="coreshop-padding-15 coreshop-margin-bottom-15 coreshop-bg-white coreshop-solid-bottom">
            <u-search placeholder="请输入关键字搜索" v-model="key" :show-action="true" action-text="搜索" :animation="false" @search="search" @custom="search"></u-search>
        </view>
 
        <!--搜索区域-->
        <view class="coreshop-padding-15 coreshop-margin-15">
            <!--搜索记录-->
            <view class="coreshop-margin-bottom-15" v-show="keys.length > 0">
                <coreshop-section title="历史搜索"  font-size="16" sub-title="删除" :arrow="false" @click="deleteKey"></coreshop-section>
                <view class="coreshop-margin-top-15 coreshop-margin-bottom-15 coreshop-flex coreshop-flex-wrap coreshop-flex-direction-row coreshop-justify-start">
                    <view class="coreshop-width-fit-content coreshop-margin-right-5" v-for="(item, key) in keys" :key="key">
                        <u-tag class="coreshop-padding-10" size="mini" :text="item" type="info" @click="toNav(item)" />
                    </view>
                </view>
            </view>
 
            <!--推荐搜索-->
            <view class="coreshop-margin-bottom-15" v-show="recommend && recommend.length > 0">
                <coreshop-section title="推荐搜索" :right="false" font-size="16"></coreshop-section>
                <view class="coreshop-margin-top-15 coreshop-margin-bottom-15 coreshop-flex coreshop-flex-wrap coreshop-flex-direction-row coreshop-justify-start">
                    <view class="coreshop-width-fit-content coreshop-margin-right-5" v-for="(item, key) in recommend" :key="key">
                        <u-tag class="coreshop-padding-10" size="mini" :text="item" type="info" @click="toNav(item)" />
                    </view>
                </view>
            </view>
        </view>
        <!-- 登录提示 -->
        <coreshop-login-modal></coreshop-login-modal>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                keys: [],
                key: '',
                navType: 'toNav',
                focus: true,
            }
        },
        computed: {
            recommend() {
                return this.$store.state.config.recommendKeys
            }
        },
        methods: {
            //搜索
            search: function () {
                let keys = this.key;
                if (keys != '') {
                    let search_key = this.$db.get('search_key');
                    if (!search_key) {
                        search_key = [];
                    }
                    let flag = true;
                    for (var key in search_key) {
                        if (search_key[key] == keys) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        search_key.unshift(keys);
                    }
                    this.$db.set('search_key', search_key);
                    this.$db.set('search_term', keys);
                    this.$u.route('/pages/category/list/list?key=' + keys);
                } else {
                    this.$refs.uToast.show({
                        message: '请输入要查询的关键字',
                        type: 'warning',
                    })
                }
            },
 
            //清除
            deleteKey: function () {
                //删除显示
                this.keys = [];
                //删除存储
                this.$db.del('search_key');
            },
 
            //跳转操作
            toNav: function (keys) {
                this.$db.set('search_term', keys);
                let search_key = this.$db.get('search_key');
                if (!search_key) {
                    search_key = [];
                }
                var flag = true;
                for (var key in search_key) {
                    if (search_key[key] == keys) {
                        flag = false;
                    }
                }
                if (flag) {
                    search_key.unshift(keys);
                }
                this.$db.set('search_key', search_key);
                this.$u.route('/pages/category/list/list?key=' + keys);
            },
        },
        //加载触发
        onShow(e) {
            this.keys = this.$db.get('search_key');
            this.focus = true;
        },
        //页面卸载触发
        onUnload() {
            this.$db.set('search_term', '');
        }
    }
</script>
 
<style lang="scss">
    page { background: #fff; }
</style>