|
@@ -146,12 +146,15 @@
|
|
|
<UpdateCollectInfoForm ref="updateCollectInfoForm" @refreshList="refreshList"></UpdateCollectInfoForm>
|
|
<UpdateCollectInfoForm ref="updateCollectInfoForm" @refreshList="refreshList"></UpdateCollectInfoForm>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ <CollectImageTemplate v-if="exportTemplateData" ref="collectImageTemplate" :template-data="exportTemplateData">
|
|
|
|
|
+ </CollectImageTemplate>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import UserSelect from '@/components/userSelect'
|
|
import UserSelect from '@/components/userSelect'
|
|
|
import CollectService from '@/api/psi/CollectService'
|
|
import CollectService from '@/api/psi/CollectService'
|
|
|
|
|
+import CollectImageTemplate from './CollectImageTemplate'
|
|
|
import UpdateCollectInfoForm from './UpdateCollectInfoForm'
|
|
import UpdateCollectInfoForm from './UpdateCollectInfoForm'
|
|
|
import SelectTree from '@/components/treeSelect/treeSelect.vue'
|
|
import SelectTree from '@/components/treeSelect/treeSelect.vue'
|
|
|
import taskService from '@/api/flowable/taskService'
|
|
import taskService from '@/api/flowable/taskService'
|
|
@@ -188,7 +191,9 @@ export default {
|
|
|
isAdmin: false,
|
|
isAdmin: false,
|
|
|
create: '',
|
|
create: '',
|
|
|
processDefinitionAuditIdReturn: '',
|
|
processDefinitionAuditIdReturn: '',
|
|
|
- procDefAuditKeyReturn: ''
|
|
|
|
|
|
|
+ procDefAuditKeyReturn: '',
|
|
|
|
|
+ exportTemplateData: null,
|
|
|
|
|
+ html2CanvasLoader: null
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
collectService: null,
|
|
collectService: null,
|
|
@@ -198,7 +203,8 @@ export default {
|
|
|
components: {
|
|
components: {
|
|
|
UserSelect,
|
|
UserSelect,
|
|
|
SelectTree,
|
|
SelectTree,
|
|
|
- UpdateCollectInfoForm
|
|
|
|
|
|
|
+ UpdateCollectInfoForm,
|
|
|
|
|
+ CollectImageTemplate
|
|
|
},
|
|
},
|
|
|
computed: {
|
|
computed: {
|
|
|
userName() {
|
|
userName() {
|
|
@@ -665,8 +671,8 @@ export default {
|
|
|
// 导出
|
|
// 导出
|
|
|
exportFile() {
|
|
exportFile() {
|
|
|
const options = {
|
|
const options = {
|
|
|
- filename: `${this.moment(new Date()).format('YYYY-MM-DD')}采购数据导出`,
|
|
|
|
|
- sheetName: '采购数据导出',
|
|
|
|
|
|
|
+ filename: `${this.moment(new Date()).format('YYYY-MM-DD')}领用数据导出`,
|
|
|
|
|
+ sheetName: '领用数据导出',
|
|
|
mode: 'all'
|
|
mode: 'all'
|
|
|
}
|
|
}
|
|
|
this.loading = true
|
|
this.loading = true
|
|
@@ -683,22 +689,93 @@ export default {
|
|
|
this.loading = false
|
|
this.loading = false
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- exportByTemplate(row) {
|
|
|
|
|
- const options = {
|
|
|
|
|
- filename: `${this.moment(new Date()).format('YYYY-MM-DD')}领用单`,
|
|
|
|
|
- sheetName: '领用单',
|
|
|
|
|
- mode: 'all'
|
|
|
|
|
|
|
+ waitForTemplateRender() {
|
|
|
|
|
+ return new Promise((resolve) => {
|
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
|
+ setTimeout(resolve, 80)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ ensureHtml2Canvas() {
|
|
|
|
|
+ if (window.html2canvas) {
|
|
|
|
|
+ return Promise.resolve(window.html2canvas)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.html2CanvasLoader) {
|
|
|
|
|
+ return this.html2CanvasLoader
|
|
|
|
|
+ }
|
|
|
|
|
+ this.html2CanvasLoader = new Promise((resolve, reject) => {
|
|
|
|
|
+ const script = document.createElement('script')
|
|
|
|
|
+ script.src = '/datav/cdn/html2canvas/html2canvas.min.js'
|
|
|
|
|
+ script.async = true
|
|
|
|
|
+ script.onload = () => {
|
|
|
|
|
+ if (window.html2canvas) {
|
|
|
|
|
+ resolve(window.html2canvas)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ reject(new Error('html2canvas不存在'))
|
|
|
|
|
+ }
|
|
|
|
|
+ script.onerror = () => reject(new Error('load html2canvas failed'))
|
|
|
|
|
+ document.body.appendChild(script)
|
|
|
|
|
+ })
|
|
|
|
|
+ return this.html2CanvasLoader
|
|
|
|
|
+ },
|
|
|
|
|
+ // 通过将模板转换canvas的方式下载图片
|
|
|
|
|
+ downloadCanvas(canvas, filename) {
|
|
|
|
|
+ const realFilename = filename.endsWith('.png') ? filename : `${filename}.png`
|
|
|
|
|
+ const triggerDownload = (href) => {
|
|
|
|
|
+ const downloadElement = document.createElement('a')
|
|
|
|
|
+ downloadElement.href = href
|
|
|
|
|
+ downloadElement.download = realFilename
|
|
|
|
|
+ document.body.appendChild(downloadElement)
|
|
|
|
|
+ downloadElement.click()
|
|
|
|
|
+ document.body.removeChild(downloadElement)
|
|
|
|
|
+ if (href.indexOf('blob:') === 0) {
|
|
|
|
|
+ window.URL.revokeObjectURL(href)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (canvas.toBlob) {
|
|
|
|
|
+ canvas.toBlob((blob) => {
|
|
|
|
|
+ if (!blob) {
|
|
|
|
|
+ triggerDownload(canvas.toDataURL('image/png'))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ triggerDownload(window.URL.createObjectURL(blob))
|
|
|
|
|
+ }, 'image/png')
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+ triggerDownload(canvas.toDataURL('image/png'))
|
|
|
|
|
+ },
|
|
|
|
|
+ // 导出领用单,图片格式
|
|
|
|
|
+ async exportByTemplate(row) {
|
|
|
|
|
+ const filename = `${this.moment(new Date()).format('YYYY-MM-DD')}领用单`
|
|
|
this.loading = true
|
|
this.loading = true
|
|
|
- this.collectService.exportFileByTemplate({
|
|
|
|
|
- ...options,
|
|
|
|
|
- id: row.id
|
|
|
|
|
- }).then((res) => {
|
|
|
|
|
- this.$utils.downloadExcel(res, options.filename)
|
|
|
|
|
- this.loading = false
|
|
|
|
|
- }).catch(() => {
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const data = await this.collectService.templateImageData({
|
|
|
|
|
+ id: row.id
|
|
|
|
|
+ })
|
|
|
|
|
+ this.exportTemplateData = {
|
|
|
|
|
+ ...data,
|
|
|
|
|
+ collectList: Array.isArray(data.collectList) ? data.collectList : []
|
|
|
|
|
+ }
|
|
|
|
|
+ await this.waitForTemplateRender()
|
|
|
|
|
+ const html2canvas = await this.ensureHtml2Canvas()
|
|
|
|
|
+ //将组件作为模板
|
|
|
|
|
+ const exportEl = this.$refs.collectImageTemplate && this.$refs.collectImageTemplate.getExportElement()
|
|
|
|
|
+ if (!exportEl) {
|
|
|
|
|
+ throw new Error('领用模板不存在')
|
|
|
|
|
+ }
|
|
|
|
|
+ const canvas = await html2canvas(exportEl, {
|
|
|
|
|
+ backgroundColor: '#ffffff',
|
|
|
|
|
+ scale: 2,
|
|
|
|
|
+ useCORS: true
|
|
|
|
|
+ })
|
|
|
|
|
+ this.downloadCanvas(canvas, filename)
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ this.$message.error('领用单图片导出失败')
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ this.exportTemplateData = null
|
|
|
this.loading = false
|
|
this.loading = false
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|