long
2021-04-08 d8f5a1fcb8632a9fb51cac9d72fb3bacaa41cbc2
提交 | 用户 | age
2a61f6 1 <template>
L 2   <div class="app-container">
3     <!-- 搜索区 ↓↓↓↓↓↓↓↓↓↓ -->
4     <el-form v-show="showSearch" ref="searchForm" :inline="true">
5       <el-form-item label="角色名称">
6         <el-input
7           v-model="keyWord"
8           placeholder="请输入角色名称"
9           clearable
10           size="small"
11           style="width: 240px"
36b711 12           maxlength="50"
2a61f6 13           @keyup.enter.native="reGetList"
L 14         />
15       </el-form-item>
16       <el-form-item>
17         <el-button type="cyan" icon="el-icon-search" size="mini" @click="reGetList">搜索</el-button>
18         <el-button icon="el-icon-refresh" size="mini" @click="resetHandle">重置</el-button>
19       </el-form-item>
20     </el-form>
21     <!-- 搜索区 ↑↑↑↑↑↑↑↑↑↑ -->
22
23     <!-- 操作区 ↓↓↓↓↓↓↓↓↓↓ -->
24     <el-row :gutter="10" class="mb8">
25       <el-col :span="1.5">
26         <el-button
27           type="primary"
28           icon="el-icon-plus"
29           size="mini"
838f4f 30           @click="showAddDialog"
2a61f6 31         >新增</el-button>
L 32       </el-col>
33       <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
34     </el-row>
35     <!-- 操作区 ↑↑↑↑↑↑↑↑↑↑ -->
36
dbf068 37     <el-table :data="list" stripe>
2a61f6 38       <el-table-column type="index" label="序号" align="center" width="60" />
L 39       <el-table-column label="角色名称" prop="name" align="center" min-width="120" />
838f4f 40       <el-table-column label="是否上架" prop="isUp" align="center" min-width="100">
L 41         <template slot-scope="scope">
42           <el-switch
43             v-model="scope.row.isUp"
44             :active-value="1"
45             :inactive-value="0"
46             @change="handleUpChange(scope.row)"
47           />
48         </template>
49       </el-table-column>
50       <el-table-column label="创建时间" prop="createTime" align="center" min-width="160" />
36b711 51       <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
2a61f6 52         <template slot-scope="scope">
L 53           <el-button
54             size="mini"
55             type="text"
56             icon="el-icon-edit"
838f4f 57             @click="showEditDialog(scope.row)"
2a61f6 58           >编辑</el-button>
L 59           <el-button
60             size="mini"
61             type="text warn"
62             icon="el-icon-delete"
63             @click="handleDelete(scope.row)"
64           >删除</el-button>
65         </template>
66       </el-table-column>
67     </el-table>
838f4f 68
L 69     <!-- 新增&编辑 -->
4dde14 70     <el-dialog v-el-drag-dialog :title="dialogData.type=='add'?'新增医院科室':'编辑医院科室'" width="500px" :visible.sync="dialogVisible" append-to-body :before-close="hideDialog" :close-on-click-modal="false">
838f4f 71       <el-form ref="refDialog" :model="dialogData" label-width="110px" :rules="rules" size="small">
L 72         <el-form-item label="名称" prop="name">
36b711 73           <el-input v-model="dialogData.name" placeholder="请输入名称" maxlength="50" />
838f4f 74         </el-form-item>
L 75         <el-form-item label="是否上架" prop="isUp">
76           <el-switch
77             v-model="dialogData.isUp"
78             :active-value="1"
79             :inactive-value="0"
80           />
81         </el-form-item>
82       </el-form>
83       <div slot="footer" class="dialog-footer">
84         <el-button @click="hideDialog">取消</el-button>
85         <el-button type="primary" @click="submitHandle">确定</el-button>
86       </div>
87     </el-dialog>
2a61f6 88
L 89     <pagination
90       v-show="total>0"
91       :total="total"
92       :page.sync="pageNum"
93       :limit.sync="pageSize"
94       @pagination="getList"
95     />
d8f5a1 96
L 97     <back-to-top :visibility-height="300" :back-position="50" transition-name="fade" />
2a61f6 98   </div>
L 99 </template>
100
101 <script>
d8f5a1 102 import BackToTop from '@/components/BackToTop'
2a61f6 103 export default {
838f4f 104   name: 'Demo',
d8f5a1 105   components: { BackToTop },
2a61f6 106   data() {
L 107     return {
108       showSearch: true, // 是否显示搜索区
109       keyWord: '',
110
111       list: [],
112
838f4f 113       // 弹窗数据
L 114       dialogVisible: false,
115       dialogData: {},
116
2a61f6 117       // 分页 ↓↓↓↓↓↓↓↓↓↓
L 118       total: 0,
119       pageNum: 1,
838f4f 120       pageSize: 20,
2a61f6 121       // 分页 ↑↑↑↑↑↑↑↑↑↑
838f4f 122
L 123       // 表单校验
124       rules: {
125         name: [
126           { required: true, message: '名称不能为空', trigger: 'change' }
127         ],
128         isUp: [
129           { required: true, message: '是否上架不能为空', trigger: 'change' }
130         ]
131       }
2a61f6 132     }
L 133   },
134   mounted() {
135     this.init()
136   },
137   methods: {
138     // 初始化
139     init() {
140       this.getList()
141     },
142
143     // 获取列表
144     getList() {
145       var { pageNum, pageSize, keyWord } = this
146       this.postFN({
147         url: 'xxx',
148         params: {
149           pageNum: pageNum,
efd7c8 150           pageSize: pageSize,
2a61f6 151           keyWord: keyWord
L 152         },
153         mockData: {
154           code: 100,
155           msg: '',
156           data: {
157             list: [{
158               id: 'xxx',
159               index: 1,
160               name: '超级管理员',
161               createTime: '2020-08-09 10:10:10'
162             }],
163             total: 100
164           }
165         }
166       }, (inf) => {
167         this.list = inf.list || []
168         this.total = inf.total
169       })
170     },
171     // 重新获取列表
172     reGetList() {
173       this.pageNum = 1
174       this.getList()
175     },
176     // 重置
177     resetHandle() {
178       this.keyWord = ''
179       this.reGetList()
180     },
181     // 删除
182     handleDelete(item) {
183       // 打开二次确认弹窗
184       this.$confirm('是否确认删除该角色?', '提示', {
185         confirmButtonText: '确定',
186         cancelButtonText: '取消',
187         type: 'warning'
188       }).then(() => {
189         // 确定回调
190         this.postFN({
191           url: 'xxx',
192           params: {
193             id: item.id
194           },
195           mockData: {
196             code: 100,
197             msg: '',
198             data: {}
199           }
200         }, () => {
201           this.getList()
202           this.$messageSuc('删除成功')
203         })
204       }).catch(() => {})
838f4f 205     },
L 206     // 修改是否上架 todo
207     handleUpChange(item) {
208       const text = item.isUp === 1 ? '上架' : '下架'
209       this.$confirm('确认要' + text + '该角色吗?', '提示', {
210         confirmButtonText: '确定',
211         cancelButtonText: '取消',
212         type: 'warning'
213       }).then(() => {
214         this.postFN({
215           url: 'xxx',
216           params: {
217             id: item.id
218           },
219           mockData: {
220             code: 100,
221             msg: '',
222             data: {}
223           }
224         }, () => {
225           this.$messageSuc(text + '成功')
4dde14 226         }, (res) => {
L 227           item.isUp = item.isUp === 1 ? 0 : 1
228           this.$messageError(res.msg)
838f4f 229         })
L 230       }).catch(() => {
231         item.isUp = item.isUp === 1 ? 0 : 1
232       })
233     },
234
235     // 打开新增弹窗
236     showAddDialog() {
237       var dialogData = {
238         type: 'add',
239         isUp: 1
240       }
241       this.dialogVisible = true
242       this.$nextTick(() => {
243         this.dialogData = dialogData
244         this.$refs['refDialog'].resetFields()
245       })
246     },
247     // 打开编辑弹框
248     showEditDialog(item) {
249       var dialogData = {
250         type: 'edit',
251         ...item
252       }
253       console.log('dialogData', dialogData)
254       this.dialogVisible = true
255       this.$nextTick(() => {
256         this.dialogData = dialogData
257         this.$refs['refDialog'].resetFields()
258       })
259     },
260     // 关闭编辑弹窗
261     hideDialog() {
262       this.dialogData = {}
263       this.dialogVisible = false
264     },
265     // 提交新增&编辑
266     submitHandle() {
267       this.$refs['refDialog'].validate(valid => {
268         if (valid) {
269           this.submitReq()
270         }
271       })
272     },
273     // 提交接口
274     submitReq() {
275       var { dialogData } = this
276       var params = {
277         name: dialogData.name,
278         isUp: dialogData.isUp
279       }
280
281       if (dialogData.password) params.password = dialogData.password
282
283       var isAdd = dialogData.type === 'add'
284       var url = isAdd ? 'admin/hospital/department/add' : 'admin/hospital/department/edit'
285
286       !isAdd && (params.id = dialogData.id)
287
288       this.postFN({
289         url: url,
290         params: params,
291         mockData: {
292           code: 100,
293           msg: '',
294           data: {}
295         }
296       }, () => {
297         this.$messageSuc('保存成功')
298         this.hideDialog()
299         this.reGetList()
300       })
2a61f6 301     }
L 302   }
303 }
304 </script>
305
306 <style lang="scss" scoped>
307
308 </style>