<template>
  <div class="container" id="searchResult">
    <search-title :keyword="key" @showAction="showAction" @typeAction="onTypeChanged"></search-title>
    <store-content v-show="show" @pageAction="onPageChanged"></store-content>
  </div>
</template>
<script>
  import { SearchTitle, StoreContent } from '~components/searchStore'
  export default {
    layout: 'main',
    components: {
      SearchTitle,
      StoreContent
    },
    data () {
      return {
        key: this.$route.query.w,
        show: true,
        type: 'AGENCY-DISTRIBUTION-ORIGINAL_FACTORY'
      }
    },
    fetch ({store, route}) {
      return Promise.all([
        store.dispatch('searchStore/searchStoreDetail', {page: 1, count: 8, keyword: route.query.w, types: 'AGENCY-DISTRIBUTION-ORIGINAL_FACTORY', op: 'pageByType'})
      ])
    },
    methods: {
      showAction: function (show) {
        this.show = show
      },
      onPageChanged: function (page) {
        this.$store.dispatch('searchStore/searchStoreDetail', {page: page, count: 8, keyword: this.$route.query.w, types: this.type, op: 'pageByType'})
      },
      onTypeChanged: function (type) {
        this.type = type
      }
    }
  }
</script>

