index.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <el-card class="tjm_card_style_custom">
  3. <div class="tjm_card_tools">
  4. <div class="tjm_card_tools_left">
  5. <el-button type="primary" icon="plus" @click="table_add">新增</el-button>
  6. </div>
  7. </div>
  8. <div class="tjm_card_table">
  9. <el-table v-loading="loading" row-key="id" header-cell-class-name="tjm_card_table_header" height="400" :data="tableData" border>
  10. <el-table-column type="index" label="序号" width="55"></el-table-column>
  11. <el-table-column label="模板名称" prop="templateName"></el-table-column>
  12. <el-table-column label="模板类型">
  13. <template #default="scope">{{ formatType(scope.row.refType) }}</template>
  14. </el-table-column>
  15. <el-table-column label="操作" fixed="right" width="240">
  16. <template #default="scope">
  17. <el-button type="primary" link icon="edit" @click="table_edit(scope.row)">修改</el-button>
  18. <el-button type="primary" link icon="delete" @click="table_del(scope.row)">删除</el-button>
  19. </template>
  20. </el-table-column>
  21. </el-table>
  22. </div>
  23. </el-card>
  24. <temp-dialog v-if="dialog" ref="tempDialog" @success="reloadTable" @closed="closed"></temp-dialog>
  25. </template>
  26. <script>
  27. import API from "@/api/system/template";
  28. import { typeDic } from "./main";
  29. import tempDialog from "./dialog.vue";
  30. export default {
  31. components: {
  32. tempDialog
  33. },
  34. data() {
  35. return {
  36. loading: false,
  37. tableData: [],
  38. dialog: false
  39. }
  40. },
  41. mounted() {
  42. this.reloadTable();
  43. },
  44. methods: {
  45. formatType(type) {
  46. return typeDic[type] || "";
  47. },
  48. reloadTable() {
  49. this.loading = true;
  50. API.get().then(res => {
  51. this.loading = false;
  52. if (res.code === 200) this.tableData = res.data.records;
  53. else ElMessage.error(res.msg);
  54. }).catch(() => this.loading = false);
  55. },
  56. table_add() {
  57. this.dialog = true;
  58. nextTick(() => this.$refs.tempDialog.open());
  59. },
  60. table_edit(row) {
  61. this.dialog = true;
  62. nextTick(() => this.$refs.tempDialog.open("edit").setData(row));
  63. },
  64. table_del(row) {
  65. ElMessageBox.confirm(`是否确认删除"${row.templateName}"?`, "删除警告", {
  66. type: "warning",
  67. confirmButtonText: "确定",
  68. cancelButtonText: "取消"
  69. }).then(() => {
  70. API.del({ ids: row.id }).then(res => {
  71. if (res.code == 200) {
  72. ElMessage.success("操作成功");
  73. this.reloadTable();
  74. } else ElMessage.error(res.msg);
  75. });
  76. }).catch(() => ElMessage.info("已取消"));
  77. },
  78. closed(e) {
  79. e && this.reloadTable();
  80. this.dialog = false;
  81. }
  82. }
  83. }
  84. </script>