feat(contract): 添加合同模板管理功能并优化导出逻辑
- 新增合同模板管理组件,支持模板的增删改查 - 优化合同导出功能,从订单项获取产品数据并添加金额大写转换 - 在合同编辑页面添加模板选择功能 - 为字典键值字段添加溢出提示 - 将数据键值输入框改为多行文本框
This commit is contained in:
@@ -121,6 +121,7 @@
|
||||
|
||||
<script>
|
||||
import { listOrder, updateOrder } from "@/api/crm/order";
|
||||
import { listOrderItem } from '@/api/crm/orderItem'
|
||||
import * as ExcelJS from 'exceljs';
|
||||
import { saveAs } from 'file-saver';
|
||||
|
||||
@@ -197,11 +198,73 @@ export default {
|
||||
toggleMoreFilter() {
|
||||
this.showMoreFilter = !this.showMoreFilter;
|
||||
},
|
||||
convertToChinese(amount) {
|
||||
if (amount === 0) return '零元整'
|
||||
|
||||
const digits = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
|
||||
const units = ['', '拾', '佰', '仟']
|
||||
const bigUnits = ['', '万', '亿']
|
||||
|
||||
let integerPart = Math.floor(amount)
|
||||
let decimalPart = Math.round((amount - integerPart) * 100)
|
||||
|
||||
let result = ''
|
||||
let unitIndex = 0
|
||||
let bigUnitIndex = 0
|
||||
|
||||
if (integerPart === 0) {
|
||||
result = '零'
|
||||
} else {
|
||||
while (integerPart > 0) {
|
||||
let section = integerPart % 10000
|
||||
if (section > 0) {
|
||||
let sectionResult = ''
|
||||
let sectionUnitIndex = 0
|
||||
|
||||
while (section > 0) {
|
||||
let digit = section % 10
|
||||
if (digit > 0) {
|
||||
sectionResult = digits[digit] + units[sectionUnitIndex] + sectionResult
|
||||
} else if (sectionResult && !sectionResult.startsWith('零')) {
|
||||
sectionResult = '零' + sectionResult
|
||||
}
|
||||
section = Math.floor(section / 10)
|
||||
sectionUnitIndex++
|
||||
}
|
||||
|
||||
result = sectionResult + bigUnits[bigUnitIndex] + result
|
||||
}
|
||||
integerPart = Math.floor(integerPart / 10000)
|
||||
bigUnitIndex++
|
||||
}
|
||||
}
|
||||
|
||||
result += '元'
|
||||
|
||||
if (decimalPart === 0) {
|
||||
result += '整'
|
||||
} else {
|
||||
const jiao = Math.floor(decimalPart / 10)
|
||||
const fen = decimalPart % 10
|
||||
if (jiao > 0) {
|
||||
result += digits[jiao] + '角'
|
||||
}
|
||||
if (fen > 0) {
|
||||
result += digits[fen] + '分'
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
},
|
||||
/** 导出合同 */
|
||||
async handleExport(row) {
|
||||
// 1. 创建excel
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const worksheet = workbook.addWorksheet('产品销售合同');
|
||||
let orderItems = [];
|
||||
// 2. 查询合同详情
|
||||
const res = await listOrderItem({ orderId: row.orderId, pageNum: 1, pageSize: 1000 });
|
||||
orderItems = res.rows || [];
|
||||
|
||||
// 2. 设置列宽
|
||||
worksheet.columns = [
|
||||
@@ -345,9 +408,33 @@ export default {
|
||||
totalAmountInWords: '零元整'
|
||||
};
|
||||
|
||||
if (row.productContent) {
|
||||
if (orderItems) {
|
||||
try {
|
||||
productData = JSON.parse(row.productContent);
|
||||
// 改为从orderItems中获取产品内容
|
||||
const productName = orderItems[0].productType || '冷硬钢卷';
|
||||
const remark = row.remark || '';
|
||||
const products = orderItems.map(item => ({
|
||||
spec: item.finishedProductSpec || '',
|
||||
material: item.material || '',
|
||||
quantity: parseFloat(item.weight || 0),
|
||||
taxPrice: parseFloat(item.contractPrice || 0),
|
||||
noTaxPrice: parseFloat(item.itemAmount || 0),
|
||||
taxTotal: parseFloat(item.contractPrice) * parseFloat(item.weight || 0),
|
||||
remark: item.remark || ''
|
||||
}));
|
||||
|
||||
const totalQuantity = products.reduce((acc, product) => acc + parseFloat(product.quantity || 0), 0);
|
||||
const totalTaxTotal = products.reduce((acc, product) => acc + parseFloat(product.taxTotal || 0), 0);
|
||||
const totalAmountInWords = this.convertToChinese(totalTaxTotal);
|
||||
|
||||
productData = {
|
||||
products,
|
||||
productName,
|
||||
remark,
|
||||
totalQuantity,
|
||||
totalTaxTotal,
|
||||
totalAmountInWords
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('解析产品内容失败:', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user