|
@@ -26,6 +26,9 @@ interface defaultState {
|
|
|
enumMap: any;
|
|
|
// tabldId: number;
|
|
|
bednet_qingdan: any;
|
|
|
+ default_font: any;
|
|
|
+ default_alignment: any;
|
|
|
+ variables: variablesProps[];
|
|
|
}
|
|
|
|
|
|
interface wfQingdanProps {
|
|
@@ -45,6 +48,21 @@ interface wfQingdanProps {
|
|
|
// replace?: any;
|
|
|
// formula_ori?: any;
|
|
|
differ?: any;
|
|
|
+ /**
|
|
|
+ * @description 表头字段
|
|
|
+ */
|
|
|
+ fields?: any;
|
|
|
+}
|
|
|
+
|
|
|
+interface variablesProps {
|
|
|
+ /**
|
|
|
+ * @description 单元格变量
|
|
|
+ */
|
|
|
+ cell: string;
|
|
|
+ /**
|
|
|
+ * @description 变量名称
|
|
|
+ */
|
|
|
+ field: string;
|
|
|
}
|
|
|
|
|
|
export const useHooksCpQuote = (t?: any) => {
|
|
@@ -124,7 +142,14 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
}
|
|
|
],
|
|
|
newTableData: [],
|
|
|
- enumMap: null
|
|
|
+ enumMap: null,
|
|
|
+ default_font: { size: 12, name: "宋体" },
|
|
|
+ default_alignment: {
|
|
|
+ vertical: "middle", // 垂直居中
|
|
|
+ horizontal: "left", // 水平居左
|
|
|
+ wrapText: true // 自动换行
|
|
|
+ },
|
|
|
+ variables: []
|
|
|
});
|
|
|
|
|
|
const isFilterPrice = data => {
|
|
@@ -1002,6 +1027,7 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
let reg = /\【(.*?)\】/g;
|
|
|
let formulaItemArr = formulaItem.value.match(reg);
|
|
|
|
|
|
+ console.log("init_new_formula_item formulaItemArr :>> ", formulaItemArr);
|
|
|
if (formulaItemArr.length) {
|
|
|
formulaItemArr.map(fName => {
|
|
|
let _item = {
|
|
@@ -1042,6 +1068,7 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
_itemMattress.costamt = isFilterPrice(_valueReplace?.value ?? 0);
|
|
|
}
|
|
|
});
|
|
|
+ console.log("init_new_formula_item _itemMattress item :>> ", _itemMattress, differ);
|
|
|
arr.push(_itemMattress);
|
|
|
});
|
|
|
}
|
|
@@ -1092,6 +1119,7 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ console.log("init_new_formula_item 小计 item :>> ", item);
|
|
|
arr.push(_item);
|
|
|
});
|
|
|
}
|
|
@@ -1397,6 +1425,42 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
}
|
|
|
});
|
|
|
break;
|
|
|
+ case "innerClothLayerMx":
|
|
|
+ case "topCottonMx":
|
|
|
+ console.log("innerClothLayer item.data :>> ", item.data, formulakindenum);
|
|
|
+
|
|
|
+ item.data.map(itm => {
|
|
|
+ if (Number(itm.mtrlid ?? 0) > 0 || Number(itm.costamt ?? 0) != 0) {
|
|
|
+ let result: any = cloneDeep(result_default);
|
|
|
+ result.label = itm.chastr != "" ? itm.chastr : item.label;
|
|
|
+ let _formulaName = "";
|
|
|
+ if (formulakindenum) {
|
|
|
+ _formulaName = formulakindenum.find(t => t.value == itm.formulakind)?.label ?? "";
|
|
|
+ }
|
|
|
+
|
|
|
+ _formulaName = _formulaName.replace(item.replace, "");
|
|
|
+
|
|
|
+ // console.log("_formulaName rp:>> ", _formulaName, item.replace);
|
|
|
+ result.dscrp = `${_formulaName}:${itm.mtrlname}`;
|
|
|
+
|
|
|
+ if (Number(itm.thickness) > 0) {
|
|
|
+ result.dscrp += ` 厚度:${isFilterPrice(itm.thickness)}`;
|
|
|
+ }
|
|
|
+ result.qty = Number(itm.qty);
|
|
|
+ if (userInfo.usermode == 0) {
|
|
|
+ result.costamt = isFilterPrice(itm.costamt ?? 0);
|
|
|
+ result.costamt_1 = isFilterPrice(formatCutNumber({ val: floatMul(itm.costamt ?? 0, 1 + itm.dannum1_rate) }));
|
|
|
+ result.costamt_2 = isFilterPrice(formatCutNumber({ val: floatMul(itm.costamt ?? 0, 1 + itm.dannum2_rate) }));
|
|
|
+ result.costamt_3 = isFilterPrice(formatCutNumber({ val: floatMul(itm.costamt ?? 0, 1 + itm.dannum3_rate) }));
|
|
|
+ result.costamt_4 = isFilterPrice(formatCutNumber({ val: floatMul(itm.costamt ?? 0, 1 + itm.dannum4_rate) }));
|
|
|
+ result.useqty = Number(itm.useqty ?? 0);
|
|
|
+ result.price = isFilterPrice(itm.price ?? 0);
|
|
|
+ }
|
|
|
+ result.index = index;
|
|
|
+ mattressArr.push(result);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1494,16 +1558,14 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
return sums;
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * @description 旧核价格式
|
|
|
+ * @param params
|
|
|
+ * @param fileName
|
|
|
+ */
|
|
|
const toExcelQuote = async (params: wfQingdanProps, fileName: string) => {
|
|
|
const { data, mxdata } = params;
|
|
|
- console.log("mainData :>> ", data);
|
|
|
-
|
|
|
- let default_font = { size: 12, name: "宋体" };
|
|
|
- let default_alignment: any = {
|
|
|
- vertical: "middle", // 垂直居中
|
|
|
- horizontal: "left", // 水平居左
|
|
|
- wrapText: true // 自动换行
|
|
|
- };
|
|
|
+ console.log("mainData :>> ", params);
|
|
|
|
|
|
const workbook = new Exceljs.Workbook(); // 创建工作簿
|
|
|
const worksheet = workbook.addWorksheet("sheet1"); // 创建工作表(sheet1)
|
|
@@ -1535,43 +1597,43 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
BCol.width = 13.55;
|
|
|
BCol.key = "label";
|
|
|
BCol.style = {
|
|
|
- font: default_font,
|
|
|
- alignment: { ...default_alignment, vertical: "top" }
|
|
|
+ font: state.default_font,
|
|
|
+ alignment: { ...state.default_alignment, vertical: "top" }
|
|
|
};
|
|
|
const CCol = worksheet.getColumn("C");
|
|
|
CCol.width = 49.33;
|
|
|
CCol.key = "dscrp";
|
|
|
CCol.style = {
|
|
|
- font: default_font,
|
|
|
- alignment: default_alignment
|
|
|
+ font: state.default_font,
|
|
|
+ alignment: state.default_alignment
|
|
|
};
|
|
|
const DCol = worksheet.getColumn("D");
|
|
|
DCol.width = 5.69;
|
|
|
DCol.key = "qty";
|
|
|
DCol.style = {
|
|
|
- font: default_font,
|
|
|
- alignment: { ...default_alignment, horizontal: "center" }
|
|
|
+ font: state.default_font,
|
|
|
+ alignment: { ...state.default_alignment, horizontal: "center" }
|
|
|
};
|
|
|
const ECol = worksheet.getColumn("E");
|
|
|
ECol.width = 10;
|
|
|
ECol.key = "costamt";
|
|
|
ECol.style = {
|
|
|
- font: default_font,
|
|
|
- alignment: { ...default_alignment, horizontal: "right" }
|
|
|
+ font: state.default_font,
|
|
|
+ alignment: { ...state.default_alignment, horizontal: "right" }
|
|
|
};
|
|
|
const FCol = worksheet.getColumn("F");
|
|
|
FCol.width = 13;
|
|
|
FCol.key = "useqty";
|
|
|
FCol.style = {
|
|
|
- font: default_font,
|
|
|
- alignment: { ...default_alignment, horizontal: "right" }
|
|
|
+ font: state.default_font,
|
|
|
+ alignment: { ...state.default_alignment, horizontal: "right" }
|
|
|
};
|
|
|
const GCol = worksheet.getColumn("G");
|
|
|
GCol.width = 12.48;
|
|
|
GCol.key = "price";
|
|
|
GCol.style = {
|
|
|
- font: default_font,
|
|
|
- alignment: { ...default_alignment, horizontal: "right" }
|
|
|
+ font: state.default_font,
|
|
|
+ alignment: { ...state.default_alignment, horizontal: "right" }
|
|
|
};
|
|
|
|
|
|
//======================================= 第一行 =================================
|
|
@@ -1584,7 +1646,7 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
cellB1.value = `报价日期:${formatTime(data.createtime, "{y}-{m}-{d}", false)} 报价金额:${foreign_cost}${currency}报价清单`;
|
|
|
// 设置第一行的单元格样式
|
|
|
cellB1.font = { size: 15, bold: true, name: "宋体" };
|
|
|
- cellB1.alignment = default_alignment;
|
|
|
+ cellB1.alignment = state.default_alignment;
|
|
|
worksheet.getRow(1).height = 26; // 设置行高
|
|
|
|
|
|
//======================================= 第二行 =================================
|
|
@@ -1593,8 +1655,8 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
cellB2.value = `财务底价:${formatAmount(data.nottax_dept_cost)} 佣金点数:${formatAmount(
|
|
|
data.commission
|
|
|
)} 税率:${formatAmount(data.taxrate)} `;
|
|
|
- cellB2.font = default_font;
|
|
|
- cellB2.alignment = default_alignment;
|
|
|
+ cellB2.font = state.default_font;
|
|
|
+ cellB2.alignment = state.default_alignment;
|
|
|
worksheet.getRow(2).height = 39;
|
|
|
|
|
|
//======================================= 第三行 =================================
|
|
@@ -1603,8 +1665,8 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
cellB3.value = `额外点数:${formatAmount(data.other_rate)} 额外费用:${formatAmount(
|
|
|
data.extras_cost
|
|
|
)} 汇率:${formatAmount(data.moneyrate)} `;
|
|
|
- cellB3.font = default_font;
|
|
|
- cellB3.alignment = default_alignment;
|
|
|
+ cellB3.font = state.default_font;
|
|
|
+ cellB3.alignment = state.default_alignment;
|
|
|
worksheet.getRow(3).height = 18;
|
|
|
|
|
|
//======================================= 第四行 =================================
|
|
@@ -1613,8 +1675,8 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
cellB4.value = `款式费用:${formatAmount(data.hrcost)} 边带费用:${formatAmount(
|
|
|
data.biandaicost
|
|
|
)} 总成本:${formatAmount(data.total_cost)} `;
|
|
|
- cellB4.font = default_font;
|
|
|
- cellB4.alignment = default_alignment;
|
|
|
+ cellB4.font = state.default_font;
|
|
|
+ cellB4.alignment = state.default_alignment;
|
|
|
worksheet.getRow(4).height = 18;
|
|
|
|
|
|
//======================================= 第五行 =================================
|
|
@@ -1623,8 +1685,8 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
cellB5.value = `工厂利润率${formatAmount(data.profitrate)} 工艺点数:${formatAmount(
|
|
|
data.profitrate_point
|
|
|
)} 不含税出厂价:${formatAmount(data.nottax_factory_cost)} `;
|
|
|
- cellB5.font = default_font;
|
|
|
- cellB5.alignment = default_alignment;
|
|
|
+ cellB5.font = state.default_font;
|
|
|
+ cellB5.alignment = state.default_alignment;
|
|
|
worksheet.getRow(5).height = 18;
|
|
|
|
|
|
//======================================= 第六行 =================================
|
|
@@ -1633,16 +1695,16 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
cellB6.value = `部门利润率:${formatAmount(data.dept_profitrate)} FOB费用:${formatAmount(
|
|
|
data.fob
|
|
|
)} 部门售价:${formatAmount(data.nottax_dept_cost)} `;
|
|
|
- cellB6.font = default_font;
|
|
|
- cellB6.alignment = default_alignment;
|
|
|
+ cellB6.font = state.default_font;
|
|
|
+ cellB6.alignment = state.default_alignment;
|
|
|
worksheet.getRow(6).height = 18;
|
|
|
|
|
|
//======================================= 第七行 =================================
|
|
|
worksheet.mergeCells("B7:F7");
|
|
|
const cellB7 = worksheet.getCell("B7");
|
|
|
cellB7.value = `让利点数:${formatAmount(data.dept_profitrate_rangli)} 海绵款扣点:${formatAmount(data.haimian_point)} `;
|
|
|
- cellB7.font = default_font;
|
|
|
- cellB7.alignment = default_alignment;
|
|
|
+ cellB7.font = state.default_font;
|
|
|
+ cellB7.alignment = state.default_alignment;
|
|
|
worksheet.getRow(7).height = 18;
|
|
|
|
|
|
//======================================= 第八行 =================================
|
|
@@ -1755,9 +1817,280 @@ export const useHooksCpQuote = (t?: any) => {
|
|
|
saveAs(new Blob([buffer], { type: "application/octet-stream" }), fileName + ".xlsx");
|
|
|
});
|
|
|
};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 新核价格式
|
|
|
+ * @param params
|
|
|
+ * @param fileName 文件名
|
|
|
+ * @param ifShowDetail 是否显示明细
|
|
|
+ */
|
|
|
+ const toExcelQuoteNew = async (params: wfQingdanProps, fileName: string, ifShowDetail = true) => {
|
|
|
+ const { data, fields } = params;
|
|
|
+ console.log("toExcelQuoteNew mainData :>> ", params);
|
|
|
+
|
|
|
+ const workbook = new Exceljs.Workbook(); // 创建工作簿
|
|
|
+ const worksheet = workbook.addWorksheet("sheet1"); // 创建工作表(sheet1)
|
|
|
+
|
|
|
+ // 宽度设置
|
|
|
+ const ACol = worksheet.getColumn("A");
|
|
|
+ ACol.width = 0.78;
|
|
|
+ ACol.key = "";
|
|
|
+ getColumnStyle(worksheet, "B", "level", 13.55, { vertical: "top" });
|
|
|
+ getColumnStyle(worksheet, "C", "level1", 13.55, { vertical: "top" });
|
|
|
+ getColumnStyle(worksheet, "D", "level2", 13.55);
|
|
|
+
|
|
|
+ // let mergeCellName = "K";
|
|
|
+ let _val = "";
|
|
|
+ if (ifShowDetail) {
|
|
|
+ // 展开明细
|
|
|
+ getColumnStyle(worksheet, "E", "label", 13.55, { horizontal: "center" });
|
|
|
+ getColumnStyle(worksheet, "F", "dscrp", 26, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "G", "qty", 13, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "H", "useqty", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "I", "price", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "J", "costamt_2", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "K", "costamt_1", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "L", "costamt_4", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "M", "costamt_3", 12.48, { horizontal: "right" });
|
|
|
+ // mergeCellName = "K";
|
|
|
+ } else {
|
|
|
+ getColumnStyle(worksheet, "E", "costamt_2", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "F", "costamt_1", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "G", "costamt_4", 12.48, { horizontal: "right" });
|
|
|
+ getColumnStyle(worksheet, "H", "costamt_3", 12.48, { horizontal: "right" });
|
|
|
+ // mergeCellName = "G";
|
|
|
+ }
|
|
|
+
|
|
|
+ //======================================= 第一行 =================================
|
|
|
+ // 合并A1到L1的单元格 (大标题)
|
|
|
+ // worksheet.mergeCells(`B1:${mergeCellName}1`);
|
|
|
+ // const cellB1 = worksheet.getCell("B1");
|
|
|
+
|
|
|
+ let foreign_cost = formatAmount(data?.foreign_cost);
|
|
|
+ let currency = Number(data?.moneyrate) != 1 ? "美金" : "人民币";
|
|
|
+ let _val1 = `报价日期:${formatTime(data.createtime, "{y}-{m}-{d}", false)}`;
|
|
|
+ let _val2 = `报价金额:${foreign_cost}${currency}`;
|
|
|
+ setHeaderStyle(worksheet, 1, `B1:E1`, _val1, 26, { size: 15, bold: true, name: "宋体" });
|
|
|
+ // setHeaderStyle(worksheet, 1, `E1:G1`, "报价清单", 26, { size: 15, bold: true, name: "宋体" }, { horizontal: "center" });
|
|
|
+ setHeaderStyle(worksheet, 1, `F1:M1`, _val2, 26, { size: 15, bold: true, name: "宋体" }, { horizontal: "right" });
|
|
|
+
|
|
|
+ //======================================= 第二行 =================================
|
|
|
+ let rowIndex = 2;
|
|
|
+ if (fields.length > 0) {
|
|
|
+ _val = "";
|
|
|
+ let rowArr = [
|
|
|
+ {
|
|
|
+ sCell: "B",
|
|
|
+ eCell: "E"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ sCell: "F",
|
|
|
+ eCell: "I"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ sCell: "J",
|
|
|
+ eCell: "M"
|
|
|
+ }
|
|
|
+ ];
|
|
|
+ fields
|
|
|
+ .filter(t => t.type != "variable")
|
|
|
+ .forEach((t, i) => {
|
|
|
+ let rowItem = rowArr[i % 3];
|
|
|
+ let _cell = `${rowItem.sCell + rowIndex}:${rowItem.eCell + rowIndex}`;
|
|
|
+
|
|
|
+ _val = `${t.label}: ${t.value}`;
|
|
|
+ setHeaderStyle(worksheet, rowIndex, _cell, _val.trim(), 18);
|
|
|
+ // 每三个一行
|
|
|
+ if ((i + 1) % 3 == 0) {
|
|
|
+ rowIndex = (i + 1) / 3 + 2;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ fields
|
|
|
+ .filter(t => t.type == "variable")
|
|
|
+ .forEach((t, i) => {
|
|
|
+ // 每三个一行
|
|
|
+ if (i % 3 == 0) {
|
|
|
+ rowIndex++;
|
|
|
+ }
|
|
|
+ let rowItem = rowArr[i % 3];
|
|
|
+ let _cell = `${rowItem.sCell + rowIndex}:${getPreLetter(rowItem.eCell) + rowIndex}`;
|
|
|
+ let _cellname_var = rowItem.eCell + rowIndex;
|
|
|
+
|
|
|
+ state.variables.push({
|
|
|
+ cell: _cellname_var,
|
|
|
+ field: t.field
|
|
|
+ });
|
|
|
+
|
|
|
+ _val = `${t.label}:`;
|
|
|
+ setHeaderStyle(worksheet, rowIndex, _cell, _val, 18);
|
|
|
+
|
|
|
+ const _cellVar = worksheet.getCell(_cellname_var);
|
|
|
+ _cellVar.value = t.value;
|
|
|
+ _cellVar.font = state.default_font;
|
|
|
+ _cellVar.alignment = state.default_alignment;
|
|
|
+ _cellVar.fill = {
|
|
|
+ type: "pattern",
|
|
|
+ pattern: "darkTrellis",
|
|
|
+ fgColor: { argb: "FF90c5ff" },
|
|
|
+ bgColor: { argb: "FF90c5ff" }
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 冻结前7行
|
|
|
+ console.log("冻结行数rowIndex :>> ", rowIndex);
|
|
|
+ worksheet.views = [{ state: "frozen", xSplit: 0, ySplit: rowIndex }];
|
|
|
+ console.log("冻结行数rowIndex end:>> ", rowIndex);
|
|
|
+ //======================================= 表格内容 =================================
|
|
|
+
|
|
|
+ console.log("百分 state.tableData :>> ", state.tableData);
|
|
|
+ await wf_retrieve_qingdan(params, true, ifShowDetail);
|
|
|
+ console.log("af state.tableData :>> ", JSON.stringify(state.tableData));
|
|
|
+
|
|
|
+ console.log("表格内容 bf rowIndex :>> ", rowIndex);
|
|
|
+ rowIndex++;
|
|
|
+
|
|
|
+ const headerRows = worksheet.insertRow(
|
|
|
+ rowIndex,
|
|
|
+ {
|
|
|
+ level: "类目",
|
|
|
+ level1: "一级项目",
|
|
|
+ level2: "二级项目",
|
|
|
+ label: "项目",
|
|
|
+ dscrp: "内容",
|
|
|
+ qty: "数量",
|
|
|
+ useqty: "用量",
|
|
|
+ price: "单价",
|
|
|
+ costamt_2: "标准金额",
|
|
|
+ costamt_1: "散单金额",
|
|
|
+ costamt_4: "小单金额",
|
|
|
+ costamt_3: "大单金额"
|
|
|
+ },
|
|
|
+ "n"
|
|
|
+ );
|
|
|
+ console.log("表格内容 ed rowIndex :>> ", rowIndex);
|
|
|
+ rowIndex++;
|
|
|
+ const insertedRows = worksheet.insertRows(rowIndex, state.tableData, "n");
|
|
|
+ // const cellBSum = worksheet.getCell(`B${9 + state.tableData.length}`);
|
|
|
+ // cellBSum.value = "材料合计:";
|
|
|
+ // const cellESum = worksheet.getCell(`E${9 + state.tableData.length}`);
|
|
|
+ // cellESum.value = getSummaries(state.tableData, "costamt");
|
|
|
+ // const footerRows = worksheet.insertRow(
|
|
|
+ // 9 + state.tableData.length,
|
|
|
+ // {
|
|
|
+ // label: "材料合计:",
|
|
|
+ // dscrp: "",
|
|
|
+ // qty: "",
|
|
|
+ // costamt: getSummaries(state.tableData, "costamt"),
|
|
|
+ // costamt_1: getSummaries(state.tableData, "costamt_1"),
|
|
|
+ // costamt_2: getSummaries(state.tableData, "costamt_2"),
|
|
|
+ // costamt_3: getSummaries(state.tableData, "costamt_3"),
|
|
|
+ // costamt_4: getSummaries(state.tableData, "costamt_4"),
|
|
|
+ // useqty: "",
|
|
|
+ // price: ""
|
|
|
+ // },
|
|
|
+ // "n"
|
|
|
+ // );
|
|
|
+
|
|
|
+ // 设置单元格边框
|
|
|
+ let default_border: any = {
|
|
|
+ top: { style: "thin", color: { argb: "FF000000" } },
|
|
|
+ left: { style: "thin", color: { argb: "FF000000" } },
|
|
|
+ bottom: { style: "thin", color: { argb: "FF000000" } },
|
|
|
+ right: { style: "thin", color: { argb: "FF000000" } }
|
|
|
+ };
|
|
|
+ headerRows.eachCell(cell => {
|
|
|
+ cell.border = default_border;
|
|
|
+ });
|
|
|
+ // footerRows.eachCell(cell => {
|
|
|
+ // cell.border = default_border;
|
|
|
+ // });
|
|
|
+ insertedRows.map(row => {
|
|
|
+ row.eachCell(cell => {
|
|
|
+ cell.border = default_border;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ toMergeCells(worksheet, "level", "B", rowIndex);
|
|
|
+ toMergeCells(worksheet, "level1", "C", rowIndex);
|
|
|
+ toMergeCells(worksheet, "level2", "D", rowIndex);
|
|
|
+ ifShowDetail && toMergeCells(worksheet, "label", "E", rowIndex);
|
|
|
+
|
|
|
+ console.log("wf_retrieve_qingdan tableData :>> ", state.tableData);
|
|
|
+
|
|
|
+ //======================================= 下载工作簿 =================================
|
|
|
+ workbook.xlsx.writeBuffer().then(buffer => {
|
|
|
+ saveAs(new Blob([buffer], { type: "application/octet-stream" }), fileName + ".xlsx");
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const getColumnStyle = (worksheet: any, colNuame: string, key: string, width: number, style: any = {}) => {
|
|
|
+ const col = worksheet.getColumn(colNuame);
|
|
|
+ col.width = width;
|
|
|
+ col.key = key;
|
|
|
+ col.style = {
|
|
|
+ font: state.default_font,
|
|
|
+ alignment: { ...style, ...state.default_alignment }
|
|
|
+ };
|
|
|
+ };
|
|
|
+
|
|
|
+ const setHeaderStyle = (
|
|
|
+ worksheet: any,
|
|
|
+ rowIndex: Number,
|
|
|
+ mergeCellName: string,
|
|
|
+ value: string,
|
|
|
+ height: number,
|
|
|
+ fontStyle: any = state.default_font,
|
|
|
+ alignment: any = {}
|
|
|
+ ) => {
|
|
|
+ worksheet.mergeCells(mergeCellName);
|
|
|
+ let colName = mergeCellName.split(":")[0];
|
|
|
+ const cellB1 = worksheet.getCell(colName);
|
|
|
+
|
|
|
+ cellB1.value = value;
|
|
|
+ // 设置第一行的单元格样式
|
|
|
+ cellB1.font = fontStyle;
|
|
|
+ cellB1.alignment = { ...state.default_alignment, ...alignment };
|
|
|
+ worksheet.getRow(rowIndex).height = height; // 设置行高
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 取上一个字母(从A到Z)
|
|
|
+ * @param letter 当前字母
|
|
|
+ * @returns, z -> y, a -> z, b -> a
|
|
|
+ */
|
|
|
+ const getPreLetter = letter => {
|
|
|
+ let code = letter.charCodeAt(0);
|
|
|
+ if (code === 65) {
|
|
|
+ return String.fromCharCode(code + 25);
|
|
|
+ } else {
|
|
|
+ return String.fromCharCode(code - 1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 合并单元格
|
|
|
+ */
|
|
|
+ const toMergeCells = (worksheet: any, field: string, cellname: string, startRowIndex: number) => {
|
|
|
+ // label列内容相同时合并单元格
|
|
|
+ let same = 0;
|
|
|
+ state.tableData.map((t, i) => {
|
|
|
+ // label列内容相同的时候,多行合并单元格
|
|
|
+ if (i > 0 && t[field] && t[field] === state.tableData[i - 1][field]) {
|
|
|
+ same++;
|
|
|
+ } else {
|
|
|
+ if (same > 0) {
|
|
|
+ worksheet.mergeCells(`${cellname}${startRowIndex + i - 1}:${cellname}${startRowIndex + i - 1 - same}`);
|
|
|
+ }
|
|
|
+ same = 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return {
|
|
|
...toRefs(state),
|
|
|
wf_retrieve_qingdan,
|
|
|
- toExcelQuote
|
|
|
+ toExcelQuote,
|
|
|
+ toExcelQuoteNew
|
|
|
};
|
|
|
};
|