index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!-- 供应商附件管理 -->
  2. <script>
  3. import { referFile, download } from "@/api/purchase/supAtttachment";
  4. import useColumns from "./columns";
  5. export default {
  6. name: "SupAtttachment",
  7. components: {
  8. ElSuperUxTable: () => import("@/components/super-ux-table/index.vue"),
  9. },
  10. data() {
  11. const page = this.$init.page();
  12. const { TableColumns } = useColumns();
  13. return {
  14. page,
  15. size: "mini",
  16. TableColumns,
  17. loading: false,
  18. tableData: [],
  19. };
  20. },
  21. methods: {
  22. async getList(params) {
  23. try {
  24. this.loading = true;
  25. let { code, msg, rows, total } = await referFile(params);
  26. if (code == 200) {
  27. this.tableData = rows;
  28. this.page.total = total;
  29. }
  30. } catch (error) {
  31. console.log(error);
  32. } finally {
  33. this.loading = false;
  34. }
  35. },
  36. // 下载
  37. async useDownload(row) {
  38. try {
  39. this.$modal.loading("请稍候...");
  40. let formData = new FormData();
  41. formData.append("url", row.url);
  42. await download(formData).then((res) => {
  43. var blob = new Blob([res], {
  44. type: "image/jpeg",
  45. });
  46. const link = document.createElement("a");
  47. link.href = URL.createObjectURL(blob);
  48. link.download = row.name; // 这里填保存成的文件名
  49. link.click();
  50. URL.revokeObjectURL(link.href);
  51. });
  52. } catch (error) {
  53. } finally {
  54. this.$modal.closeLoading();
  55. }
  56. },
  57. useDbclick(row) {
  58. window.open(row.url);
  59. },
  60. },
  61. async created() {
  62. let { code } = this.$route.query;
  63. await this.getList({ ...this.page, code });
  64. },
  65. };
  66. </script>
  67. <template>
  68. <el-card
  69. v-loading="loading"
  70. :body-style="{
  71. height: '100%',
  72. padding: 0,
  73. display: 'flex',
  74. 'flex-direction': 'column',
  75. }"
  76. >
  77. <el-super-ux-table
  78. v-model="tableData"
  79. :size="size"
  80. :page="page"
  81. :columns="TableColumns"
  82. index
  83. pagination
  84. storage-key="SupAtttachmentSuperTable"
  85. @row-dblclick="useDbclick"
  86. @pagination="getList(page)"
  87. >
  88. <ux-table-column fixed="right" title="操作" align="center" width="100">
  89. <template slot-scope="scope">
  90. <el-button type="text" @click="useDownload(scope.row)" :size="size"
  91. >下载</el-button
  92. >
  93. </template>
  94. </ux-table-column>
  95. </el-super-ux-table>
  96. </el-card>
  97. </template>
  98. <style scoped lang="scss">
  99. .el-card {
  100. width: calc(100% - 32px);
  101. height: calc(100vh - 32px);
  102. margin: 16px;
  103. padding: 16px;
  104. border-radius: 8px;
  105. }
  106. .el-button-group + .el-button-group {
  107. margin: 0 0 0 8px;
  108. }
  109. </style>