houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 <template>
H 2   <div class="app-container">
3     <!-- 操作工具栏 -->
4     <el-row :gutter="10" class="mb8">
5       <el-col :span="1.5">
6         <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
7                    v-hasPermi="['infra:student:create']">新增</el-button>
8       </el-col>
9     </el-row>
10             <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
11                 <el-table-column label="编号" align="center" prop="id" />
12                  <el-table-column label="名字" align="center" prop="name" />
13                 <el-table-column label="简介" align="center" prop="description" />
14                 <el-table-column label="出生日期" align="center" prop="birthday" width="180">
15                   <template v-slot="scope">
16                     <span>{{ parseTime(scope.row.birthday) }}</span>
17                   </template>
18                 </el-table-column>
19                 <el-table-column label="性别" align="center" prop="sex">
20                   <template v-slot="scope">
21                     <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
22                   </template>
23                 </el-table-column>
24                 <el-table-column label="是否有效" align="center" prop="enabled">
25                   <template v-slot="scope">
26                     <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" />
27                   </template>
28                 </el-table-column>
29                 <el-table-column label="头像" align="center" prop="avatar" />
30                 <el-table-column label="附件" align="center" prop="video" />
31                 <el-table-column label="备注" align="center" prop="memo" />
32                 <el-table-column label="创建时间" align="center" prop="createTime" width="180">
33                   <template v-slot="scope">
34                     <span>{{ parseTime(scope.row.createTime) }}</span>
35                   </template>
36                 </el-table-column>
37     <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
38       <template v-slot="scope">
39         <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
40                    v-hasPermi="['infra:student:update']">修改</el-button>
41         <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
42                    v-hasPermi="['infra:student:delete']">删除</el-button>
43       </template>
44     </el-table-column>
45   </el-table>
46     <!-- 分页组件 -->
47     <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
48                 @pagination="getList"/>
49   <!-- 对话框(添加 / 修改) -->
50   <StudentContactForm ref="formRef" @success="getList" />
51   </div>
52 </template>
53
54 <script>
55   import * as StudentApi from '@/api/infra/demo';
56   import StudentContactForm from './StudentContactForm.vue';
57   export default {
58     name: "StudentContactList",
59     components: {
60        StudentContactForm
61     },
62     props:[
63       'studentId'
64     ],// 学生编号(主表的关联字段)
65     data() {
66       return {
67         // 遮罩层
68         loading: true,
69         // 列表的数据
70         list: [],
71         // 列表的总页数
72         total: 0,
73         // 查询参数
74         queryParams: {
75           pageNo: 1,
76           pageSize: 10,
77           studentId: undefined
78         }
79       };
80     },
81     watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
82         studentId:{
83             handler(val) {
84               this.queryParams.studentId = val;
85               if (val){
86                 this.handleQuery();
87               }
88             },
89             immediate: true
90       }
91     },
92     methods: {
93       /** 查询列表 */
94       async getList() {
95         try {
96           this.loading = true;
97             const res = await StudentApi.getStudentContactPage(this.queryParams);
98             this.list = res.data.list;
99             this.total = res.data.total;
100         } finally {
101           this.loading = false;
102         }
103       },
104       /** 搜索按钮操作 */
105       handleQuery() {
106         this.queryParams.pageNo = 1;
107         this.getList();
108       },
109       /** 添加/修改操作 */
110       openForm(id) {
111         if (!this.studentId) {
112           this.$modal.msgError('请选择一个学生');
113           return;
114         }
115         this.$refs["formRef"].open(id, this.studentId);
116       },
117       /** 删除按钮操作 */
118       async handleDelete(row) {
119         const id = row.id;
120         await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?');
121         try {
122           await StudentApi.deleteStudentContact(id);
123           await this.getList();
124           this.$modal.msgSuccess("删除成功");
125         } catch {}
126       },
127     }
128   };
129 </script>