function generate(data) {
return {
name: "customCode",
data() {
return {
pagination: false,
visible: false,
data: {
list: [],
},
columns: [{
title: "序",
dataIndex: "index",
width: 30,
align: "center",
customRender: (text, row, index) => {
const obj = {
children: text,
attrs: {
rowSpan: 1,
},
};
if (row.productName == "合计") {
return "";
}
if (index % 2 == 0) {
obj.attrs.rowSpan = 2;
} else {
obj.attrs.rowSpan = 0;
}
return obj;
},
},
{
title: "产品",
dataIndex: "productName",
align: "center",
width: 320,
customRender: (text, row, index) => {
const obj = {
children: text,
attrs: {
colSpan: 1,
},
};
if (index % 2 == 1) {
obj.children = "备注:" + row.planBz;
obj.attrs.colSpan = 6;
return obj;
} else {
return text;
}
},
},
{
title: "件数",
dataIndex: "productCount",
align: "center",
width: 36,
customRender: (text, row, index) => {
const obj = {
children: text,
attrs: {
colSpan: 1,
},
};
if (index % 2 == 1) {
obj.attrs.colSpan = 0;
return obj;
} else {
return text;
}
},
},
{
title: "数量",
dataIndex: "totalNum",
align: "center",
width: 60,
customRender: (text, row, index) => {
const that = this.$refs.tableRef;
const obj = {
children: text,
attrs: {
colSpan: 1,
},
};
if (index % 2 == 1) {
obj.attrs.colSpan = 0;
} else {
// obj.children = that.$scopedSlots["totalNum"](text, row, index);
}
return obj;
},
},
{
title: '批次信息',
dataIndex: 'productBatch',
align: 'center',
customRender: (text, row, index) => {
const that = this.$refs.tableRef
const obj = {
children: text,
attrs: {
colSpan: 1
},
}
if (index % 2 == 1) {
obj.attrs.colSpan = 0
} else {
obj.children = that.$scopedSlots['productBatch'](text, row, index)
}
return obj
},
},
],
};
},
async mounted() {
if (data.name == "custome") {
//开发模式
const ret = await this.loadData();
if (!ret.success || ret.result.length < 1) {
return;
}
const newData = ret.result[0];
newData.list = await this.merge(newData.list, newData);
let unit = newData.list[0].unit2
console.log(newData);
this.data = newData;
this.data.unit = unit
} else {
data.list = await this.merge(data.list, data);
let unit = data.list[0].unit2
console.log(data);
this.data = data;
this.data.unit = unit
}
this.$emit("onload");
//this.showModal()
},
methods: {
async loadData() {
const ret = await this.$http.get(
`/erp/order/getPrintingReturn?planIds=1745635825326120961`
);
return ret;
},
async merge(list, data) {
const map = {};
let totalSquareNum = 0;
let totalProductCount = 0;
for (let item of list) {
let key = item.productName + "_" + item.sizeWidth; // 修改这里
let row = map[key];
item.square = (
((item.sizeWidth || 0) / 1000) *
(item.sizeLength || 0) *
(item.productCount || 0)
).round(2);
item.weight = (
(item.sizeWeight || 0) * (item.productCount || 0)
).round(2);
if (!item.planBz || item.planBz == "null") {
item.planBz = ""
}
if (item.planBz && /bh[0-9]{19}.*/.test(item.planBz)) {
const m = item.planBz.match(/bh([0-9]{19})/)
item.bh = "" + "-" + m[1].substr(11, 8)
item.planBz = item.planBz.replace(/bh([0-9]{19}),/, '')
} else {
item.bh = ""
}
if (!row) {
row = {
...item,
};
row.subList = [{
...item,
}, ];
map[key] = row;
} else {
row.totalNum = (row.totalNum * 1 + item.totalNum * 1).round(2);
row.square = (row.square * 1 + item.square * 1).round(2);
row.weight = (row.weight * 1 + item.weight * 1).round(2);
row.productCount =
row.productCount * 1 + (item.productCount * 1).round(2);
row.planBz = row.planBz + item.planBz;
row.subList.push({
...item,
});
}
if (!isNaN(item.totalNum)) {
// 检查item.totalNum是否是数字
totalSquareNum += (item.totalNum * 1).round(2);
}
if (!isNaN(item.productCount)) {
// 检查item.productCount是否是数字
totalProductCount += (item.productCount * 1).round(2);
}
}
console.log("totalSquareNum:");
console.log(totalSquareNum);
const newList = [];
let index = 1;
Object.keys(map).forEach((key) => {
if (
key !== "undefined_undefined" &&
key !== "/" &&
key !== "/_undefined" &&
key !== "_undefined" &&
key
) {
console.log(key);
map[key].index = index;
index++;
newList.push(map[key]);
newList.push({
productName: "备注",
bz: map[key].planBz,
});
}
});
const hjRow = {
productName: "合计",
subList: [],
squareNum: totalSquareNum.round(2),
productCount: totalProductCount.round(2),
};
newList.push(hjRow);
return newList.filter((item) => {
return item.productName + "_" + item.sizeWidth && item.productName != "/";
});
},
},
};
}
console