华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

556 lines
17 KiB

<template>
<div>
<div class="edit-container" v-if="open">
<div class="edit-top">
<div class="left-top">
<img src="@/assets/images/back.png" @click="cancel()" />
<div class="left-title"></div>
</div>
<div class="center-top">
</div>
<div class="right-top">
<el-button @click="cancel()">{{ $t('form.close') }}</el-button>
<el-button type="primary" v-if="form.bdzt === 5 && form.tbzt === 1" @click="openApprove = true">{{
$t('page.business.study.studyFormFill.tb') }}</el-button>
</div>
</div>
<!-- 1:流程;3:编辑;5:人员;7:修改;9:补充说明 -->
<el-button type="primary" @click="exportExcel(-1)">{{ $t('page.business.study.studyFormFill.dcqbjcgj') }}
</el-button>
<el-button type="primary" @click="exportExcel(1)">{{ $t('page.business.study.studyFormFill.dclcjcgj') }}
</el-button>
<el-button type="primary" @click="exportExcel(3)">{{ $t('page.business.study.studyFormFill.dcbjjcgj') }}
</el-button>
<el-button type="primary" @click="exportExcel(7)">{{ $t('page.business.study.studyFormFill.dcxgjcgj') }}
</el-button>
<el-button type="primary" @click="exportExcel(999)">{{ $t('page.business.study.studyFormFill.dcbhsjgj') }}
</el-button>
<div class="edit-content">
<div class="detail-content" style="width: 100%; height: 100%;">
<vue-html2pdf :show-layout="true" pdf-content-width="100%" :pdf-format="form.templatePdfSize" :pdf-quality="2"
:float-layout="false" pdf-orientation="landscape" :paginate-elements-by-height="0" :enable-download="true"
:preview-modal="false" :filename="form.bdmc" @beforeDownload="addDynamicWatermark" ref="html2Pdf"
@progress="onProgress">
<section slot="pdf-content">
<div class="pdf-content">
<TemplateTable ref="templateTable" :sn="form.templateSn" :templateData="form" fillType="detail" />
<div v-if="showExport" style="width: 100%; padding: 0px 30px ;">
<div class="content-title" style="margin-bottom: 10px;">
<div class="line"></div>
<div class="subtitle"> {{ $t('page.business.study.studyFormFill.qmxx') }}</div>
</div>
<table class="datatable">
<thead>
<tr>
<th style="width: 20%;">{{ $t('page.business.study.studyFormFill.qmr') }}</th>
<th style="width: 20%;">{{ $t('page.business.study.studyFormFill.qmyy') }}</th>
<th style="width: 20%;">{{ $t('page.business.study.studyFormFill.qmsj') }}</th>
<th style="width: 40%;">{{ $t('page.business.study.studyFormFill.bzyy') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in qmxxExportList" :key="index">
<td>{{ item.qmrMc }}</td>
<td>{{ $i18n.locale === 'zh_CN' ? item.qmyy : item.qmyyEn }}</td>
<td>{{ item.createTime }}</td>
<td>{{ item.remark }}</td>
</tr>
</tbody>
</table>
<div class="content-title" style="margin-top: 10px;" v-show="jcgjlxExport != 999">
<div class="line"></div>
<div class="subtitle"> {{ $t('page.business.study.studyFormFill.jcgj') }}</div>
</div>
<JcgjList ref="jcgjExportList" :readonly="true" v-show="jcgjlxExport != 999" />
</div>
</div>
<div v-if="showExport" id="watermark-overlay" ref="watermarkContainer" :style="{
'--watermark-text': `'${watermarkText}'`,
'--watermark-opacity': opacity,
'--watermark-size': '14px',
'--watermark-color': 'red'
}"></div>
</section>
</vue-html2pdf>
<div style="padding: 0px 20px 0px 30px;margin-left: 10px;">
<div class="content-title">
<div class="line"></div>
<div class="subtitle"> {{ $t('page.business.study.studyFormFill.qmxx') }}</div>
</div>
<div class="pal">
<el-table :data="qmxxList" v-loading="loadingQmxx" style="width: 100%;">
<el-table-column :label="$t('page.business.study.studyFormFill.qmr')" align="center" prop="qmrMc" />
<el-table-column :label="$t('page.business.study.studyFormFill.qmyy')" align="center"
:prop="$i18n.locale === 'zh_CN' ? 'qmyy' : 'qmyyEn'" />
<el-table-column :label="$t('page.business.study.studyFormFill.qmsj')" align="center"
prop="createTime" />
<el-table-column :label="$t('page.business.study.studyFormFill.bzyy')" align="center" prop="remark" />
</el-table>
</div>
<pagination v small layout="prev, pager, next" :total="totalQmxx" :page.sync="queryParamsQmxx.pageNum"
:limit.sync="queryParamsQmxx.pageSize" @pagination="getQmxxList" />
<div class="content-title" style="margin-top: 10px;">
<div class="line"></div>
<div class="subtitle"> {{ $t('page.business.study.studyFormFill.jcgj') }}</div>
</div>
<JcgjList ref="jcgjList" @handleQuery="getJjcgjList" :showXg="true" />
<pagination v small layout="prev, pager, next" :total="jcgjTotal" @pagination="getJjcgjList" />
</div>
</div>
</div>
</div>
<!-- 填报 -->
<el-dialog :title="$t('page.business.study.studyFormFill.cjjl')" :visible.sync="openApprove" width="500px"
append-to-body :close-on-click-modal="false">
<el-form ref="formApprove" :model="formApprove" :rules="rulesApprove" label-width="120px" v-if="openApprove">
<el-alert :title="$t('page.business.study.studyFormFill.ts')" :closable="false" type="success">
</el-alert>
<el-row>
<el-col :span="24">
<el-form-item :label="$t('form.qmyy')" prop="qmyy">
<el-input type="text" :value="formApprove.qmyy" maxlength="50" disabled
:placeholder="$t('form.placeholderInput')" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item :label="$t('form.remark')" prop="remark">
<el-input type="textarea" v-model="formApprove.remark" :rows="5" maxlength="500"
:placeholder="$t('form.placeholderInput')">
</el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item :label="$t('form.signer')">
<el-input type="text" v-model="nickName" maxlength="50" disabled
:placeholder="$t('form.placeholderInput')" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item :label="$t('form.password')" prop="qmrmm">
<el-input type="password" show-password v-model="formApprove.qmrmm" maxlength="20"
:placeholder="$t('form.placeholderInput')" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="approve">{{ $t('form.confirm') }}</el-button>
<el-button @click="openApprove = false">{{ $t('form.cancel') }}</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { studyFormFill_jcgjqmxxList, studyFormFill_tb, studyFormFill_info, studyFormFill_jcgj, studyFormFill_qmxx, studyFormFill_exportDetail } from "@/api/business/study/studyFormFill"
import { mapGetters } from 'vuex'
import JcgjList from "@/views/business/comps/common/JcgjList";
import TemplateTable from '@/views/business/comps/template/TemplateTable';
import moment from "moment";
import VueHtml2pdf from 'vue-html2pdf'
export default {
name: "Xq",
components: { JcgjList, TemplateTable, VueHtml2pdf },
data() {
return {
watermarkText:'',
opacity: 0.8,
watermarkOpacity: 0.8,
watermarkSize: 40,
openApprove: false,
formApprove: {
id: null,
qmyy: this.$t('page.business.study.studyFormFill.cjjl'),
remark: '',
qmrmm: '',
},
rulesApprove: {
qmrmm: [{
required: true,
message: ' ',
trigger: 'blur'
}]
},
qmxxList: [],
totalQmxx: 0,
loadingQmxx: true,
queryParamsQmxx: {
formId: null,
pageNum: 1,
pageSize: 5
},
open: false,
showIndex: 1,
form: {},
rules: {
bdmc: [{
required: true,
message: ' ',
trigger: 'blur'
}],
templateId: [{
required: true,
message: ' ',
trigger: 'blur'
}]
},
jcgjTotal: 0,
jcgjList: [],
queryParamsJcgj: {
pageNum: 1,
formId: null,
pageSize: 5,
},
showExport: false,
qmxxExportList: [],
jcgjExportList: [],
jcgjlxExport: 0
}
},
computed: {
...mapGetters([
'nickName', 'name'
]),
},
created() {
},
methods: {
updateWatermark() {
// 创建水印背景
const text = this.nickName +' '+ moment().format("YYYY-MM-DD HH:mm:ss");
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// 设置canvas尺寸
canvas.width = 300;
canvas.height = 300;
// 绘制水印
ctx.fillStyle = `rgba(255, 0, 0, ${this.opacity})`;
ctx.font = '12px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// 旋转45度
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.rotate(-45 * Math.PI / 180);
ctx.fillText(text, 0, 0);
// 设置为背景
const container = this.$refs.watermarkContainer;
container.style.backgroundImage = `url(${canvas.toDataURL()})`;
container.style.backgroundRepeat = 'repeat';
},
onProgress(progress) {
console.log(`生成进度: ${progress}%`)
this.removePageBreak()
if (progress == 100) {
this.showExport = false
this.$modal.closeLoading()
}
},
exportExcel(jcgjlx) {
this.$modal.loading()
this.jcgjlxExport = jcgjlx
this.showExport = true
studyFormFill_jcgjqmxxList({ jcgjlx: jcgjlx, id: this.form.id }).then(response => {
this.jcgjExportList = response.data.jcgj
this.qmxxExportList = response.data.qmxx
this.updateWatermark()
this.$refs.jcgjExportList.init(this.jcgjExportList)
setTimeout(() => {
this.$refs.html2Pdf.generatePdf()
}, 200);
})
},
//添加水印
async addDynamicWatermark({ pdfContent }) {
return new Promise((resolve) => {
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
// 获取内容区域尺寸
const rect = this.$refs.contentArea.getBoundingClientRect()
canvas.width = rect.width
canvas.height = rect.height
// 绘制动态水印
ctx.fillStyle = `rgba(100, 100, 100, ${this.watermarkOpacity})`
ctx.font = `${this.watermarkSize}px Arial`
ctx.textAlign = 'center'
ctx.textBaseline = 'middle'
// 计算水印密度
const stepX = 300
const stepY = 200
// 绘制倾斜水印
ctx.save()
ctx.translate(canvas.width / 2, canvas.height / 2)
ctx.rotate(-Math.PI / 4) // 45度倾斜
for (let x = -canvas.width; x < canvas.width * 2; x += stepX) {
for (let y = -canvas.height; y < canvas.height * 2; y += stepY) {
// 动态水印内容
const dynamicText = `${this.watermarkText} - ${this.getCurrentTime()}`
ctx.fillText(dynamicText, x, y)
}
}
ctx.restore()
// 创建水印层
const watermarkLayer = document.createElement('div')
watermarkLayer.className = 'watermark-layer'
watermarkLayer.style.cssText = `
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
background-image: url(${canvas.toDataURL('image/png')});
background-repeat: repeat;
z-index: 9999;
`
// 插入水印
this.$refs.contentArea.style.position = 'relative'
this.$refs.contentArea.appendChild(watermarkLayer)
// 等待渲染
setTimeout(() => resolve(), 100)
})
},
//移除分页空白
removePageBreak() {
document.querySelectorAll('.html2pdf__page-break').forEach(el => {
el.remove()
})
},
exportExcel_bak(jcgjlx) {
this.$modal.loading()
studyFormFill_exportDetail(_.merge({}, this.queryParamsJcgj, { jcgjlx: jcgjlx, lang: this.$store.getters.language.split("_")[0] })).then(response => {
window.open(process.env.VUE_APP_FILE_DOMAIN + response.msg)
}).finally(() => {
this.$modal.closeLoading()
})
},
getJjcgjList(val) {
this.$modal.loading()
studyFormFill_jcgj(_.merge({}, this.queryParamsJcgj, val)).then(response => {
this.jcgjList = response.rows
this.jcgjTotal = response.total
this.$refs.jcgjList.init(this.jcgjList)
}).finally(() => {
this.$modal.closeLoading()
})
},
getQmxxList() {
this.loadingQmxx = true
studyFormFill_qmxx(this.queryParamsQmxx).then(response => {
this.qmxxList = response.rows
this.totalQmxx = response.total
this.loadingQmxx = false
})
},
cancel() {
this.$emit('close')
this.open = false
},
reset() {
this.form = {
id: null,
studyId: null,
bdbh: null,
bdmc: null,
bdsm: null,
templateId: null,
templateMc: null,
bdnr: null
}
this.resetForm("form")
},
show(row) {
this.reset()
this.$modal.loading()
this.formApprove.id = row.id
this.queryParamsJcgj.formId = row.id
this.queryParamsQmxx.formId = row.id
studyFormFill_info({ id: row.id }).then(response => {
this.form = response.data
this.getQmxxList()
this.getJjcgjList()
this.open = true
}).finally(() => {
this.$modal.closeLoading()
})
},
approve() {
this.$refs["formApprove"].validate(valid => {
if (valid) {
this.$modal.loading()
studyFormFill_tb(this.formApprove).then(response => {
this.openApprove = false
this.$emit('close')
this.open = false
}).finally(() => {
this.$modal.closeLoading()
})
}
})
}
}
}
</script>
<style scoped>
.content-title {
width: 100%;
background: #f9f9ff;
font-size: 0.96rem;
font-weight: bold;
padding-left: 10px;
height: 40px;
line-height: 40px;
display: flex;
justify-content: flex-start;
text-align: left;
}
.line {
width: 2px;
float: left;
height: 16px;
margin-top: 12px;
margin-right: 8px;
border-left: #3178ff 3px solid;
}
.subtitle {
height: 40px;
line-height: 40px;
color: #464647 !important;
}
.pdf-content {
padding: 0px;
font-family: Arial, sans-serif;
}
#watermark-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0.6;
font-size: 12px;
pointer-events: none;
z-index: 10;
color: red;
}
.pdf-content h1 {
color: #333;
border-bottom: 2px solid #4CAF50;
padding-bottom: 10px;
}
.pdf-content table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.pdf-content th,
.pdf-content td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.pdf-content th {
background-color: #f2f2f2;
}
.datatable {
border-collapse: collapse;
width: 100%;
page-break-inside: avoid;
}
.upload-file-list .el-upload-list__item {
margin-bottom: 0px !important;
}
.datatable thead {
border-left: 1px solid #d0d0d0;
}
.datatable th {
padding: 5px 5px 4px 5px;
max-width: 200px;
line-height: 35px;
text-align: center;
color: #414753;
background: #F5F7FA;
border: 1px solid #d0d0d0;
}
.el-dialog__body {
padding: 10px 20px !important;
}
.datatable th.operate {
padding: 5px 5px 4px 5px;
width: 100px;
line-height: 35px;
background: #F5F7FA;
border: 1px solid #d0d0d0;
text-align: center;
}
.datatable .rowAlt td,
.datatable tbody tr:nth-child(2n) td {
background: #F5F7FA;
}
.datatable td {
border: solid 1px #d0d0d0;
padding: 3px 5px 4px 5px;
max-width: 100px;
color: #414753;
line-height: 35px;
text-align: center;
}
.html2pdf__page-break {
display: none !important;
}
.content {
position: relative;
z-index: 1;
}
.controls {
margin-bottom: 20px;
padding: 10px;
background: #f5f5f5;
}
input {
margin: 0 10px;
padding: 8px;
}
</style>