Browse Source

'全局搜索联调'

zhangyu 4 years ago
parent
commit
1a998ea92d
1 changed files with 39 additions and 13 deletions
  1. 39 13
      src/views/GlobalSearch.vue

+ 39 - 13
src/views/GlobalSearch.vue

@@ -16,7 +16,7 @@
       <p class="title-style equip-box-title">设备</p>
       <div class="equip-box-list">
         <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
-          <van-cell v-for="(item, index) in equipList" :key="index" :title="item.eqName" />
+          <van-cell v-for="(item, index) in equipList" :key="index" :title="item.sbjc" />
         </van-list>
       </div>
     </div>
@@ -32,6 +32,7 @@
 import Vue from 'vue'
 import { mapGetters } from 'vuex'
 import { Search, List, Cell } from 'vant'
+import { queryEquipmentList } from '@/api/equipmentList.js'
 Vue.use(Search).use(List).use(Cell);
 export default {
   name: 'GlobalSearch',
@@ -47,9 +48,9 @@ export default {
       loading: false,
       finished: false,
       refreshing: false,
-      equipList: [{
-        eqName: "地下一层/强电井/1#/配电箱120-1"
-      }], //设备列表
+      equipList: [], //设备列表
+      page: 1, //当前页码
+      size: 10, //每页条数
     }
   },
   props: {},
@@ -60,7 +61,27 @@ export default {
   methods: {
     // 全局搜索事件
     onSearch() {
-
+      this.page = 1;
+      this.equipList = [];
+      this.finished = false;
+      let data = {
+        plazaId: this.plazaId,
+        page: this.page,
+        size: this.size,
+        keyword: `${this.keyWord}:sbjc,assetnum;`
+      },
+      postParams = { }
+      queryEquipmentList({data, postParams}).then(res => {
+        console.log(res)
+        this.flag = false;
+        if (res.data.result == "success" && res.data.data) {
+          this.equipList = res.data.data;
+        }
+        // 数据全部加载完成
+        if (this.equipList.length >= res.data.count) {
+          this.finished = true;
+        }
+      })
     },
     // 修改输入内容
     onInput() {
@@ -73,22 +94,27 @@ export default {
     },
     onLoad() {
       // 异步更新数据
-      // setTimeout 仅做示例,真实场景中一般为 ajax 请求
-      setTimeout(() => {
-        for (let i = 0; i < 10; i++) {
-          this.equipList.push({
-            eqName: "地下一层/强电井/1#/配电箱120-1"
-          });
+      this.page++;
+      let data = {
+        plazaId: this.plazaId,
+        page: this.page,
+        size: this.size,
+        keyword: `${this.keyWord}:sbjc,assetnum;`
+      },
+      postParams = { }
+      queryEquipmentList({data, postParams}).then(res => {
+        if (res.data.result == "success" && res.data.data) {
+          this.equipList = this.equipList.concat(res.data.data);
         }
 
         // 加载状态结束
         this.loading = false;
 
         // 数据全部加载完成
-        if (this.equipList.length >= 40) {
+        if (this.equipList.length >= res.data.count) {
           this.finished = true;
         }
-      }, 1000);
+      })
     },
   },
   watch: {