bugfix
This commit is contained in:
parent
a937a057bf
commit
80be8d5e31
@ -200,4 +200,23 @@ export function reqHomepageCategoryTreeDelete(data){
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//供需一级分类
|
||||||
|
export function reqSupplyAndDemandFirstCategory(data){
|
||||||
|
return request({
|
||||||
|
url: '/product/product_category_search.dspy',
|
||||||
|
method: 'post',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
//供需二级分类
|
||||||
|
export function reqSupplyAndDemandSecondCategory(data){
|
||||||
|
return request({
|
||||||
|
url: '/product/supply_and_demand_first_category.dspy',
|
||||||
|
method: 'post',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
data
|
||||||
|
})
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@
|
|||||||
<!-- 如果有四级菜单(product_list),直接显示所有四级菜单项 -->
|
<!-- 如果有四级菜单(product_list),直接显示所有四级菜单项 -->
|
||||||
<div v-if="third.product_list && third.product_list.length > 0"
|
<div v-if="third.product_list && third.product_list.length > 0"
|
||||||
class="product-grid">
|
class="product-grid">
|
||||||
<div @click="openTalk" v-for="(product, index) in third.product_list"
|
<div @click="goSearch(product)" v-for="(product, index) in third.product_list"
|
||||||
:key="product.id"
|
:key="product.id"
|
||||||
class="product-tag">
|
class="product-tag">
|
||||||
{{ product.first_level_name }}
|
{{ product.first_level_name }}
|
||||||
@ -120,12 +120,63 @@ export default {
|
|||||||
hideTimer: null,
|
hideTimer: null,
|
||||||
categories: [],
|
categories: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
|
keyword: '',
|
||||||
|
publish_type: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getCategories();
|
this.getCategories();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
performFormalSearch(keyword, type) {
|
||||||
|
console.log('=== 执行正式搜索开始 ===');
|
||||||
|
console.log('搜索参数:', { keyword, type });
|
||||||
|
console.log('当前路由:', this.$route.path);
|
||||||
|
console.log('事件总线实例:', eventBus);
|
||||||
|
|
||||||
|
reqSearch({
|
||||||
|
url_link: window.location.href,
|
||||||
|
keyword: keyword,
|
||||||
|
publish_type: type,
|
||||||
|
display_page: 'list', // 正式搜索使用 list
|
||||||
|
current_page: 1,
|
||||||
|
page_size: 8
|
||||||
|
}).then(res => {
|
||||||
|
console.log('正式搜索结果:', res);
|
||||||
|
|
||||||
|
// 准备发送事件数据
|
||||||
|
const eventData = {
|
||||||
|
type: type,
|
||||||
|
keyword: keyword,
|
||||||
|
data: res.data
|
||||||
|
};
|
||||||
|
console.log('准备发送事件数据:', eventData);
|
||||||
|
|
||||||
|
// 通过事件总线触发搜索事件,让兄弟组件处理结果
|
||||||
|
try {
|
||||||
|
eventBus.$emit('search', eventData);
|
||||||
|
console.log('事件总线事件发送成功');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('事件总线事件发送失败:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('正式搜索完成,已触发搜索事件');
|
||||||
|
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('正式搜索失败:', error);
|
||||||
|
this.$message.error('搜索失败,请重试');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
goSearch(product) {
|
||||||
|
this.keyword = 'A800';
|
||||||
|
this.publish_type ='1';
|
||||||
|
this.$router.push({
|
||||||
|
path: '/ncmatch/search',
|
||||||
|
|
||||||
|
})
|
||||||
|
this.performFormalSearch(this.keyword, this.publish_type);
|
||||||
|
},
|
||||||
|
|
||||||
async openTalk() {
|
async openTalk() {
|
||||||
await this.hideProductList('quick')
|
await this.hideProductList('quick')
|
||||||
this.$store.commit('setShowTalk', true);
|
this.$store.commit('setShowTalk', true);
|
||||||
|
|||||||
@ -35,21 +35,21 @@
|
|||||||
<div class="category-section">
|
<div class="category-section">
|
||||||
<div class="category-title">所属类别</div>
|
<div class="category-title">所属类别</div>
|
||||||
<div class="category-tags">
|
<div class="category-tags">
|
||||||
<span v-for="category in typeList" :key="category.id"
|
<span v-for="category in firstCategories" :key="category.id"
|
||||||
:class="['category-tag', { active: selectedCategory === category.value }]"
|
:class="['category-tag', { active: activeFirstId === category.id }]"
|
||||||
@click="selectCategory(category.value)">
|
@click="selectFirstCategory(category.id)">
|
||||||
{{ category.label }}
|
{{ category.product_category || category.label }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="category-section">
|
<div class="category-section" v-if="secondCategories.length > 0">
|
||||||
<div class="category-title">所属品类</div>
|
<div class="category-title">所属品类</div>
|
||||||
<div class="category-tags">
|
<div class="category-tags">
|
||||||
<span v-for="category in typeList" :key="category.id"
|
<span v-for="category in secondCategories" :key="category.id"
|
||||||
:class="['category-tag', { active: selectedCategory === category.value }]"
|
:class="['category-tag', { active: activeSecondId === category.id }]"
|
||||||
@click="selectCategory(category.value)">
|
@click="selectSecondCategory(category.id)">
|
||||||
{{ category.label }}
|
{{ category.product_category || category.label }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -87,7 +87,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { reqGetProductCategorySearch, reqGetSupplyAndDemandSquareList, reqCompanyCategorySearch } from '@/api/ncmatch'
|
import { reqGetSupplyAndDemandSquareList, reqCompanyCategorySearch, reqSupplyAndDemandFirstCategory } from '@/api/ncmatch'
|
||||||
import { mapGetters, mapState } from 'vuex'
|
import { mapGetters, mapState } from 'vuex'
|
||||||
export default {
|
export default {
|
||||||
name: 'supplyAndDemandSquare',
|
name: 'supplyAndDemandSquare',
|
||||||
@ -100,12 +100,19 @@ export default {
|
|||||||
current_page: 1,
|
current_page: 1,
|
||||||
typeList: [],
|
typeList: [],
|
||||||
publish_type: '1', // 默认选中商品
|
publish_type: '1', // 默认选中商品
|
||||||
selectedCategory: '', // 默认选中项
|
selectedCategory: '', // 兼容旧逻辑,最终请求用这个字段
|
||||||
selectedCompanies: [], // 默认选中项,改为数组支持多选
|
selectedCompanies: [], // 默认选中项,改为数组支持多选
|
||||||
categories: [],
|
categories: [],
|
||||||
companies: [],
|
companies: [],
|
||||||
productList: [],
|
productList: [],
|
||||||
detailVisible: false
|
detailVisible: false,
|
||||||
|
oneLevelCategory:[],
|
||||||
|
twoLevelCategory:[],
|
||||||
|
// 新增:一二级分类数据与高亮状态(平级数组)
|
||||||
|
firstCategories: [],
|
||||||
|
secondCategories: [],
|
||||||
|
activeFirstId: null,
|
||||||
|
activeSecondId: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@ -136,16 +143,28 @@ export default {
|
|||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getOneLevelCategory(){
|
||||||
|
// reqSupplyAndDemandFirstCategory({url_link:window.location.href}).then(res=>{
|
||||||
|
// if(res.status){
|
||||||
|
// this.oneLevelCategory=res.data
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
},
|
||||||
|
getTwoLevelCategory(){
|
||||||
|
// reqSupplyAndDemandSecondCategory({url_link:window.location.href}).then(res=>{
|
||||||
|
// if(res.status){
|
||||||
|
// this.twoLevelCategory=res.data
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
},
|
||||||
handleCurrentChange(val) {
|
handleCurrentChange(val) {
|
||||||
this.current_page = val
|
this.current_page = val
|
||||||
this.initData()
|
this.initData()
|
||||||
},
|
},
|
||||||
initAllData() {
|
initAllData() {
|
||||||
// 先初始化产品类别,确保 selectedCategory 设置完成
|
// 先获取一级分类,随后根据默认一级请求二级,再加载数据
|
||||||
this.init_product_category().then(() => {
|
this.init_product_category().then(() => {
|
||||||
// 然后初始化公司类别
|
|
||||||
this.init_company_category().then(() => {
|
this.init_company_category().then(() => {
|
||||||
// 最后调用 initData
|
|
||||||
this.initData()
|
this.initData()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -166,26 +185,54 @@ export default {
|
|||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
selectCategory(categoryId) {
|
// 选中一级分类
|
||||||
if (categoryId === this.selectedCategory) return;
|
selectFirstCategory(id) {
|
||||||
this.selectedCategory = categoryId
|
if (id === this.activeFirstId) return
|
||||||
this.initData(this.selectedCategory)
|
this.activeFirstId = id
|
||||||
|
// 切换一级时不自动高亮二级,置空
|
||||||
|
this.activeSecondId = null
|
||||||
|
this.selectedCategory = id
|
||||||
|
// 获取二级分类(平级数组)
|
||||||
|
this.loadSecondCategories(id)
|
||||||
|
this.initData()
|
||||||
},
|
},
|
||||||
init_product_category(product_category) {
|
// 选中二级分类
|
||||||
return reqGetProductCategorySearch({ url_link: window.location.href, to_page: 'show' }).then(res => {
|
selectSecondCategory(id) {
|
||||||
|
if (id === this.activeSecondId) return
|
||||||
|
this.activeSecondId = id
|
||||||
|
this.selectedCategory = id
|
||||||
|
this.initData()
|
||||||
|
},
|
||||||
|
init_product_category() {
|
||||||
|
// 获取一级分类(平级数组)
|
||||||
|
return reqSupplyAndDemandFirstCategory({to_page: 'show', url_link: window.location.href }).then(res => {
|
||||||
if (res.status) {
|
if (res.status) {
|
||||||
let list = []
|
this.$message.success('获取一级分类成功')
|
||||||
for (let item of res.data) {
|
this.firstCategories = Array.isArray(res.data) ? res.data : []
|
||||||
if (item.parentid === null) {
|
if (this.firstCategories.length > 0) {
|
||||||
list.push({
|
this.activeFirstId = this.firstCategories[0].id
|
||||||
label: item.product_category,
|
this.selectedCategory = this.activeFirstId
|
||||||
value: item.id
|
this.activeSecondId = null
|
||||||
})
|
// 立即拉取对应二级分类
|
||||||
}
|
return this.loadSecondCategories(this.activeFirstId)
|
||||||
|
} else {
|
||||||
|
this.activeFirstId = null
|
||||||
|
this.activeSecondId = null
|
||||||
|
this.selectedCategory = ''
|
||||||
|
this.secondCategories = []
|
||||||
}
|
}
|
||||||
this.selectedCategory = list[0].value
|
}
|
||||||
this.typeList = list
|
return res
|
||||||
|
})
|
||||||
|
},
|
||||||
|
loadSecondCategories(firstId) {
|
||||||
|
// 同一个接口,通过是否传 first_level_id 区分一级/二级
|
||||||
|
return reqSupplyAndDemandFirstCategory({ to_page: 'show',url_link: window.location.href, first_level_id: firstId }).then(res => {
|
||||||
|
this.$message.success('获取二级级分类成功')
|
||||||
|
if (res.status) {
|
||||||
|
this.secondCategories = Array.isArray(res.data) ? res.data : []
|
||||||
|
} else {
|
||||||
|
this.secondCategories = []
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user