WXL (wul)
4 天以前 fb34ba28cb908bd328cf6690ab0b19a56428f4e2
src/views/system/user/index.vue
@@ -125,7 +125,7 @@
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:user:edit']"
              >修改</el-button
            >
          </el-col>
@@ -199,14 +199,39 @@
            v-if="columns[2].visible"
            :show-overflow-tooltip="true"
          />
          <!-- <el-table-column
            label="部门"
          <el-table-column
            label="科室"
            align="center"
            key="deptName"
            prop="dept.deptName"
            key="deptNames"
            v-if="columns[3].visible"
            :show-overflow-tooltip="true"
          /> -->
          >
            <template slot-scope="scope">
              <span>{{ scope.row._deptNames || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="病区"
            align="center"
            key="wardNames"
            v-if="columns[7].visible"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{ scope.row._wardNames || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="院区"
            align="center"
            key="campusName"
            v-if="columns[8].visible && (orgname === '第一人民医院湖滨院区' || orgname === '第一人民医院吴山院区' || orgname === '第一人民医院城东院区')"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{ scope.row._campusName || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="手机号码"
            align="center"
@@ -253,7 +278,7 @@
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:user:edit']"
                >修改</el-button
              >
              <el-button
@@ -282,7 +307,7 @@
                  <el-dropdown-item
                    command="handleAuthRole"
                    icon="el-icon-circle-check"
                    v-hasPermi="['system:user:edit']"
                    >分配角色</el-dropdown-item
                  >
                </el-dropdown-menu>
@@ -331,7 +356,7 @@
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="适用课题组" prop="region">
        <el-form-item label="适用科室" prop="region">
            <el-cascader
              style="width: 478px"
              v-model="form.deptCodes"
@@ -552,6 +577,7 @@
  deptTreeSelect,
} from "@/api/system/user";
import { getToken } from "@/utils/auth";
import { getorganization } from "@/api/AiCentre/index";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { type } from "jquery";
@@ -572,6 +598,8 @@
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 当前机构名称
      orgname: localStorage.getItem("orgname") || "",
      // 总条数
      total: 0,
      // 用户表格数据
@@ -581,6 +609,12 @@
      // 部门树选项
      deptOptionsks: undefined,
      deptOptionsbq: undefined,
      // 科室编码 -> 名称映射
      deptNameMap: {},
      // 病区编码 -> 名称映射
      wardNameMap: {},
      // 院区编码 -> 名称映射
      campusNameMap: {},
      // 是否显示弹出层
      open: false,
      // 部门名称
@@ -626,7 +660,7 @@
        deptId: undefined,
      },
      searchscopelist: [
        { value: "1", label: "课题组" },
        { value: "1", label: "科室" },
        { value: "2", label: "病区" },
        { value: "0", label: "全部" },
        { value: "9", label: "无" },
@@ -636,10 +670,12 @@
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户工号`, visible: true },
        { key: 2, label: `用户昵称`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 3, label: `科室`, visible: true },
        { key: 4, label: `手机号码`, visible: true },
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `创建时间`, visible: true },
        { key: 7, label: `病区`, visible: true },
        { key: 8, label: `院区`, visible: true },
      ],
      // 表单校验
@@ -689,7 +725,6 @@
    },
  },
  created() {
    this.getList();
    this.getDeptTree();
    this.getConfigKey("sys.user.initPassword").then((response) => {
      this.initPassword = response.msg;
@@ -712,23 +747,82 @@
        (response) => {
          this.userList = response.rows;
          this.total = response.total;
          this.enrichUserDept();
          this.loading = false;
        }
      );
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      // 课题组列表
      deptTreeSelect(1).then((response) => {
      // 科室列表
      const ksPromise = deptTreeSelect(1).then((response) => {
        this.deptOptionsks = response.data;
        this.deptNameMap = this.flattenDeptTree(response.data);
      });
      deptTreeSelect(2).then((response) => {
      // 病区列表
      const bqPromise = deptTreeSelect(2).then((response) => {
        this.deptOptionsbq = response.data;
        this.wardNameMap = this.flattenDeptTree(response.data);
      });
      // 院区列表
      //  deptTreeSelect().then((response) => {
      //   this.deptOptions = response.data;
      // });
      const campusPromise = getorganization({ pageSize: 100 }).then((res) => {
        if (res.code == 200) {
          (res.rows || []).forEach((item) => {
            this.campusNameMap[String(item.organizationID)] =
              item.organizationName;
          });
        }
      });
      // 科室/病区/院区映射就绪后再加载列表,保证首屏能显示名称
      Promise.all([ksPromise, bqPromise, campusPromise]).then(() => {
        this.getList();
      });
    },
    /** 将科室/病区树拍平为 { deptCode: label } 映射 */
    flattenDeptTree(nodes) {
      const map = {};
      const walk = (list) => {
        (list || []).forEach((node) => {
          if (node.deptCode) {
            map[node.deptCode] = node.label;
          }
          if (node.children && node.children.length) {
            walk(node.children);
          }
        });
      };
      walk(nodes);
      return map;
    },
    /** 把 hospInfo/deptInfo 中的编码转成名称,写入行的展示字段 */
    enrichUserDept() {
      (this.userList || []).forEach((row) => {
        row._deptNames = this.mapCodesToNames(row.hospInfo, this.deptNameMap);
        row._wardNames = this.mapCodesToNames(row.deptInfo, this.wardNameMap);
        row._campusName = this.campusNameMap[String(row.campusid)] || "-";
      });
    },
    /** 解析编码 JSON 并映射为名称:级联路径各层用 "/" 连接,多条用 "、" 连接 */
    mapCodesToNames(jsonStr, nameMap) {
      if (!jsonStr || !nameMap) return "";
      let data = [];
      try {
        data = JSON.parse(jsonStr);
      } catch (e) {
        return "";
      }
      if (!Array.isArray(data)) data = [data];
      return data
        .map((item) => {
          // 级联多选的值是整条路径(数组),旧数据可能是单个编码
          const path = Array.isArray(item) ? item : [item];
          return path
            .map((code) => nameMap[code] || code)
            .filter(Boolean)
            .join(" / ");
        })
        .filter(Boolean)
        .join("、");
    },
    // 筛选节点
    filterNode(value, data) {
@@ -855,9 +949,9 @@
        this.form.password = "";
      });
    },
    // 删除课题组
    // 删除科室
    removehpsp(valueArray) {
      console.log(valueArray, "删除课题组");
      console.log(valueArray, "删除科室");
      console.log(this.form.userId, "删除");
      let code = valueArray[valueArray.length - 1];
      removeusertd(this.form.userId, code).then((res) => {
@@ -907,7 +1001,7 @@
            updateUser(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.adduserdept();
              // this.adduserdept();
            });
          } else {
            addUser(this.form).then((response) => {
@@ -916,7 +1010,7 @@
              this.form.userId = response.data;
              console.log("开始加部门");
              this.adduserdept();
              // this.adduserdept();
            });
          }
        }