rkadyPrint.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <div>
  3. <div class="tools" style="width: 100%;height:80px;margin: 0 auto">
  4. <div style="width:800px;height:80px;display: flex; justify-content: space-between; align-items: center;margin: 0 auto">
  5. <div style="width: 800px;height: 40px">
  6. <pagination
  7. v-show="total>0"
  8. :total="total"
  9. :page.sync="queryParams.pageNum"
  10. :limit.sync="queryParams.pageSize"
  11. @pagination="flowCardListApi"
  12. :page-sizes="[5,10,20]"
  13. />
  14. </div>
  15. <div style="width: 200px;height: 40px">
  16. <el-button type="primary" icon="el-icon-search" size="mini" v-print="printViewInfo">打印</el-button>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="base" id="printView" >
  21. <div class="box" style="page-break-after:always;" v-for="(item,index) in listDate" v-if="index%2==0">
  22. <div class="left" style="margin-top: 15px">
  23. <div class="top">
  24. <table border="2px" class="left-top-table">
  25. <tr>
  26. <td rowspan="2" style="width: 30%;">
  27. <div class="titleBox" style="position: relative;">
  28. <div class="erweima" ><img :src="item.base46MaD" alt=""></div>
  29. </div>
  30. </td>
  31. <td style="width: 30%;">订单号</td>
  32. <td style="width: 40%;">{{item.orderNumber}}</td>
  33. </tr>
  34. <tr>
  35. <td style="width: 20%;">产品编号</td>
  36. <td style="width: 30%;">{{item.serialNumber}}</td>
  37. </tr>
  38. </table>
  39. </div>
  40. </div>
  41. <div class="right" style="margin-left: 15px;margin-top: 15px">
  42. <div class="top" v-if="index+1<listDate.length">
  43. <table border="2px" class="right-top-table">
  44. <tr>
  45. <td rowspan="2" style="width: 30%;">
  46. <div class="titleBox" style="position: relative;">
  47. <div class="erweima" ><img :src="item.base46MaD" alt=""></div>
  48. </div>
  49. </td>
  50. <td style="width: 30%;">订单号</td>
  51. <td style="width: 40%;">{{item.orderNumber}}</td>
  52. </tr>
  53. <tr>
  54. <td style="width: 20%;">产品编号</td>
  55. <td style="width: 30%;">{{item.serialNumber}}</td>
  56. </tr>
  57. </table>
  58. </div >
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import {flowCardList} from "@/api/amichi/planTask/planTaskDetails.js";
  66. export default {
  67. name: "rkadyPrint",
  68. data () {
  69. return {
  70. queryParams:{
  71. pageNum: 1,
  72. pageSize: 5,
  73. orderNumberList:[],
  74. },
  75. total:0,
  76. listDate:[],
  77. dialogVisible: false,
  78. msg: "打印",
  79. printViewInfo: {
  80. id: "printView", //打印区域的唯一的id属性
  81. // popTitle: '配置页眉标题', // 页眉文字 (不设置时显示undifined)(页眉页脚可以在打印页面的更多设置的选项中取消勾选)
  82. // extraHead: '打印,印刷', // 最左上方的头部文字,附加在head标签上的额外标签,使用逗号分割
  83. preview: false, // 是否启动预览模式,默认是false (开启预览模式ture会占满整个屏幕,不建议开启,除非业务需要)
  84. // previewTitle: '预览的标题', // 打印预览的标题(预览模式preview为true时才显示)
  85. // previewPrintBtnLabel: '预览结束,开始打印', // 打印预览的标题下方的按钮文本,点击可进入打印(预览模式preview为true时才显示)
  86. zIndex: 20002, // 预览窗口的z-index,默认是20002,最好比默认值更高
  87. previewBeforeOpenCallback (that) { console.log('正在加载预览窗口!'); console.log(that.msg, this) }, // 预览窗口打开之前的callback (预览模式preview为true时才执行) (that可以取到data里的变量值)
  88. previewOpenCallback () { console.log('已经加载完预览窗口,预览打开了!') }, // 预览窗口打开时的callback (预览模式preview为true时才执行)
  89. beforeOpenCallback () { console.log('开始打印之前!') }, // 开始打印之前的callback
  90. openCallback () { console.log('执行打印了!') }, // 调用打印时的callback
  91. closeCallback () { console.log('关闭了打印工具!') }, // 关闭打印的callback(无法区分确认or取消)
  92. clickMounted () { console.log('点击v-print绑定的按钮了!') },
  93. // url: 'http://localhost:8080/', // 打印指定的URL,确保同源策略相同
  94. // asyncUrl (reslove) {
  95. // setTimeout(() => {
  96. // reslove('http://localhost:8080/')
  97. // }, 2000)
  98. // },
  99. standard: '',
  100. extarCss: '',
  101. isDataLoaded: false,
  102. }
  103. }
  104. },
  105. methods: {
  106. getNextOrderNumber(index) {
  107. if (index < this.listDate.length - 1) {
  108. return this.listDate[index + 1];
  109. } else {
  110. return 0
  111. }
  112. },
  113. //渲染表格内容
  114. async flowCardListApi(){
  115. let res = await flowCardList(this.queryParams)
  116. if (res.code == 200) {
  117. this.listDate = res.rows;
  118. this.total = res.total;
  119. this.isDataLoaded = true;
  120. this.$nextTick(()=>{
  121. this.adjustFontSize();
  122. this.adjustFontSizebzxsm()
  123. })
  124. }
  125. },
  126. adjustFontSize() {
  127. const element = this.$refs.bzx;
  128. if (!element) return; // 如果元素不存在,直接返回
  129. for (let i=0;i<element.length;i++) {
  130. const maxHeight = 115;
  131. let currentFontSize = 21;
  132. while (element[i].scrollHeight > maxHeight && currentFontSize > 8) {
  133. currentFontSize -= 0.5; // 每次减少0.5px
  134. element[i].style.fontSize = `${currentFontSize}px`;
  135. }
  136. }
  137. console.log(element[0].style)
  138. },
  139. adjustFontSizebzxsm() {
  140. const element = this.$refs.bzxsm;
  141. console.log(element.length)
  142. if (!element) return; // 如果元素不存在,直接返回
  143. for (let i=0;i<element.length;i++){
  144. const maxHeight = 50;
  145. let currentFontSize = 21;
  146. while (element[i].scrollHeight > maxHeight && currentFontSize > 8) {
  147. currentFontSize -= 0.5; // 每次减少0.5px
  148. element[i].style.fontSize = `${currentFontSize}px`;
  149. }
  150. }
  151. console.log(element[0].style)
  152. }
  153. },
  154. mounted() {
  155. // this.adjustFontSize();
  156. },
  157. created(){
  158. // console.log(this.$route.query.orderNumberS)
  159. // this.queryParams.orderNumberList =this.$route.query.orderNumberS;
  160. this.queryParams.orderNumberList =this.$route.query.orderNumberSTwo;
  161. // console.log(this.queryParams.orderNumberList)
  162. this.flowCardListApi();
  163. },
  164. }
  165. </script>
  166. <style media="print" scoped>
  167. ::v-deep .pagination-container {
  168. margin-top: -10px;
  169. }
  170. .bzx{
  171. width: 454px;
  172. max-height: 115px;
  173. overflow: hidden;
  174. font-size: 21px;
  175. }
  176. .bs{
  177. height: 115px;
  178. min-height: 115px;
  179. }
  180. .bzxsm{
  181. width: 180px;
  182. max-height: 50px;
  183. overflow: hidden;
  184. font-size: 21px;
  185. }
  186. @media print {
  187. /* 隐藏页眉页脚 */
  188. @page {
  189. size: auto;
  190. margin: 3mm;
  191. .box{
  192. margin-top: 10px;
  193. }
  194. }
  195. html {
  196. zoom: 90%; /* 缩放比例设置 */
  197. }
  198. .noprint {
  199. display: none; /* 隐藏打印区域不需要打印的内容 */
  200. }
  201. }
  202. .base{
  203. .heg{
  204. height: 30px;
  205. }
  206. .heg td{
  207. height: 30px;
  208. }
  209. .jc{
  210. font-weight: bold;
  211. font-size: 50px;
  212. }
  213. .page-break {
  214. page-break-after: always;
  215. position: relative;
  216. }
  217. .tools {
  218. margin-top: 10px;
  219. display: flex;
  220. justify-content: flex-end;
  221. margin-bottom: 10px;
  222. }
  223. *{
  224. margin: 0 auto;
  225. padding: 0;
  226. }
  227. .box{
  228. font-size: 21px;
  229. width: 800px;
  230. /* border: 1px solid red; */
  231. display: flex;
  232. justify-content: start;
  233. margin-bottom: 10px;
  234. }
  235. td{
  236. text-align: center;
  237. }
  238. .left{
  239. width: 48%;
  240. }
  241. .right{
  242. width: 48%;
  243. }
  244. .left-top-table{
  245. width: 100%;
  246. border: 2px solid black;
  247. border-collapse: collapse;
  248. color: black;
  249. font-weight: bold;
  250. }
  251. .left-top-table tr td{
  252. padding: 4px 4px;
  253. word-wrap:break-word;
  254. word-break:break-all;
  255. color: black;
  256. font-weight: bold;
  257. }
  258. .right-top-table{
  259. width: 100%;
  260. border: 1px solid black;
  261. border-collapse: collapse;
  262. color: black;
  263. font-weight: bold;
  264. color: black;
  265. font-weight: bold;
  266. }
  267. .right-top-table tr td{
  268. padding: 4px 4px;
  269. word-wrap:break-word;
  270. word-break:break-all;
  271. color: black;
  272. font-weight: bold;
  273. }
  274. .erweima{
  275. width: 100px;
  276. height: 80px;;
  277. background-color: red;
  278. margin-top: 8px;
  279. }
  280. .titleBox{
  281. display: flex;
  282. color: black;
  283. width: 100%;
  284. height: 120px;
  285. font-weight: bold;
  286. }
  287. .left-top-table .titleBox .xh{
  288. position: relative;
  289. }
  290. .left-top-table .titleBox .xh span{
  291. position: absolute;
  292. width: 80px;
  293. left: -421px;
  294. top: 80px;
  295. }
  296. .left-top-table .titleBox .time span{
  297. position: absolute;
  298. left: 290px;
  299. top: 75px;
  300. }
  301. .right-top-table .titleBox .time span{
  302. position: absolute;
  303. left: 290px;
  304. top: 82px;
  305. }
  306. .titleBox .time span i{
  307. font-style: normal;
  308. }
  309. .titleBox .title{
  310. margin-left: 60px;
  311. margin-top: 7px;
  312. font-family: 'Courier New', Courier, monospace;
  313. }
  314. .abc{
  315. color: rebeccapurple;
  316. font-size: 15px;
  317. /* word-wrap: break-word; */
  318. /* white-space: pre-wrap; */
  319. }
  320. .right-top-table .titleBox .xh{
  321. position: relative;
  322. }
  323. .right-top-table .titleBox .xh span{
  324. position: absolute;
  325. width: 80px;
  326. left: -424px;
  327. top: 80px;
  328. }
  329. .right-top-table .titleBox .time span{
  330. position: absolute;
  331. left: 290px;
  332. top: 82px;
  333. }
  334. .right-top-table .titleBox .time span{
  335. position: absolute;
  336. left: 290px;
  337. top: 82px;
  338. }
  339. .left-top-table td{
  340. border: 3px solid black;
  341. }
  342. .right-top-table td{
  343. border: 3px solid black;
  344. }
  345. .right-top-table td{
  346. border: 3px solid black;
  347. }
  348. .right-top-table td{
  349. border: 3px solid black;
  350. }
  351. }
  352. </style>