WXL (wul)
6 天以前 a5cba9ab040f6f97558046885dce3017f9bab7e9
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
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户名称
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <div class="pull-right">{{ user.email }}</div>
              </li>
 
              <!-- ===== 所属病区 ===== -->
              <li class="list-group-item" v-if="user.belongWards && user.belongWards.length">
                <svg-icon icon-class="tree" />所属病区
                <div class="pull-right">
                  <!-- 南华附一:可编辑模式 -->
                  <template v-if="isNanhua && editing">
                    <el-cascader
                      v-model="formWardCodes"
                      :options="deptOptionsbq"
                      :props="cascaderProps"
                      filterable
                      clearable
                      size="small"
                      style="width: 100%"
                      @remove-tag="onWardRemoveTag"
                    />
                  </template>
                  <!-- 南华附一:只读模式 -->
                  <template v-else-if="isNanhua">
                    <el-tag
                      v-for="ward in user.belongWards"
                      :key="ward.districtId"
                      size="small"
                      class="ward-tag"
                    >{{ ward.districtName }}</el-tag>
                  </template>
                  <!-- 其他机构:原有 Popover 展示 -->
                  <template v-else>
                    <el-popover
                      v-model="showAllWardsPopover"
                      placement="right-start"
                      :width="300"
                      trigger="manual"
                      popper-class="ward-popover"
                    >
                      <div class="popover-content">
                        <p v-for="ward in user.belongWards" :key="ward.districtId" class="popover-item">
                          {{ ward.districtName }}
                        </p>
                      </div>
                      <div slot="reference">
                        <el-tag
                          v-for="(ward, index) in displayWards"
                          :key="ward.districtId"
                          size="small"
                          class="ward-tag"
                        >{{ ward.districtName }}</el-tag>
                        <el-tag
                          v-if="user.belongWards.length > maxTagCount"
                          size="small"
                          class="more-tag"
                          @click="showAllWardsPopover = !showAllWardsPopover"
                        >+{{ user.belongWards.length - maxTagCount }}</el-tag>
                      </div>
                    </el-popover>
                  </template>
                </div>
              </li>
              <li class="list-group-item" v-else>
                <svg-icon icon-class="tree" />所属病区
                <div class="pull-right">未配置</div>
              </li>
 
              <!-- ===== 所属科室 ===== -->
              <li class="list-group-item" v-if="user.belongDepts && user.belongDepts.length">
                <svg-icon icon-class="tree" />所属科室
                <div class="pull-right">
                  <!-- 南华附一:可编辑模式 -->
                  <template v-if="isNanhua && editing">
                    <el-cascader
                      v-model="formDeptCodes"
                      :options="deptOptionsks"
                      :props="cascaderProps"
                      filterable
                      clearable
                      size="small"
                      style="width: 100%"
                      @remove-tag="onDeptRemoveTag"
                    />
                  </template>
                  <!-- 南华附一:只读模式 -->
                  <template v-else-if="isNanhua">
                    <el-tag
                      v-for="dept in user.belongDepts"
                      :key="dept.deptId"
                      size="small"
                      class="dept-tag"
                    >{{ dept.deptName }}</el-tag>
                  </template>
                  <!-- 其他机构:原有 Popover 展示 -->
                  <template v-else>
                    <el-popover
                      v-model="showAllDeptsPopover"
                      placement="right-start"
                      :width="300"
                      trigger="manual"
                      popper-class="dept-popover"
                    >
                      <div class="popover-content">
                        <p v-for="dept in user.belongDepts" :key="dept.deptId" class="popover-item">
                          {{ dept.deptName }}
                        </p>
                      </div>
                      <div slot="reference">
                        <el-tag
                          v-for="(dept, index) in displayDepts"
                          :key="dept.deptId"
                          size="small"
                          class="dept-tag"
                        >{{ dept.deptName }}</el-tag>
                        <el-tag
                          v-if="user.belongDepts.length > maxTagCount"
                          size="small"
                          class="more-tag"
                          @click="showAllDeptsPopover = !showAllDeptsPopover"
                        >+{{ user.belongDepts.length - maxTagCount }}</el-tag>
                      </div>
                    </el-popover>
                  </template>
                </div>
              </li>
              <li class="list-group-item" v-else>
                <svg-icon icon-class="tree" />所属科室
                <div class="pull-right">未配置</div>
              </li>
 
              <!-- 南华附一:编辑/保存按钮 -->
              <li class="list-group-item" v-if="isNanhua" style="justify-content: center; padding-top: 16px;">
                <template v-if="!editing">
                  <el-button type="primary" size="small" icon="el-icon-edit" @click="startEdit">编辑科室/病区</el-button>
                </template>
                <template v-else>
                  <el-button size="small" @click="cancelEdit">取消</el-button>
                  <el-button type="primary" size="small" :loading="saving" @click="saveEdit">保存</el-button>
                </template>
              </li>
 
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />所属角色
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
 
<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile, updateUser, deptTreeSelect, adduserdept, removeusertd } from "@/api/system/user";
 
