|
|
@@ -527,6 +527,13 @@
|
|
|
@click="handleDetails(scope.row)"
|
|
|
>查看
|
|
|
</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-download"
|
|
|
+ @click="handleDownloadOrder(scope.row)"
|
|
|
+
|
|
|
+ >下载收据</el-button>
|
|
|
<!-- <el-button
|
|
|
size="mini"
|
|
|
type="text"
|
|
|
@@ -814,7 +821,7 @@ import {
|
|
|
addStoreOrder,
|
|
|
updateStoreOrder,
|
|
|
importCodeExpressTemplate,
|
|
|
- exportHealthStoreOrder, exportHealthStoreOrderDetails, exportHealthStoreOrderItemsDetails
|
|
|
+ exportHealthStoreOrder, exportHealthStoreOrderDetails, exportHealthStoreOrderItemsDetails, downloadOrderExcel
|
|
|
} from '@/api/hisStore/storeOrder'
|
|
|
import {getUserList} from '@/api/hisStore/user'
|
|
|
import {getAddressList} from '@/api/hisStore/userAddress'
|
|
|
@@ -1165,6 +1172,100 @@ export default {
|
|
|
this.$refs.order.getOrder(orderId)
|
|
|
}, 500)
|
|
|
},
|
|
|
+
|
|
|
+ /** 下载单个订单的Excel收据 */
|
|
|
+ handleDownloadOrder(row) {
|
|
|
+ this.$confirm(`是否下载订单 "${row.orderCode}" 的Excel收据?`, "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "info"
|
|
|
+ }).then(() => {
|
|
|
+ // 显示加载状态
|
|
|
+ const loading = this.$loading({
|
|
|
+ lock: true,
|
|
|
+ text: '正在生成Excel文件...',
|
|
|
+ spinner: 'el-icon-loading',
|
|
|
+ background: 'rgba(0, 0, 0, 0.7)'
|
|
|
+ });
|
|
|
+ console.log("输出ID:" + row.id)
|
|
|
+ return downloadOrderExcel(row.id)
|
|
|
+ .then(response => {
|
|
|
+ // 确保我们处理的是Blob响应
|
|
|
+ if (response instanceof Blob) {
|
|
|
+ // 创建下载链接
|
|
|
+ const blob = new Blob([response], {
|
|
|
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
+ });
|
|
|
+ const url = window.URL.createObjectURL(blob);
|
|
|
+ const link = document.createElement('a');
|
|
|
+
|
|
|
+ // 设置文件名 - 使用后端返回的文件名或默认名称
|
|
|
+ const contentDisposition = response.headers?.['content-disposition'];
|
|
|
+ let fileName = `打印详情表格.xlsx`;
|
|
|
+
|
|
|
+ if (contentDisposition) {
|
|
|
+ const fileNameMatch = contentDisposition.match(/filename\*=utf-8''(.+)/);
|
|
|
+ if (fileNameMatch && fileNameMatch[1]) {
|
|
|
+ fileName = decodeURIComponent(fileNameMatch[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ link.href = url;
|
|
|
+ link.download = fileName;
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+
|
|
|
+ // 清理
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
+ document.body.removeChild(link);
|
|
|
+
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: '文件下载成功'
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 如果不是Blob,可能是错误信息
|
|
|
+ console.error('响应不是Blob类型:', response);
|
|
|
+ this.$message({
|
|
|
+ type: 'error',
|
|
|
+ message: '文件格式错误,下载失败'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error('下载失败:', error);
|
|
|
+
|
|
|
+ let errorMessage = '下载失败,请重试';
|
|
|
+ if (error.response) {
|
|
|
+ // HTTP错误
|
|
|
+ if (error.response.status === 404) {
|
|
|
+ errorMessage = '模板文件不存在';
|
|
|
+ } else if (error.response.status === 500) {
|
|
|
+ errorMessage = '服务器错误,请稍后重试';
|
|
|
+ } else if (error.response.data && error.response.data.message) {
|
|
|
+ errorMessage = error.response.data.message;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$message({
|
|
|
+ type: 'error',
|
|
|
+ message: errorMessage
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ // 关闭加载状态
|
|
|
+ loading.close();
|
|
|
+ });
|
|
|
+ }).catch(() => {
|
|
|
+ // 用户取消下载
|
|
|
+ this.$message({
|
|
|
+ type: 'info',
|
|
|
+ message: '已取消下载'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
handleClick(tab, event) {
|
|
|
this.activeName = tab.name
|
|
|
this.queryParams.status = tab.name
|