调整
This commit is contained in:
@@ -33,6 +33,10 @@
|
||||
<label>结束页:</label>
|
||||
<el-input size="small" placeholder="请输入起始页" type="number" v-model="endPage"></el-input>
|
||||
</div>
|
||||
<div class="search-item">
|
||||
<label>SKC:</label>
|
||||
<el-input size="small" placeholder="请输入SKC,多个用逗号隔开" v-model="skcs"></el-input>
|
||||
</div>
|
||||
</template>
|
||||
<template #right>
|
||||
<el-button type="primary" @click="toLoad">加载</el-button>
|
||||
@@ -40,7 +44,8 @@
|
||||
</ai-search-bar>
|
||||
<ai-card title="数据明细" style="padding-bottom: 40px;">
|
||||
<template #right>
|
||||
<el-button type="primary" :disabled="tableData.length == 0" @click="exportWaitUploadToExcel">导出</el-button>
|
||||
<el-button type="primary" :disabled="tableData.length == 0" @click="exportWaitUploadToExcel">导出当前</el-button>
|
||||
<el-button type="primary" @click="exportAllToExcel">导出所有店铺</el-button>
|
||||
</template>
|
||||
<ai-table
|
||||
:isShowPagination="false"
|
||||
@@ -69,7 +74,6 @@
|
||||
<script>
|
||||
import { Message } from 'element-ui'
|
||||
import {sendChromeAPIMessage} from '@/api/chromeApi'
|
||||
import {timestampToTime} from '@/utils/date'
|
||||
import * as XLSX from 'xlsx'
|
||||
import { saveAs } from 'file-saver'
|
||||
|
||||
@@ -83,6 +87,7 @@ import { saveAs } from 'file-saver'
|
||||
},
|
||||
startPage: 1,
|
||||
endPage: 10,
|
||||
skcs: null,
|
||||
reqData: {
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
@@ -130,6 +135,9 @@ import { saveAs } from 'file-saver'
|
||||
Message.error("起始页不能大于结束页")
|
||||
return
|
||||
}
|
||||
if (this.skcs) {
|
||||
this.reqData.productSkcIdList = this.skcs.split(',')
|
||||
}
|
||||
this.$userCheck(this.form.mallId).then(() => {
|
||||
this.reqData.page = this.startPage
|
||||
this.tableData = []
|
||||
@@ -182,6 +190,91 @@ import { saveAs } from 'file-saver'
|
||||
}
|
||||
})
|
||||
},
|
||||
async exportAllToExcel() {
|
||||
this.isLoading = true
|
||||
let list = []
|
||||
for (let j = 0; j < this.$store.state.mallList.length; j++) {
|
||||
let page = 1
|
||||
while(true) {
|
||||
let res = await sendChromeAPIMessage({
|
||||
url: 'bg-visage-mms/labelcode/pageQuery',
|
||||
needMallId: true,
|
||||
mallId: this.$store.state.mallList[j].mallId,
|
||||
anti: true,
|
||||
data: {
|
||||
page: page,
|
||||
pageSize: 100
|
||||
}})
|
||||
if (res.errorCode == 1000000) {
|
||||
for(let i = 0;i < res.result.pageItems.length; i++) {
|
||||
let item = res.result.pageItems[i];
|
||||
let data = {};
|
||||
data.productName = item.productName
|
||||
data.mainImageUrl = item.displayImage
|
||||
data.productSkcId = item.labelCodeVO.productSkcId
|
||||
data.productSkuId = item.labelCodeVO.productSkuId
|
||||
data.labelCode = item.labelCodeVO.labelCode
|
||||
data.extCode = item.labelCodeVO.skcExtCode
|
||||
data.skuExtCode = item.labelCodeVO.skuExtCode
|
||||
data.category = item.leafCat.catName
|
||||
data.displayImage = item.displayImage
|
||||
data.mallName = this.$store.state.mallList[j].mallName
|
||||
|
||||
let temp = item.productSkcSpecList.map(item2 => {
|
||||
return item2.specName
|
||||
})
|
||||
data.skcSpecName = temp.join(',')
|
||||
|
||||
temp = item.productSkuSpecList.map(item2 => {
|
||||
return item2.specName
|
||||
})
|
||||
data.skuSpecName = temp.join(',')
|
||||
|
||||
list.push(data)
|
||||
}
|
||||
|
||||
if (res.result.pageItems.length == 100) {
|
||||
page ++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
await this.$sleepSync(200)
|
||||
}
|
||||
}
|
||||
|
||||
// 假设你有一个表格数据的数组
|
||||
const data = [
|
||||
["商品名称", "分类", "条码编码", "SKC","SKU", "SKC货号", "SKU货号", "主销售属性", "次销售属性", "模板名称", "店铺名称", "图片"]
|
||||
]
|
||||
|
||||
list.map(item => {
|
||||
data.push([item.productName, item.category, item.labelCode, item.productSkcId, item.productSkuId, item.extCode, item.skuExtCode, item.skcSpecName, item.skuSpecName, "", item.mallName, item.displayImage])
|
||||
})
|
||||
|
||||
// 将数据转换为工作表
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(data);
|
||||
|
||||
// 创建工作簿并添加工作表
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
||||
|
||||
// 生成Excel文件
|
||||
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
||||
|
||||
// 使用blob和FileReader创建一个Blob URL
|
||||
const dataBlob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' });
|
||||
const blobUrl = window.URL.createObjectURL(dataBlob);
|
||||
|
||||
// 使用saveAs下载文件
|
||||
saveAs(dataBlob, '商品条码列表.xlsx');
|
||||
|
||||
// 清理
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
|
||||
this.isLoading = false
|
||||
|
||||
},
|
||||
exportWaitUploadToExcel() {
|
||||
// 假设你有一个表格数据的数组
|
||||
const data = [
|
||||
|
||||
Reference in New Issue
Block a user