main #18
@ -40,7 +40,10 @@ async def product_category_search(ns={}):
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
# 首页不登录 通过域名筛选
|
||||
if to_page == 'show':
|
||||
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND del_flg = '0' ORDER BY priority;""" % domain_name
|
||||
if ns.get('first_level_id'):
|
||||
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND del_flg = '0' AND parentid = '%s' ORDER BY priority;""" % (domain_name, ns.get('first_level_id'))
|
||||
else:
|
||||
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND del_flg = '0' AND parentid is NULL ORDER BY priority;""" % domain_name
|
||||
result = await sor.sqlExe(find_sql, {})
|
||||
return {
|
||||
'status': True,
|
||||
@ -64,7 +67,7 @@ async def product_category_search(ns={}):
|
||||
orgid = user_list[0]['orgid']
|
||||
user_role = await get_user_role({'userid': userid, 'sor': sor})
|
||||
try:
|
||||
if user_role == '客户' or user_role == '管理员':
|
||||
if user_role == '客户' or user_role == '管理员':
|
||||
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND permission = '1' AND del_flg = '0' ORDER BY priority;""" % domain_name
|
||||
else:
|
||||
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND del_flg = '0' ORDER BY priority;""" % domain_name
|
||||
|
||||
@ -200,4 +200,23 @@ export function reqHomepageCategoryTreeDelete(data){
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
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),直接显示所有四级菜单项 -->
|
||||
<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);
|
||||
|
||||
@ -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 = []
|
||||
}
|
||||
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
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user