Commit 91661084 by qinjianhui

fix: 关键字查询amazon属性

parent dc8f0564
......@@ -89,7 +89,9 @@
style="width: 100%"
filterable
clearable
popper-class="custom-popper-select"
v-model="productType"
@change="productTypeChange"
placeholder="请选择分类">
<el-option
v-for="item in productTypeList"
......@@ -434,12 +436,12 @@ export default {
lock: true
})
try {
const find = this.shopList.find(
(item) => item.marketplaceId === this.shopId
)
// const find = this.shopList.find(
// (item) => item.marketplaceId === this.shopId
// )
const res = await get('amazon/category/getChildListByKeywords', {
keywords: this.keyWord,
shopId: find.id
marketplaceId: this.shopId
})
if (res.code !== 200) return
this.productTypeList = res.data.map((item) => {
......@@ -452,6 +454,26 @@ export default {
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) {
if (!id || id.length === 0) return
if (Array.isArray(id)) id = id[id.length - 1]
......@@ -490,68 +512,100 @@ export default {
})
},
categoryTypeChange(val) {
const nodes = this.$refs.amCateCascadersRef.getCheckedNodes()
let targetNode
if (this.aliCatePathIds) {
targetNode = nodes[nodes.length - 1]
}
this.dataGroupForm = {}
if (targetNode) {
const { data } = targetNode
this.getCateAttrs(
data.productTypeDefinitions,
data.browsePathByName,
({ list, groupProps }) => {
this.$nextTick(() => {
const nodes = this.$refs.amCateCascadersRef.getCheckedNodes()
let targetNode
if (this.aliCatePathIds) {
targetNode = nodes[nodes.length - 1]
}
this.dataGroupForm = {}
if (targetNode) {
const { data } = targetNode
this.getCateAttrs(
data.productTypeDefinitions,
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) {
this.jsonSchema = list
groupProps.forEach((item) => {
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 {
this.jsonSchema = {}
this.dataGroupForm = {}
}
}
)
} else if (val) {
this.getCateAttrs(val, '', ({ list, groupProps }) => {
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 = {}
}
})
} else {
this.jsonSchema = {}
this.dataGroupForm = {}
}
})
},
async initCate(marketplaceId) {
async initCate(ids, callback) {
const loading = this.$loading({
lock: true
})
try {
const res = await get('amazon/category/getChildListByBrowseNodeId', {
marketplaceId
const arr = [
get('amazon/category/getChildListByBrowseNodeId', {
marketplaceId: this.shopId
})
if (res.code !== 200) return
this.amCateCascaders = res.data
} catch (e) {
console.error(e)
} finally {
loading.close()
]
for (let i = 0; i < ids.length - 1; i++) {
arr.push(
get('amazon/category/getChildListByBrowseNodeId', {
browseNodeId: ids[i],
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) {
if (node.level === 0) return
......@@ -590,7 +644,7 @@ export default {
},
shopChange(val) {
if (!val) return
this.initCate(val)
this.initCate([])
},
async saveGrouping() {
const nodes = this.$refs.amCateCascadersRef.getCheckedNodes()
......@@ -824,4 +878,10 @@ export default {
font-weight: 500;
}
}
.custom-popper-select {
.el-select-dropdown__item {
border-bottom: 1px solid #ddd;
height: unset;
}
}
</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