tb-orders-print.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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='6' style="text-align:center;font-weight: bold;" >{{m.tradeAreaName}}交易凭证</td>
  53. </tr>
  54. <tr>
  55. <td colspan='6'>交易信息</td>
  56. </tr>
  57. <tr>
  58. <th>订单编号</th>
  59. <td>{{m.orderNo}}</td>
  60. <th>银行流水</th>
  61. <td>{{m.result}}</td>
  62. <th>交易时间</th>
  63. <td>{{m.payTime}}</td>
  64. </tr>
  65. <tr>
  66. <th>卖家</th>
  67. <td>{{m.leaderName}}</td>
  68. <th>证件号码</th>
  69. <td>{{m.idCard}}</td>
  70. <th>所属合作社(互助组)</th>
  71. <td>{{m.groupName}}</td>
  72. </tr>
  73. <tr>
  74. <th>买家</th>
  75. <td>{{m.purchaserName}}</td>
  76. <th>支付方式</th>
  77. <td></td>
  78. <th>交易金额</th>
  79. <td>{{m.resalePrice}}</td>
  80. </tr>
  81. <tr>
  82. <th>关区</th>
  83. <td>天保海关</td>
  84. <th>口岸</th>
  85. <td colspan='3'>{{m.tradeAreaName}}</td>
  86. </tr>
  87. <tr>
  88. <td colspan='6'>商品信息</td>
  89. </tr>
  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>{{m.goodsName}}</td>
  100. <td>{{m.singlePrice}}</td>
  101. <td>{{m.buyQty}}</td>
  102. <td>{{m.netWet}}</td>
  103. <td>{{m.goodsUnit}}</td>
  104. <td>{{m.resalePrice}}</td>
  105. </tr>
  106. </table>
  107. </el-form>
  108. </div>
  109. </div>
  110. <!-- ------- 底部按钮 ------- -->
  111. <div class="s-foot">
  112. <el-button type="success" icon="el-icon-printer" @click="htmlToPdf()">打印凭证</el-button>
  113. <el-button type="primary" icon="el-icon-download" @click="downloadToPdf()">下载凭证</el-button>
  114. <el-button @click="sa.closeCurrIframe()">关闭</el-button>
  115. </div>
  116. </div>
  117. <script>
  118. var app = new Vue({
  119. components: {
  120. "sa-info": httpVueLoader('../../sa-frame/com/sa-info.vue')
  121. },
  122. el: '.vue-box',
  123. data: {
  124. id: sa.p('id', 0), // 获取数据ID
  125. m: null
  126. },
  127. methods: {
  128. downloadToPdf() {
  129. const element = document.getElementById('content-to-convert');
  130. html2canvas(element).then(canvas => {
  131. // 使用 jsPDF 将 canvas 转换成 PDF
  132. const imgData = canvas.toDataURL('image/png');
  133. const pdf = new jspdf.jsPDF({
  134. orientation: 'pportrait',
  135. unit: 'px',
  136. format: 'a4'
  137. });
  138. const imgProps = pdf.getImageProperties(imgData);
  139. const pdfWidth = pdf.internal.pageSize.getWidth();
  140. const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
  141. // 添加图片,适应页面大小
  142. pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
  143. pdf.save(Date.now()+'.pdf');
  144. });
  145. },
  146. htmlToPdf() {
  147. const element = document.getElementById('content-to-convert');
  148. html2canvas(element).then(canvas => {
  149. // 使用 jsPDF 将 canvas 转换成 PDF
  150. const imgData = canvas.toDataURL('image/png');
  151. const pdf = new jspdf.jsPDF({
  152. orientation: 'portrait',
  153. unit: 'px',
  154. format: 'a4'
  155. });
  156. const imgProps = pdf.getImageProperties(imgData);
  157. const pdfWidth = pdf.internal.pageSize.getWidth();
  158. const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
  159. // 添加图片,适应页面大小
  160. pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
  161. // 将 PDF 保存为 Blob 并处理它 这里需要处理跨域问题
  162. const pdfBlob = pdf.output('blob');
  163. var blobURL = window.URL.createObjectURL(pdfBlob);
  164. var newWindow = window.open(blobURL, '_blank');
  165. if (newWindow) {
  166. newWindow.focus();
  167. } else {
  168. alert('请允许弹出窗口或在新标签页中手动查看 PDF。');
  169. }
  170. });
  171. },
  172. },
  173. mounted: function() {
  174. sa.ajax('/level-two-server/TbOrders/getSubPrint?id=' + this.id, function(res) {
  175. this.m = res.data;
  176. if(res.data == null) {
  177. sa.alert('未能查找到 id=' + this.id + " 详细数据");
  178. }
  179. }.bind(this))
  180. }
  181. })
  182. </script>
  183. </body>
  184. </html>