Commit f84c5b272490e15fa6e47badc84b8f4453074b03

Authored by gesilong
2 parents b7053a15 7eccee4a

Merge branch 'cjerp-contract-1.0' into test_cjerp

... ... @@ -20,6 +20,14 @@ export const statusMap = {
20 20 }
21 21
22 22 const baseUrl = '/contract';
  23 +// 打印功能
  24 +export function printStandardContractApi(params) {
  25 + return request({
  26 + url: `${baseUrl}/contractDistributorStandard/printStandardContract`,
  27 + method: 'get',
  28 + params
  29 + })
  30 +}
23 31 // 查询当前人所在办事处
24 32 export function getDeptApi(params) {
25 33 return request({
... ...
... ... @@ -122,6 +122,7 @@ import FileUpload from '@/components/file-upload/index.vue'
122 122 import SingleSelectSheet from '@/components/single-select/index.vue'
123 123 import { fillStandardApprovedName } from '@/utils/dic.js'
124 124 import { downloadFile } from '@/utils/downloadFile.js'
  125 +import { printFile } from '@/utils/print.js'
125 126
126 127 export default {
127 128 name: 'ContractForeignStdDetail',
... ... @@ -225,6 +226,12 @@ export default {
225 226 variant: 'outline',
226 227 event: 'copy'
227 228 },
  229 + {
  230 + text: '打印',
  231 + visible: true,
  232 + variant: 'outline',
  233 + event: 'print'
  234 + },
228 235 ],
229 236 }
230 237 },
... ... @@ -241,6 +248,7 @@ export default {
241 248 { ...this.buttons[5], visible: (s === 'STANDARD' && this.$auth.hasPermi('contract-manage:foreign-trade-standard-contract:review')) },
242 249 { ...this.buttons[4], visible: (s === 'STANDARD' && e && t === 'AUDIT' && this.$auth.hasPermi('contract-manage:foreign-trade-standard-contract:approve')) },
243 250 { ...this.buttons[6], visible: (s !== 'DELETED' && this.$auth.hasPermi('contract-manage:foreign-trade-standard-contract:copy')) },
  251 + { ...this.buttons[7], visible: true },
244 252 ]
245 253 }
246 254 },
... ... @@ -371,6 +379,10 @@ export default {
371 379 if (e === 'audit') return this.onAudit(btn && btn.params)
372 380 if (e === 'auditDetail') return this.onAuditDetail(btn && btn.params)
373 381 if (e === 'copy') return this.onCopy(btn && btn.params)
  382 + if (e === 'print') return this.onPrint(this.detail.id || '')
  383 + },
  384 + onPrint(id) {
  385 + printFile(id)
374 386 },
375 387 getBusinessId() {
376 388 return (this.detail && (this.detail.id || this.detail.code)) || ''
... ... @@ -396,6 +408,7 @@ export default {
396 408 uni.navigateTo({ url: '/pages/flow/audit_detail' })
397 409 },
398 410 downloadFile,
  411 + printFile,
399 412 async loadDetail() {
400 413 if (!this.id) return
401 414 try {
... ...
... ... @@ -141,6 +141,7 @@ import FileUpload from '@/components/file-upload/index.vue'
141 141 import SingleSelectSheet from '@/components/single-select/index.vue'
142 142 import { fillStandardApprovedName, fillFormalApprovedName } from '@/utils/dic.js'
143 143 import { downloadFile } from '@/utils/downloadFile.js'
  144 +import { printFile } from '@/utils/print.js'
144 145
145 146 export default {
146 147 name: 'ContractForeignStockDetail',
... ... @@ -285,6 +286,12 @@ export default {
285 286 variant: 'outline',
286 287 event: 'copy'
287 288 },
  289 + {
  290 + text: '打印',
  291 + visible: true,
  292 + variant: 'outline',
  293 + event: 'print'
  294 + },
288 295 ],
289 296 }
290 297 },
... ... @@ -311,6 +318,7 @@ export default {
311 318 { ...this.buttons[7], visible: (s === 'STANDARD' && e && t === 'AUDIT' && this.$auth.hasPermi('contract-manage:foreign-trade-inventory-contract:approve')) },
312 319 { ...this.buttons[8], visible: (s === 'STANDARD' && f && a === 'AUDIT' && this.$auth.hasPermi('contract-manage:foreign-trade-inventory-contract:standard-approve')) },
313 320 { ...this.buttons[13], visible: (s !== 'DELETED' && this.$auth.hasPermi('contract-manage:foreign-trade-inventory-contract:copy')) },
  321 + { ...this.buttons[14], visible: true },
314 322 ]
315 323 }
316 324 },
... ... @@ -459,7 +467,10 @@ export default {
459 467 if (e === 'auditDetail3') return this.onAuditDetail(this.detail.id || '', 'STANDARD_CONTRACT')
460 468 if (e === 'uploadSeal') return this.uploadContract(this.detail.id || '', 'seal')
461 469 if (e === 'copy') return this.onCopy(btn && btn.params)
462   -
  470 + if (e === 'print') return this.onPrint(this.detail.id || '')
  471 + },
  472 + onPrint(id) {
  473 + printFile(id)
463 474 },
464 475 getBusinessId() {
465 476 return (this.detail && (this.detail.id || this.detail.code)) || ''
... ... @@ -490,6 +501,7 @@ export default {
490 501 uni.navigateTo({ url: '/pages/flow/audit_detail' })
491 502 },
492 503 downloadFile,
  504 + printFile,
493 505 async loadDetail() {
494 506 if (!this.id) return
495 507 try {
... ...
... ... @@ -142,6 +142,7 @@ import FileUpload from '@/components/file-upload/index.vue'
142 142 import SingleSelectSheet from '@/components/single-select/index.vue'
143 143 import { fillStandardApprovedName, fillFormalApprovedName } from '@/utils/dic.js'
144 144 import { downloadFile } from '@/utils/downloadFile.js'
  145 +import { printFile } from '@/utils/print.js'
145 146
146 147 export default {
147 148 name: 'ContractForeignUnplanDetail',
... ... @@ -291,6 +292,12 @@ export default {
291 292 variant: 'outline',
292 293 event: 'copy'
293 294 },
  295 + {
  296 + text: '打印',
  297 + visible: true,
  298 + variant: 'outline',
  299 + event: 'print'
  300 + },
294 301 ],
295 302 }
296 303 },
... ... @@ -318,6 +325,7 @@ export default {
318 325 { ...this.buttons[8], visible: (s === 'STANDARD' && e && a === 'AUDIT' && this.$auth.hasPermi('contract-manage:foreign-trade-unlocked-contract:approve')) }, //审核正式合同
319 326 { ...this.buttons[9], visible: (s === 'STANDARD' && f && t === 'AUDIT' && this.$auth.hasPermi('contract-manage:foreign-trade-unlocked-contract:standard-approve')) }, //审核标准合同
320 327 { ...this.buttons[14], visible: (s !== 'DELETED' && this.$auth.hasPermi('contract-manage:foreign-trade-unlocked-contract:copy')) },
  328 + { ...this.buttons[15], visible: true },
321 329 ]
322 330 }
323 331 },
... ... @@ -455,6 +463,7 @@ export default {
455 463 this.sheet = { ...this.sheet, visible: true, title: '合同是否规范', options, value: match ? match.value : '' }
456 464 },
457 465 downloadFile,
  466 + printFile,
