Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #117 from ntutshop/develop/search
Browse files Browse the repository at this point in the history
Develop search function
  • Loading branch information
yaoandy107 committed Jan 13, 2019
2 parents 474c053 + 0b4ee30 commit 968fdff
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 52 deletions.
35 changes: 3 additions & 32 deletions components/good/good-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:label="item.title"
>
<good
v-for="(item, index) in goodList"
v-for="(item, index) in list"
:key="index"
:meta="item"
/>
Expand All @@ -25,12 +25,12 @@ export default {
props: {
list: {
type: Array,
default () {
default() {
return []
}
}
},
data () {
data() {
return {
orderLabel: [
{
Expand All @@ -45,37 +45,8 @@ export default {
{
title: '評價最高'
}
],
goodList: [
{
name: '雲南菜',
imgUrl:
'http://p1.meituan.net/600.600/deal/dd5fb74439b6601228cf0cb4d9275889323455.jpg@220w_125h_1e_1c',
rate: 5,
owner: 'Andy Meow',
price: 238,
type: '食物'
},
{
name: '雲南菜',
imgUrl:
'http://p1.meituan.net/600.600/deal/dd5fb74439b6601228cf0cb4d9275889323455.jpg@220w_125h_1e_1c',
rate: 5,
owner: 'Andy Meow',
price: 238,
type: '食物'
}
]
}
},
async asyncData ({ app }) {
let { data } = await app.$axios.get('searchList')
return { items: data.list }
},
methods: {
navSelect: function () {
console.log('select')
}
}
}
</script>
Expand Down
5 changes: 4 additions & 1 deletion components/good/good.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ export default {
props: {
meta: {
type: Object,
default () {
default() {
return {}
}
}
},
created() {
console.log(this.meta)
}
}
</script>
Expand Down
4 changes: 4 additions & 0 deletions components/index/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"uid": "yGk4p9RPWkgT56IBeYnAro1IJeU2",
"apiKey": "AIzaSyDlcf8iUDzlJ9mVEiCR8tLR51pD1HeUqvs"
}
16 changes: 4 additions & 12 deletions components/public/header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@
:span="8"
class="search"
>
<el-autocomplete
v-model="value"
:fetch-suggestions="querySearchAsync"
placeholder="請輸入內容"
@select="handleSelect"
>
<el-button
slot="append"
icon="el-icon-search"
/>
</el-autocomplete>
<search-bar/>
</el-col>
<el-col :span="8">
<v-layout>
Expand All @@ -54,11 +44,13 @@
import Navbar from './nav.vue'
import User from './user.vue'
import Cart from './cart.vue'
import SearchBar from './search.vue'
export default {
components: {
Navbar,
User,
Cart
Cart,
SearchBar
},
props: {
prominent: {
Expand Down
36 changes: 34 additions & 2 deletions components/public/header/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,49 @@
v-model="value"
:fetch-suggestions="querySearchAsync"
placeholder="請輸入內容"
@select="handleSelect"
@select="searchCommit"
>
<el-button
slot="append"
icon="el-icon-search"
@click="searchCommit"
/>
</el-autocomplete>
</el-col>
</div>
</template>

<style lang="scss">
<script>
export default {
data() {
return {
value: '',
timeout: null
}
},
methods: {
async querySearchAsync(queryString, callback) {
let { data } = await this.$axios.get(`/goods?keyword=${queryString}`)
let searchResult = []
data.forEach(element => {
searchResult.push({
value: element.name,
id: element.id
})
})
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
callback(searchResult)
}, 1000 * Math.random())
},
searchCommit(item) {
this.$router.push({
path: `/good/${item.id}`
})
}
}
}
</script>

<style lang="scss">
</style>
Loading

0 comments on commit 968fdff

Please sign in to comment.