index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div>
  3. <el-button type="text" size="small" @click="queryModelList">打 印</el-button>
  4. <el-dialog append-to-body title="选择模板" :visible.sync="dialogTableVisible" width="400px">
  5. <el-table size="mini" :data="gridData">
  6. <el-table-column prop="modelname" label="模板名称"></el-table-column>
  7. <el-table-column width="100" label="操作">
  8. <template slot-scope="scope">
  9. <el-button size="small" type="text" @click="selectMode(scope.row)">选择</el-button>
  10. </template>
  11. </el-table-column>
  12. </el-table>
  13. </el-dialog>
  14. </div>
  15. </template>
  16. <script>
  17. // import {defaultElementTypeProvider, hiprint} from '@/index'
  18. import {mapGetters} from 'vuex'
  19. export default {
  20. props:['dataid'],
  21. data () {
  22. return {
  23. gridData:[],
  24. panel:{},
  25. printData:{},
  26. sys_printmodelid:null,
  27. dialogTableVisible:false
  28. }
  29. },
  30. computed:{
  31. ...mapGetters({
  32. activeApp:'activeApp'
  33. })
  34. },
  35. methods:{
  36. async queryModelList () {
  37. this.dialogTableVisible = true
  38. const res = await this.$api.requested({
  39. "id": 20221121174201,
  40. "content": {
  41. "systemappid":this.activeApp.systemappid
  42. }
  43. })
  44. this.gridData = res.data
  45. },
  46. async queryPrintData() {
  47. const res = await this.$api.requested({
  48. "id": 20221121174301,
  49. "content": {
  50. "sys_printmodelid": this.sys_printmodelid,
  51. "dataid":this.dataid
  52. }
  53. })
  54. this.panel = JSON.parse(res.data.modeljson)
  55. let obj = this.panel.panels[0].printElements
  56. obj.forEach(element => {
  57. if (element.printElementType.type === 'text') {
  58. element.options.sys_printdatasetid?this.printData[element.options.field] = res.data.data['dataset'+ element.options.sys_printdatasetid][0][element.options.field]:""
  59. } else {
  60. console.log(element.options.sys_printdatasetid)
  61. this.printData[element.options.field] = res.data.data['dataset'+ element.options.sys_printdatasetid]
  62. }
  63. })
  64. this.onlyPrint()
  65. },
  66. selectMode (row) {
  67. this.sys_printmodelid = row.sys_printmodelid
  68. this.dialogTableVisible = false
  69. this.queryPrintData()
  70. },
  71. onlyPrint() {
  72. let hiprintTemplate = this.$print(undefined, this.panel, this.printData, {}, {
  73. styleHandler: () => {
  74. let css = '<link href="http://hiprint.io/Content/hiprint/css/print-lock.css" media="print" rel="stylesheet">';
  75. return css
  76. }
  77. })
  78. console.log(hiprintTemplate);
  79. },
  80. }
  81. }
  82. </script>
  83. <style>
  84. </style>