Browse Source

导出word

master
蔡玲玲 5 days ago
parent
commit
8fd861c022
  1. 3
      base-vue/package.json
  2. 69
      base-vue/src/views/modules/contract/temp-add-or-update.vue
  3. 249
      base-vue/src/views/modules/contract/temp-add-or-update的副本.vue
  4. BIN
      base-vue/static/word/template.docx
  5. 29
      base-vue/yarn.lock

3
base-vue/package.json

@ -21,8 +21,10 @@
"bpmn-js": "^6.0.4",
"bpmn-js-properties-panel": "^0.33.0",
"camunda-bpmn-moddle": "^4.3.0",
"docxtemplater": "^3.60.2",
"echarts": "^5.4.2",
"element-ui": "^2.15.14",
"file-saver": "^2.0.5",
"gulp": "4.0.2",
"gulp-concat": "2.6.1",
"gulp-load-plugins": "2.0.5",
@ -31,6 +33,7 @@
"lodash": "4.17.5",
"node-sass": "^6.0.1",
"npm": "^6.9.0",
"pizzip": "^3.1.8",
"pubsub-js": "^1.9.4",
"sass-loader": "6.0.6",
"svg-sprite-loader": "3.7.3",

69
base-vue/src/views/modules/contract/temp-add-or-update.vue

@ -82,13 +82,16 @@
</div>
<span slot="footer" class="dialog-footer">
<el-button size="mini" @click="visible = false">取消</el-button>
<el-button size="mini" type="primary" @click="addAndPrint">打印</el-button>
<el-button size="mini" type="primary" @click="exportToWord">导出为 Word 文档</el-button>
</span>
</el-dialog>
</template>
<script>
import { getLodop } from '@/utils/lodop/LodopFuncs'
import Docxtemplater from 'docxtemplater'
import PizZip from 'pizzip'
import PizZipUtils from 'pizzip/utils/index.js'
import { saveAs } from 'file-saver'
export default {
data () {
return {
@ -101,7 +104,7 @@ export default {
totalSum: null,
totalSumChina: null
},
dataList: [{materialCode: 'S9410002000002'}, {materialCode: 'S9410002000003'}]
dataList: []
}
},
props: {
@ -163,40 +166,34 @@ export default {
}
return result.join('') + (decimalPart > 0 ? '元' : '元整')
},
//
addAndPrint () {
const LODOP = getLodop()
if (LODOP === undefined || LODOP === null) {
this.visible = false
return
exportToWord () {
const data = {
clientId: this.dataForm.clientId,
contractNumber: this.dataForm.contractNumber
}
LODOP.PRINT_INITA('0mm', '0mm', '213mm', '297mm', '打印合同模板')
LODOP.SET_PRINT_PAGESIZE(1, 2100, 2970, 'A4')
LODOP.ADD_PRINT_TEXT(0, 0, '0', '0', '')
// HTML
const h1Content = `<h1>产品供销合同</h1>`
const popupContent = document.getElementById('popupContent').innerHTML
const printHtml = `
<style>
h1 {font-size: 14px;line-height: 1;text-align: center;margin-bottom: 30px;}
.zd-row {width: 100%;display: flex;}
.zd-col-12 {width: 50%;}
.dialog_content {width: 100%;font-family: '黑体'}
.item_p {font-size: 14px;color: #000;line-height: 1.5;padding-bottom: 12px;}
.tip_p {font-size: 14px;line-height: 1.5;margin: 0;}
.det_table {width: 100%;table-layout: fixed;width: 100%; border-collapse: collapse;border: 1px solid #000;}
.det_table th {font-size: 12px;color: #000;line-height: 23px;padding: 4px;border: 1px solid #000;text-align: center;}
.det_table td {font-size: 13px;color: #000;line-height: 23px;padding: 4px;border: 1px solid #000;text-align: center;}
.det_table_1 th, .det_table_1 td {text-align: left;}
</style>
${h1Content}
${popupContent}
`
//
LODOP.ADD_PRINT_HTM(0, '5%', '90%', '90%', printHtml)
// LODOP.PREVIEW()
LODOP.PRINT()
},
const templatePath = './static/word/template.docx'
PizZipUtils.getBinaryContent(templatePath, (error, content) =>{
if (error) {
throw error
}
const zip = new PizZip(content)
const doc = new Docxtemplater(zip, {
paragraphLoop: true,
linebreaks: true
})
doc.setData(data)
try {
doc.render()
} catch (error) {
console.error('模板渲染错误:', error)
}
const out = doc.getZip().generate({
type: 'blob',
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
})
saveAs(out, `合同${new Date().getTime()}.docx`)
})
}
}
}
</script>

249
base-vue/src/views/modules/contract/temp-add-or-update的副本.vue

