import * as API from '@/apis/query.js' export default { data() { return { ing:false, key:'', record:[], result:[], recordsTotal:0, back:false, } }, methods: { gotoLine(item){ uni.redirectTo({ url:'/pages/route/index?id='+item.id+"&downid="+item.stationId }) }, setHistory(){ //搜索记录保存 var sz=this.carhelp.get("searchHistory"); if(!sz){ sz=[]; } var temp =[]; //去重 ,后插入的,排队到最前面 if(sz.length){ for(var i in sz){ if(i==0){ temp.push(this.key); } if(sz[i]==this.key){ continue; } temp.push(sz[i]); if(temp.length==10){ break } } }else{ temp.push(this.key); } this.record=temp; this.carhelp.set("searchHistory",temp); }, clearBtn(){ this.carhelp.set("searchHistory",[]); this.record=[]; this.$refs.common.alert("搜索内容已清空") }, change(){ this.ing=false; document.getElementsByTagName('uni-page-wrapper')[0].style="background-color: #ffffff;" if(this.key==""){ this.result=[] } }, itemBtn(){ }, submit(){ if(this.key==""){ return } this.setHistory(); var region= this.carhelp.get("car_region"); if(!region){ region= this.carhelp.get("car_region_temp"); } var form={ name:this.key, pageIndex:1, pageSize:20, regionId:region } API.routeList(form).then((res) => { this.ing=true; this.result=res.data.data; this.recordsTotal=res.data.recordsTotal for(var i in this.result){ var item=this.result[i]; var len =item.name.indexOf(this.key) this.result[i].name1=item.name.substring(0,len); this.result[i].name2=item.name.substring(len+this.key.length); } document.getElementsByTagName('uni-page-wrapper')[0].style="background-color: #f7f7f7;" }).catch(error => { this.$refs.common.alert( error); }) } }, onLoad(op) { if(op.back){ this.back=true; } },onReady(){ this.record=this.carhelp.get("searchHistory"); } }