2023-10-15 22:09:33 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
2023-10-16 01:23:01 +08:00
|
|
|
|
<el-alert
|
|
|
|
|
|
title="采集一个商品添加进草稿箱,将消耗20金币"
|
|
|
|
|
|
type="success"
|
2024-01-10 01:27:15 +08:00
|
|
|
|
:closable="false" style="margin-bottom: 10px;">
|
2023-10-16 01:23:01 +08:00
|
|
|
|
</el-alert>
|
2023-12-20 20:45:00 +08:00
|
|
|
|
<el-form class="ai-form" :model="form" label-width="150px" ref="form">
|
|
|
|
|
|
<el-form-item v-if="!isMultiCopy" label="商品地址:" style="width: 100%;" prop="url" :rules="[{ required: true, message: '请输入商品地址', trigger: 'blur' }]">
|
|
|
|
|
|
<el-input type="textarea" :rows="5" v-model="form.url"></el-input>
|
2023-10-15 22:09:33 +08:00
|
|
|
|
</el-form-item>
|
2024-09-19 21:28:59 +08:00
|
|
|
|
<el-form-item
|
|
|
|
|
|
prop="isSemi"
|
|
|
|
|
|
label="是否半托管:"
|
|
|
|
|
|
:rules="[{ required: true, message: '请选择是否半托管', trigger: 'blur' }]">
|
|
|
|
|
|
<el-radio-group v-model="form.isSemi" size="medium">
|
|
|
|
|
|
<el-radio :label="false">否</el-radio>
|
|
|
|
|
|
<el-radio :label="true">是</el-radio>
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
</el-form-item>
|
2023-10-15 22:09:33 +08:00
|
|
|
|
<el-form-item label="店铺:" style="width: 100%;" prop="targetMallId" :rules="[{ required: true, message: '请选择店铺', trigger: 'blur' }]">
|
2024-09-19 21:28:59 +08:00
|
|
|
|
<el-select style="width: 380px" multiple v-model="form.targetMallId" placeholder="请选择">
|
2023-10-15 22:09:33 +08:00
|
|
|
|
<el-option
|
2024-09-19 21:28:59 +08:00
|
|
|
|
v-for="item in mallList"
|
2023-10-15 22:09:33 +08:00
|
|
|
|
:key="item.mallId"
|
|
|
|
|
|
:label="item.mallName"
|
|
|
|
|
|
:value="item.mallId">
|
|
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2024-02-27 15:38:08 +08:00
|
|
|
|
<el-form-item v-if="form.isSemi" label="经营站点" style="width: 100%;" prop="siteId" :rules="[{ required: true, message: '请选择经营站点', trigger: 'blur' }]">
|
|
|
|
|
|
<el-select style="width: 380px" multiple v-model="form.siteId" placeholder="请选择">
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in siteList"
|
|
|
|
|
|
:key="item.siteId"
|
|
|
|
|
|
:label="item.siteName"
|
|
|
|
|
|
:value="item.siteId">
|
|
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2023-12-20 20:45:00 +08:00
|
|
|
|
<el-form-item
|
|
|
|
|
|
prop="isSameCategory"
|
|
|
|
|
|
label="是否保持相同类目:"
|
|
|
|
|
|
:rules="[{ required: true, message: '请选择是否保持相同类目', trigger: 'blur' }]">
|
|
|
|
|
|
<el-radio-group v-model="form.isSameCategory" size="medium">
|
|
|
|
|
|
<el-radio :label="false">否</el-radio>
|
|
|
|
|
|
<el-radio :label="true">是</el-radio>
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item v-if="!form.isSameCategory" label="商品分类:" style="width: 100%;" prop="targetCatId" :rules="[{ required: true, message: '请选择商品分类', trigger: 'blur' }]">
|
2023-10-25 12:20:10 +08:00
|
|
|
|
<ai-lazy-cascader
|
|
|
|
|
|
style="width: 380px"
|
|
|
|
|
|
v-model="form.targetCatId"
|
|
|
|
|
|
filterable
|
|
|
|
|
|
:props="props"></ai-lazy-cascader>
|
2023-10-15 22:09:33 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<div class="bottom flex-center">
|
|
|
|
|
|
<el-button @click="$emit('onClose')">取 消</el-button>
|
2023-11-10 10:41:19 +08:00
|
|
|
|
<el-button type="primary" @click="toAddToDraft" :loading="isCopying">确定</el-button>
|
2023-10-15 22:09:33 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2023-11-10 10:41:19 +08:00
|
|
|
|
import {sendChromeAPIMessage, sendTemuAPIMessage, sendChromeWebReqMessage} from '@/api/chromeApi'
|
2023-10-25 12:20:10 +08:00
|
|
|
|
import AiLazyCascader from "@/components/AiLazyCascader.vue"
|
2023-10-15 22:09:33 +08:00
|
|
|
|
import { Message } from 'element-ui'
|
2023-12-20 20:45:00 +08:00
|
|
|
|
import { MessageBox } from 'element-ui';
|
2023-10-15 22:09:33 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'AiCopyFromTemu',
|
2023-12-20 20:45:00 +08:00
|
|
|
|
props: ['params', 'isMultiCopy'],
|
2023-10-25 12:20:10 +08:00
|
|
|
|
components: {AiLazyCascader},
|
2023-10-15 22:09:33 +08:00
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
props: {
|
|
|
|
|
|
value: 'catId',
|
|
|
|
|
|
label: 'catName',
|
|
|
|
|
|
lazy: true,
|
2023-10-25 12:20:10 +08:00
|
|
|
|
lazyLoad (value, resolve) {
|
2023-10-15 22:09:33 +08:00
|
|
|
|
sendChromeAPIMessage({
|
|
|
|
|
|
url: 'bg-anniston-mms/category/children/list',
|
|
|
|
|
|
needMallId: true,
|
|
|
|
|
|
data: {
|
2023-10-25 12:20:10 +08:00
|
|
|
|
parentCatId: value || ''
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res.errorCode === 1000000) {
|
|
|
|
|
|
resolve(res.result.categoryNodeVOS.map(v => {
|
|
|
|
|
|
return {
|
|
|
|
|
|
...v,
|
|
|
|
|
|
leaf: v.isLeaf
|
|
|
|
|
|
}
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-10-25 12:20:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
lazySearch(queryString, resolve) {
|
|
|
|
|
|
sendChromeAPIMessage({
|
|
|
|
|
|
url: 'bg-anniston-mms/category/search',
|
|
|
|
|
|
needMallId: true,
|
|
|
|
|
|
data: {
|
|
|
|
|
|
searchText: queryString || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res.errorCode === 1000000) {
|
|
|
|
|
|
resolve(res.result.categoryPaths.map(v => {
|
|
|
|
|
|
let value = []
|
|
|
|
|
|
let label = []
|
|
|
|
|
|
for (let i = 1; i <= 10; i++ ) {
|
|
|
|
|
|
if (v['cat'+i+'NodeVO']) {
|
|
|
|
|
|
value.push(v['cat'+i+'NodeVO'].catId)
|
|
|
|
|
|
label.push(v['cat'+i+'NodeVO'].catName)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
|
|
|
catId: value,
|
|
|
|
|
|
catName: label
|
|
|
|
|
|
}
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
form: {
|
|
|
|
|
|
url: '',
|
|
|
|
|
|
type: 1, // 默认从temu复制
|
|
|
|
|
|
targetMallId: '',
|
2023-12-20 20:45:00 +08:00
|
|
|
|
targetCatId: [],
|
2024-02-27 15:38:08 +08:00
|
|
|
|
isSameCategory: true,
|
|
|
|
|
|
isSemi: false,
|
|
|
|
|
|
siteId: []
|
2023-10-15 22:09:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
goods: {},
|
|
|
|
|
|
sku: {},
|
2023-10-28 12:28:12 +08:00
|
|
|
|
productDetail: {},
|
2023-11-10 10:41:19 +08:00
|
|
|
|
isCopying: false,
|
2023-12-20 20:45:00 +08:00
|
|
|
|
goodsId: '',
|
|
|
|
|
|
currentUrl: '',
|
|
|
|
|
|
goodsProperty: [],
|
|
|
|
|
|
catId: null,
|
|
|
|
|
|
currentIndex: 0,
|
2024-02-27 15:38:08 +08:00
|
|
|
|
successList: [],
|
|
|
|
|
|
siteList: []
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2024-09-19 21:28:59 +08:00
|
|
|
|
computed: {
|
|
|
|
|
|
mallList () {
|
|
|
|
|
|
const filteredData = this.$store.state.mallList.filter(item => {
|
|
|
|
|
|
return item.isSemiManagedMall == this.form.isSemi
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return filteredData
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-10-15 22:09:33 +08:00
|
|
|
|
created () {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
this.getSiteList()
|
2023-12-20 20:45:00 +08:00
|
|
|
|
if (this.params?.url) {
|
|
|
|
|
|
this.form.url = this.params.url
|
|
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
getSiteList() {
|
|
|
|
|
|
sendChromeAPIMessage({
|
|
|
|
|
|
url: 'bg-visage-mms/config/common/site/query',
|
|
|
|
|
|
needMallId: true,
|
|
|
|
|
|
mallId: this.$store.state.mallList[0].mallId,
|
|
|
|
|
|
data: {}}).then((res) => {
|
|
|
|
|
|
if (res.success) {
|
|
|
|
|
|
this.siteList = res.result.siteBaseList.filter(item => {
|
|
|
|
|
|
return item.matchSemiManaged
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2023-11-10 10:41:19 +08:00
|
|
|
|
toAddToDraft() {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
this.$refs.form.validate((valid) => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
if (this.isMultiCopy) {
|
|
|
|
|
|
this.successList = []
|
|
|
|
|
|
this.currentIndex = 0
|
|
|
|
|
|
this.currentUrl = this.params.urlList[this.currentIndex]
|
|
|
|
|
|
this.execAddToDraft()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.currentUrl = this.form.url
|
|
|
|
|
|
this.execAddToDraft()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
execAddToDraft() {
|
|
|
|
|
|
if (!this.currentUrl.startsWith("http")) {
|
|
|
|
|
|
this.goodsId = this.currentUrl
|
2023-11-10 10:41:19 +08:00
|
|
|
|
this.addToDraftNew()
|
|
|
|
|
|
} else {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
let t = this.currentUrl
|
2023-11-10 10:41:19 +08:00
|
|
|
|
let urlParams = this.parseURL(t)
|
|
|
|
|
|
t = t.substring(0,t.indexOf(".html"))
|
|
|
|
|
|
if (t.lastIndexOf("-g-") > 0) {
|
|
|
|
|
|
t = t.substring(t.lastIndexOf("-g-"), t.length);
|
|
|
|
|
|
t = t.substring(3, t.length);
|
|
|
|
|
|
this.goodsId = t
|
|
|
|
|
|
this.addToDraftNew()
|
|
|
|
|
|
} else if(urlParams.params) {
|
|
|
|
|
|
let goodsId = urlParams.params.goods_id
|
|
|
|
|
|
if (!goodsId) {
|
|
|
|
|
|
this.addToDraft()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.goodsId = goodsId
|
|
|
|
|
|
this.addToDraftNew()
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.addToDraft()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
async addToDraftNew() {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
this.isCopying = true
|
|
|
|
|
|
sendTemuAPIMessage({
|
|
|
|
|
|
url: 'api/oak/integration/render',
|
|
|
|
|
|
anti: true,
|
|
|
|
|
|
data: {
|
|
|
|
|
|
goods_id: this.goodsId
|
|
|
|
|
|
}}).then((res) => {
|
|
|
|
|
|
if (!res.goods || !res.goods.productName) {
|
|
|
|
|
|
//this.isCopying = false
|
|
|
|
|
|
//Message.error("获取商品信息失败,采集失败")
|
|
|
|
|
|
this.addToDraft()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.goods = res.goods
|
|
|
|
|
|
this.sku = res.sku
|
|
|
|
|
|
this.productDetail = res.product_detail
|
|
|
|
|
|
this.catId = this.goods.cat_id
|
|
|
|
|
|
this.goodsProperty = this.goods.goods_property
|
|
|
|
|
|
let specIds = []
|
|
|
|
|
|
this.sku.forEach(item => {
|
|
|
|
|
|
item.specs.forEach(item1 => {
|
|
|
|
|
|
let flag = false
|
|
|
|
|
|
specIds.forEach(item2 => {
|
|
|
|
|
|
if (item2.spec_value == item1.spec_value) {
|
|
|
|
|
|
flag = true
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-02-27 15:38:08 +08:00
|
|
|
|
/*if (!flag && (item1.specKeyId != 1001 && item1.specKeyId != 43404162)) {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
specIds.push({spec_key_id: item1.spec_key_id, spec_value: item1.spec_value})
|
2024-02-27 15:38:08 +08:00
|
|
|
|
}*/
|
2024-03-04 19:28:50 +08:00
|
|
|
|
if (!flag) {
|
|
|
|
|
|
specIds.push({spec_key_id: item1.spec_key_id, spec_value: item1.spec_value})
|
|
|
|
|
|
}
|
2023-12-20 20:45:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2024-09-19 21:28:59 +08:00
|
|
|
|
/*Promise.all(specIds.map(item => this.getSpecIdNew(item).then(res => {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
this.sku.forEach(item1 => {
|
|
|
|
|
|
item1.specs.forEach(item2 => {
|
|
|
|
|
|
if (item2.spec_value == item.spec_value) {
|
|
|
|
|
|
item2.spec_value_id = res.result.specId
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}))).then(() => {
|
|
|
|
|
|
this.$http.post('/api/copyProduct/translateNew',{type: 1, goods: this.goods, sku: this.sku, productDetail: this.productDetail}).then(res => {
|
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
|
this.createDraft(res.data)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-09-19 21:28:59 +08:00
|
|
|
|
})*/
|
|
|
|
|
|
this.toCreateDraftNew(specIds)
|
2023-12-20 20:45:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
async addToDraft() {
|
|
|
|
|
|
this.isCopying = true
|
|
|
|
|
|
this.$http.post('/api/copyProduct/check',null, {params: {type: 0}}).then(res => {
|
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
|
let source
|
|
|
|
|
|
if (this.form.type == '1') {
|
|
|
|
|
|
source = 'temu'
|
|
|
|
|
|
} else if (this.form.type == '2') {
|
|
|
|
|
|
source = 'aliexpress'
|
|
|
|
|
|
}
|
|
|
|
|
|
sendChromeWebReqMessage({
|
|
|
|
|
|
type: source,
|
|
|
|
|
|
url: this.currentUrl,
|
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
|
if (this.form.type == '1') {
|
|
|
|
|
|
if (res.indexOf("window.rawData") == -1) {
|
|
|
|
|
|
this.isCopying = false
|
|
|
|
|
|
Message.error("请检查地址是否正确,或者“TEMU”网站是否出现图形验证码")
|
2023-11-10 10:41:19 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2023-12-20 20:45:00 +08:00
|
|
|
|
let str = res.substring(res.indexOf("window.rawData"))
|
|
|
|
|
|
str = str.substring(0, str.indexOf("<\/script>"))
|
|
|
|
|
|
str = str.substring(str.indexOf("{"))
|
|
|
|
|
|
str = str.substring(0, str.lastIndexOf("}"))
|
|
|
|
|
|
str = str + "}"
|
|
|
|
|
|
|
|
|
|
|
|
let goodsObj = JSON.parse(str)
|
|
|
|
|
|
this.goods = goodsObj.store.goods
|
|
|
|
|
|
this.sku = goodsObj.store.sku
|
|
|
|
|
|
this.catId = this.goods.catId
|
|
|
|
|
|
this.goodsProperty = this.goods.goodsProperty
|
|
|
|
|
|
this.productDetail = goodsObj.store.productDetail
|
|
|
|
|
|
|
2023-11-10 10:41:19 +08:00
|
|
|
|
let specIds = []
|
|
|
|
|
|
this.sku.forEach(item => {
|
|
|
|
|
|
item.specs.forEach(item1 => {
|
|
|
|
|
|
let flag = false
|
|
|
|
|
|
specIds.forEach(item2 => {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
if (item2.specValue == item1.specValue) {
|
2023-11-10 10:41:19 +08:00
|
|
|
|
flag = true
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-02-27 15:38:08 +08:00
|
|
|
|
/*if (!flag && (item1.specKeyId != 1001 && item1.specKeyId != 43404162)) {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
specIds.push({specKeyId: item1.specKeyId, specValue: item1.specValue})
|
2024-02-27 15:38:08 +08:00
|
|
|
|
}*/
|
2024-03-04 19:28:50 +08:00
|
|
|
|
if (!flag) {
|
|
|
|
|
|
specIds.push({specKeyId: item1.specKeyId, specValue: item1.specValue})
|
|
|
|
|
|
}
|
2023-11-10 10:41:19 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
2023-10-15 22:09:33 +08:00
|
|
|
|
|
2024-09-19 21:28:59 +08:00
|
|
|
|
/*Promise.all(specIds.map(item => this.getSpecId(item).then(res => {
|
2023-11-10 10:41:19 +08:00
|
|
|
|
this.sku.forEach(item1 => {
|
|
|
|
|
|
item1.specs.forEach(item2 => {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
if (item2.specValue == item.specValue) {
|
|
|
|
|
|
item2.specValueId = res.result.specId
|
2023-11-10 10:41:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}))).then(() => {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
this.$http.post('/api/copyProduct/translate',{type: 1, goods: this.goods, sku: this.sku, productDetail: this.productDetail}).then(res => {
|
2023-11-10 10:41:19 +08:00
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
|
this.createDraft(res.data)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-09-19 21:28:59 +08:00
|
|
|
|
})*/
|
|
|
|
|
|
this.toCreateDraft(specIds)
|
2023-12-20 20:45:00 +08:00
|
|
|
|
} else if (this.form.type == '2') {
|
2023-11-10 10:41:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-12-20 20:45:00 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.isCopying = false
|
2023-11-10 10:41:19 +08:00
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
2024-09-19 21:28:59 +08:00
|
|
|
|
async toCreateDraft(specIds) {
|
|
|
|
|
|
for (let kk = 0; kk < this.form.targetMallId.length; kk++) {
|
|
|
|
|
|
await Promise.all(specIds.map(item => this.getSpecId(item, this.form.targetMallId[kk]).then(res => {
|
|
|
|
|
|
this.sku.forEach(item1 => {
|
|
|
|
|
|
item1.specs.forEach(item2 => {
|
|
|
|
|
|
if (item2.specValue == item.specValue) {
|
|
|
|
|
|
item2.specValueId = res.result.specId
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
return 0
|
|
|
|
|
|
})))
|
|
|
|
|
|
let res = await this.$http.post('/api/copyProduct/translate',{type: 1, goods: this.goods, sku: this.sku, productDetail: this.productDetail})
|
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
|
await this.createDraft(res.data, this.form.targetMallId[kk])
|
|
|
|
|
|
}
|
|
|
|
|
|
await this.$sleepSync(500)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
async toCreateDraftNew(specIds) {
|
|
|
|
|
|
for (let kk = 0; kk < this.form.targetMallId.length; kk++) {
|
|
|
|
|
|
await Promise.all(specIds.map(item => this.getSpecIdNew(item, this.form.targetMallId[kk]).then(res => {
|
|
|
|
|
|
this.sku.forEach(item1 => {
|
|
|
|
|
|
item1.specs.forEach(item2 => {
|
|
|
|
|
|
if (item2.spec_value == item.spec_value) {
|
|
|
|
|
|
item2.spec_value_id = res.result.specId
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
return 0
|
|
|
|
|
|
})))
|
|
|
|
|
|
let res = await this.$http.post('/api/copyProduct/translateNew',{type: 1, goods: this.goods, sku: this.sku, productDetail: this.productDetail})
|
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
|
await this.createDraft(res.data, this.form.targetMallId[kk])
|
|
|
|
|
|
}
|
|
|
|
|
|
await this.$sleepSync(500)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
async createDraft(data, mallId) {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
let reqData = {}
|
2023-12-20 20:45:00 +08:00
|
|
|
|
let catId = null;
|
|
|
|
|
|
if (this.form.isSameCategory) {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
reqData.catId = this.catId;
|
2023-12-20 20:45:00 +08:00
|
|
|
|
} else {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
reqData.catId = this.form.targetCatId[this.form.targetCatId.length - 1]
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.form.isSemi) {
|
|
|
|
|
|
reqData.productSemiManagedReq = {
|
|
|
|
|
|
bindSiteIds: this.form.siteId
|
|
|
|
|
|
}
|
2023-12-20 20:45:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
let res = await sendChromeAPIMessage({
|
2023-10-15 22:09:33 +08:00
|
|
|
|
url: 'bg-visage-mms/product/draft/add',
|
|
|
|
|
|
needMallId: true,
|
2024-09-19 21:28:59 +08:00
|
|
|
|
mallId: mallId,
|
2024-02-27 15:38:08 +08:00
|
|
|
|
data: reqData})
|
2023-12-20 20:45:00 +08:00
|
|
|
|
|
|
|
|
|
|
if (res.errorCode == 1000000) {
|
|
|
|
|
|
let draftId = res.result.productDraftId
|
|
|
|
|
|
let content = data
|
|
|
|
|
|
let i = 0
|
|
|
|
|
|
if (this.form.isSameCategory) {
|
2024-06-29 11:51:35 +08:00
|
|
|
|
/*let res2 = await this.$http.post('/api/innerCategory/fullById',null , {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
params: {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
id: reqData.catId
|
2023-12-20 20:45:00 +08:00
|
|
|
|
}
|
2024-06-29 11:51:35 +08:00
|
|
|
|
})*/
|
|
|
|
|
|
for (; i < 10; i++) {
|
|
|
|
|
|
if (content['cat' + (i+1) + 'Id']) {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}else {
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-20 20:45:00 +08:00
|
|
|
|
let res3 = await sendChromeAPIMessage({
|
|
|
|
|
|
url: 'bg-anniston-mms/category/template/query',
|
|
|
|
|
|
needMallId: true,
|
2024-09-19 21:28:59 +08:00
|
|
|
|
mallId: mallId,
|
2023-12-20 20:45:00 +08:00
|
|
|
|
data: {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
catId: reqData.catId,
|
2023-12-20 20:45:00 +08:00
|
|
|
|
productCreateTime: null,
|
|
|
|
|
|
langList: [
|
|
|
|
|
|
"en"
|
|
|
|
|
|
]
|
|
|
|
|
|
}})
|
|
|
|
|
|
content.productPropertyReqs = []
|
|
|
|
|
|
for (let j = 0; j < this.goodsProperty.length; j++) {
|
|
|
|
|
|
let temp = {}
|
|
|
|
|
|
|
|
|
|
|
|
for (let k = 0; k < res3.result.properties.length; k++) {
|
|
|
|
|
|
if (this.goodsProperty[j].key == res3.result.properties[k].lang2Name.en) {
|
|
|
|
|
|
temp.templatePid = res3.result.properties[k].templatePid
|
|
|
|
|
|
temp.pid = res3.result.properties[k].pid
|
|
|
|
|
|
temp.refPid = res3.result.properties[k].refPid
|
|
|
|
|
|
temp.propName = res3.result.properties[k].name
|
|
|
|
|
|
for (let x = 0; x < this.goodsProperty[j].values.length; x++) {
|
|
|
|
|
|
if (null == res3.result.properties[k].values) break
|
|
|
|
|
|
for (let l = 0; l < res3.result.properties[k].values.length; l++) {
|
|
|
|
|
|
if (res3.result.properties[k].values[l].lang2Value.en == this.goodsProperty[j].values[x]) {
|
|
|
|
|
|
temp.vid = res3.result.properties[k].values[l].vid
|
|
|
|
|
|
temp.propValue = res3.result.properties[k].values[l].value
|
|
|
|
|
|
temp.valueUnit = ''
|
|
|
|
|
|
temp.valueExtendInfo = ''
|
|
|
|
|
|
temp.controlType = res3.result.properties[k].values[l].controlType
|
|
|
|
|
|
|
|
|
|
|
|
content.productPropertyReqs.push({...temp})
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
} else {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
for (; i < this.form.targetCatId.length; i++) {
|
|
|
|
|
|
content['cat' + (i+1) + 'Id'] = this.form.targetCatId[i]
|
|
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
2024-07-18 14:48:44 +08:00
|
|
|
|
if (content['cat'+(i)+'Id'] != reqData.catId) {
|
2024-06-29 11:51:35 +08:00
|
|
|
|
content['cat'+(++i)+'Id'] = reqData.catId
|
|
|
|
|
|
}
|
2023-12-20 20:45:00 +08:00
|
|
|
|
for (; i < 10; i++) {
|
|
|
|
|
|
content['cat' + (i+1) + 'Id'] = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-18 14:48:44 +08:00
|
|
|
|
content.personalizationSwitch = 0
|
2023-12-20 20:45:00 +08:00
|
|
|
|
content.productDraftId = draftId
|
|
|
|
|
|
|
2024-09-19 21:28:59 +08:00
|
|
|
|
await this.createProduct(content, mallId)
|
2023-12-20 20:45:00 +08:00
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
},
|
2024-09-19 21:28:59 +08:00
|
|
|
|
async createProduct(content, mallId) {
|
2024-02-27 15:38:08 +08:00
|
|
|
|
if (this.form.isSemi) {
|
|
|
|
|
|
content.productSemiManagedReq = {
|
|
|
|
|
|
bindSiteIds: this.form.siteId
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-19 21:28:59 +08:00
|
|
|
|
let res = await sendChromeAPIMessage({
|
2023-10-15 22:09:33 +08:00
|
|
|
|
url: 'bg-visage-mms/product/draft/save',
|
|
|
|
|
|
needMallId: true,
|
2024-09-19 21:28:59 +08:00
|
|
|
|
mallId: mallId,
|
2023-10-15 22:09:33 +08:00
|
|
|
|
data: {
|
|
|
|
|
|
...content
|
2024-09-19 21:28:59 +08:00
|
|
|
|
}})
|
|
|
|
|
|
if (res.errorCode == 1000000) {
|
|
|
|
|
|
this.successList.push(this.currentUrl)
|
|
|
|
|
|
this.saveInfo(mallId)
|
|
|
|
|
|
if (this.isMultiCopy) {
|
|
|
|
|
|
this.currentIndex ++
|
|
|
|
|
|
if (this.currentIndex == this.params.urlList.length) {
|
2023-12-20 20:45:00 +08:00
|
|
|
|
this.isCopying = false
|
2024-09-19 21:28:59 +08:00
|
|
|
|
this.$emit('onSuccess')
|
|
|
|
|
|
MessageBox.alert(`成功添加${this.successList.length}个商品进入草稿箱`)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.currentUrl = this.params.urlList[this.currentIndex]
|
|
|
|
|
|
this.execAddToDraft()
|
2023-12-20 20:45:00 +08:00
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
} else {
|
2024-09-19 21:28:59 +08:00
|
|
|
|
this.isCopying = false
|
|
|
|
|
|
Message.success("成功添加到草稿箱")
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
2024-09-19 21:28:59 +08:00
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await this.$sleepSync(1000)
|
|
|
|
|
|
this.createProduct(content)
|
|
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
},
|
2023-11-10 10:41:19 +08:00
|
|
|
|
getSpecIdNew(data) {
|
|
|
|
|
|
return sendChromeAPIMessage({
|
|
|
|
|
|
url: 'bg-anniston-mms/sku/spec/byName/queryOrAdd',
|
|
|
|
|
|
needMallId: true,
|
|
|
|
|
|
mallId: this.form.targetMallId,
|
|
|
|
|
|
data: {
|
|
|
|
|
|
parentSpecId: data.spec_key_id,
|
|
|
|
|
|
specName: data.spec_value
|
|
|
|
|
|
}}).then((res) => {
|
|
|
|
|
|
if (res.errorCode == 1000000) {
|
|
|
|
|
|
return res
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.getSpecIdNew(data)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2024-09-19 21:28:59 +08:00
|
|
|
|
getSpecId(data, mallId) {
|
2023-10-15 22:09:33 +08:00
|
|
|
|
return sendChromeAPIMessage({
|
|
|
|
|
|
url: 'bg-anniston-mms/sku/spec/byName/queryOrAdd',
|
|
|
|
|
|
needMallId: true,
|
2024-09-19 21:28:59 +08:00
|
|
|
|
mallId: mallId,
|
2023-10-15 22:09:33 +08:00
|
|
|
|
data: {
|
|
|
|
|
|
parentSpecId: data.specKeyId,
|
|
|
|
|
|
specName: data.specValue
|
|
|
|
|
|
}}).then((res) => {
|
|
|
|
|
|
if (res.errorCode == 1000000) {
|
|
|
|
|
|
return res
|
|
|
|
|
|
} else {
|
2024-09-19 21:28:59 +08:00
|
|
|
|
this.getSpecId(data, mallId)
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2024-09-19 21:28:59 +08:00
|
|
|
|
saveInfo(mallId) {
|
2023-10-15 22:09:33 +08:00
|
|
|
|
let mallInfo = this.$store.state.mallList.filter(item => {
|
2024-09-19 21:28:59 +08:00
|
|
|
|
return item.mallId == mallId
|
2023-10-15 22:09:33 +08:00
|
|
|
|
})
|
|
|
|
|
|
this.$http.post('/api/copyProduct/add', {
|
|
|
|
|
|
mallId: mallInfo[0].mallId,
|
|
|
|
|
|
mallName: mallInfo[0].mallName,
|
2023-12-20 20:45:00 +08:00
|
|
|
|
url: this.currentUrl,
|
2023-10-15 22:09:33 +08:00
|
|
|
|
type: this.form.type
|
|
|
|
|
|
}).then(res1 => {
|
|
|
|
|
|
if (res1.code == 0) {
|
|
|
|
|
|
this.$store.dispatch('getUserInfo')
|
2023-12-20 20:45:00 +08:00
|
|
|
|
if (!this.isMultiCopy) {
|
|
|
|
|
|
this.$emit('onSuccess')
|
|
|
|
|
|
}
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-11-10 10:41:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
parseURL(url) {
|
|
|
|
|
|
let a = document.createElement('a');
|
|
|
|
|
|
a.href = url;
|
|
|
|
|
|
return {
|
|
|
|
|
|
source: url,
|
|
|
|
|
|
protocol: a.protocol.replace(':',''),
|
|
|
|
|
|
host: a.hostname,
|
|
|
|
|
|
port: a.port,
|
|
|
|
|
|
query: a.search,
|
|
|
|
|
|
params: (function(){
|
|
|
|
|
|
var ret = {},
|
|
|
|
|
|
seg = a.search.replace(/^\?/,'').split('&'),
|
|
|
|
|
|
len = seg.length, i = 0, s;
|
|
|
|
|
|
for (;i<len;i++) {
|
|
|
|
|
|
if (!seg[i]) { continue; }
|
|
|
|
|
|
s = seg[i].split('=');
|
|
|
|
|
|
ret[s[0]] = s[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
})(),
|
|
|
|
|
|
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
|
|
|
|
|
|
hash: a.hash.replace('#',''),
|
|
|
|
|
|
path: a.pathname.replace(/^([^\/])/,'/$1'),
|
|
|
|
|
|
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
|
|
|
|
|
|
segments: a.pathname.replace(/^\//,'').split('/')
|
|
|
|
|
|
};
|
2023-10-15 22:09:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.bottom {
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|