搜索
This commit is contained in:
parent
357b8d9bd9
commit
cb5efbc0ec
@ -1,8 +1,8 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/index/category",
|
||||
"pages/index/search",
|
||||
"pages/index/category",
|
||||
"pages/shop/show",
|
||||
"pages/order/list",
|
||||
"pages/order/show",
|
||||
|
@ -6,4 +6,4 @@
|
||||
<template is="shop" wx:for="{{list}}" wx:key="{{seller_id}}" data="{{...item}}"></template>
|
||||
</view>
|
||||
|
||||
<template is="load-more" data="{{loading: loading, hasMore: hasMore, noMoreLabel: '更多商家接入中, 敬请期待'}}"></template>
|
||||
<template is="load-more" data="{{loading: loading, hasMore: hasMore, noMoreLabel: '更多商家接入中, 敬请期待'}}"></template>
|
@ -6,9 +6,9 @@
|
||||
<navigator url="./address?callback=callback" class="address trangle">
|
||||
<image class="address__icon" src="/images/location.png"></image>{{currentAddress ? currentAddress.title : '定位中...'}}
|
||||
</navigator>
|
||||
<view class="search">
|
||||
<navigator url="./search" class="search">
|
||||
<icon type="search" size="20" /> 搜索
|
||||
</view>
|
||||
</navigator>
|
||||
</view>
|
||||
<view class="category">
|
||||
<navigator class="category__item" url="/pages/index/category?id={{item.category_id}}" wx:for="{{category}}" wx:key="category_id">
|
||||
|
@ -1,80 +1,154 @@
|
||||
// pages/index/search.js
|
||||
import debounce from '../../utils/debounce'
|
||||
import {
|
||||
search
|
||||
} from '../../utils/apis'
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
inputShowed: false,
|
||||
inputVal: "",
|
||||
page: 0,
|
||||
hasMore: true,
|
||||
loading: false
|
||||
},
|
||||
showInput: function () {
|
||||
this.setData({
|
||||
inputShowed: true
|
||||
});
|
||||
},
|
||||
hideInput: function () {
|
||||
this.setData({
|
||||
inputVal: "",
|
||||
inputShowed: false
|
||||
});
|
||||
},
|
||||
clearInput: function () {
|
||||
this.setData({
|
||||
inputVal: ""
|
||||
});
|
||||
},
|
||||
inputTyping: function (e) {
|
||||
var {value} = e.detail
|
||||
this.setData({
|
||||
inputVal: value,
|
||||
page: 0,
|
||||
hasMore: true,
|
||||
loading: false
|
||||
});
|
||||
if (value) {
|
||||
this.loadData()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
|
||||
this.inputTyping = debounce(this.inputTyping, 300)
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
var {loading, hasMore} = this.data
|
||||
if (hasMore && !loading) {
|
||||
this.loadData()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
|
||||
},
|
||||
loadData() {
|
||||
var that = this
|
||||
var {id: category_id} = this
|
||||
var {
|
||||
loading, page,
|
||||
inputVal: keyword
|
||||
} = this.data
|
||||
if (loading) {
|
||||
return
|
||||
}
|
||||
that.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
search({
|
||||
keyword, page,
|
||||
success(data) {
|
||||
var {list} = that.data
|
||||
var {
|
||||
list: list2, count, page
|
||||
} = data
|
||||
list2 = list2.map(item => {
|
||||
item['distanceFormat'] = (item.distance / 1000).toFixed(2)
|
||||
return item
|
||||
})
|
||||
that.setData({
|
||||
loading: false,
|
||||
list: list ? list.concat(list2) : list2,
|
||||
hasMore: count == 10,
|
||||
page: +page + 1
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
})
|
@ -1 +1,3 @@
|
||||
{}
|
||||
{
|
||||
"navigationBarTitleText": "搜索"
|
||||
}
|
@ -1,2 +1,27 @@
|
||||
<!--pages/index/search.wxml-->
|
||||
<text>pages/index/search.wxml</text>
|
||||
<import src="/templates/load-more.wxml" />
|
||||
<import src="templates/shop.wxml" />
|
||||
<import src="templates/goods.wxml" />
|
||||
<view class="weui-search-bar">
|
||||
<view class="weui-search-bar__form">
|
||||
<view class="weui-search-bar__box">
|
||||
<icon class="weui-icon-search_in-box" type="search" size="14"></icon>
|
||||
<input type="text" class="weui-search-bar__input" placeholder="搜索" value="{{inputVal}}" focus="{{inputShowed}}" bindinput="inputTyping" />
|
||||
<view class="weui-icon-clear" wx:if="{{inputVal.length > 0}}" bindtap="clearInput">
|
||||
<icon type="clear" size="14"></icon>
|
||||
</view>
|
||||
</view>
|
||||
<label class="weui-search-bar__label" hidden="{{inputShowed}}" bindtap="showInput">
|
||||
<icon class="weui-icon-search" type="search" size="14"></icon>
|
||||
<view class="weui-search-bar__text">搜索</view>
|
||||
</label>
|
||||
</view>
|
||||
<view class="weui-search-bar__cancel-btn" hidden="{{!inputShowed}}" bindtap="hideInput">取消</view>
|
||||
</view>
|
||||
<view wx:if="{{inputVal}}">
|
||||
<view class="search-list">
|
||||
<template is="{{item.goods_id ? 'goods' : 'shop'}}" wx:for="{{list}}" wx:key="{{index}}" data="{{...item}}"></template>
|
||||
</view>
|
||||
|
||||
<template is="load-more" data="{{loading: loading, hasMore: hasMore}}"></template>
|
||||
</view>
|
@ -1 +1,7 @@
|
||||
/* pages/index/search.wxss */
|
||||
/* pages/index/search.wxss */
|
||||
@import '/templates/load-more.wxss';
|
||||
@import './templates/shop.wxss';
|
||||
|
||||
.search-list {
|
||||
margin-top: 10px;
|
||||
}
|
13
app/pages/index/templates/goods.wxml
Normal file
13
app/pages/index/templates/goods.wxml
Normal file
@ -0,0 +1,13 @@
|
||||
<template name="goods">
|
||||
<navigator url="/pages/shop/show?id={{seller_id}}" class="weui-media-box weui-media-box_appmsg shop__item" hover-class="weui-cell_active">
|
||||
<view class="weui-media-box__hd weui-media-box__hd_in-appmsg">
|
||||
<image class="weui-media-box__thumb" src="{{pic_url}}" />
|
||||
</view>
|
||||
<view class="weui-media-box__bd weui-media-box__bd_in-appmsg">
|
||||
<view class="weui-media-box__title">{{goods_name}}({{seller_name}})</view>
|
||||
<view class="weui-media-box__desc goods__desc">
|
||||
<view>月售 {{sales}} 单</view>
|
||||
</view>
|
||||
</view>
|
||||
</navigator>
|
||||
</template>
|
0
app/pages/index/templates/goods.wxss
Normal file
0
app/pages/index/templates/goods.wxss
Normal file
@ -517,3 +517,33 @@ export function getSellersByCategory(options) {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// 搜索商家和商品
|
||||
export function search(options) {
|
||||
var {
|
||||
keyword, page,
|
||||
success, error
|
||||
} = options
|
||||
page = page || 0
|
||||
getApp().getCurrentAddress(address => {
|
||||
var {
|
||||
location: {longitude, latitude},
|
||||
city_id,
|
||||
city: city_name,
|
||||
district_id,
|
||||
district: district_name
|
||||
} = address
|
||||
fetch({
|
||||
url: 'index.php?m=Mall&c=Seller&a=search',
|
||||
data: {
|
||||
keyword,
|
||||
city_id, city_name,
|
||||
district_id, district_name,
|
||||
page,
|
||||
longitude, latitude
|
||||
},
|
||||
success, error
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user