|
|
@@ -20,6 +20,8 @@ Component({
|
|
|
sidebarItems: [],
|
|
|
firstClassList: [],
|
|
|
currentFirstClass: null,
|
|
|
+ showSidebar: false,
|
|
|
+ condition: ''
|
|
|
},
|
|
|
methods: {
|
|
|
openAction() {
|
|
|
@@ -134,19 +136,26 @@ Component({
|
|
|
// 保存完整的分类数据
|
|
|
this.allCategories = res.data[0].ttemclass;
|
|
|
console.log('allCategories:', this.allCategories);
|
|
|
-
|
|
|
- const firstClassList = this.allCategories.map(v => {
|
|
|
+
|
|
|
+ // 添加"全部"选项
|
|
|
+ const firstClassList = [{
|
|
|
+ itemclassid: "",
|
|
|
+ itemclassname: "全部",
|
|
|
+ name: "全部",
|
|
|
+ subdep: []
|
|
|
+ }].concat(this.allCategories.map(v => {
|
|
|
v.name = v.itemclassname;
|
|
|
return v;
|
|
|
- });
|
|
|
-
|
|
|
+ }));
|
|
|
+
|
|
|
this.setData({
|
|
|
firstClassList: firstClassList,
|
|
|
- currentFirstClass: this.allCategories[0]
|
|
|
+ currentFirstClass: firstClassList[0],
|
|
|
+ showSidebar: false
|
|
|
});
|
|
|
-
|
|
|
- // 初始显示第一个一级分类的末级分类
|
|
|
- this.updateSidebarItems(this.allCategories[0]);
|
|
|
+
|
|
|
+ // 初始不显示侧边栏(因为默认选中"全部")
|
|
|
+ content.where.itemclassid = "";
|
|
|
}
|
|
|
this.getList(true);
|
|
|
})
|
|
|
@@ -217,21 +226,24 @@ Component({
|
|
|
}
|
|
|
console.log('选中的索引:', index);
|
|
|
|
|
|
- // 确保allCategories存在
|
|
|
- if (!this.allCategories || this.allCategories.length === 0) {
|
|
|
- console.log('allCategories未定义或为空');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- console.log('allCategories:', this.allCategories);
|
|
|
- const selectedClass = this.allCategories[index];
|
|
|
+ // 获取选中的分类
|
|
|
+ const selectedClass = this.data.firstClassList[index];
|
|
|
console.log('选中的分类:', selectedClass);
|
|
|
|
|
|
if (selectedClass) {
|
|
|
this.setData({
|
|
|
- currentFirstClass: selectedClass
|
|
|
+ currentFirstClass: selectedClass,
|
|
|
+ showSidebar: index > 0 // 索引为0时是"全部",不显示侧边栏
|
|
|
});
|
|
|
- this.updateSidebarItems(selectedClass);
|
|
|
+
|
|
|
+ if (index > 0) {
|
|
|
+ // 选择了具体的一级分类,更新侧边栏
|
|
|
+ this.updateSidebarItems(selectedClass);
|
|
|
+ } else {
|
|
|
+ // 选择了"全部",清空分类ID
|
|
|
+ content.where.itemclassid = "";
|
|
|
+ }
|
|
|
+
|
|
|
this.getList(true);
|
|
|
} else {
|
|
|
console.log('未找到选中的分类');
|
|
|
@@ -272,10 +284,16 @@ Component({
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
+ /* 搜索输入变化 */
|
|
|
+ onChange(e) {
|
|
|
+ const value = e.detail;
|
|
|
+ this.setData({
|
|
|
+ condition: value
|
|
|
+ });
|
|
|
+ },
|
|
|
/* 开始搜索 */
|
|
|
- onSearch({
|
|
|
- detail
|
|
|
- }) {
|
|
|
+ onSearch(e) {
|
|
|
+ const detail = this.data.condition;
|
|
|
content.where.condition = detail;
|
|
|
wx.showLoading({
|
|
|
title: '搜索中...',
|
|
|
@@ -285,21 +303,6 @@ Component({
|
|
|
})
|
|
|
this.getList(true)
|
|
|
},
|
|
|
- onChange({
|
|
|
- detail
|
|
|
- }) {
|
|
|
- content.where.condition = detail
|
|
|
- this.setData({
|
|
|
- 'condition': detail
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- /* 跳转到搜索页面 */
|
|
|
- goToSearch() {
|
|
|
- wx.navigateTo({
|
|
|
- url: '/pages/index/search/index'
|
|
|
- });
|
|
|
- },
|
|
|
|
|
|
|
|
|
|