This commit is contained in:
liushiwei
2024-06-29 11:51:35 +08:00
parent 9253427bcc
commit 6356004d74
29 changed files with 3905 additions and 501 deletions

View File

@@ -18,6 +18,15 @@
:value="item.mallId">
</el-option>
</el-select>
<label style="width:90px">站点</label>
<el-select v-model="siteId" placeholder="请选择" size="small">
<el-option
v-for="item in siteList"
:key="item.siteId"
:label="item.siteName"
:value="item.siteId">
</el-option>
</el-select>
</div>
</div>
</template>
@@ -29,6 +38,10 @@
<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:140px; text-align: right;">起始页</label>
<el-input size="small" placeholder="请输入起始页" style="width: 100px; display: inline" type="number" v-model="search.startPage"></el-input>
<label style="width:140px; text-align: right;">结束页</label>
<el-input size="small" placeholder="请输入起始页" style="width: 100px; display: inline" type="number" v-model="search.endPage"></el-input>
<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>
@@ -37,7 +50,6 @@
<ai-table
:tableData="tableData"
:col-configs="colConfigs"
:total="total"
style="margin-top: 8px;"
@selection-change="handleSelectionChange"
:isShowPagination="false">
@@ -52,7 +64,12 @@
:close-on-click-modal="false"
width="790px"
customFooter
@close="handleClose">
@close="dlgShow = false">
<el-alert
title="默认“承诺发货时效”为“2个工作日内发货”"
type="success"
:closable="false">
</el-alert>
<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="请选择运费模板">
@@ -64,12 +81,6 @@
</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
@@ -80,6 +91,30 @@
</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
prop="upMoney"
label="上浮金额:"
:rules="[{ required: true, message: '请输入上浮金额', trigger: 'blur' }]">
<el-input size="small" placeholder="请输入上浮金额" type="number" v-model="configForm.upMoney"></el-input>
</el-form-item>
<el-form-item
prop="brand"
label="品牌:">
<el-select style="width: 380px" clearable v-model="configForm.brandId" placeholder="请选择品牌">
<el-option
v-for="item in brandList"
:key="item.vid"
:label="item.brandNameEn"
:value="item.vid">
</el-option>
</el-select>
</el-form-item>
</el-form>
<div class="dialog-footer" slot="footer">
<el-button @click="dlgShow = false"> </el-button>
@@ -92,15 +127,19 @@
<script>
import {sendChromeAPIMessage} from '@/api/chromeApi'
import {timestampToTime} from '@/utils/date'
import {transform, transformSubmitForHalf} from '@/utils/product'
import { Message } from 'element-ui'
import {transformSubmitForHalf} from '@/utils/product'
import { Message, MessageBox } from 'element-ui'
export default {
name: 'CopyProduct',
name: 'Draft',
data () {
return {
mallId: '',
siteId: '',
siteList: [],
search: {
startPage: 1,
endPage: 10,
productName: ''
},
colConfigs: [
@@ -115,7 +154,6 @@ import { Message } from 'element-ui'
page: 1,
pageSize: 100,
tableData: [],
total: 0,
dlgShow: false,
@@ -124,7 +162,10 @@ import { Message } from 'element-ui'
freightTemplateId: '',
stockNumber: 5,
siteList: [],
wareHouseList: []
upMoney: 0.0,
wareHouseList: [],
brandId: '',
brandName: ''
},
wareHouseList: [],
@@ -133,11 +174,16 @@ import { Message } from 'element-ui'
ids: [],
sites: [],
loadingText: '拼命加载中……'
loadingText: '拼命加载中……',
successNumber: 0,
errorNumber: 0,
brandList: [],
selectBrand: {}
}
},
created () {
// this.getDraftList()
this.getSiteList()
},
methods: {
@@ -146,11 +192,33 @@ import { Message } from 'element-ui'
Message.error("请选择店铺")
return
}
if (!this.siteId) {
Message.error("请选择站点")
return
}
if (!this.search.startPage || (this.search.startPage < 1)) {
Message.error("起始页不能为空且不能小于1")
return
}
if (!this.search.endPage || (this.search.startPage < 1)) {
Message.error("结束页不能为空")
return
}
if (this.search.startPage > this.search.endPage) {
Message.error("起始页不能大于结束页")
return
}
this.isLoading = true
this.loadingText = '拼命加载中……'
this.tableData = []
this.page = this.search.startPage
this.getDraftList()
},
async getDraftList () {
let sites = []
if (this.siteId) {
sites.push(this.siteId)
}
let res = await sendChromeAPIMessage({
url: 'bg-visage-mms/product/draft/pageQuery',
needMallId: true,
@@ -158,7 +226,8 @@ import { Message } from 'element-ui'
data: {
page: this.page,
pageSize: this.pageSize,
...this.search
...this.search,
bindSiteIds: sites
}})
if (res.success && res.errorCode == 1000000) {
@@ -191,7 +260,7 @@ import { Message } from 'element-ui'
if (this.page == 1 && res.result.pageItems.length == 0) {
this.isLoading = false
}
else if (res.result.pageItems.length == this.pageSize) {
else if (res.result.pageItems.length == this.pageSize && this.page < this.search.endPage) {
this.page ++
this.getDraftList()
} else {
@@ -205,32 +274,51 @@ import { Message } from 'element-ui'
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.sites.push(this.siteId)
this.configForm.siteList = this.sites
this.freightTmplList = []
this.wareHouseList = []
this.configForm.freightTemplateId = ''
this.configForm.wareHouseList = []
await this.getFreightTmplList(this.sites)
await this.getWareahouseList(this.sites)
await this.getBrandList()
this.dlgShow = true
},
async toBtachSubmit() {
this.$refs.configForm.validate((valid) => {
if (valid) {
if (this.configForm.brandId) {
this.brandList.map(item => {
if (item.vid == this.configForm.brandId) {
this.selectBrand = item
}
})
}
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
this.successNumber = 0
this.errorNumber = 0
this.submitSpu(0)
}
})
},
async submitSpu(spuId) {
async submitSpu(idx) {
if (idx == this.ids.length) {
this.isLoading = false
MessageBox.alert('总共提交' + this.ids.length + '个商品,成功' + this.successNumber + '个,失败' + this.errorNumber + '个', '提示', {
confirmButtonText: '确定',
callback: action => {
this.toLoad()
}
})
return
} else {
this.loadingText = '正在提交第' + (idx+1) + '/' + this.ids.length + '个商品,成功' + this.successNumber + '个,失败' + this.errorNumber + '个'
}
let spuId = this.ids[idx]
let res = await sendChromeAPIMessage({
url: 'bg-visage-mms/product/draft/query',
needMallId: true,
@@ -239,15 +327,53 @@ import { Message } from 'element-ui'
productDraftId: spuId
}})
if (res.success && res.errorCode == 1000000) {
let catId = this.getCategoryId(res.result)
let brandProperty = await this.queryProperty(catId)
let content = transformSubmitForHalf(res.result, this.configForm, spuId)
if (this.configForm.brandId && brandProperty) {
let flag = false
content.productPropertyReqs.map(item => {
if (item.propName == '品牌名') {
flag = true
item.pid = brandProperty.pid
item.refPid = brandProperty.refPid
item.templatePid = brandProperty.templatePid
item.propValue = this.selectBrand.brandNameEn
item.vid = this.selectBrand.vid
}
})
if (!flag) {
content.productPropertyReqs.push({
"templatePid": brandProperty.templatePid,
"pid": brandProperty.pid,
"refPid": brandProperty.refPid,
"propName": "品牌名",
"vid": this.selectBrand.vid,
"propValue": this.selectBrand.brandNameEn,
"valueUnit": "",
"valueExtendInfo": "",
"numberInputValue": ""
})
}
}
let res1 = await sendChromeAPIMessage({
url: 'bg-visage-mms/product/add',
needMallId: true,
mallId: this.mallId,
data: content})
console.log(res1)
if (res1.success && res1.errorCode == 1000000) {
this.successNumber += 1
} else {
this.errorNumber += 1
}
setTimeout(() => {
idx ++
this.submitSpu(idx)
}, 1000)
}
},
async getFreightTmplList(siteId) {
@@ -294,39 +420,6 @@ import { Message } from 'element-ui'
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',
@@ -339,6 +432,52 @@ import { Message } from 'element-ui'
})
}
},
async getBrandList() {
let res = await sendChromeAPIMessage({
url: 'bg-anniston-mms/category/brand/property/value/pageQuery',
needMallId: true,
mallId: this.mallId,
data: {
"page": 1,
"pageSize": 50
}})
if (res.success && res.errorCode == 1000000) {
this.brandList = res.result.pageItems
}
},
async queryProperty(catId) {
let res = await sendChromeAPIMessage({
url: 'bg-anniston-mms/category/template/query',
needMallId: true,
mallId: this.mallId,
data: {
"catId": catId,
"productCreateTime": null,
"langList": [
"en"
]
}})
if (res.success && res.errorCode == 1000000) {
let properties = res.result.properties.filter(item => {
return item.name == '品牌名'
})
if (properties && properties.length > 0) {
return properties[0]
} else {
return null
}
}
},
getCategoryId(obj) {
let i = 1
while(true) {
if (!obj.categories['cat'+i].catId) {
break
}
i++
}
return obj.categories['cat'+(i-1)].catId
}
}
}
</script>