ePolicy.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="page">
  3. <image class="ePolicy-back" :src="detailbackimg" mode=""></image>
  4. <uni-NavBar headerTitle="电子保单" background="transparent" :isShared="false" :isSlot="false"></uni-NavBar>
  5. <view class="ePolicy-tabs ">
  6. <text v-for="(item,index) in tabslist" :key="index" @click="tabclick(item)"
  7. :class="{active:tabsvalue===item.name}">{{item.name}}</text>
  8. </view>
  9. <view class="pdf-container">
  10. <template v-if="pdfUrl">
  11. <pdf-viewer v-if="pdfLoaded" :pdfUrl="pdfUrl" :key="pdfUrl" />
  12. <view v-else class="loading">加载中...</view>
  13. </template>
  14. <u-empty v-else mode="car" icon="/static/image/Empty1.png" text="暂无相关保单数据">
  15. </u-empty>
  16. </view>
  17. <view class="footer">
  18. <view class="btn" @click="downloadPolicy">
  19. 下载文件
  20. </view>
  21. <view class="btn">
  22. 分享
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. var wv; //计划创建的webview
  29. import PdfViewer from '@/components/PdfViewer/PdfViewer.nvue'; // 引入组件
  30. import {
  31. turnBase64Image
  32. } from '@/plugins/utils.js';
  33. export default {
  34. components: {
  35. PdfViewer
  36. },
  37. data() {
  38. return {
  39. tabsvalue: '交强险',
  40. tabslist: [{
  41. name: '交强险',
  42. url: 'https://sxzgkj.baoxianzhanggui.com/web-api/upload/file/2025/03/21/c9396840fb34be4a2775435357bd49e8.pdf',
  43. },
  44. {
  45. name: '商业险',
  46. url: null,
  47. },
  48. {
  49. name: '交强险标志',
  50. url: null
  51. },
  52. {
  53. name: '驾意险',
  54. url: null,
  55. }
  56. ],
  57. detailbackimg: "", //背景图
  58. pdfUrl: '', // 动态 PDF 地址
  59. pdfLoaded: false, //控制webview重新渲染
  60. };
  61. },
  62. computed: {},
  63. watch: {
  64. pdfUrl(newVal) {
  65. if (!newVal) {
  66. this.pdfLoaded = false;
  67. return;
  68. }
  69. this.pdfLoaded = false;
  70. // 添加延迟确保DOM更新
  71. this.$nextTick(() => {
  72. this.pdfLoaded = true;
  73. // APP端特殊处理
  74. // #ifdef APP-PLUS
  75. setTimeout(() => {
  76. const currentWebview = this.$scope.$getAppWebview();
  77. const wv = currentWebview.children()[0];
  78. if (wv) {
  79. wv.setStyle({
  80. top: '128px',
  81. height: '75%',
  82. })
  83. // wv.loadURL(newVal);
  84. }
  85. }, 300);
  86. // #endif
  87. });
  88. }
  89. },
  90. onReady() {
  91. // #ifdef APP-PLUS
  92. var currentWebview = this.$scope
  93. .$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
  94. setTimeout(function() {
  95. wv = currentWebview.children()[0]
  96. wv.setStyle({
  97. top: '128px',
  98. height: '75%',
  99. })
  100. }, 1000); //如果是页面初始化调用时,需要延时一下
  101. // #endif
  102. },
  103. async mounted() {
  104. this.detailbackimg = await turnBase64Image('/static/image/ePolicy.png');
  105. },
  106. async onLoad(options) {
  107. if (options.ordersNo) {
  108. let res = await this.$http.post('/unify/order/downloadPolicy', {
  109. order: {
  110. ordersNo: options.ordersNo
  111. }
  112. });
  113. if (res.code == '200') {
  114. // this.tabslist[0].url = res.data.jqUrl;
  115. // this.tabslist[1].url = res.data.syUrl;
  116. // this.tabslist[2].url = res.data.jqSignUrl;
  117. // this.tabslist[3].url = res.data.jyUrl;
  118. }
  119. }
  120. this.pdfUrl = this.tabslist[0].url;
  121. },
  122. methods: {
  123. downloadPolicy() {
  124. let file = this.tabslist.find(val => val.name == this.tabsvalue).url;
  125. //#ifdef APP-PLUS
  126. uni.showLoading({
  127. title: '文件下载中'
  128. });
  129. let index = file.lastIndexOf("\/")
  130. let licensename = file.substring(index + 1, file.length)
  131. let dtask = plus.downloader.createDownload(file, {
  132. filename: "_downloads/" + 'this.name' + '-' + '-' + licensename
  133. }, function(d, status) {
  134. if (status == 200) {
  135. uni.hideLoading()
  136. //下载成功,d.filename是文件在保存在本地的相对路径,使用下面的API可转为平台绝对路径
  137. let fileSaveUrl = plus.io.convertLocalFileSystemURL(d
  138. .filename);
  139. plus.runtime.openFile(d.filename); //选择软件打开文件
  140. } else {
  141. uni.hideLoading()
  142. //下载失败
  143. plus.downloader.clear(); //清除下载任务
  144. }
  145. })
  146. dtask.start();
  147. //#endif
  148. //#ifdef H5
  149. var win = window.open();
  150. win.document.write(
  151. '<body style="margin:0px;"><object data="' +
  152. file +
  153. '" type="application/pdf" width="100%" height="100%"><iframe src="' +
  154. file +
  155. '" scrolling="no" width="100%" height="100%" frameborder="0" ></iframe></object></body>'
  156. );
  157. //#endif
  158. },
  159. tabclick(item) {
  160. setTimeout(() => {
  161. this.tabsvalue = item.name;
  162. this.pdfUrl = item.url;
  163. }, 50); // 50ms的过渡间隙
  164. },
  165. // openDeviceText() {
  166. // uni.navigateTo({
  167. // url: "/pages/quote/pdfView?pdfUrl=https://sxzgkj.baoxianzhanggui.com/web-api/upload/file/2025/03/21/c9396840fb34be4a2775435357bd49e8.pdf",
  168. // })
  169. // },
  170. }
  171. };
  172. </script>
  173. <!--使用scss,只在本组件生效-->
  174. <style lang="scss" scoped>
  175. /* 背景图 */
  176. .ePolicy-back {
  177. width: 100%;
  178. height: 256rpx;
  179. position: fixed;
  180. top: 0;
  181. left: 0;
  182. z-index: 9999;
  183. }
  184. .ePolicy-tabs {
  185. position: fixed;
  186. top: 180rpx;
  187. left: 0;
  188. width: 100%;
  189. padding: 16rpx 30rpx;
  190. box-sizing: border-box;
  191. z-index: 9999;
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. text {
  196. font-size: 30rpx;
  197. color: rgba(51, 51, 51, 0.7);
  198. text-align: center;
  199. }
  200. .active {
  201. font-weight: bold;
  202. color: #333;
  203. font-size: 32rpx;
  204. }
  205. }
  206. .footer {
  207. position: fixed;
  208. bottom: 0;
  209. left: 0;
  210. width: 100%;
  211. background: linear-gradient(0, #FFFFFF 0%, rgba(255, 254, 245, 0.8) 100%);
  212. border-radius: 0rpx 0rpx 0rpx 0rpx;
  213. display: flex;
  214. align-items: center;
  215. justify-content: space-between;
  216. padding: 25rpx 30rpx 68rpx;
  217. box-sizing: border-box;
  218. backdrop-filter: blur(40rpx);
  219. z-index: 9999;
  220. }
  221. .footer .btn {
  222. width: 330rpx;
  223. height: 88rpx;
  224. background: #FDE935;
  225. border-radius: 58rpx 58rpx 58rpx 58rpx;
  226. display: flex;
  227. justify-content: center;
  228. align-items: center;
  229. font-weight: bold;
  230. }
  231. .loading {
  232. height: 80vh;
  233. display: flex;
  234. justify-content: center;
  235. align-items: center;
  236. color: #666;
  237. }
  238. .pdf-container {
  239. transition: opacity 0.3s;
  240. }
  241. .u-empty {
  242. width: 100%;
  243. position: absolute;
  244. top: 30%;
  245. left: 50%;
  246. transform: translate(-50%);
  247. }
  248. </style>