certCard copy.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div id="certCard">
  3. <el-row>
  4. <el-col :span="24">
  5. <el-col :span="24" class="btn">
  6. <el-button type="primary" size="mini" @click="submit">生成打印文件</el-button>
  7. <el-button v-if="url" type="success" size="mini" @click="openPdf">
  8. 打开生成文件
  9. </el-button>
  10. </el-col>
  11. <el-col :span="24" class="list">
  12. <data-table :fields="fields" :data="list" :opera="opera" :usePage="false"></data-table>
  13. </el-col>
  14. </el-col>
  15. </el-row>
  16. <!-- 不需要输入了, 作为参数传过来,班级最后一天为毕业日期 -->
  17. <!-- <el-dialog title="毕业日期" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
  18. <el-col :span="24">
  19. <el-date-picker v-model="endDate" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy 年 MM 月 dd 日" placeholder="选择日期">
  20. </el-date-picker>
  21. </el-col>
  22. <span slot="footer" class="dialog-footer">
  23. <el-button @click="dialogVisible = false">取 消</el-button>
  24. <el-button type="primary" @click="submit">确 定</el-button>
  25. </span>
  26. </el-dialog> -->
  27. </div>
  28. </template>
  29. <script>
  30. const moment = require('moment');
  31. import _ from 'lodash';
  32. import printTemplate from 'print-template';
  33. import dataTable from '@frame/components/filter-page-table';
  34. import { mapState, createNamespacedHelpers } from 'vuex';
  35. export default {
  36. name: 'certCard',
  37. props: {
  38. list: { type: Array, default: () => [] },
  39. startdate: { type: String },
  40. enddate: { type: String },
  41. },
  42. components: {
  43. dataTable,
  44. },
  45. data: function() {
  46. return {
  47. url: '',
  48. template: null,
  49. zhengshu: require('@/assets/zhengshu.jpg'),
  50. opera: [],
  51. fields: [
  52. { label: '姓名', prop: 'name' },
  53. { label: '学校名称', prop: 'school_name' },
  54. { label: '院系', prop: 'faculty' },
  55. { label: '专业', prop: 'major' },
  56. { label: '职务', prop: 'job' },
  57. { label: '是否优秀', prop: 'is_fine', format: i => (i === '0' ? '否' : i === '1' ? '是' : '无资格') },
  58. ],
  59. dialogVisible: false,
  60. };
  61. },
  62. created() {
  63. this.init();
  64. },
  65. methods: {
  66. init() {
  67. this.template = new printTemplate();
  68. this.template.push({
  69. name: 'expressDelivery1',
  70. unit: 'px',
  71. size: [1046.93, 714.02],
  72. fixed: [
  73. { type: 'image', x: 0, y: 0, default: this.zhengshu, width: 1046.93, height: 714.02 },
  74. { type: 'text', x: 138, y: 356, default: '学校(院):', fontSize: 18, fontFamily: '华文中宋' },
  75. { type: 'text', x: 607, y: 356, default: '级', fontSize: 18, fontFamily: '华文中宋' },
  76. { type: 'text', x: 857, y: 356, default: '专业', fontSize: 18, fontFamily: '华文中宋' },
  77. { type: 'text', x: 138, y: 426, default: '学生:', fontSize: 18, fontFamily: '华文中宋' },
  78. { type: 'text', x: 365, y: 426, default: '于', fontSize: 18, fontFamily: '华文中宋' },
  79. { type: 'text', x: 480, y: 426, default: '年', fontSize: 18, fontFamily: '华文中宋' },
  80. { type: 'text', x: 560, y: 426, default: '月参加吉林省大学生创新创业培训', fontSize: 18, fontFamily: '华文中宋' },
  81. { type: 'text', x: 138, y: 500, default: '第', fontSize: 18, fontFamily: '华文中宋' },
  82. { type: 'text', x: 238, y: 500, default: '期培训班。培训合格,特发此证。', fontSize: 18, fontFamily: '华文中宋' },
  83. { type: 'text', x: 155, y: 580, default: '证书编号:', fontSize: 18, fontFamily: '华文中宋' },
  84. ],
  85. data: {
  86. school_name: { type: 'text', x: 268, y: 356, fontSize: 20, fontFamily: '华文中宋' },
  87. entry_year: { type: 'text', x: 555, y: 356, fontSize: 20, fontFamily: '华文中宋' },
  88. major: { type: 'text', x: 635, y: 356, fontSize: 20, fontFamily: '华文中宋' },
  89. name: { type: 'text', x: 206, y: 426, fontSize: 20, fontFamily: '华文中宋' },
  90. year: { type: 'text', x: 417, y: 426, fontSize: 20, fontFamily: '华文中宋' },
  91. month: { type: 'text', x: 507, y: 426, fontSize: 20, fontFamily: '华文中宋' },
  92. termnames: { type: 'text', x: 190, y: 500, fontSize: 20, fontFamily: '华文中宋' },
  93. cernum: { type: 'text', x: 270, y: 580, fontSize: 20, fontFamily: '华文中宋' },
  94. end_date: { type: 'text', x: 655, y: 580, fontSize: 20, fontFamily: '华文中宋' },
  95. },
  96. });
  97. },
  98. openPdf() {
  99. let link = document.createElement('a');
  100. link.href = this.url;
  101. link.target = '_blank';
  102. link.click();
  103. },
  104. print() {
  105. this.dialogVisible = true;
  106. },
  107. submit() {
  108. let msg = this.$message({ message: '正在生成...', duration: 0 });
  109. this.dialogVisible = false;
  110. let end_date = { end_date: moment(this.enddate).format('YYYY 年 MM 月 DD 日') };
  111. let year = { year: this.startdate.substring(0, 4) };
  112. let month = { month: this.startdate.substring(5, 7) };
  113. var enticeNew = this.list.map(item => ({ ...item, ...end_date, ...year, ...month }));
  114. let data = [];
  115. this.url = null;
  116. let duplicate = _.cloneDeep(enticeNew);
  117. duplicate = duplicate.map(i => {
  118. i.school_name = `${i.school_name}`;
  119. i.entry_year = `${i.entry_year}`;
  120. i.major = `${i.major}`;
  121. i.name = `${i.name}`;
  122. i.year = `${i.year}`;
  123. i.month = `${i.month}`;
  124. i.termnames = `${i.termname}`;
  125. i.cernum = `${i.year}${i.termname}${i.classname}01`;
  126. i.end_date = `${i.end_date}`;
  127. return i;
  128. });
  129. // this.template.print('expressDelivery1', [duplicate[0]]).then(pdf => {
  130. this.template.print('expressDelivery1', duplicate).then(pdf => {
  131. msg.close();
  132. if (pdf) {
  133. this.$message.success('生成成功');
  134. this.url = pdf.output('bloburi', { filename: '证书' });
  135. } else {
  136. this.$message.warring('生成失败');
  137. }
  138. });
  139. },
  140. handleClose(done) {
  141. done();
  142. },
  143. },
  144. computed: {
  145. ...mapState(['user']),
  146. pageTitle() {
  147. return `${this.$route.meta.title}`;
  148. },
  149. },
  150. metaInfo() {
  151. return { title: this.$route.meta.title };
  152. },
  153. };
  154. </script>
  155. <style lang="less" scoped>
  156. .btn {
  157. margin: 0 0 15px 0;
  158. }
  159. </style>