@ -0,0 +1,249 @@
<template>
<el-dialog
title="产品供应合同"
:close-on-click-modal="false"
:visible.sync="visible">
<div class="dialog_content" id="popupContent">
<div style="width: 100%;">
<div class="zd-row">
<div class="zd-col-12 item_p">需方{{ dataForm.clientId }}</div>
<div class="zd-col-12 item_p">合同编号{{ dataForm.contractNumber }}</div>
</div>
<div class="zd-row">
<div class="zd-col-12 item_p">供方上海诺力智能科技有限公司</div>
<div class="zd-col-12 item_p">签订时间</div>
</div>
<p class="tip_p">产品明细单</p>
<table class="det_table">
<tr>
<th width="6.25%">序号</th>
<th width="25%">产品名称+订货代码</th>
<th width="25%">型号</th>
<th width="6.25%">数量</th>
<th width="6.25%">单位</th>
<th width="12.5%">单价()</th>
<th width="12.5%">总价()</th>
<th width="6.25%">备注</th>
</tr>
<tr v-for="(e, i) in dataForm.materData" :key="i">
<td>{{ i+1 }}</td>
<td>{{ e.materialName }}<br/>{{ e.materialCode }}</td>
<td>{{ e.materialType }}</td>
<td>{{ e.quantity }}</td>
<td>{{ e.unit }}</td>
<td>{{ e.price }}</td>
<td>{{ e.total }}</td>
<td>{{ e.remark }}</td>
</tr>
<tr>
<td colspan="6" style="text-align: left">共计</td>
<td>{{ dataForm.totalSum }}</td>
<td></td>
</tr>
<tr>
<td colspan="6" style="text-align: left">共计人民币金额大写{{ dataForm.totalSumChina }}</td>
<td colspan="2">含13%增值税</td>
</tr>
</table>
<p class="tip_p">质量要求技术标准供方对质量负责的条件和期限:技术标准符合行业标准</p>
<p class="tip_p">售后服务:保修期6个月人为造成的损坏不在质保范围内</p>
<p class="tip_p">交货时间地点:货期:待定;交货地:待客户通知</p>
<p class="tip_p">运输方式及到达站和费用负担:由供方负担</p>
<p class="tip_p">包装标准:按国内标准包装</p>
<p class="tip_p">结算方式:款到发货付款方式:电汇</p>
<p class="tip_p">违约责任:中华人民共和国民法典执行</p>
<p class="tip_p">解决合同纠纷的方式:买卖双方首先友好协商解决协商不成任何一方均可向有管辖权法院起诉</p>
<p class="tip_p">其它约定事项:合同扫描件有效签字盖章之日起生效</p>
<table class="det_table det_table_1">
<tr>
<th width="50%">需方</th>
<th width="50%">供方</th>
</tr>
<tr>
<td>
<div>单位名称:</div>
<div>地址:</div>
<div>委托代理电话:</div>
<div>传真:</div>
<div>开户银行:</div>
<div>帐号:</div>
</td>
<td>
<div>单位名称:上海诺力智能科技有限公司(盖章)</div>
<div>地址:上海青浦区徐泾镇高光路215弄99号4号楼302室</div>
<div>委托代理电话:</div>
<div>传真:</div>
<div>开户银行:招商银行虹桥支行</div>
<div>帐号:12191702501091</div>
</td>
</tr>
</table>
</div>
</div>
<span slot="footer" class="dialog-footer">
<el-button size="mini" @click="visible = false">取消</el-button>
<el-button size="mini" type="primary" @click="addAndPrint">打印</el-button>
</span>
</el-dialog>
</template>
<script>
import { getLodop } from '@/utils/lodop/LodopFuncs'
export default {
data () {
return {
visible: false,
dataForm: {
contractId: 0,
clientId: null,
contractNumber: null,
materData: [],
totalSum: null,
totalSumChina: null
},
dataList: [{materialCode: 'S9410002000002'}, {materialCode: 'S9410002000003'}]
}
},
methods: {
init (id) {
this.dataForm.contractId = id || 0
this.visible = true
this.$nextTick(() => {
if (this.dataForm.contractId) {
this.$http({
url: this.$http.adornUrl(`/flow/contract/info/${this.dataForm.contractId}`),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
if (data && data.code === 0) {
this.dataForm.contractNumber = data.contract.contractNumber
this.dataForm.clientId = data.contract.clientId
this.dataForm.materData = JSON.parse(data.contract.materialJson).material
this.dataForm.totalSum = JSON.parse(data.contract.materialJson).total
this.dataForm.totalSumChina = this.toChineseCurrency(this.dataForm.totalSum)
}
})
}
})
},
toChineseCurrency (amount) {
if (amount === 0) return '零元整'
const units = ['', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿']
const digits = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
const result = []
//
const integerPart = Math.floor(amount) //
const decimalPart = amount - integerPart //
//
let integerStr = integerPart.toString()
for (let i = 0; i < integerStr.length; i++) {
const digit = integerStr[integerStr.length - 1 - i];
if (digit !== '0') {
result.push(digits[digit], units[i])
} else if (!result.includes('零') && result.length > 0) {
result.push('零')
}
}
//
if (decimalPart > 0) {
const decimalStr = (decimalPart * 100).toFixed(0).padStart(2, '0') // 100
if (decimalStr !== '00') {
result.push('点')
for (let i = 0; i < decimalStr.length; i++) {
result.push(digits[decimalStr[i]])
}
}
}
//
while (result[0] === '零') {
result.shift()
}
return result.join('') + (decimalPart > 0 ? '元' : '元整')
},
//
addAndPrint () {
const LODOP = getLodop()
LODOP.PRINT_INITA('0mm', '0mm', '213mm', '297mm', '打印合同模板')
LODOP.SET_PRINT_PAGESIZE(1, 2100, 2970, 'A4')
LODOP.ADD_PRINT_TEXT(0, 0, '0', '0', '')
// HTML
const h1Content = `<h1>产品供销合同</h1>`
const popupContent = document.getElementById('popupContent').innerHTML
const printHtml = `
<style>
h1 {font-size: 14px;line-height: 1;text-align: center;margin-bottom: 30px;}
.zd-row {width: 100%;display: flex;}
.zd-col-12 {width: 50%;}
.dialog_content {width: 100%;font-family: '黑体'}
.item_p {font-size: 14px;color: #000;line-height: 1.5;padding-bottom: 12px;}
.tip_p {font-size: 14px;line-height: 1.5;margin: 0;}
.det_table {width: 100%;table-layout: fixed;width: 100%; border-collapse: collapse;border: 1px solid #000;}
.det_table th {font-size: 12px;color: #000;line-height: 23px;padding: 4px;border: 1px solid #000;text-align: center;}
.det_table td {font-size: 13px;color: #000;line-height: 23px;padding: 4px;border: 1px solid #000;text-align: center;}
.det_table_1 th, .det_table_1 td {text-align: left;}
</style>
${h1Content}
${popupContent}
`
//
LODOP.ADD_PRINT_HTM(0, '5%', '90%', '90%', printHtml)
// LODOP.PREVIEW()
LODOP.PRINT()
},
}
}
</script>
<style scoped>
.zd-row {
width: 100%;
display: flex;
}
.zd-col-12 {
width: 50%;
}
.dialog_content {
width: 100%;
}
.item_p {
font-size: 14px;
color: #606266;
line-height: 1.5;
padding-bottom: 12px;
}
.tip_p {
font-size: 14px;
font-weight: 700;
color: #606266;
line-height: 1.5;
margin: 0;
}
.det_table {
width: 100%;
table-layout: fixed;
border-collapse: collapse;
border: 1px solid #EBEEF5;
margin-top: 10px;
}
.det_table th {
font-size: 13px;
line-height: 23px;
color: #515a6e;
padding: 6px 6px;
font-weight: 700;
border: 1px solid #EBEEF5;
text-align: center;
background-color: #f5f5f5;
}
.det_table td {
font-size: 12px;
line-height: 23px;
color: #606266;
padding: 6px 6px;
border: 1px solid #EBEEF5;
text-align: center;
}
.det_table_1 th, .det_table_1 td {
text-align: left;
}
</style>

BIN
base-vue/static/word/template.docx

Binary file not shown.

29
base-vue/yarn.lock

@ -92,6 +92,11 @@
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"
integrity sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==
"@xmldom/xmldom@^0.9.7":
version "0.9.8"
resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.9.8.tgz#1471e82bdff9e8f20ee8bbe60d4ffa8a516e78d8"
integrity sha512-p96FSY54r+WJ50FIOsCOjyj/wavs8921hG5+kVMmZgKcvIKxMXHTrjNJvRgWa/zuX3B6t2lijLNFaOyuxUH+2A==
JSONStream@^1.3.4, JSONStream@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
@ -3495,6 +3500,13 @@ doctrine@^2.0.0:
dependencies:
esutils "^2.0.2"
docxtemplater@^3.60.2:
version "3.60.2"
resolved "https://registry.yarnpkg.com/docxtemplater/-/docxtemplater-3.60.2.tgz#597d0a3df6423623f48bf4be3f3a225ff9d96c35"
integrity sha512-x6p8Vr5FgZn0ibmFJz4IS9u8KANQKLzhrp3EMxMvzBAxFW/c3kYhJKFNN8QzjJzXqKO2+XWCN1KTcaSKjqtnqg==
dependencies:
"@xmldom/xmldom" "^0.9.7"
dom-converter@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768"
@ -4545,6 +4557,11 @@ file-loader@1.1.4:
loader-utils "^1.0.2"
schema-utils "^0.3.0"
file-saver@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38"
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==
file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
@ -9336,6 +9353,11 @@ pacote@^9.1.0, pacote@^9.5.12, pacote@^9.5.3:
unique-filename "^1.1.1"
which "^1.3.1"
pako@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==
pako@~1.0.5:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
@ -9581,6 +9603,13 @@ pinkie@^2.0.0:
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==
pizzip@^3.1.8:
version "3.1.8"
resolved "https://registry.yarnpkg.com/pizzip/-/pizzip-3.1.8.tgz#2028944e4845cb08fb79412939fc41d842659858"
integrity sha512-Nynadaz6/o1cmXDQGKqmTnbeaY10BGNc1PPOZYJMfLcjWfVJQ1ARngpVO+BrrRl/WUNIj0V9uJNrP72mkfsY5A==
dependencies:
pako "^2.1.0"
pkg-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4"

Loading…
Cancel
Save