wlzboy
2025-11-15 caf56217dc2bf898b63b0e1f31a7098202c32825
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="部门名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="部门状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dept:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="toggleExpandAll"
        >展开/折叠</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
 
    <el-table
      v-if="refreshTable"
      v-loading="loading"
      :data="deptList"
      row-key="deptId"
      :default-expand-all="false"
      :expand-row-keys="expandRowKeys"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
      <el-table-column prop="departmentId" label="SQL Server部门ID" width="150" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.departmentId">{{ scope.row.departmentId }}</span>
          <span v-else style="color: #909399;">-</span>
        </template>
      </el-table-column>
      <el-table-column prop="serviceOrderClass" label="服务单编码" width="120" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.serviceOrderClass" type="success" size="mini">{{ scope.row.serviceOrderClass }}</el-tag>
          <span v-else style="color: #909399;">-</span>
        </template>
      </el-table-column>
      <el-table-column prop="dispatchOrderClass" label="调度单编码" width="120" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.dispatchOrderClass" type="warning" size="mini">{{ scope.row.dispatchOrderClass }}</el-tag>
          <span v-else style="color: #909399;">-</span>
        </template>
      </el-table-column>
      <el-table-column prop="orderNum" label="排序" width="150"></el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dept:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleAdd(scope.row)"
            v-hasPermi="['system:dept:add']"
          >新增</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-location"
            @click="handleManageRegion(scope.row)"
            v-hasPermi="['system:dept:edit']"
          >管理区域</el-button>
          <el-button
            v-if="scope.row.parentId != 0"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dept:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <!-- 管理区域对话框 -->
    <el-dialog title="管理区域" :visible.sync="regionDialogVisible" width="900px" append-to-body>
      <div style="margin-bottom: 10px;">
        <el-button type="primary" icon="el-icon-plus" size="small" @click="handleAddRegion">新增区域</el-button>
      </div>
      
      <el-table :data="regionList" border>
        <el-table-column label="区域类型" align="center" width="120">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.regionType === 'AREA'" type="success">地域范围</el-tag>
            <el-tag v-else-if="scope.row.regionType === 'HOSPITAL'" type="primary">指定医院</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="省份" prop="province" align="center" width="100" />
        <el-table-column label="城市" prop="city" align="center" width="100" />
        <el-table-column label="县/区" prop="area" align="center" width="100" />
        <el-table-column label="详细地址" prop="address" align="center" show-overflow-tooltip />
        <el-table-column label="指定医院" prop="hospitalName" align="center" show-overflow-tooltip />
        <el-table-column label="状态" align="center" width="80">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="150">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEditRegion(scope.row)">编辑</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteRegion(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="regionDialogVisible = false">关 闭</el-button>
      </div>
    </el-dialog>
 
    <!-- 添加或修改区域对话框 -->
    <el-dialog :title="regionFormTitle" :visible.sync="regionFormVisible" width="600px" append-to-body>
      <el-form ref="regionForm" :model="regionForm" :rules="regionRules" label-width="100px">
        <el-form-item label="区域类型" prop="regionType">
          <el-radio-group v-model="regionForm.regionType" @change="handleRegionTypeChange">
            <el-radio label="AREA">地域范围</el-radio>
            <el-radio label="HOSPITAL">指定医院</el-radio>
          </el-radio-group>
        </el-form-item>
        
        <!-- 地域范围配置 -->
        <div v-if="regionForm.regionType === 'AREA'">
          <el-form-item label="省份" prop="province">
            <el-input v-model="regionForm.province" placeholder="请输入省份,如:广东省" />
          </el-form-item>
          <el-form-item label="城市" prop="city">
            <el-input v-model="regionForm.city" placeholder="请输入城市,如:深圳市" />
          </el-form-item>
          <el-form-item label="县/区" prop="area">
            <el-input v-model="regionForm.area" placeholder="请输入县/区,如:南山区" />
          </el-form-item>
          <el-form-item label="详细地址" prop="address">
            <el-input v-model="regionForm.address" type="textarea" placeholder="请输入详细地址或关键词" :rows="3" />
          </el-form-item>
        </div>
        
        <!-- 指定医院配置 -->
        <div v-if="regionForm.regionType === 'HOSPITAL'">
          <el-form-item label="医院名称" prop="hospitalName">
            <el-input v-model="regionForm.hospitalName" placeholder="请输入医院名称或关键词" />
          </el-form-item>
        </div>
        
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="regionForm.status">
            <el-radio label="0">正常</el-radio>
            <el-radio label="1">停用</el-radio>
          </el-radio-group>
        </el-form-item>
        
        <el-form-item label="备注" prop="remark">
          <el-input v-model="regionForm.remark" type="textarea" placeholder="请输入备注" :rows="2" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRegionForm">确 定</el-button>
        <el-button @click="regionFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
 
    <!-- 添加或修改部门对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24" v-if="form.parentId !== 0">
            <el-form-item label="上级部门" prop="parentId">
              <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="部门名称" prop="deptName">
              <el-input v-model="form.deptName" placeholder="请输入部门名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="SQL Server部门ID" prop="departmentId">
              <el-input v-model="form.departmentId" placeholder="SQL Server中的部门ID" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="服务单编码" prop="serviceOrderClass">
              <el-input v-model="form.serviceOrderClass" placeholder="请输入服务单编码" maxlength="20" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="调度单编码" prop="dispatchOrderClass">
              <el-input v-model="form.dispatchOrderClass" placeholder="请输入调度单编码" maxlength="20" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="负责人" prop="leader">
              <el-input v-model="form.leader" placeholder="请输入负责人" maxlength="20" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入联系电话" maxlength="11" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept";
