print.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div>
  3. <a-button
  4. key="1"
  5. type="default"
  6. v-if="$hasPermissions('B_transferReturnPrint')"
  7. id="editGrap-db-print-btn"
  8. :disabled="disabled"
  9. @click="handlePrint('views')">打印预览</a-button>
  10. <a-button
  11. key="2"
  12. type="primary"
  13. class="button-info"
  14. v-if="$hasPermissions('B_transferReturnPrint')"
  15. id="editGrap-dbfl-print-btn"
  16. :disabled="disabled"
  17. @click="handlePrint('print')">快捷打印</a-button>
  18. <a-divider type="vertical" />
  19. <a-button
  20. key="3"
  21. type="primary"
  22. class="button-warning"
  23. v-if="$hasPermissions('B_transferReturnExport')"
  24. id="editGrap-export-btn"
  25. :disabled="disabled"
  26. @click="handleExcel">导出Excel</a-button>
  27. <!-- 打印 -->
  28. <div id="print"></div>
  29. </div>
  30. </template>
  31. <script>
  32. import { hdExportExcel } from '@/libs/exportExcel'
  33. import { allocateReturnExcel, allocateReturnPrint } from '@/api/allocateReturn'
  34. export default {
  35. props: {
  36. params: {
  37. type: Object,
  38. default: function () {
  39. return {}
  40. }
  41. },
  42. disabled: {
  43. type: Boolean,
  44. default: false
  45. }
  46. },
  47. methods: {
  48. handlePrint (type) {
  49. const _this = this
  50. const params = {
  51. allocateReturnSn: this.params.allocateReturnSn || ''
  52. }
  53. this.$emit('loading')
  54. allocateReturnPrint(params).then(res => {
  55. _this.spinning = false
  56. if (res.type == 'application/json') {
  57. var reader = new FileReader()
  58. reader.addEventListener('loadend', function () {
  59. const obj = JSON.parse(reader.result)
  60. _this.$notification.error({
  61. message: '提示',
  62. description: obj.message
  63. })
  64. })
  65. reader.readAsText(res)
  66. } else {
  67. this.print(res, type)
  68. }
  69. _this.$emit('unloading')
  70. })
  71. },
  72. print (data, type) {
  73. if (!data) {
  74. return
  75. }
  76. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  77. console.log(url)
  78. document.getElementById('print').innerHTML = '<iframe id="printftoe" name="printftoe" src="' + url + '" hidden></iframe>'
  79. if (type == 'views') { // 预览
  80. window.open(url)
  81. } else if (type == 'print') { // 打印
  82. window.frames['printftoe'].focus()
  83. window.frames['printftoe'].print()
  84. }
  85. },
  86. // 导出
  87. handleExcel () {
  88. const _this = this
  89. this.$emit('loading')
  90. hdExportExcel(allocateReturnExcel, { allocateReturnSn: this.params.allocateReturnSn || '' }, '调拨退货单明细', function () {
  91. _this.$emit('unloading')
  92. })
  93. }
  94. }
  95. }
  96. </script>
  97. <style>
  98. </style>