Browse Source

导出excel时可以剔除不需要的列

java8
han\hanst 9 months ago
parent
commit
49db63ea41
  1. 13
      src/utils/excel-util.js
  2. 60
      src/utils/export-options.js
  3. 28
      src/views/modules/ecss/pallet_upload_excel.vue

13
src/utils/excel-util.js

@ -20,7 +20,8 @@ const exportOptionDefault = {
mergeSetting: {
refs: [], //检测需要合并的数据列属性名
columns: [] //检测需要合并后,要合并的列,以第一条数据为准合并
}
},
dropColumns: [],//导出时需要过滤掉的列
};
let HEADERS = [];
for (let i =0;i< 200;i++) {
@ -88,16 +89,18 @@ let getMergeSetting = (data, s, allCols) => {
let setStyle = (ws, s) => {}
let getColSetting = mapping => {
let getColSetting = (mapping,dropColums) => {
let columns = [];
for (let i = 0; i < mapping.length; i++) {
let c = mapping[i];
if (dropColums.indexOf(c.columnProp) == -1) {
columns.push({
property: c.prop || c.property,
label: c.label,
property: c.columnProp || c.property,
label: c.columnLabel,
type: "default"
});
}
}
return {
columns: columns
};
@ -105,7 +108,7 @@ let getColSetting = mapping => {
let export2Excel = opt => {
validOption(opt);
let options = Object.assign({}, exportOptionDefault, opt);
let expColSetting = !!options.tableRef ? options.tableRef : getColSetting(options.columnMapping);
let expColSetting = !!options.tableRef ? options.tableRef : getColSetting(options.columnMapping, options.dropColumns);
ajax.$post(options.url, options.params, resp => {
if (resp.status !== 200) {
Message.error({

60
src/utils/export-options.js

@ -1,64 +1,64 @@
const PalletSku = {
columnMapping: [
{
prop: "seqNo",
label: "序号",
columnProp: "seqNo",
columnLabel: "序号",
},
{
prop: "cmcInvoice",
label: "发票号",
columnProp: "cmcInvoice",
columnLabel: "发票号",
},
{
prop: "seqNo",
label: "托盘号/箱号",
columnProp: "seqNo",
columnLabel: "托盘号/箱号",
},
{
prop: "customerPO",
label: "PO",
columnProp: "customerPO",
columnLabel: "PO",
},
{
prop: "pn",
label: "PN",
columnProp: "pn",
columnLabel: "PN",
},
{
prop: "qty",
label: "数量",
columnProp: "qty",
columnLabel: "数量",
},
{
prop: "seqNo",
label: "箱数",
columnProp: "boxQty",
columnLabel: "箱数",
},
{
prop: "seqNo",
label: "Rolls",
columnProp: "Rolls",
columnLabel: "Rolls",
},
{
prop: "seqNo",
label: "托数",
columnProp: "pallet_qty",
columnLabel: "托数",
},
{
prop: "seqNo",
label: "长(M)",
columnProp: "length",
columnLabel: "长(M)",
},
{
prop: "seqNo",
label: "宽(M)",
columnProp: "width",
columnLabel: "宽(M)",
},
{
prop: "seqNo",
label: "高(M)",
columnProp: "height",
columnLabel: "高(M)",
},
{
prop: "seqNo",
label: "体积",
columnProp: "volume",
columnLabel: "体积",
},
{
prop: "seqNo",
label: "毛重",
columnProp: "grossWeight",
columnLabel: "毛重",
},
{
prop: "seqNo",
label: "净重",
columnProp: "netWeight",
columnLabel: "净重",
}
],
mergeSetting: {

28
src/views/modules/ecss/pallet_upload_excel.vue

@ -106,41 +106,41 @@
columnLabel: "数量",
},
{
columnProp: "seqNo",
columnProp: "boxQty",
columnLabel: "箱数",
},
{
columnProp: "seqNo",
columnProp: "Rolls",
columnLabel: "Rolls",
},
{
columnProp: "seqNo",
columnProp: "pallet_qty",
columnLabel: "托数",
},
{
columnProp: "seqNo",
columnProp: "length",
columnLabel: "长(M)",
},
{
columnProp: "seqNo",
columnProp: "width",
columnLabel: "宽(M)",
},
{
columnProp: "seqNo",
columnProp: "height",
columnLabel: "高(M)",
},
{
columnProp: "seqNo",
columnProp: "volume",
columnLabel: "体积",
},
{
columnProp: "seqNo",
columnProp: "grossWeight",
columnLabel: "毛重",
},
{
columnProp: "seqNo",
columnProp: "netWeight",
columnLabel: "净重",
},
}
],
}
},
@ -153,15 +153,15 @@
cmcInvoice: this.pageData.cmcInvoice,
createBy: this.$store.state.user.name,
}
let columnMapping = excelOpts.PalletSku.columnMapping;
excel.exportTable({
url: "/ecss/coDel/searchEcssCoDelNotifyDetail",
columnMapping: columnMapping,
mergeSetting: excelOpts.PalletSku.mergeSetting,
columnMapping: this.columnList1,//table
mergeSetting: [],//
params: searchData,
fileName: this.exportName+".xlsx",
rowFetcher: res => res.data,
columnFormatter: []
columnFormatter: [],
dropColumns: [],//dropColumns: ["netWeight"]
});
},
//

Loading…
Cancel
Save