458 467 handleButtonClick(btn) {
459 468 if (!btn || btn.disabled) return
460 469 if (typeof btn.onClick === 'function') return btn.onClick(this.detail, btn.params)
... ... @@ -474,6 +483,10 @@ export default {
474 483 if (e === 'auditDetail3') return this.onAuditDetail(this.detail.id || '', 'STANDARD_CONTRACT')
475 484 if (e === 'uploadSeal') return this.uploadContract(this.detail.id || '', 'seal')
476 485 if (e === 'copy') return this.onCopy(btn && btn.params)
  486 + if (e === 'print') return this.onPrint(this.detail.id || '')
  487 + },
  488 + onPrint(id) {
  489 + printFile(id)
477 490 },
478 491 getBusinessId() {
479 492 return (this.detail && (this.detail.id || this.detail.code)) || ''
... ...
... ... @@ -120,6 +120,7 @@ import FileUpload from '@/components/file-upload/index.vue'
120 120 import SingleSelectSheet from '@/components/single-select/index.vue'
121 121 import { fillStandardApprovedName } from '@/utils/dic.js'
122 122 import { downloadFile } from '@/utils/downloadFile.js'
  123 +import { printFile } from '@/utils/print.js'
123 124
124 125 export default {
125 126 name: 'ContractProcessDetail',
... ... @@ -216,6 +217,12 @@ export default {
216 217 variant: 'outline',
217 218 event: 'copy'
218 219 },
  220 + {
  221 + text: '打印',
  222 + visible: true,
  223 + variant: 'outline',
  224 + event: 'print'
  225 + },
219 226 ],
220 227 }
221 228 },
... ... @@ -231,6 +238,7 @@ export default {
231 238 { ...this.buttons[4], visible: (s === 'STANDARD' && this.$auth.hasPermi('contract-manage:processed-standard-contract:review')) },
232 239 { ...this.buttons[3], visible: (s === 'STANDARD' && e && t === 'AUDIT' && this.$auth.hasPermi('contract-manage:processed-standard-contract:approve')) },
233 240 { ...this.buttons[5], visible: (s !== 'DELETED' && this.$auth.hasPermi('contract-manage:processed-standard-contract:copy')) },
  241 + { ...this.buttons[6], visible: true },
234 242 ]
235 243 }
236 244 },
... ... @@ -354,6 +362,10 @@ export default {
354 362 if (e === 'audit') return this.onAudit(this.detail.id || '', 'PROCESS_STD_AGMT')
355 363 if (e === 'auditDetail') return this.onAuditDetail(this.detail.id || '', 'PROCESS_STD_AGMT')
356 364 if (e === 'copy') return this.onCopy(btn && btn.params)
  365 + if (e === 'print') return this.onPrint(this.detail.id || '')
  366 + },
  367 + onPrint(id) {
  368 + printFile(id)
357 369 },
358 370 getBusinessId() {
359 371 return (this.detail && (this.detail.id || this.detail.code)) || ''
... ... @@ -383,6 +395,7 @@ export default {
383 395 uni.navigateTo({ url: '/pages/flow/audit_detail' })
384 396 },
385 397 downloadFile,
  398 + printFile,
386 399 async loadDetail() {
387 400 if (!this.id) return
388 401 try {
... ...
... ... @@ -123,6 +123,7 @@ import FileUpload from '@/components/file-upload/index.vue'
123 123 import SingleSelectSheet from '@/components/single-select/index.vue'
124 124 import { getDicByCodes, getDicName } from '@/utils/dic.js'
125 125 import { downloadFile } from '@/utils/downloadFile.js'
  126 +import { printFile } from '@/utils/print.js'
126 127
127 128 export default {
128 129 name: 'ContractRetailDetail',
... ... @@ -214,6 +215,12 @@ export default {
214 215 visible: true,
215 216 variant: 'outline',
216 217 event: 'copy'
  218 + },
  219 + {
  220 + text: '打印',
  221 + visible: true,
  222 + variant: 'outline',
  223 + event: 'print'
217 224 }
218 225 ],
219 226 statusStyle: statusStyle,
... ... @@ -232,6 +239,7 @@ export default {
232 239 { ...this.buttons[4], visible: (s === 'STANDARD' && this.$auth.hasPermi('contract-manage:distribution-standard-contract:review')) },
233 240 { ...this.buttons[3], visible: (s === 'STANDARD' && e && t === 'AUDIT' && this.$auth.hasPermi('contract-manage:distribution-standard-contract:approve')) },
234 241 { ...this.buttons[5], visible: (s !== 'DELETED' && this.$auth.hasPermi('contract-manage:distribution-standard-contract:copy')) },
  242 + { ...this.buttons[6], visible: true },
235 243 ]
236 244 }
237 245 },
... ... @@ -358,6 +366,7 @@ export default {
358 366 })
359 367 },
360 368 downloadFile,
  369 + printFile,
