chengjunhui 1 miesiąc temu
rodzic
commit
3967a4f6b2
2 zmienionych plików z 52 dodań i 5 usunięć
  1. 2 2
      pages/dashen/index.js
  2. 50 3
      pages/home/location/index.js

+ 2 - 2
pages/dashen/index.js

@@ -198,8 +198,8 @@ Page({
         ...this.data.params,
         page: isRefresh ? 1 : this.data.params.page + 1,
         // category: this.data.nameIndex == 0 ? '' : `0${this.data.nameIndex}`,
-        // city: nowCity.cityId,
-        city: "",
+        city: nowCity.cityId,
+        // city: "",
         // area: nowCity.areaId
       },
     });

+ 50 - 3
pages/home/location/index.js

@@ -12,8 +12,8 @@ Page({
     city: [],//热门城市
     currentCity: '武汉市',//当前城市
     search: '',
-    list:[],// city list
-
+    list: [],// city list=
+    originalList: [], // 原始数据
   },
 
   /**
@@ -25,6 +25,51 @@ Page({
   onReady: function () {
     this.loadData();
   },
+  // 基础搜索功能
+  searchMt(e) {
+    // this.search = e.detail.value;
+    // console.log(e.detail.value);
+    if (e.detail.value) {
+      this.setData({
+        search: e.detail.value
+      })
+      this.handleList();
+    } else {
+      this.setData({
+        search: '',
+        list: this.data.originalList
+      });
+    }
+    // console.log(this.data.originalList);
+  },
+  handleList() {
+    let list = [];
+    this.data.originalList.forEach(item => {
+      // if (item.name.indexOf(this.data.search) > -1) {
+      //   list.push(item);
+      // }
+      if (item.title == '热门城市') {
+        list.push(item);
+      } else {
+        let itemList = [];
+        item.item.forEach(v => {
+          if (v.name.indexOf(this.data.search) > -1) {
+            itemList.push(v);
+          }
+        });
+        if (itemList.length) {
+          list.push({
+            title: item.title,
+            item: itemList
+          });
+        }
+      }
+    });
+    // console.log(list);
+    this.setData({
+      list
+    });
+  },
   //选择城市
   bindtap(e) {
     let cityName = e.currentTarget.dataset.detail.name ? e.currentTarget.dataset.detail.name : ''
@@ -102,8 +147,10 @@ Page({
           }
           _array.push(_arrayItem)
         })
+        let list = [...this.data.list, ..._array];
         this.setData({
-          list: [...this.data.list, ..._array]
+          list: list,
+          originalList: list,
         })
         break;
     }