export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
      maxTagCount: 3, // 控制默认显示的标签数量
      showAllWardsPopover: false, // 控制病区Popover的显示
      showAllDeptsPopover: false, // 控制科室Popover的显示
      // 编辑模式(仅南华附一)
      editing: false,
      saving: false,
      deptOptionsks: [],  // 科室级联树
      deptOptionsbq: [],  // 病区级联树
      formDeptCodes: [],  // 科室级联绑定值
      formWardCodes: [],  // 病区级联绑定值
      originalDeptCodes: [], // 原始科室值(取消时恢复)
      originalWardCodes: [], // 原始病区值(取消时恢复)
      cascaderProps: { multiple: true, value: "deptCode", label: "label" },
    };
  },
  computed: {
    // 计算要显示的病区标签(前maxTagCount个)
    displayWards() {
      if (!this.user.belongWards) return [];
      return this.user.belongWards.slice(0, this.maxTagCount);
    },
    // 计算要显示的科室标签(前maxTagCount个)
    displayDepts() {
      if (!this.user.belongDepts) return [];
      return this.user.belongDepts.slice(0, this.maxTagCount);
    },
    // 南华大学附属第一医院 允许编辑科室/病区
    isNanhua() {
      return localStorage.getItem("orgname") === "南华大学附属第一医院";
    },
  },
  created() {
    this.getUser();
    if (localStorage.getItem("orgname") === "南华大学附属第一医院") {
      this.loadDeptTree();
    }
  },
  methods: {
    getUser() {
      getUserProfile().then((response) => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
        // 解析已保存的科室/病区级联路径(hospInfo = 科室, deptInfo = 病区)
        try {
          this.formDeptCodes = this.user.hospInfo ? JSON.parse(this.user.hospInfo) : [];
        } catch (e) { this.formDeptCodes = []; }
        try {
          this.formWardCodes = this.user.deptInfo ? JSON.parse(this.user.deptInfo) : [];
        } catch (e) { this.formWardCodes = []; }
        this.originalDeptCodes = JSON.parse(JSON.stringify(this.formDeptCodes));
        this.originalWardCodes = JSON.parse(JSON.stringify(this.formWardCodes));
      });
    },
    // 加载科室/病区级联树
    loadDeptTree() {
      deptTreeSelect(1).then((res) => { this.deptOptionsks = res.data || []; });
      deptTreeSelect(2).then((res) => { this.deptOptionsbq = res.data || []; });
    },
    // 进入编辑模式
    startEdit() {
      this.originalDeptCodes = JSON.parse(JSON.stringify(this.formDeptCodes));
      this.originalWardCodes = JSON.parse(JSON.stringify(this.formWardCodes));
      this.editing = true;
    },
    // 取消编辑
    cancelEdit() {
      this.formDeptCodes = JSON.parse(JSON.stringify(this.originalDeptCodes));
      this.formWardCodes = JSON.parse(JSON.stringify(this.originalWardCodes));
      this.editing = false;
    },
    // 保存科室/病区
    saveEdit() {
      if (!this.user.userId) return;
      this.saving = true;
 
      const deptCodes = this.formDeptCodes.length
        ? this.formDeptCodes.map(arr => arr[arr.length - 1])
        : [];
      const wardCodes = this.formWardCodes.length
        ? this.formWardCodes.map(arr => arr[arr.length - 1])
        : [];
 
      const params = {
        userId: this.user.userId,
        hospInfo: JSON.stringify(this.formDeptCodes),
        deptInfo: JSON.stringify(this.formWardCodes),
        deptCodes: deptCodes,
        wardCodes: wardCodes,
      };
 
      updateUser(params).then(() => {
        // 同步新增/删除的科室病区
        this.syncUserDept(wardCodes, 2);
        this.syncUserDept(deptCodes, 1);
        this.$modal.msgSuccess("科室/病区修改成功");
        this.editing = false;
        this.saving = false;
        this.getUser(); // 刷新用户信息
      }).catch(() => {
        this.saving = false;
      });
    },
    // 同步用户科室/病区(新增和删除差异)
    syncUserDept(codes, deptType) {
      const original = deptType === 1
        ? this.originalDeptCodes.map(arr => arr[arr.length - 1])
        : this.originalWardCodes.map(arr => arr[arr.length - 1]);
 
      // 新增
      codes.forEach(code => {
        if (!original.includes(code)) {
          adduserdept({ deptCode: code, deptType, userId: this.user.userId });
        }
      });
      // 删除
      original.forEach(code => {
        if (!codes.includes(code)) {
          removeusertd(this.user.userId, code);
        }
      });
    },
    // 级联选择器 remove-tag 事件
    onDeptRemoveTag(removedValues) {
      const currentCodes = (removedValues || []).map(arr => arr[arr.length - 1]);
      const prevCodes = (this.originalDeptCodes || []).map(arr => arr[arr.length - 1]);
      prevCodes.forEach(code => {
        if (!currentCodes.includes(code)) {
          removeusertd(this.user.userId, code);
        }
      });
    },
    onWardRemoveTag(removedValues) {
      const currentCodes = (removedValues || []).map(arr => arr[arr.length - 1]);
      const prevCodes = (this.originalWardCodes || []).map(arr => arr[arr.length - 1]);
      prevCodes.forEach(code => {
        if (!currentCodes.includes(code)) {
          removeusertd(this.user.userId, code);
        }
      });
    },
  },
};
</script>
 
<style scoped>
/* 为标签添加一些右边距,使其不紧贴在一起 */
.ward-tag,
.dept-tag,
.more-tag {
  margin-right: 6px;
  margin-bottom: 4px;
}
/* 设置"更多"标签的样式,使其看起来可点击 */
.more-tag {
  cursor: pointer;
  background-color: #f0f0f0;
  border-color: #ddd;
  color: #999;
}
.list-group-item {
  display: flex;
  align-items: center;
}
.pull-right {
  flex: 1;
  text-align: right;
}
/* 级联选择器内部样式 */
.pull-right .el-cascader {
  width: 100%;
}
</style>
 
<style>
/* Popover内容区域样式 */
.popover-content {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px;
}
.popover-item {
  margin: 8px 0;
  line-height: 1.4;
}
/* 病区Popover样式 */
.ward-popover.el-popover,
.dept-popover.el-popover {
  max-width: 300px;
}
/* 调整Popover箭头位置 */
.ward-popover[x-placement^="right"],
.dept-popover[x-placement^="right"] {
  margin-left: 10px;
}
</style>