// 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