Pdf.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <el-dialog
  3. class="my-dialog"
  4. fullscreen
  5. append-to-body
  6. :model-value="showDialog"
  7. @close="closeDialog()"
  8. >
  9. <div class="pdf-main">
  10. <div class="title" >
  11. <div class="name" ></div>
  12. <div class="pdf-close cursor-pointer" @click="closeDialog"></div>
  13. </div>
  14. <div id="printTest" class="pdf-dialog-box">
  15. <div class="pdf-my-body" >
  16. <div class="pdfBox" >
  17. <div class="a4" >
  18. <div class="a4_title">确权单</div>
  19. <table class="a4_table" border=1 style="border-collapse: collapse;">
  20. <tr>
  21. <td class="name">农场地址</td>
  22. <td class="text">{{rowData.address}}</td>
  23. <td class="name">农场名称</td>
  24. <td class="text">{{rowData.farmName}}</td>
  25. </tr>
  26. <tr>
  27. <td class="name">创建时间</td>
  28. <td class="text">{{rowData.createDate}}</td>
  29. <td class="name">农场面积</td>
  30. <td class="text">{{rowData.area}}亩</td>
  31. </tr>
  32. <tr>
  33. <td class="name">作物物种</td>
  34. <td class="text">{{rowData.speciesTypeName}}</td>
  35. <td class="name">客户姓名</td>
  36. <td class="text">{{rowData.masterName}}</td>
  37. </tr>
  38. <tr>
  39. <td class="name">联系电话</td>
  40. <td class="text">{{rowData.masterTel}}</td>
  41. </tr>
  42. <tr>
  43. <td class="name">经纬度</td>
  44. <td colspan="3" class="text2">{{rowData.points}}</td>
  45. </tr>
  46. </table>
  47. <div class="a4_sub_title">地块四至图</div>
  48. <img :key="imgUrl" v-show="imgUrl" class="img-content img" style="z-index: 999" width="595" height="500" :src="imgUrl" />
  49. <div :key="imgUrl" v-show="!imgUrl" class="img-content" ref="mapRef" id="mapRefId"></div>
  50. <div class="signature">签名:______________</div>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. <div style="text-align: left">
  56. <el-button size="large" color="#626aef" v-print="printObj">打印</el-button>
  57. <!-- <el-button size="large" color="#626aef" @click="closeDialog">关闭</el-button>-->
  58. </div>
  59. </div>
  60. </el-dialog>
  61. </template>
  62. <script setup>
  63. import {reactive, ref, toRefs, computed, nextTick, onMounted} from "vue";
  64. import {useStore} from "vuex";
  65. import {WKT} from "ol/format";
  66. import PdfMap from "./pdfMap";
  67. import { dateFormat } from "@/utils/date_util";
  68. import {getAreaByWkt} from "../../utils/map";
  69. const emit = defineEmits(["closeDialog","success"])
  70. const state = useStore().state;
  71. const sendConfirmShow = ref(false)
  72. const mapRef = ref(null)
  73. let pdfMap = new PdfMap()
  74. let rowData = ref({})
  75. async function send(){
  76. closeDialog();
  77. }
  78. const props = defineProps({
  79. title:{
  80. type:String,
  81. required:true
  82. },
  83. showDialog: {
  84. type: Boolean,
  85. default: true,
  86. },
  87. rowId:{
  88. type: Number,
  89. required:true,
  90. }
  91. });
  92. let printObj = {
  93. id:"printTest",
  94. popTitle: 'good print',
  95. beforeOpenCallback (vue) {
  96. toImg(true)
  97. console.log('打开之前')
  98. },
  99. openCallback (vue) {
  100. let {masterName, farmName, masterTel} = rowData.value
  101. document.title =`${farmName}-${masterTel}-${masterName}`
  102. console.log('执行了打印')
  103. },
  104. closeCallback (vue) {
  105. document.title =`飞鸟确权平台`
  106. console.log('关闭了打印工具')
  107. }
  108. }
  109. let imgUrl = ref(null)
  110. const executor = ref([])
  111. const executorList = ref([])
  112. const formRef = ref(null);
  113. const {title, rowId} = toRefs(props);
  114. const closeDialog = (key) => {
  115. switch (key){
  116. case "sendConfirm":
  117. sendConfirmShow.value = false;
  118. return
  119. }
  120. emit("closeDialog", "pdf");
  121. };
  122. function toImg(show) {
  123. let canvas = pdfMap.kmap.map.getViewport().querySelector('canvas')
  124. let dataURL = canvas.toDataURL('image/webp');
  125. // if(show){
  126. imgUrl.value = dataURL;
  127. // }
  128. }
  129. onMounted(()=>{
  130. VE_API.authentic.getDetails({id:rowId.value}).then(({data})=>{
  131. data.createDate = dateFormat(new Date(), "YYYY-mm-dd HH:MM:SS");
  132. data.area = getAreaByWkt(data.geom)
  133. rowData.value = data
  134. pdfMap.initMap(data,mapRef.value)
  135. setTimeout(function(){
  136. toImg(false)
  137. },1500)
  138. })
  139. })
  140. </script>
  141. <style lang="scss" scoped>
  142. $title-height:0px;
  143. $body-height:calc(100% - $title-height);
  144. .pdf-main{
  145. left: 25%;
  146. right: 25%;
  147. top:10%;
  148. bottom:10%;
  149. background: rgba(1,17,22,0.8);
  150. box-shadow: 0px 0px 20px 0px #00FFF0;
  151. border-radius: 4px;
  152. border: 2px solid rgba(81,233,240,0.6);
  153. position: absolute;
  154. .title{
  155. width: 100%;
  156. height: $title-height;
  157. box-sizing: border-box;
  158. background: rgba(0,77,101,0.8);
  159. border-radius: 4px 4px 0px 0px;
  160. border-bottom: 2px solid rgba(81,233,240,0.3);
  161. display: flex;
  162. align-items: center;
  163. justify-content: space-between;
  164. .name{
  165. margin-left: 20px;
  166. font-size: 16px;
  167. font-weight: 600;
  168. color: #00FFF0;
  169. height: 22px;
  170. }
  171. .pdf-close{
  172. width: 16px;
  173. height: 16px;
  174. background-image: url("@/assets/img/close.png");
  175. background-size: 100% 100%;
  176. }
  177. }
  178. }
  179. .pdf-dialog-box{
  180. font-family: PingFangSC-Regular, PingFang SC;
  181. width: 100%;
  182. height: 100%;
  183. .pdf-my-body{
  184. width: 100%;
  185. height: $body-height;
  186. box-sizing: border-box;
  187. padding: 20px;
  188. ::-webkit-scrollbar-thumb {
  189. /* 滚动条里面小方块 */
  190. background: rgb(70, 71, 71);;
  191. border-radius: 6px;
  192. }
  193. ::-webkit-scrollbar-track {
  194. /* 滚动条里面轨道 */
  195. background: #ededed;
  196. }
  197. }
  198. .pdfBox{
  199. height: calc(100%);
  200. width: 100%;
  201. overflow-y: scroll;
  202. background-color: rgba(141, 142, 142);
  203. padding: 10px;
  204. box-sizing: border-box;
  205. display: flex;
  206. justify-content: center;
  207. }
  208. .a4{
  209. font-family: PingFangSC-Medium, PingFang SC;
  210. background-color: #FFFFFF;
  211. width:595px;
  212. height:1000px;
  213. margin: 5px 0px 5px 0px;
  214. padding: 19px 63px 19px 63px;
  215. font-weight: 600;
  216. color: #000000;
  217. .a4_title{
  218. width:595px;
  219. height: 33px;
  220. font-size: 24px;
  221. text-align: center;
  222. margin: 10px 0px 10px 0px;
  223. }
  224. .a4_sub_title{
  225. font-size: 16px;
  226. margin: 10px 0px 10px 0px;
  227. }
  228. .a4_table{
  229. height: calc(842px - 33px - 26px - 600px);
  230. max-height: calc(842px - 33px - 26px - 600px);
  231. width:595px;
  232. font-size: 12px;
  233. .name{
  234. width: 50px;
  235. height: 20px;
  236. line-height: 20px;
  237. padding-right: 9px;
  238. box-sizing: border-box;
  239. text-align: right;
  240. }
  241. .text{
  242. width: 122px;
  243. height: 20px;
  244. line-height: 20px;
  245. text-align: left;
  246. padding-left: 9px;
  247. box-sizing: border-box;
  248. }
  249. .text2{
  250. text-align: left;
  251. font-size: 10px;
  252. font-weight: normal;
  253. }
  254. }
  255. .img-content{
  256. width:595px;
  257. height: 500px;
  258. z-index: 1000;
  259. .ol-viewport{
  260. width:595px !important;
  261. height: 500px !important;
  262. .ol-layers{
  263. width:595px !important;
  264. height: 500px !important;
  265. .ol-layer{
  266. width:595px !important;
  267. height: 500px !important;
  268. }
  269. }
  270. }
  271. }
  272. .img{
  273. z-index: 999;
  274. }
  275. .signature{
  276. width:595px;
  277. height: 20px;
  278. z-index: 1000;
  279. margin-top: 40px;
  280. text-align: right;
  281. }
  282. }
  283. }
  284. canvas{
  285. width:595px;
  286. height: 500px;
  287. }
  288. </style>