1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<template>
<div class="container">
<el-page-header @back="$emit('back')" :content="orgMap.orgName">
</el-page-header>
<direct-search
ref="form"
:label-position="'right'"
:forms="searchList"
:style="{ textAlign: 'left', marginTop: '20px' }"
@handleSearch="handleFormSearch"
/>
<el-table-self
ref="table"
:table-data="tableData"
:columns="columns"
:list-loading="listLoading"
:current-page="pageIndex"
:total-count="total"
:page-sizes="pageSizes"
:page-size="pageSize"
@pageSizeChange="handleSizeChange"
@currentPageChange="handleCurrentChange"
/>
<dialog-form
width="450px"
:close-modal="false"
ref="dialog"
:title="title"
:form-edit="formEdit"
:form-data="formData"
@handleConfirm="handleConfirm"
></dialog-form>
</div>
</template>
<script>
import paginationMixin from "@/components/TabComponents/mixin"
import { getDepartPage, addDepart, delDepart } from "@/api/org.js"
export default {
name: "OrgManage",
props: ["orgMap"],
data() {
return {
listLoading: false,
// 查询列表
searchList: [
{
label: "科室名称",
type: "input",
prop: "deptName",
placeholder: "请输入科室名称",
},
{
type: "button",
value: "查询",
icon: "el-icon-search",
},
{
type: "button",
color: "primary",
icon: "el-icon-plus",
value: "添加",
func: this.handleAdd,
},
],
columns: [
{
label: "科室名称",
minWidth: 120,
value: "deptName",
},
{
label: "科室代码",
minWidth: 120,
value: "deptCode",
},
{
label: "操作",
width: 280,
fixed: "right",
operType: "button",
operations: [
{
func: this.handleAdd,
formatter(row) {
return {
label: "编辑",
type: "primary",
}
},
},
{
func: this.handleDel,
formatter(row) {
return {
label: "删除",
type: "warning",
}
},
},
],
},
],
tableData: [],
cacheForm: {},
title: "",
formData: [
{
type: "input",
label: "科室名称",
placeholder: "请输入科室名称",
prop: "deptName",
rules: [{ required: true, message: "请输入科室名称" }],
},
{
type: "input",
label: "科室代码",
placeholder: "请输入科室代码",
prop: "deptCode",
rules: [{ required: true, message: "请输入科室代码" }],
},
],
formEdit: {},
}
},
mixins: [paginationMixin],
methods: {
handleAdd({ id, deptName, deptCode }) {
this.title = id ? "编辑科室" : "新增科室"
this.formEdit = id ? { id, deptName, deptCode } : {}
this.$refs.dialog.open()
},
handleConfirm(form) {
const data = Object.assign({ ...this.orgMap }, form)
const msg = data.id ? "编辑成功" : "新增成功"
addDepart(data).then((res) => {
if (res.code === 1) {
this.$message.success(msg)
this.handleSearch()
this.$refs.dialog.close()
}
})
},
handleDel(row) {
this.$confirm(`是否删除【${row.deptName}】?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
delDepart(row.id).then((res) => {
if (res.code === 1) {
this.$message({
type: "success",
message: "删除成功!",
})
this.handleSearch()
}
})
})
.catch(() => {})
},
// 查询
handleFormSearch(form) {
this.pageIndex = 1
this.handleSearch(form)
},
handleSearch(form) {
this.cacheForm = Object.assign(this.cacheForm, form)
this.listLoading = true
const params = Object.assign({ orgId: this.orgMap.orgId }, this.cacheForm)
for (let key in params) {
if (params[key] === "") {
delete params[key]
}
}
params.current = this.pageIndex
params.size = this.pageSize
getDepartPage(params).then((res) => {
this.listLoading = false
if (res.code === 1) {
const d = res.data
this.tableData = d.records || []
this.total = Number(d.total)
}
})
},
},
created() {
this.handleFormSearch()
},
}
</script>