index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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
  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 form={
  66. name:this.key,
  67. pageIndex:1,
  68. pageSize:20
  69. }
  70. API.routeList(form).then((res) => {
  71. this.ing=true;
  72. this.result=res.data.data;
  73. this.recordsTotal=res.data.recordsTotal
  74. for(var i in this.result){
  75. var item=this.result[i];
  76. var len =item.name.indexOf(this.key)
  77. this.result[i].name1=item.name.substring(0,len);
  78. this.result[i].name2=item.name.substring(len+this.key.length);
  79. }
  80. document.getElementsByTagName('uni-page-wrapper')[0].style="background-color: #f7f7f7;"
  81. }).catch(error => {
  82. this.$refs.common.alert( error);
  83. })
  84. }
  85. },
  86. onLoad(op) {
  87. if(op.back){
  88. this.back=true;
  89. }
  90. },onReady(){
  91. this.record=this.carhelp.get("searchHistory");
  92. }
  93. }