361 370 onUpload() {
362 371 this.$refs.uploadPopup.open()
363 372 },
... ... @@ -371,7 +380,11 @@ export default {
371 380 if (e === 'audit') return this.onAudit(btn && btn.params)
372 381 if (e === 'auditDetail') return this.onAuditDetail(btn && btn.params)
373 382 if (e === 'copy') return this.onCopy(btn && btn.params)
  383 + if (e === 'print') return this.onPrint(btn && btn.params)
374 384 },
  385 + onPrint() {
  386 + printFile(this.detail.id)
  387 + },
375 388 getBusinessId() {
376 389 return (this.detail && (this.detail.id || this.detail.code)) || ''
377 390 },
... ...
... ... @@ -138,6 +138,8 @@ import DetailButtons from '@/components/detail-buttons/index.vue'
138 138 import FileUpload from '@/components/file-upload/index.vue'
139 139 import SingleSelectSheet from '@/components/single-select/index.vue'
140 140 import { downloadFile } from '@/utils/downloadFile.js'
  141 +import { printFile } from '@/utils/print.js'
  142 +
141 143 export default {
142 144 name: 'ContractStockDetail',
143 145 components: { ProductRel, DetailButtons, FileUpload, SingleSelectSheet },
... ... @@ -271,6 +273,12 @@ export default {
271 273 visible: true,
272 274 variant: 'outline',
273 275 event: 'copy'
  276 + },
  277 + {
  278 + text: '打印',
  279 + visible: true,
  280 + variant: 'outline',
  281 + event: 'print'
274 282 }
275 283 ],
276 284 uploadId: '',
... ... @@ -299,6 +307,7 @@ export default {
299 307 { ...this.buttons[7], visible: (s === 'STANDARD' && e && t === 'AUDIT' && this.$auth.hasPermi('contract-manage:distribution-inventory-contract:approve')) },
300 308 { ...this.buttons[8], visible: (s === 'STANDARD' && f && a === 'AUDIT' && this.$auth.hasPermi('contract-manage:distribution-inventory-contract:standard-approve')) },
301 309 { ...this.buttons[12], visible: (s !== 'DELETED' && this.$auth.hasPermi('contract-manage:distribution-inventory-contract:copy')) },
  310 + { ...this.buttons[13], visible: true },
302 311 ]
303 312 }
304 313 },
... ... @@ -402,6 +411,7 @@ export default {
402 411
403 412 },
404 413 downloadFile,
  414 + printFile,
