Commit 91661084 by qinjianhui

fix: 关键字查询amazon属性

parent dc8f0564
...@@ -89,7 +89,9 @@ ...@@ -89,7 +89,9 @@
style="width: 100%" style="width: 100%"
filterable filterable
clearable clearable
popper-class="custom-popper-select"
v-model="productType" v-model="productType"
@change="productTypeChange"
placeholder="请选择分类"> placeholder="请选择分类">
<el-option <el-option
v-for="item in productTypeList" v-for="item in productTypeList"
...@@ -434,12 +436,12 @@ export default { ...@@ -434,12 +436,12 @@ export default {
lock: true lock: true
}) })
try { try {
const find = this.shopList.find( // const find = this.shopList.find(
(item) => item.marketplaceId === this.shopId // (item) => item.marketplaceId === this.shopId
) // )
const res = await get('amazon/category/getChildListByKeywords', { const res = await get('amazon/category/getChildListByKeywords', {
keywords: this.keyWord, keywords: this.keyWord,
shopId: find.id marketplaceId: this.shopId
}) })
if (res.code !== 200) return if (res.code !== 200) return
this.productTypeList = res.data.map((item) => { this.productTypeList = res.data.map((item) => {
...@@ -452,6 +454,26 @@ export default { ...@@ -452,6 +454,26 @@ export default {
loading.close() loading.close()
} }
}, },
productTypeChange(val) {
if (!val) return
const item = this.productTypeList.find(
(item) => item.browseNodeId === val
)
if (!item) return
const categoryPath = item.browsePathById
?.split(',')
?.slice(1)
?.map((e) => Number(e))
this.initCate(categoryPath || [], () => {
if (item.productType && categoryPath) {
this.aliCatePathIds = categoryPath
this.categoryTypeChange(item.productType, true)
} else {
this.jsonSchema = {}
this.groupList = []
}
})
},
getCateAttrs(id, categoryFullPath, callback) { getCateAttrs(id, categoryFullPath, callback) {
if (!id || id.length === 0) return if (!id || id.length === 0) return
if (Array.isArray(id)) id = id[id.length - 1] if (Array.isArray(id)) id = id[id.length - 1]
...@@ -490,68 +512,100 @@ export default { ...@@ -490,68 +512,100 @@ export default {
}) })
}, },
categoryTypeChange(val) { categoryTypeChange(val) {
const nodes = this.$refs.amCateCascadersRef.getCheckedNodes() this.$nextTick(() => {
let targetNode const nodes = this.$refs.amCateCascadersRef.getCheckedNodes()
if (this.aliCatePathIds) { let targetNode
targetNode = nodes[nodes.length - 1] if (this.aliCatePathIds) {
} targetNode = nodes[nodes.length - 1]
this.dataGroupForm = {} }
if (targetNode) { this.dataGroupForm = {}
const { data } = targetNode if (targetNode) {
this.getCateAttrs( const { data } = targetNode
data.productTypeDefinitions, this.getCateAttrs(
data.browsePathByName, data.productTypeDefinitions,
({ list, groupProps }) => { data.browsePathByName,
({ list, groupProps }) => {
if (list) {
this.jsonSchema = list
groupProps.forEach((item) => {
item.propertyList.forEach((e) => {
this.$set(this.dataGroupForm, e.propertyNameEn, item.id)
})
})
this.cloneDataGroupForm = JSON.parse(
JSON.stringify(this.dataGroupForm)
)
} else {
this.jsonSchema = {}
this.dataGroupForm = {}
}
}
)
} else if (val) {
this.getCateAttrs(val, '', ({ list, groupProps }) => {
if (list) { if (list) {
this.jsonSchema = list this.jsonSchema = list
groupProps.forEach((item) => { groupProps.forEach((item) => {
item.propertyList.forEach((e) => { item.propertyList.forEach((e) => {
this.$set(this.dataGroupForm, e.propertyNameEn, item.id) this.$set(this.dataGroupForm, e.propertyNameEn, item.groupId)
}) })
}) })
this.cloneDataGroupForm = JSON.parse(
JSON.stringify(this.dataGroupForm)
)
} else { } else {
this.jsonSchema = {} this.jsonSchema = {}
this.dataGroupForm = {} this.dataGroupForm = {}
} }
} })
) } else {
} else if (val) { this.jsonSchema = {}
this.getCateAttrs(val, '', ({ list, groupProps }) => { this.dataGroupForm = {}
if (list) { }
this.jsonSchema = list })
groupProps.forEach((item) => {
item.propertyList.forEach((e) => {
this.$set(this.dataGroupForm, e.propertyNameEn, item.groupId)
})
})
} else {
this.jsonSchema = {}
this.dataGroupForm = {}
}
})
} else {
this.jsonSchema = {}
this.dataGroupForm = {}
}
}, },
async initCate(marketplaceId) { async initCate(ids, callback) {
const loading = this.$loading({ const loading = this.$loading({
lock: true lock: true
}) })
try { const arr = [
const res = await get('amazon/category/getChildListByBrowseNodeId', { get('amazon/category/getChildListByBrowseNodeId', {
marketplaceId marketplaceId: this.shopId
}) })
if (res.code !== 200) return ]
this.amCateCascaders = res.data for (let i = 0; i < ids.length - 1; i++) {
} catch (e) { arr.push(
console.error(e) get('amazon/category/getChildListByBrowseNodeId', {
} finally { browseNodeId: ids[i],
loading.close() marketplaceId: this.shopId
})
)
} }
Promise.all(arr)
.then((res) => {
const catearr = res[0].data.map((e) => {
return {
...e,
leaf: !e.childId
}
})
let arr1 = catearr
for (let i = 0; i < ids.length - 1; i++) {
for (const iterator of arr1) {
if (iterator.browseNodeId === ids[i]) {
iterator.children = res[i + 1].data.map((e) => {
return {
...e,
leaf: !e.childId
}
})
arr1 = iterator.children
}
}
}
this.amCateCascaders = catearr
callback && callback(catearr)
})
.finally(() => {
loading.close()
})
}, },
lazyLoad(node, resolve) { lazyLoad(node, resolve) {
if (node.level === 0) return if (node.level === 0) return
...@@ -590,7 +644,7 @@ export default { ...@@ -590,7 +644,7 @@ export default {
}, },
shopChange(val) { shopChange(val) {
if (!val) return if (!val) return
this.initCate(val) this.initCate([])
}, },
async saveGrouping() { async saveGrouping() {
const nodes = this.$refs.amCateCascadersRef.getCheckedNodes() const nodes = this.$refs.amCateCascadersRef.getCheckedNodes()
...@@ -824,4 +878,10 @@ export default { ...@@ -824,4 +878,10 @@ export default {
font-weight: 500; font-weight: 500;
} }
} }
.custom-popper-select {
.el-select-dropdown__item {
border-bottom: 1px solid #ddd;
height: unset;
}
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment