This commit is contained in:
liushiwei
2024-05-25 10:12:50 +08:00
parent 10c5bce468
commit 9253427bcc
5 changed files with 525 additions and 3 deletions

347
src/view/product/Draft.vue Normal file
View File

@@ -0,0 +1,347 @@
<template>
<div>
<ai-list class="list" v-loading="isLoading" :element-loading-text="loadingText">
<ai-title
slot="title"
title="草稿箱管理"
tips="请先在当前浏览器登录“拼多多跨境卖家中心”,期间保持登录状态"
isShowBottomBorder>
<template #rightBtn>
<div class="title-right">
<div>
<label style="width:90px">店铺</label>
<el-select v-model="mallId" placeholder="请选择" size="small">
<el-option
v-for="item in $store.state.mallList"
:key="item.mallId"
:label="item.mallName"
:value="item.mallId">
</el-option>
</el-select>
</div>
</div>
</template>
</ai-title>
<template slot="content">
<div class="content">
<ai-search-bar>
<template #left>
<el-button v-if="$store.state.mallName" type="button" :class="'el-button el-button--primary'" @click="batchSubmitConfig()">批量提交</el-button>
</template>
<template #right>
<label style="width:120px">商品名称</label>
<el-input clearable size="small" style="display: inline" placeholder="请输入商品名称" v-model="search.productName"></el-input>
<el-button type="primary" @click="toLoad">查询</el-button>
</template>
</ai-search-bar>
<ai-table
:tableData="tableData"
:col-configs="colConfigs"
:total="total"
style="margin-top: 8px;"
@selection-change="handleSelectionChange"
:isShowPagination="false">
</ai-table>
</div>
</template>
</ai-list>
<ai-dialog
title="配置参数"
:visible.sync="dlgShow"
:close-on-click-modal="false"
width="790px"
customFooter
@close="handleClose">
<el-form class="ai-form" :model="configForm" label-width="160px" ref="configForm">
<el-form-item label="运费模板" style="width: 100%;" prop="freightTemplateId" :rules="[{ required: true, message: '请选择运费模板', trigger: 'blur' }]">
<el-select style="width: 380px" v-model="configForm.freightTemplateId" placeholder="请选择运费模板">
<el-option
v-for="item in freightTmplList"
:key="item.freightTemplateId"
:label="item.templateName"
:value="item.freightTemplateId">
</el-option>
</el-select>
</el-form-item>
<el-form-item
prop="stockNumber"
label="库存数量:"
:rules="[{ required: true, message: '请输入库存数量', trigger: 'blur' }]">
<el-input size="small" placeholder="请输入库存数量" type="number" v-model="configForm.stockNumber"></el-input>
</el-form-item>
<el-form-item label="发货仓" style="width: 100%;" prop="wareHouseList" :rules="[{ required: true, message: '请选择发货仓', trigger: 'blur' }]">
<el-select style="width: 380px" multiple v-model="configForm.wareHouseList" placeholder="请选择发货仓">
<el-option
v-for="item in wareHouseList"
:key="item.warehouseId"
:label="item.warehouseName"
:value="item.warehouseId">
</el-option>
</el-select>
</el-form-item>
</el-form>
<div class="dialog-footer" slot="footer">
<el-button @click="dlgShow = false"> </el-button>
<el-button type="primary" @click="toBtachSubmit">确定</el-button>
</div>
</ai-dialog>
</div>
</template>
<script>
import {sendChromeAPIMessage} from '@/api/chromeApi'
import {timestampToTime} from '@/utils/date'
import {transform, transformSubmitForHalf} from '@/utils/product'
import { Message } from 'element-ui'
export default {
name: 'CopyProduct',
data () {
return {
mallId: '',
search: {
productName: ''
},
colConfigs: [
{ type: "selection", width: '70px', align: 'left', fixed: 'left'},
{ prop: 'spuId', label: 'SPU ID', width: '100px', align: 'left' },
{ prop: 'productName', label: '商品名称', align: 'left' },
{ prop: 'category', label: '商品分类', align: 'left'},
{ prop: 'bindSites', label: '经营站点', width: '120px', align: 'left'},
{ prop: 'updatedAt', label: '修改时间', width: '180px', fixed: 'right'}
],
isLoading: false,
page: 1,
pageSize: 100,
tableData: [],
total: 0,
dlgShow: false,
configForm: {
sendGoodsSecond: 172800,
freightTemplateId: '',
stockNumber: 5,
siteList: [],
wareHouseList: []
},
wareHouseList: [],
freightTmplList: [],
ids: [],
sites: [],
loadingText: '拼命加载中……'
}
},
created () {
// this.getDraftList()
},
methods: {
toLoad() {
if (!this.mallId) {
Message.error("请选择店铺")
return
}
this.isLoading = true
this.loadingText = '拼命加载中……'
this.getDraftList()
},
async getDraftList () {
let res = await sendChromeAPIMessage({
url: 'bg-visage-mms/product/draft/pageQuery',
needMallId: true,
mallId: this.mallId,
data: {
page: this.page,
pageSize: this.pageSize,
...this.search
}})
if (res.success && res.errorCode == 1000000) {
res.result.pageItems.map(item => {
let category = ''
for (let i = 1; i < 11; i++) {
if (item.categories['cat'+i].catName) {
category += '->' + item.categories['cat'+i].catName
} else {
break
}
}
category = category.substring(2)
let site = []
let siteId = []
item.copyFromFullyToSemiInfo.bindSites.map(item1 => {
site.push(item1.siteName)
siteId.push(item1.siteId)
})
this.tableData.push({
spuId: item.productDraftId,
productName: item.productName,
category: category,
bindSites: site.join(','),
bindSiteIds: siteId.join(','),
updatedAt: timestampToTime(item.updatedAt)
})
})
if (this.page == 1 && res.result.pageItems.length == 0) {
this.isLoading = false
}
else if (res.result.pageItems.length == this.pageSize) {
this.page ++
this.getDraftList()
} else {
this.isLoading = false
}
}
},
async batchSubmitConfig() {
if (this.ids.length <= 0) {
Message.error('请选择要提交的商品');
return;
}
let id = this.ids[0]
this.sites = []
for (let i = 0; i < this.tableData.length; i++) {
if (this.tableData[i].spuId == id) {
this.sites = this.tableData[i].bindSiteIds.split(',')
}
}
this.configForm.siteList = this.sites
await this.getFreightTmplList(this.sites)
await this.getWareahouseList(this.sites)
this.dlgShow = true
},
async toBtachSubmit() {
this.$refs.configForm.validate((valid) => {
if (valid) {
this.isLoading = true
this.dlgShow = false
for(let i = 0; i < this.ids.length; i++) {
this.loadingText = '正在提交第' + (i+1) + '/' + this.ids.length + '个商品'
this.submitSpu(this.ids[i])
}
this.isLoading = false
}
})
},
async submitSpu(spuId) {
let res = await sendChromeAPIMessage({
url: 'bg-visage-mms/product/draft/query',
needMallId: true,
mallId: this.mallId,
data: {
productDraftId: spuId
}})
if (res.success && res.errorCode == 1000000) {
let content = transformSubmitForHalf(res.result, this.configForm, spuId)
let res1 = await sendChromeAPIMessage({
url: 'bg-visage-mms/product/add',
needMallId: true,
mallId: this.mallId,
data: content})
console.log(res1)
}
},
async getFreightTmplList(siteId) {
let res = await sendChromeAPIMessage({
url: 'bg-visage-mms/freight/template/list',
needMallId: true,
mallId: this.mallId,
data: {
siteIds: siteId
}})
if (res.success && res.errorCode == 1000000) {
res.result.freightTmplSimpleList.map(item => {
this.freightTmplList.push({
freightTemplateId: item.freightTemplateId,
templateName: item.templateName
})
})
}
},
async getWareahouseList(siteId) {
let res = await sendChromeAPIMessage({
url: 'marvel-mms/cn/api/kiana/starlaod/btg/sales/stock/querySiteCanSelectWarehouseList',
needMallId: true,
mallId: this.mallId,
data: {
siteIdList: siteId
}})
if (res.success && res.errorCode == 1000000) {
res.result.warehouseDTOList.map(item => {
item.validWarehouseList.map(item1 => {
this.wareHouseList.push({
warehouseId: item1.warehouseId,
warehouseName: item1.warehouseName
})
})
})
}
},
handleSelectionChange(val) {
this.ids = [];
val.forEach(e => {
this.ids.push(e.spuId);
});
},
saveDraftTemplate(spu, index) {
sendChromeAPIMessage({
url: 'bg-visage-mms/product/draft/query',
needMallId: true,
mallId: this.productPage.mallId,
data: {
productDraftId: spu
}}).then((res) => {
if (res.errorCode == 1000000) {
let content = transform(res.result)
let mallInfo = this.$store.state.mallList.filter(item => {
return item.mallId == this.productPage.mallId
})
this.$http.post('/api/product/add', {
mallId: mallInfo[0].mallId,
mallName: mallInfo[0].mallName,
productSpu: spu,
productName: res.result.productName,
type: 0,
content: content
}).then(res1 => {
if (res1.code == 0) {
Message.success("商品【" + res.result.productName + "】成功添加为商品模板")
if (index == this.productIds.length - 1) {
this.getList()
}
}
})
} else {
this.saveDraftTemplate(spu, index)
}
})
},
async getSiteList() {
let res = await sendChromeAPIMessage({
url: 'bg-visage-mms/config/common/site/query',
needMallId: true,
mallId: this.$store.state.mallList[0].mallId,
data: {}})
if (res.success && res.errorCode == 1000000) {
this.siteList = res.result.siteBaseList.filter(item => {
return item.matchSemiManaged
})
}
},
}
}
</script>
<style scoped lang="scss">
</style>