index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import * as API from '@/apis/query.js'
  2. export default {
  3. data() {
  4. return {
  5. ing:false,
  6. key:'',
  7. record:[],
  8. result:[],
  9. recordsTotal:0,
  10. back:false,
  11. }
  12. },
  13. methods: {
  14. gotoLine(item){
  15. uni.redirectTo({
  16. url:'/pages/route/index?id='+item.id+"&downid="+item.stationId
  17. })
  18. },
  19. setHistory(){
  20. //搜索记录保存
  21. var sz=this.carhelp.get("searchHistory");
  22. if(!sz){
  23. sz=[];
  24. }
  25. var temp =[];
  26. //去重 ,后插入的,排队到最前面
  27. if(sz.length){
  28. for(var i in sz){
  29. if(i==0){
  30. temp.push(this.key);
  31. }
  32. if(sz[i]==this.key){
  33. continue;
  34. }
  35. temp.push(sz[i]);
  36. if(temp.length==10){
  37. break
  38. }
  39. }
  40. }else{
  41. temp.push(this.key);
  42. }
  43. this.record=temp;
  44. this.carhelp.set("searchHistory",temp);
  45. },
  46. clearBtn(){
  47. this.carhelp.set("searchHistory",[]);
  48. this.record=[];
  49. this.$refs.common.alert("搜索内容已清空")
  50. },
  51. change(){
  52. this.ing=false;
  53. document.getElementsByTagName('uni-page-wrapper')[0].style="background-color: #ffffff;"
  54. if(this.key==""){
  55. this.result=[]
  56. }
  57. },
  58. itemBtn(){
  59. },
  60. submit(){
  61. if(this.key==""){
  62. return
  63. }
  64. this.setHistory();
  65. var region= this.carhelp.get("car_region");
  66. if(!region){
  67. region= this.carhelp.get("car_region_temp");
  68. }
  69. var form={
  70. name:this.key,
  71. pageIndex:1,
  72. pageSize:20,
  73. regionId:region
  74. }
  75. API.routeList(form).then((res) => {
  76. this.ing=true;
  77. this.result=res.data.data;
  78. this.recordsTotal=res.data.recordsTotal
  79. for(var i in this.result){
  80. var item=this.result[i];
  81. var len =item.name.indexOf(this.key)
  82. this.result[i].name1=item.name.substring(0,len);
  83. this.result[i].name2=item.name.substring(len+this.key.length);
  84. }
  85. document.getElementsByTagName('uni-page-wrapper')[0].style="background-color: #f7f7f7;"
  86. }).catch(error => {
  87. this.$refs.common.alert( error);
  88. })
  89. }
  90. },
  91. onLoad(op) {
  92. if(op.back){
  93. this.back=true;
  94. }
  95. },onReady(){
  96. this.record=this.carhelp.get("searchHistory");
  97. }
  98. }