import { listDeptRegion, addDeptRegion, updateDeptRegion, delDeptRegion } from "@/api/system/deptRegion";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
 
export default {
  name: "Dept",
  dicts: ['sys_normal_disable'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 表格树数据
      deptList: [],
      // 部门树选项
      deptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开,默认全部展开
      isExpandAll: false,
      // 默认展开的行
      expandRowKeys: [],
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        deptName: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 区域管理相关
      regionDialogVisible: false,
      currentDept: null,
      regionList: [],
      regionFormVisible: false,
      regionFormTitle: '',
      regionForm: {},
      regionRules: {
        regionType: [
          { required: true, message: "区域类型不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ]
      },
      // 表单校验
      rules: {
        parentId: [
          { required: true, message: "上级部门不能为空", trigger: "blur" }
        ],
        deptName: [
          { required: true, message: "部门名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "显示排序不能为空", trigger: "blur" }
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询部门列表 */
    getList() {
      this.loading = true;
      listDept(this.queryParams).then(response => {
        this.deptList = this.handleTree(response.data, "deptId");
        // 默认只展开第一层(总公司及其直接子部门)
        this.expandRowKeys = this.deptList.map(item => item.deptId);
        this.loading = false;
      });
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children
      };
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        departmentId: undefined,
        serviceOrderClass: undefined,
        dispatchOrderClass: undefined,
        orderNum: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      if (row != undefined) {
        this.form.parentId = row.deptId;
      }
      this.open = true;
      this.title = "添加部门";
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "deptId");
      });
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      if (this.isExpandAll) {
        // 展开全部:收集所有部门ID
        this.expandRowKeys = this.getAllDeptIds(this.deptList);
      } else {
        // 收起:只展开第一层
        this.expandRowKeys = this.deptList.map(item => item.deptId);
      }
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 获取所有部门ID(递归) */
    getAllDeptIds(depts) {
      let ids = [];
      depts.forEach(dept => {
        ids.push(dept.deptId);
        if (dept.children && dept.children.length > 0) {
          ids = ids.concat(this.getAllDeptIds(dept.children));
        }
      });
      return ids;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      getDept(row.deptId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改部门";
        listDeptExcludeChild(row.deptId).then(response => {
          this.deptOptions = this.handleTree(response.data, "deptId");
          if (this.deptOptions.length == 0) {
            const noResultsOptions = { deptId: this.form.parentId, deptName: this.form.parentName, children: [] };
            this.deptOptions.push(noResultsOptions);
          }
        });
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.deptId != undefined) {
            updateDept(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDept(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.deptName + '"的数据项?').then(function() {
        return delDept(row.deptId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 管理区域按钮操作 */
    handleManageRegion(row) {
      this.currentDept = row;
      this.regionDialogVisible = true;
      this.loadRegionList();
    },
    /** 加载区域列表 */
    loadRegionList() {
      if (!this.currentDept) return;
      listDeptRegion(this.currentDept.deptId).then(response => {
        this.regionList = response.data;
      });
    },
    /** 新增区域 */
    handleAddRegion() {
      this.resetRegionForm();
      this.regionFormTitle = "新增区域";
      this.regionFormVisible = true;
    },
    /** 编辑区域 */
    handleEditRegion(row) {
      this.regionForm = { ...row };
      this.regionFormTitle = "编辑区域";
      this.regionFormVisible = true;
    },
    /** 删除区域 */
    handleDeleteRegion(row) {
      this.$modal.confirm('是否确认删除该区域配置?').then(() => {
        return delDeptRegion(row.regionId);
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
        this.loadRegionList();
      }).catch(() => {});
    },
    /** 重置区域表单 */
    resetRegionForm() {
      this.regionForm = {
        regionId: undefined,
        deptId: this.currentDept.deptId,
        regionType: 'AREA',
        province: '',
        city: '',
        area: '',
        address: '',
        hospitalName: '',
        status: '0',
        remark: ''
      };
      this.resetForm("regionForm");
    },
    /** 区域类型切换 */
    handleRegionTypeChange(value) {
      if (value === 'AREA') {
        this.regionForm.hospitalName = '';
      } else if (value === 'HOSPITAL') {
        this.regionForm.province = '';
        this.regionForm.city = '';
        this.regionForm.area = '';
        this.regionForm.address = '';
      }
    },
    /** 提交区域表单 */
    submitRegionForm() {
      this.$refs["regionForm"].validate(valid => {
        if (valid) {
          if (this.regionForm.regionId) {
            updateDeptRegion(this.regionForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.regionFormVisible = false;
              this.loadRegionList();
            });
          } else {
            addDeptRegion(this.regionForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.regionFormVisible = false;
              this.loadRegionList();
            });
          }
        }
      });
    }
  }
};
</script>