Browse Source

体检报告导出PDF

lighter 3 years ago
parent
commit
664c9c0adc

+ 9 - 1
src/api/physical-exam.js

@@ -22,4 +22,12 @@ export function getPhysicalCheckResult(tjid) {
         method: 'get',
         params: {tjid},
     })
-}
+}
+
+// export function exportPDF(data) {
+//     return request({
+//         url: '/physicalCheck/exportPDF',
+//         method: 'post',
+//         data,
+//     })
+// }

BIN
src/assets/leave_weixin.png


+ 60 - 23
src/views/hospital-service/physical-exam/PhysicalExamIndex.vue

@@ -1,15 +1,18 @@
 <template>
-  <window-size>
-    <van-field v-model="idCardOrTjid" center label="身份证/体检id" placeholder="请输入身份证/体检id">
-      <template #button>
-        <van-button size="small" type="primary" icon="search" @click="handleClickSearch">查询</van-button>
-      </template>
-    </van-field>
+  <window-size :show-back-nav="false">
+    <div v-if="isWxBrowser" id="weixin-tip"><p><img style="width:82%" :src="leaveWx" alt="微信打开"/><span id="close" title="关闭" class="close">×</span></p></div>
+    <div v-else>
+      <van-field v-model="idCard" center label="身份证" placeholder="请输入身份证">
+        <template #button>
+          <van-button size="small" type="primary" icon="search" @click="handleClickSearch">查询</van-button>
+        </template>
+      </van-field>
 
       <van-list :style="listBoxStyle" id="listWrapper" v-model:loading="listLoading" :finished="listFinished" finished-text="没有更多了" @load="onLoadingList">
         <van-cell v-for="item in examIndexes" :key="item.条码号" :title="item.工作单位" :value="item.checkTime"
-                   center clickable @click="handleClickIndex(item.条码号)"></van-cell>
+                  center clickable @click="handleClickIndex(item)"></van-cell>
       </van-list>
+    </div>
 
   </window-size>
 </template>
@@ -18,6 +21,9 @@ import {getIdCard, getPhysicalCheckIndex} from '../../../api/physical-exam'
 import {RouteParamValue, useRouter} from "vue-router";
 import {onMounted, ref, Ref} from "vue";
 import {useStore} from "vuex";
+import axios from "axios";
+import leaveWx from '../../../assets/leave_weixin.png'
+import {Toast} from "vant";
 
 const store: object = useStore();
 const router: object = useRouter();
@@ -28,7 +34,7 @@ const listBoxStyle: object = {
   overflowY: 'scroll'
 }
 
-const idCardOrTjid: Ref<string> = ref();
+const idCard: Ref<string> = ref();
 const idCardTemp: Ref<string> = ref();
 const nextPage: Ref<number> = ref(1);
 
@@ -37,7 +43,7 @@ const listFinished: Ref<boolean> = ref(false);
 const examIndexes: Ref<[]> = ref([]);
 
 const onLoadingList = (): void => {
-  if (idCardOrTjid.value) {
+  if (idCard.value) {
     fetchIndexData()
   } else {
     listLoading.value = false
@@ -45,7 +51,7 @@ const onLoadingList = (): void => {
 };
 
 const handleClickSearch = (): void => {
-  if (idCardOrTjid.value !== idCardTemp.value) {
+  if (idCard.value !== idCardTemp.value) {
     listFinished.value = false
     nextPage.value = 1
     examIndexes.value = []
@@ -53,17 +59,12 @@ const handleClickSearch = (): void => {
   if (listFinished.value) {
     return
   }
-  idCardTemp.value = idCardOrTjid.value
-
-  if (idCardOrTjid.value.trim().length > 15) {
-    fetchIndexData()
-  } else {
-    handleClickIndex(idCardOrTjid.value)
-  }
+  idCardTemp.value = idCard.value
+  fetchIndexData()
 }
 
 const fetchIndexData = (): void => {
-  getPhysicalCheckIndex(idCardOrTjid.value, nextPage.value).then(index => {
+  getPhysicalCheckIndex(idCard.value, nextPage.value).then(index => {
     listLoading.value = false
     listFinished.value = index.pageInfo.nextPage === 0;
     examIndexes.value = examIndexes.value.concat(index.rows)
@@ -76,14 +77,44 @@ const fetchIndexData = (): void => {
   });
 }
 
-const handleClickIndex = (tjid:string): void => {
-  store.commit('SET_CURRENTTJID', tjid)
-  router.push('/physicalExamination/' + tjid)
+const handleClickIndex = (tjIndex:object): void => {
+  const fileName = (tjIndex['工作单位'] ? tjIndex['工作单位'] : '长沙泰和医院体检报告' ) + '.pdf'
+  axios({
+    method: 'post',
+    url: 'http://staticweb.hnthyy.cn/wxserver/physicalCheck/exportPDF',
+    data: tjIndex,
+    responseType: 'blob',
+  })
+      .then((res) => {
+        if (res.data.type === 'application/x-download') {
+          let blob = new Blob([res.data], { type: 'application/pdf' })
+          const link = document.createElement('a')
+          link.href = URL.createObjectURL(blob)
+          link.style.display = 'none'
+          link.download = fileName //下载的文件名
+          document.body.appendChild(link)
+          link.click()
+          document.body.removeChild(link)
+        } else {
+          Toast.fail('没有查询到可导出的体检报告。')
+        }
+      })
+      .catch((error) => {
+        console.error(error)
+      })
+}
+
+const isWxBrowser = ref(false)
+
+const judgeWeChatBrowser = () => {
+  var ua = navigator.userAgent.toLowerCase();
+  return ua.match(/MicroMessenger/i) == "micromessenger";
 }
 
 onMounted((): void => {
+  isWxBrowser.value = judgeWeChatBrowser()
   getIdCard(patientId).then(res => {
-    idCardOrTjid.value = res
+    idCard.value = res
   })
   nextPage.value = store.state.physicalExamNextPage
   examIndexes.value = store.state.physicalExamIndexes
@@ -96,4 +127,10 @@ onMounted((): void => {
     document.getElementById('listWrapper').scrollTop = 66 * currentIndex - 100
   }
 })
-</script>
+</script>
+
+<style type="text/css">
+#weixin-tip{display:block;position:fixed;left:0;top:0;background:rgba(0,0,0,0.8);filter:alpha(opacity=80);width:100%;height:100%;z-index:100;}
+#weixin-tip p{text-align:center;margin-top:10%;padding:0 5%;position:relative;}
+#weixin-tip .close{color:#fff;padding:5px;font:bold 20px/24px simsun;text-shadow:0 1px 0 #ddd;position:absolute;top:0;left:5%;}
+</style>