|
|
@@ -56,6 +56,20 @@
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
|
|
|
+ <el-row :gutter="10" class="mb8">
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="warning"
|
|
|
+ plain
|
|
|
+ icon="el-icon-download"
|
|
|
+ size="mini"
|
|
|
+ @click="downloadPdf"
|
|
|
+ :disabled="multiple"
|
|
|
+ >批量生成PDF</el-button>
|
|
|
+ </el-col>
|
|
|
+ <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
<!-- <el-row :gutter="10" class="mb8">
|
|
|
<el-col :span="1.5">
|
|
|
<el-button
|
|
|
@@ -158,7 +172,7 @@
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
-
|
|
|
+
|
|
|
<pagination
|
|
|
v-show="total>0"
|
|
|
:total="total"
|
|
|
@@ -275,7 +289,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { listPrescription, getPrescription, delPrescription, addPrescription, updatePrescription, exportPrescription } from "@/api/hisStore/storePrescription";
|
|
|
+import { listPrescription, getPrescription, delPrescription, addPrescription, updatePrescription, exportPrescription,downloadMedicalPdf } from "@/api/hisStore/storePrescription";
|
|
|
+import { getToken } from '@/utils/auth'
|
|
|
|
|
|
export default {
|
|
|
name: "StorePrescription",
|
|
|
@@ -372,7 +387,7 @@ export default {
|
|
|
this.queryParams.beginTime = null;
|
|
|
this.queryParams.endTime = null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
listPrescription(this.queryParams).then(response => {
|
|
|
this.prescriptionList = response.rows;
|
|
|
this.total = response.total;
|
|
|
@@ -482,7 +497,64 @@ export default {
|
|
|
this.download(response.msg);
|
|
|
this.exportLoading = false;
|
|
|
}).catch(() => {});
|
|
|
+ },
|
|
|
+ downloadPdf() {
|
|
|
+ this.$alert('是否确定批量生成PDF文件', '生成PDF', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ callback: action => {
|
|
|
+ if (this.ids.length > 3) {
|
|
|
+ return this.$message.warning('生成处方信息不能大于3条!');
|
|
|
+ }
|
|
|
+ if (this.ids.length === 0) {
|
|
|
+ return this.$message.warning('请选择需要生成的记录!');
|
|
|
+ }
|
|
|
+
|
|
|
+ const xhr = new XMLHttpRequest();
|
|
|
+ const url = process.env.VUE_APP_BASE_API + '/store/prescription/downloadMedicalPdf';
|
|
|
+ xhr.open('POST', url, true);
|
|
|
+ xhr.setRequestHeader('Authorization', 'Bearer ' + getToken()); // 携带Token
|
|
|
+ xhr.setRequestHeader('Content-Type', 'application/json'); // 声明JSON格式
|
|
|
+ xhr.responseType = 'arraybuffer';
|
|
|
+ xhr.onload = function() {
|
|
|
+ if (xhr.status === 200) {
|
|
|
+ // 6. 解析文件名(从响应头获取)
|
|
|
+ const contentDisposition = xhr.getResponseHeader('content-disposition');
|
|
|
+ let fileName = '医疗记录.pdf';
|
|
|
+ if (contentDisposition) {
|
|
|
+ const match = contentDisposition.match(/filename="?([^";]+)"?/);
|
|
|
+ if (match && match[1]) {
|
|
|
+ fileName = decodeURIComponent(match[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. 将二进制数据转为Blob并下载
|
|
|
+ const blob = new Blob([xhr.response], { type: 'application/pdf' });
|
|
|
+ const url = window.URL.createObjectURL(blob);
|
|
|
+ const aLink = document.createElement('a');
|
|
|
+ aLink.href = url;
|
|
|
+ aLink.download = fileName;
|
|
|
+ document.body.appendChild(aLink);
|
|
|
+ aLink.click();
|
|
|
+ setTimeout(() => {
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
+ document.body.removeChild(aLink);
|
|
|
+ }, 500);
|
|
|
+
|
|
|
+ this.$message.success('PDF下载成功!');
|
|
|
+ } else {
|
|
|
+ // 处理错误状态
|
|
|
+ this.$message.error(`下载失败,状态码:${xhr.status}`);
|
|
|
+ }
|
|
|
+ }.bind(this); // 绑定this上下文,确保能调用this.$message
|
|
|
+
|
|
|
+ // 9. 监听网络错误
|
|
|
+ xhr.onerror = function() {
|
|
|
+ this.$message.error('网络错误,下载失败');
|
|
|
+ }.bind(this);
|
|
|
+ xhr.send(JSON.stringify({ ids: this.ids }));
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
-</script>
|
|
|
+</script>
|