search.vue 2.11 KB
<template>
    <layout-body class="product-search">
        <search-bar class="product-search-bar" @cancel="cancel" v-model="search"></search-bar>
        <div class="frames">
            <iframe ref="ifr" name="iframe" :src="searchUrl" frameborder="0" v-if="showIframe"></iframe>
        </div>
    </layout-body>
</template>

<script>
import SearchBar from 'components/search/search-bar';
import {mapState} from 'vuex';

export default {
    name: 'Search',
    data() {
        return {
            searchKey: '',
            search: '',
            showIframe: false
        };
    },
    beforeRouteUpdate(to, from, next) {
        this.searchKey = to.query.query;
        this.search = to.query.query;
        next();
    },
    created() {
        this.searchKey = this.$route.query.query;
        this.search = this.$route.query.query;
    },
    mounted() {
        window.blkDocument = {
            goNewPage:({url}) => {
                const $appLink = document.querySelector('#yoho-app-link');

                $appLink.href = url;
                $appLink.click();
                if (this.$yoho.isiOS) {
                    $appLink.click();
                }
            }
        };
        window.yohoInterface = window.yohoInterface;
        this.$bus.$on('after-view-enter', () => {
            this.showIframe = true;
        });
        if (this.yoho.env.fs) {
            this.showIframe = true;
        }
    },
    computed: {
        ...mapState(['yoho']),
        searchUrl() {
            return `/search?query=${this.searchKey}`;
        }
    },
    methods: {
        cancel() {
            this.$yoRouter.goBack(-1);
        },
        loadYohoInterface() {
            // this.$yoho.ready(() => {

            // });
        }
    },
    components: {SearchBar}
};
</script>

<style lang="scss">
.product-search {
    display: flex;
    flex-direction: column;
}
.product-search-bar {
    height: 90px;
}
.frames {
    position: absolute;
    top: 90px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    iframe {
        width: 100%;
        height: 100%;
    }
}
</style>