405 415 onSheetConfirm({ value, label }) {
406 416 this.standardStandardized = value
407 417 this.standardStandardizedName = label || ''
... ... @@ -434,6 +444,10 @@ export default {
434 444 if (e === 'auditDetail2') return this.onAuditDetail(this.detail.parentId || '', 'FORMAL_CONTRACT')
435 445 if (e === 'auditDetail3') return this.onAuditDetail(this.detail.id || '', 'STANDARD_CONTRACT')
436 446 if (e === 'copy') return this.onCopy(this.detail)
  447 + if (e === 'print') return this.onPrint(this.detail.id || '')
  448 + },
  449 + onPrint(id) {
  450 + printFile(id)
437 451 },
438 452 onAudit(id, type) {
439 453 const CACHE_KEY = 'sourceBusinessId'
... ...
... ... @@ -139,6 +139,7 @@ import FileUpload from '@/components/file-upload/index.vue'
139 139 import SingleSelectSheet from '@/components/single-select/index.vue'
140 140 import { fillStandardApprovedName, fillFormalApprovedName } from '@/utils/dic.js'
141 141 import { downloadFile } from '@/utils/downloadFile.js'
  142 +import { printFile } from '@/utils/print.js'
142 143
143 144 export default {
144 145 name: 'ContractUnplanDetail',
... ... @@ -277,6 +278,12 @@ export default {
277 278 variant: 'outline',
278 279 event: 'copy'
279 280 },
  281 + {
  282 + text: '打印',
  283 + visible: true,
  284 + variant: 'outline',
  285 + event: 'print'
  286 + },
280 287 ],
281 288 }
282 289 },
... ... @@ -303,6 +310,7 @@ export default {
303 310 { ...this.buttons[8], visible: (s === 'STANDARD' && e && t === 'AUDIT' && this.$auth.hasPermi('contract-manage:distribution-unlocked-contract:approve')) },
304 311 { ...this.buttons[9], visible: (s === 'STANDARD' && f && a === 'AUDIT' && this.$auth.hasPermi('contract-manage:distribution-unlocked-contract:standard-approve')) },
305 312 { ...this.buttons[13], visible: (s !== 'DELETED' && this.$auth.hasPermi('contract-manage:distribution-unlocked-contract:copy')) },
  313 + { ...this.buttons[14], visible: true },
306 314 ]
307 315 }
308 316 },
... ... @@ -453,6 +461,10 @@ export default {
453 461 if (e === 'auditDetail2') return this.onAuditDetail(this.detail.parentId || '', 'FORMAL_CONTRACT')
454 462 if (e === 'auditDetail3') return this.onAuditDetail(this.detail.id || '', 'STANDARD_CONTRACT')
455 463 if (e === 'copy') return this.onCopy(btn && btn.params)
  464 + if (e === 'print') return this.onPrint(this.detail.id || '')
  465 + },
  466 + onPrint(id) {
  467 + printFile(id)
456 468 },
457 469 getBusinessId() {
458 470 return (this.detail && (this.detail.id || this.detail.code)) || ''
... ... @@ -482,6 +494,7 @@ export default {
482 494 uni.navigateTo({ url: '/pages/flow/audit_detail' })
483 495 },
484 496 downloadFile,
  497 + printFile,
485 498 async loadDetail() {
486 499 if (!this.id) return
487 500 try {
... ...
  1 +import config from '@/config'
  2 +import { getToken } from '@/utils/auth.js'
  3 +
  4 +export async function printFile(id, fileName = '合同.pdf') {
  5 + const bizId = id != null ? String(id) : ''
  6 + if (!bizId) {
  7 + uni.showToast({ title: '未获取到合同ID', icon: 'none' })
  8 + return
  9 + }
  10 +
  11 + uni.showLoading({ title: '下载中' })
  12 + try {
  13 + const baseUrl = (config && config.baseUrl) ? String(config.baseUrl).replace(/\/$/, '') : ''
  14 + const rawUrl = `${baseUrl}/contract/contractDistributorStandard/printStandardContract?id=${encodeURIComponent(bizId)}`
  15 + const token = getToken()
  16 + const header = {}
  17 + if (token) header['X-Auth-Token'] = token
  18 +
  19 + let url = rawUrl
  20 + // #ifdef H5
  21 + if (token) {
  22 + const separator = url.includes('?') ? '&' : '?'
  23 + url = `${url}${separator}X-Auth-Token=${encodeURIComponent(token)}`
  24 + }
  25 + // #endif
  26 +
  27 + const res = await new Promise((resolve, reject) => {
  28 + uni.downloadFile({
  29 + url,
  30 + header,
  31 + success: resolve,
  32 + fail: reject
  33 + })
  34 + })
  35 +
  36 + if (!(res && res.statusCode === 200)) {
  37 + uni.showToast({ title: '下载失败', icon: 'none' })
  38 + return
  39 + }
  40 +
  41 + const filePath = res.tempFilePath
  42 +
  43 + // #ifdef H5
  44 + const ua = navigator.userAgent.toLowerCase()
  45 + const isAndroid = ua.indexOf('android') > -1 || ua.indexOf('adr') > -1
  46 + const isWeChat = ua.indexOf('micromessenger') !== -1
  47 + if (isWeChat && isAndroid) {
  48 + uni.showModal({
  49 + title: '提示',
  50 + content: '微信环境下不支持直接打开,请复制链接后在浏览器打开',
  51 + confirmText: '复制链接',
  52 + showCancel: false,
  53 + success: function (r) {
  54 + if (r.confirm) {
  55 + uni.setClipboardData({
  56 + data: url,
  57 + success: function () { uni.showToast({ title: '链接已复制', icon: 'success' }) }
  58 + })
  59 + }
  60 + }
  61 + })
  62 + } else {
  63 + const win = window.open(filePath, '_blank')
  64 + if (!win) {
  65 + const link = document.createElement('a')
  66 + link.href = filePath
  67 + link.download = fileName || 'download'
  68 + document.body.appendChild(link)
  69 + link.click()
  70 + document.body.removeChild(link)
  71 + }
  72 + }
  73 + // #endif
  74 +
  75 + // #ifndef H5
  76 + const ext = fileName && String(fileName).includes('.') ? String(fileName).split('.').pop().toLowerCase() : 'pdf'
  77 + uni.openDocument({
  78 + filePath,
  79 + fileType: ext || 'pdf',
  80 + showMenu: true,
  81 + fail: function () {
  82 + uni.showToast({ title: '无法打开此文件', icon: 'none' })
  83 + }
  84 + })
  85 + // #endif
  86 + } catch (e) {
  87 + uni.showToast({ title: '下载出错', icon: 'none' })
  88 + } finally {
  89 + uni.hideLoading()
  90 + }
  91 +}
... ...