This commit is contained in:
liushiwei
2023-08-08 02:01:34 +08:00
parent 689a83eeba
commit 531aa855d2

View File

@@ -12,8 +12,8 @@
<ai-search-bar> <ai-search-bar>
<template #left> <template #left>
<el-button type="button" :icon="'el-icon-delete'" :class="'el-button el-button--primary'" @click="remove()">删除</el-button> <el-button type="button" :icon="'el-icon-delete'" :class="'el-button el-button--primary'" @click="remove()">删除</el-button>
<el-button v-if="$store.state.mallName" type="button" :class="'el-button el-button--primary'" @click="toAddTemplate()">{{$store.state.mallName}}添加商品模板</el-button> <el-button v-if="$store.state.mallName" type="button" :class="'el-button el-button--primary'" @click="toAddTemplate()">添加商品模板</el-button>
<el-button v-if="$store.state.mallName" type="button" :class="'el-button el-button--primary'" @click="addToDraft()">将商品模板添加到{{$store.state.mallName}}草稿箱</el-button> <el-button v-if="$store.state.mallName" type="button" :class="'el-button el-button--primary'" @click="beforeAddToDraft">添加到草稿箱</el-button>
</template> </template>
<template #right> <template #right>
<el-button size="small" circle icon="el-icon-refresh-right" @click="getList()"></el-button> <el-button size="small" circle icon="el-icon-refresh-right" @click="getList()"></el-button>
@@ -36,22 +36,84 @@
title="商品列表" title="商品列表"
:visible.sync="dlgShow" :visible.sync="dlgShow"
:close-on-click-modal="false" :close-on-click-modal="false"
width="70%" width="80%"
:before-close="handleClose"> :before-close="handleClose">
<ai-table <ai-list class="list">
:tableData="productTableData" <template slot="content">
:col-configs="productColConfigs" <div class="content">
:total="productPage.total" <ai-search-bar>
:current.sync="productPage.page" :size.sync="productPage.pageSize" <template #left>
style="margin-top: 8px;" <div class="search-item">
@selection-change="productHandleSelectionChange" <label style="width:90px">店铺</label>
@getList="getProductList"> <el-select v-model="productPage.mallId" @change="productTableData = [], productPage.total = 0, productPage.page =1, getProductList()" placeholder="请选择">
</ai-table> <el-option
v-for="item in $store.state.mallList"
:key="item.mallId"
:label="item.mallName"
:value="item.mallId">
</el-option>
</el-select>
</div>
<div class="search-item">
<label style="width:90px">SKC</label>
<el-input size="small" placeholder="请输入SKC多个用,隔开" v-model="productPage.productSkcIds" @keyup.enter.native="productPage.page =1, getProductList()"></el-input>
</div>
<div class="search-item">
<label style="width:90px">商品名称</label>
<el-input size="small" placeholder="请输入商品名称" v-model="productPage.productName" @keyup.enter.native="productPage.page =1, getProductList()"></el-input>
</div>
</template>
<template #right>
<el-button @click="productPage= {
page: 1,
pageSize: 10,
productName: '',
productSkcIds: ''
}, getProductList()">重置</el-button>
<el-button type="primary" @click="search.page =1, getProductList()">查询</el-button>
</template>
</ai-search-bar>
<ai-table
:tableData="productTableData"
:col-configs="productColConfigs"
:total="productPage.total"
:current.sync="productPage.page" :size.sync="productPage.pageSize"
style="margin-top: 8px;"
@selection-change="productHandleSelectionChange"
@getList="getProductList">
</ai-table>
</div>
</template>
</ai-list>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dlgShow = false"> </el-button> <el-button @click="dlgShow = false"> </el-button>
<el-button type="primary" @click="saveProduct">添加到模板</el-button> <el-button type="primary" @click="saveProduct">添加到模板</el-button>
</span> </span>
</el-dialog> </el-dialog>
<el-dialog
title="请选择店铺"
:visible.sync="mallDlgShow"
:close-on-click-modal="false"
width="500px"
:before-close="handleClose">
<el-form class="ai-form" :model="form" label-width="120px" ref="form">
<el-form-item label="店铺" style="width: 100%;" prop="targetMallId" :rules="[{ required: true, message: '请选择店铺', trigger: 'blur' }]">
<el-select v-model="form.targetMallId" placeholder="请选择">
<el-option
v-for="item in $store.state.mallList"
:key="item.mallId"
:label="item.mallName"
:value="item.mallId">
</el-option>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="mallDlgShow = false"> </el-button>
<el-button type="primary" @click="addToDraft">确定</el-button>
</span>
</el-dialog>
</div> </div>
</template> </template>
@@ -87,7 +149,7 @@ import { Message } from 'element-ui'
dlgShow: false, dlgShow: false,
productTableData: [], productTableData: [],
productPage: {page: 1, pageSize: 10, total: 0}, productPage: {page: 1, pageSize: 10, mallId: '', productName: '', productSkcIds: '', total: 0},
productColConfigs: [ productColConfigs: [
{ type: "selection", width: '70px', align: 'left', fixed: 'left'}, { type: "selection", width: '70px', align: 'left', fixed: 'left'},
{ prop: 'productSpu', label: 'SPU ID', align: 'left' }, { prop: 'productSpu', label: 'SPU ID', align: 'left' },
@@ -95,12 +157,20 @@ import { Message } from 'element-ui'
{ prop: 'productName', label: '商品名称', align: 'left' }, { prop: 'productName', label: '商品名称', align: 'left' },
{ prop: 'createTime', label: '创建时间', align: 'left' } { prop: 'createTime', label: '创建时间', align: 'left' }
], ],
mallDlgShow: false,
productIds: [], productIds: [],
form: {
targetMallId: ''
}
} }
}, },
created () { created () {
this.getList() this.getList()
if (this.$store.state.mallList.length > 0) {
this.productPage.mallId = this.$store.state.mallList[0].mallId
}
}, },
methods: { methods: {
@@ -159,11 +229,21 @@ import { Message } from 'element-ui'
}) })
}, },
getProductList() { getProductList() {
let params = {};
params.page = this.productPage.page;
params.pageSize = this.productPage.pageSize;
if (this.productPage.productName) {
params.productName = this.productPage.productName
}
if (this.productPage.productSkcIds) {
params.productSkcIds = this.productPage.productSkcIds.split(',')
}
sendChromeAPIMessage({ sendChromeAPIMessage({
url: 'bg-visage-mms/product/skc/pageQuery', url: 'bg-visage-mms/product/skc/pageQuery',
needMallId: true, needMallId: true,
mallId: this.productPage.mallId,
data: { data: {
...this.productPage ...params
}}).then((res) => { }}).then((res) => {
if (res.errorCode == 1000000) { if (res.errorCode == 1000000) {
this.productPage.total = res.result.total this.productPage.total = res.result.total
@@ -187,11 +267,11 @@ import { Message } from 'element-ui'
}, },
saveProduct() { saveProduct() {
if (this.productIds.length <= 0) { if (this.productIds.length <= 0) {
alert('请选择商品'); Message.error('请选择商品');
return; return;
} }
this.productIds.map((productSpu, index) => { this.productIds.map((productSpu, index) => {
sendChromeAPIMessage({ setTimeout(sendChromeAPIMessage({
url: 'bg-visage-mms/product/query', url: 'bg-visage-mms/product/query',
needMallId: true, needMallId: true,
data: { data: {
@@ -200,8 +280,12 @@ import { Message } from 'element-ui'
}}).then((res) => { }}).then((res) => {
if (res.errorCode == 1000000) { if (res.errorCode == 1000000) {
let content = transform(res.result) 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', { this.$http.post('/api/product/add', {
mallName: this.$store.state.mallName, mallId: mallInfo[0].mallId,
mallName: mallInfo[0].mallName,
productSpu: res.result.productId, productSpu: res.result.productId,
productName: res.result.productName, productName: res.result.productName,
content: content content: content
@@ -214,42 +298,52 @@ import { Message } from 'element-ui'
} }
}) })
} }
}) }), 200 * index)
}) })
}, },
addToDraft() { beforeAddToDraft() {
if (this.ids.length <= 0) { if (this.ids.length <= 0) {
alert('请选择商品模板'); Message.error('请选择商品模板');
return; return;
} }
this.ids.map((id, index) => { this.mallDlgShow = true
let product = this.tableData.filter((item) => { },
return item.id == id addToDraft() {
}) this.$refs.form.validate((valid) => {
setTimeout(() => { if (valid) {
sendChromeAPIMessage({ this.ids.map((id, index) => {
url: 'bg-visage-mms/product/draft/add', let product = this.tableData.filter((item) => {
needMallId: true, return item.id == id
data: { })
catId: 26117 setTimeout(() => {
}}).then((res) => {
if (res.errorCode == 1000000) {
let draftId = res.result.productDraftId
let content = JSON.parse(product[0].content)
content.productDraftId = draftId
sendChromeAPIMessage({ sendChromeAPIMessage({
url: 'bg-visage-mms/product/draft/save', url: 'bg-visage-mms/product/draft/add',
needMallId: true, needMallId: true,
mallId: this.form.targetMallId,
data: { data: {
...content catId: 26117
}}).then((res) => { }}).then((res) => {
if (res.errorCode == 1000000) { if (res.errorCode == 1000000) {
Message.success("商品【" + product[0].productName + "】成功添加到草稿箱") let draftId = res.result.productDraftId
let content = JSON.parse(product[0].content)
content.productDraftId = draftId
sendChromeAPIMessage({
url: 'bg-visage-mms/product/draft/save',
needMallId: true,
mallId: this.form.targetMallId,
data: {
...content
}}).then((res) => {
if (res.errorCode == 1000000) {
Message.success("商品【" + product[0].productName + "】成功添加到草稿箱")
}
})
} }
}) })
} }, 1000*index)
}) })
}, 1000*index) this.mallDlgShow = false
}
}) })
} }
} }