houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-card shadow="never" class="aui-card--fill">
3     <div>
4       <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
5         <el-form-item>
6           <el-input v-model="dataForm.sourcename" placeholder="名称" clearable></el-input>
7         </el-form-item>
8         <el-form-item>
9           <el-button @click="searchDataList()">查询</el-button>
10           <el-button v-if="$hasPermission('data:data-source:add')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
11           <el-button v-if="$hasPermission('data:data-source:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
12         </el-form-item>
13       </el-form>
14       <el-table
15               :data="dataList"
16               border
17               v-loading="dataListLoading"
18               @selection-change="selectionChangeHandle"
19               style="width: 100%;">
20         <el-table-column
21                 type="selection"
22                 header-align="center"
23                 align="center"
24                 width="50">
25         </el-table-column>
26         <el-table-column
27                 type="index"
28                 align="center"
29                 width="50"
30                 label="序号">
31         </el-table-column>
32         <el-table-column
33                 prop="sourcetype"
34                 header-align="center"
35                 align="center"
36                 min-width="200"
37                 label="类型">
38         </el-table-column>
39         <el-table-column
40                 prop="sourcename"
41                 header-align="center"
42                 align="center"
43                 min-width="200"
44                 label="名称">
45         </el-table-column>
46         <el-table-column
47                 prop="sourceaddress"
48                 header-align="center"
49                 align="left"
50                 min-width="400"
51                 label="地址">
52         </el-table-column>
53         <el-table-column
54                 v-if="$hasPermission('data:data-source:edit')"
55                 fixed="right"
56                 header-align="center"
57                 align="center"
58                 width="100"
59                 label="操作">
60           <template slot-scope="scope">
61             <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
62           </template>
63         </el-table-column>
64       </el-table>
65       <el-pagination
66               @size-change="sizeChangeHandle"
67               @current-change="currentChangeHandle"
68               :current-page="pageIndex"
69               :page-sizes="[10, 20, 50, 100]"
70               :page-size="pageSize"
71               :total="totalPage"
72               layout="total, sizes, prev, pager, next, jumper">
73       </el-pagination>
74       <!-- 弹窗, 新增 / 修改 -->
75       <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
76     </div>
77   </el-card>
78 </template>
79
80 <script>
81   import AddOrUpdate from './da-data-source-add-or-update'
82
83   export default {
84     data () {
85       return {
86         dataForm: {
87           sourcename: ''
88         },
89         dataList: [],
90         pageIndex: 1,
91         pageSize: 10,
92         totalPage: 0,
93         dataListLoading: false,
94         dataListSelections: [],
95         addOrUpdateVisible: false
96       }
97     },
98     components: {
99       AddOrUpdate
100     },
101     mounted () {
102       this.getDataList()
103     },
104     methods: {
105       searchDataList () {
106         this.pageIndex = 1
107         this.getDataList()
108       },
109       // 获取数据列表
110       getDataList () {
111         this.dataListLoading = true
112         this.$http({
113           url: '/data/data/data-source/list',
114           method: 'get',
115           params: this.$http.adornParams({
116             'page': this.pageIndex,
117             'limit': this.pageSize,
118             'sourcename': this.dataForm.sourcename
119           })
120         }).then(({data}) => {
121           if (data && data.code === 0) {
122             this.dataList = data.page.list
123             this.totalPage = data.page.totalCount
124           } else {
125             this.dataList = []
126             this.totalPage = 0
127           }
128           this.dataListLoading = false
129         })
130       },
131       // 每页数
132       sizeChangeHandle (val) {
133         this.pageSize = val
134         this.pageIndex = 1
135         this.getDataList()
136       },
137       // 当前页
138       currentChangeHandle (val) {
139         this.pageIndex = val
140         this.getDataList()
141       },
142       // 多选
143       selectionChangeHandle (val) {
144         this.dataListSelections = val
145       },
146       // 新增 / 修改
147       addOrUpdateHandle (id) {
148         this.addOrUpdateVisible = true
149         this.$nextTick(() => {
150           this.$refs.addOrUpdate.init(id)
151         })
152       },
153       // 删除
154       deleteHandle (id) {
155         let ids = id ? [id] : this.dataListSelections.map(item => {
156           return item.id
157         })
158         this.$confirm(`确定删除选中的${ids.length}项数据?`, '提示', {
159           confirmButtonText: '确定',
160           cancelButtonText: '取消',
161           type: 'warning'
162         }).then(() => {
163           this.$http['post'](`/data/data/data-source/delete`, ids).then(({ data: res }) => {
164             if (res.code !== 0) {
165               return this.$message.error(res.msg)
166             }
167             this.$message({
168               message: this.$t('prompt.success'),
169               type: 'success',
170               duration: 500,
171               onClose: () => {
172                 this.getDataList()
173               }
174             })
175           }).catch(() => {})
176         }).catch(() => {})
177       }
178     }
179   }
180 </script>