This commit is contained in:
木瓜一块八 2025-08-20 16:06:09 +08:00
parent a937a057bf
commit 80be8d5e31
3 changed files with 150 additions and 33 deletions

View File

@ -201,3 +201,22 @@ export function reqHomepageCategoryTreeDelete(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
})
}

View File

@ -47,7 +47,7 @@
<!-- 如果有四级菜单product_list直接显示所有四级菜单项 -->
<div v-if="third.product_list && third.product_list.length > 0"
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"
class="product-tag">
{{ product.first_level_name }}
@ -120,12 +120,63 @@ export default {
hideTimer: null,
categories: [],
loading: false,
keyword: '',
publish_type: '',
}
},
created() {
this.getCategories();
},
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() {
await this.hideProductList('quick')
this.$store.commit('setShowTalk', true);

View File

@ -35,21 +35,21 @@
<div class="category-section">
<div class="category-title">所属类别</div>
<div class="category-tags">
<span v-for="category in typeList" :key="category.id"
:class="['category-tag', { active: selectedCategory === category.value }]"
@click="selectCategory(category.value)">
{{ category.label }}
<span v-for="category in firstCategories" :key="category.id"
:class="['category-tag', { active: activeFirstId === category.id }]"
@click="selectFirstCategory(category.id)">
{{ category.product_category || category.label }}
</span>
</div>
</div>
<div class="category-section">
<div class="category-section" v-if="secondCategories.length > 0">
<div class="category-title">所属品类</div>
<div class="category-tags">
<span v-for="category in typeList" :key="category.id"
:class="['category-tag', { active: selectedCategory === category.value }]"
@click="selectCategory(category.value)">
{{ category.label }}
<span v-for="category in secondCategories" :key="category.id"
:class="['category-tag', { active: activeSecondId === category.id }]"
@click="selectSecondCategory(category.id)">
{{ category.product_category || category.label }}
</span>
</div>
</div>
@ -87,7 +87,7 @@
</template>
<script>
import { reqGetProductCategorySearch, reqGetSupplyAndDemandSquareList, reqCompanyCategorySearch } from '@/api/ncmatch'
import { reqGetSupplyAndDemandSquareList, reqCompanyCategorySearch, reqSupplyAndDemandFirstCategory } from '@/api/ncmatch'
import { mapGetters, mapState } from 'vuex'
export default {
name: 'supplyAndDemandSquare',
@ -100,12 +100,19 @@ export default {
current_page: 1,
typeList: [],
publish_type: '1', //
selectedCategory: '', //
selectedCategory: '', //
selectedCompanies: [], //
categories: [],
companies: [],
productList: [],
detailVisible: false
detailVisible: false,
oneLevelCategory:[],
twoLevelCategory:[],
//
firstCategories: [],
secondCategories: [],
activeFirstId: null,
activeSecondId: null,
}
},
created() {
@ -136,16 +143,28 @@ export default {
},
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) {
this.current_page = val
this.initData()
},
initAllData() {
// selectedCategory
//
this.init_product_category().then(() => {
//
this.init_company_category().then(() => {
// initData
this.initData()
})
})
@ -166,26 +185,54 @@ export default {
return res
})
},
selectCategory(categoryId) {
if (categoryId === this.selectedCategory) return;
this.selectedCategory = categoryId
this.initData(this.selectedCategory)
//
selectFirstCategory(id) {
if (id === this.activeFirstId) return
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) {
let list = []
for (let item of res.data) {
if (item.parentid === null) {
list.push({
label: item.product_category,
value: item.id
this.$message.success('获取一级分类成功')
this.firstCategories = Array.isArray(res.data) ? res.data : []
if (this.firstCategories.length > 0) {
this.activeFirstId = this.firstCategories[0].id
this.selectedCategory = this.activeFirstId
this.activeSecondId = null
//
return this.loadSecondCategories(this.activeFirstId)
} else {
this.activeFirstId = null
this.activeSecondId = null
this.selectedCategory = ''
this.secondCategories = []
}
}
return res
})
}
}
this.selectedCategory = list[0].value
this.typeList = list
},
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
})