You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
4.1 KiB
219 lines
4.1 KiB
// pages/search/list/index.js
|
|
import commonApi from "../../../utils/https/common"
|
|
import util from "../../../utils/util"
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
typeIndex:0,
|
|
oldKeyword:"",
|
|
list:[],
|
|
total:1,
|
|
types:[{
|
|
name:"全部",
|
|
key:""
|
|
},
|
|
{
|
|
name:"景点",
|
|
key:"scenic"
|
|
},
|
|
{
|
|
name:"门票",
|
|
key:"ticket"
|
|
},
|
|
{
|
|
name:"线路",
|
|
key:"line"
|
|
},
|
|
{
|
|
name:"场馆",
|
|
key:"venue"
|
|
},
|
|
{
|
|
name:"特产",
|
|
key:"post"
|
|
},
|
|
{
|
|
name:"美食",
|
|
key:"food"
|
|
},
|
|
// {
|
|
// name:"酒店",
|
|
// key:"room"
|
|
// },
|
|
{
|
|
name:"活动",
|
|
key:"activity"
|
|
},
|
|
{
|
|
name:"游记",
|
|
key:"travels"
|
|
},
|
|
{
|
|
name:"卡券",
|
|
key:"coupon"
|
|
}],
|
|
lon:"",
|
|
lat:""
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
oldKeyword:options.keyword,
|
|
keyword:options.keyword
|
|
})
|
|
let _this = this;
|
|
wx.getLocation({
|
|
type: 'gcj02',
|
|
success:function(res){
|
|
_this.setData({
|
|
lon:res.longitude,
|
|
lat:res.latitude
|
|
})
|
|
console.log(res)
|
|
_this.getList()
|
|
},
|
|
fail:function(){
|
|
_this.getList()
|
|
}
|
|
})
|
|
|
|
},
|
|
gotoDetail:function(e){
|
|
let item = e.currentTarget.dataset.item;
|
|
this.pagePoint({
|
|
event:'search_result_click',
|
|
id:item.ext.id,
|
|
type:item.type
|
|
},1)
|
|
if(item.type=='travels'){
|
|
// 游记做特殊处理 其他都按照原来的来
|
|
wx.navigateTo({
|
|
url: '/pages/info/strategyInfo/index?id='+item.s_id
|
|
})
|
|
}
|
|
else {
|
|
util.gotoDetail(item.ext);
|
|
}
|
|
},
|
|
changeType:function(e){
|
|
this.setData({
|
|
typeIndex:e.currentTarget.dataset.index,
|
|
list:[],
|
|
total:1
|
|
})
|
|
this.getList()
|
|
},
|
|
inputKeyword:function(e){
|
|
this.setData({
|
|
oldKeyword:e.detail.value
|
|
})
|
|
},
|
|
getList:function(){
|
|
let list = this.data.list;
|
|
if(list.length>=this.data.total) return;
|
|
commonApi._post("search/search",{
|
|
name:this.data.keyword,
|
|
offset:list.length,
|
|
limit:10,
|
|
lat:this.data.lat,
|
|
lon:this.data.lon,
|
|
type:this.data.types[this.data.typeIndex].key
|
|
}).then(res=>{
|
|
res.data.list.map(item=>{
|
|
if(item && item.ext && item.ext.display_tags){
|
|
item.ext.display_tags = item.ext.display_tags.split(",").splice(0,2)
|
|
}
|
|
else {
|
|
item.ext.display_tags = []
|
|
}
|
|
})
|
|
this.setData({
|
|
list:list.concat(res.data.list),
|
|
total:res.data.total
|
|
})
|
|
console.log(res)
|
|
})
|
|
},
|
|
search:function(){
|
|
if(!this.data.oldKeyword) {
|
|
wx.showToast({
|
|
title: '请输入搜索词',
|
|
icon:'none'
|
|
})
|
|
return;
|
|
}
|
|
let keyword = this.data.oldKeyword;
|
|
let keywords = wx.getStorageSync('sz_trip_keywords')?JSON.parse(wx.getStorageSync('sz_trip_keywords')):[];
|
|
for(let i=0;i<keywords.length;i++){
|
|
if(keywords[i]==keyword){
|
|
keywords.splice(i,1);
|
|
i--;
|
|
}
|
|
}
|
|
keywords.unshift(keyword)
|
|
wx.setStorageSync('sz_trip_keywords', JSON.stringify(keywords));
|
|
this.setData({
|
|
keyword:this.data.oldKeyword,
|
|
list:[],
|
|
total:1
|
|
})
|
|
this.getList()
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.pagePoint({event:'search_result_view'},1)
|
|
},
|
|
pagePoint: function(e,type){
|
|
util.pagePoint(e,type)
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
this.getList()
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
})
|