tb-orders-print.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>二级市场订单表-交易凭证</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <!-- 所有的 css js 资源 -->
  8. <link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
  9. <link rel="stylesheet" href="../../static/sa.css">
  10. <script src="../../static/kj/vue.min.js"></script>
  11. <script src="../../static/kj/element-ui/index.js"></script>
  12. <script src="../../static/kj/httpVueLoader.js"></script>
  13. <script src="../../static/kj/jquery.min.js"></script>
  14. <script src="../../static/kj/layer/layer.js"></script>
  15. <script src="../../static/sa.js"></script>
  16. <script src="../../static/kj/upload-util.js"></script>
  17. <!-- 引入 html2canvas 和 jsPDF -->
  18. <script src="../../static/kj/html2canvas.min.js"></script>
  19. <script src="../../static/kj/jspdf.umd.min.js"></script>
  20. <style type="text/css">
  21. .c-panel .c-label{width: 8em;}
  22. table {
  23. font-family: arial, sans-serif;
  24. border-collapse: collapse;
  25. width: 90%;
  26. margin-top: 20px ;
  27. margin-left: auto;
  28. margin-right: auto;
  29. }
  30. th {
  31. border: 1px solid darkgray;
  32. text-align: left;
  33. height: 24px;
  34. padding: 8px;
  35. background-color: #dddddd;
  36. }
  37. td {
  38. border: 1px solid darkgray;
  39. text-align: left;
  40. padding: 8px;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div class="vue-box sbot" style="display: none;" :style="'display: block;'">
  46. <!-- ------- 内容部分 ------- -->
  47. <div class="s-body">
  48. <div class="c-panel" id="content-to-convert" ref="contentToConvert">
  49. <el-form v-if="m">
  50. <table>
  51. <tr>
  52. <td colspan='4' style="text-align:center;font-weight: bold;" >{{m.tradeAreaName}}交易凭证</th>
  53. </tr>
  54. <tr>
  55. <td colspan='4'>交易信息</th>
  56. </tr>
  57. <tr>
  58. <th>订单编号</th>
  59. <td>{{m.orderNo}}</td>
  60. <th>商品名称</th>
  61. <td>{{m.goodsName}}</td>
  62. </tr>
  63. <tr>
  64. <th>买家</th>
  65. <td>{{m.purchaserName}}</td>
  66. <th>卖家</th>
  67. <td>{{m.leaderName}}</td>
  68. </tr>
  69. <tr>
  70. <th>转售金额</th>
  71. <td>{{m.resalePrice}}</td>
  72. <th>互市区</th>
  73. <td>{{m.tradeAreaName}}</td>
  74. </tr>
  75. <tr>
  76. <th>车牌号</th>
  77. <td>{{m.veNo}}</td>
  78. <th>订单状态</th>
  79. <td>
  80. <b v-if="m.orderFinish == 1">已完成</b>
  81. <b v-if="m.orderFinish == 0">未完成</b>
  82. </td>
  83. </tr>
  84. <tr>
  85. <td colspan='4'>商品信息</th>
  86. </tr>
  87. <tr>
  88. <td colspan='4' style="padding:0px">
  89. <table style="width:100%;margin:0 0 0 0;">
  90. <tr>
  91. <th>商品名称</th>
  92. <th>单价(元)</th>
  93. <th>数量</th>
  94. <th>重量</th>
  95. <th>单位</th>
  96. <th>总价(元)</th>
  97. </tr>
  98. <tr>
  99. <td>木薯淀粉</td>
  100. <td>3.23</td>
  101. <td>24</td>
  102. <td>345.01</td>
  103. <td>千克</td>
  104. <td>34663.33</td>
  105. </tr>
  106. <tr>
  107. <td>龙虾</td>
  108. <td>7.23</td>
  109. <td>12</td>
  110. <td>322.01</td>
  111. <td>千克</td>
  112. <td>4463.33</td>
  113. </tr>
  114. </table>
  115. </th>
  116. </tr>
  117. </table>
  118. </el-form>
  119. </div>
  120. </div>
  121. <!-- ------- 底部按钮 ------- -->
  122. <div class="s-foot">
  123. <!--<el-button type="primary" icon="el-icon-printer" @click="htmlToPdf()">预览凭证</el-button>-->
  124. <el-button type="primary" icon="el-icon-printer" @click="downloadToPdf()">下载凭证</el-button>
  125. <el-button @click="sa.closeCurrIframe()">取消</el-button>
  126. </div>
  127. </div>
  128. <script>
  129. var app = new Vue({
  130. components: {
  131. "sa-info": httpVueLoader('../../sa-frame/com/sa-info.vue')
  132. },
  133. el: '.vue-box',
  134. data: {
  135. id: sa.p('id', 0), // 获取数据ID
  136. m: null
  137. },
  138. methods: {
  139. downloadToPdf() {
  140. const element = document.getElementById('content-to-convert');
  141. html2canvas(element).then(canvas => {
  142. // 使用 jsPDF 将 canvas 转换成 PDF
  143. const imgData = canvas.toDataURL('image/png');
  144. const pdf = new jspdf.jsPDF({
  145. orientation: 'p',
  146. unit: 'px',
  147. format: [canvas.width, canvas.height]
  148. });
  149. const imgProps = pdf.getImageProperties(imgData);
  150. const pdfWidth = pdf.internal.pageSize.getWidth();
  151. const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
  152. // 添加图片,适应页面大小
  153. pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
  154. pdf.save(Date.now()+'.pdf');
  155. });
  156. },
  157. htmlToPdf() {
  158. const element = document.getElementById('content-to-convert');
  159. html2canvas(element).then(canvas => {
  160. // 使用 jsPDF 将 canvas 转换成 PDF
  161. const imgData = canvas.toDataURL('image/png');
  162. const pdf = new jspdf.jsPDF({
  163. orientation: 'p',
  164. unit: 'px',
  165. format: [canvas.width, canvas.height]
  166. });
  167. const imgProps = pdf.getImageProperties(imgData);
  168. const pdfWidth = pdf.internal.pageSize.getWidth();
  169. const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
  170. // 添加图片,适应页面大小
  171. pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
  172. // 将 PDF 保存为 Blob 并处理它 这里需要处理跨域问题
  173. pdf.output('blob').then(function(blob) {
  174. var blobURL = URL.createObjectURL(blob);
  175. var newWindow = window.open(blobURL, '_blank');
  176. if (newWindow) {
  177. newWindow.focus();
  178. } else {
  179. alert('请允许弹出窗口或在新标签页中手动查看 PDF。');
  180. }
  181. // 清理:当不再需要时,可以释放 Blob URL
  182. // setTimeout(function() {
  183. // URL.revokeObjectURL(blobURL);
  184. // }, 5000);
  185. });
  186. });
  187. },
  188. },
  189. mounted: function() {
  190. sa.ajax('/level-two-server/TbOrders/getById?id=' + this.id, function(res) {
  191. this.m = res.data;
  192. if(res.data == null) {
  193. sa.alert('未能查找到 id=' + this.id + " 详细数据");
  194. }
  195. }.bind(this))
  196. }
  197. })
  198. </script>
  199. </body>
  200. </html>