qx
2 天以前 e48af621e9c9a6fd97cdcff2cafa515347d05995
src/views/hosp/project/index.vue
@@ -1,5 +1,5 @@
<template>
  <div class="app-container">
  <div class="app-container" v-loading="pageLoading">
    <el-row :gutter="20">
      <el-col :span="3" :xs="24">
        <div class="head-container">
@@ -79,7 +79,13 @@
          </el-table-column>
          <el-table-column label="是否外送" align="center" prop="proDelivery" :show-overflow-tooltip="true" width="75px">
            <template v-slot="scope">
              {{ scope.row.proDelivery === 0 ? "是" : scope.row.proDelivery === 1 ? "否" : "" }}
              {{
                scope.row.proDelivery === 0
                  ? "是"
                  : scope.row.proDelivery === 1
                    ? "否"
                    : ""
              }}
            </template>
          </el-table-column>
          <el-table-column label="项目标准值" align="center" prop="proScope" :show-overflow-tooltip="true" width="90px">
@@ -236,14 +242,12 @@
        </el-form-item>
        <el-form-item label="是否参与异常" prop="sfcyyc">
          <el-select v-model="form.sfcyyc" placeholder="请选择是否参与异常" style="width: 260px">
            <el-option v-for="dict in dictTypesy" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
            <el-option v-for="dict in dictTypesy" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否外送" prop="proDelivery">
          <el-select v-model="form.proDelivery" placeholder="请选择是否外送" style="width: 200px">
            <el-option v-for="dict in wsTypesy" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
            <el-option v-for="dict in wsTypesy" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
@@ -387,8 +391,8 @@
</template>
<script>
import debounce from 'lodash/debounce';
import cnchar from 'cnchar';
import debounce from "lodash/debounce";
import cnchar from "cnchar";
import Packagese from "@/components/Packagese";
import {
  getProject,
@@ -445,6 +449,7 @@
      }
    };
    return {
      pageLoading: true,
      xiugais: true,
      xiugaiList: [],
      deptOptions: [],
@@ -460,23 +465,23 @@
      chargeId: [],
      dictTypesy: [
        {
          value:"0",
          label:"是"
          value: "0",
          label: "是",
        },
        {
          value:"1",
          label:"否"
        }
          value: "1",
          label: "否",
        },
      ],
      wsTypesy: [
        {
          value:"0",
          label:"是"
          value: "1",
          label: "是",
        },
        {
          value:"1",
          label:"否"
        }
          value: "0",
          label: "否",
        },
      ],
      List: false,
      deptName: "",
@@ -553,7 +558,7 @@
        proSex: "2",
        resultType: "",
        sfcyyc: "0",
        proDelivery:"1"
        proDelivery: "1",
      },
      rules: {
        createTime: [
@@ -587,9 +592,13 @@
        this.$nextTick(() => {
          const lastId = newVal[newVal.length - 1] || "532";
          const node = this.findNodeById(this.deptOptions, lastId);
          this.queryParams.proId = lastId
          this.getList()
          if (node) {
            this.$refs.tree1.setCurrentKey(lastId);
            const nodeElement = document.querySelector(`.el-tree-node[data-key="${lastId}"] .el-tree-node__content`);
            const nodeElement = document.querySelector(
              `.el-tree-node[data-key="${lastId}"] .el-tree-node__content`
            );
            if (nodeElement) {
              nodeElement.click();
            }
@@ -613,36 +622,93 @@
    },
  },
  created() {
    this.getConsumables();
    // this.getConsumables();
    this.getDeptList();
    this.getDeptTree().then(() => {
      this.precomputePinyin();
    });
    // this.getDeptTree().then(() => {
    //   this.precomputePinyin();
    // });
  },
  mounted() {
    this.getDeptTree().then(() => {
      this.precomputePinyin();
    });
    // this.getDeptTree().then(() => {
    //   this.precomputePinyin();
    // });
    this.loadPage();
  },
  methods: {
    async loadPage() {
      this.pageLoading = true;
      try {
        await Promise.all([
          this.getDeptTree(), // 获取左侧树
          //this.getList(),  获取右侧表格
        ]);
      } catch (error) {
        console.error("加载页面出错", error);
      } finally {
        this.pageLoading = false; // 两个都加载完再关闭 loading
      }
    },
    async getDeptTree() {
      this.loadings = true;
      try {
        const response = await deptTree111();
        this.deptOptions = response.data;
        this.precomputePinyin();
        // 保证 treeId 是数组格式
        this.treeId = [];
        if (this.treeDate?.id) {
          this.treeId.push(this.treeDate.id);
        } else {
          this.treeId.push("532");
        }
      } catch (error) {
        console.error("加载部门树失败:", error);
      } finally {
        this.loadings = false; // loading 状态结束
      }
    },
    async getList() {
      this.loading = true;
      let data = {
        proName: this.queryParams.proName,
        checkType: this.queryParams.checkType,
        deptId: this.queryParams.deptId,
        proId: this.queryParams.proId,
      };
      try {
        const res = await getAllChildListById(data); // 替换成你实际的接口
        this.projectList = res.data.list;
      } finally {
        this.loading = false;
      }
    },
    debounceFilter: debounce(function (val) {
      this.$refs.tree1.filter(val);
    }, 300),
    precomputePinyin() {
      const traverse = (nodes) => {
        nodes.forEach(node => {
        nodes.forEach((node) => {
          if (node.label) {
            const lowerSpell = cnchar.spell(node.label, 'low', 'array').join(''); // 完整小写拼音
            const upperSpell = cnchar.spell(node.label, 'up', 'array').join('');  // 完整大写拼音
            const lowerSpell = cnchar
              .spell(node.label, "low", "array")
              .join(""); // 完整小写拼音
            const upperSpell = cnchar.spell(node.label, "up", "array").join(""); // 完整大写拼音
            const shortPinyin = node.label
              .split('')
              .map(char => cnchar.spell(char, 'array')[0]?.[0]?.toLowerCase() || char) // 拼音首字母
              .join('');
              .split("")
              .map(
                (char) =>
                  cnchar.spell(char, "array")[0]?.[0]?.toLowerCase() || char
              ) // 拼音首字母
              .join("");
            this.pinyinCache.set(node.id, {
              lowerSpell,
              upperSpell,
              shortPinyin, // 缓存拼音简写
              label: node.label
              label: node.label,
            });
          }
          if (node.children) traverse(node.children);
@@ -656,9 +722,9 @@
      if (!cached) return false; // 如果没有缓存数据,不显示该节点
      const searchLower = value.toLowerCase(); // 将搜索词转为小写
      return (
        cached.label.includes(value) ||           // 直接匹配汉字
        cached.label.includes(value) || // 直接匹配汉字
        cached.shortPinyin.includes(searchLower) || // 匹配拼音简写
        cached.lowerSpell.includes(searchLower)   // 匹配完整拼音
        cached.lowerSpell.includes(searchLower) // 匹配完整拼音
      );
    },
    filterNode2(value, data) {
@@ -720,15 +786,16 @@
      this.form.hisXmbm = "";
      this.form.hisXmmc = "";
      this.form.hisdj = "";
      this.loading = true;
      // this.loading = true;
      this.proParent = false;
      this.form.proPrice = 0.0;
      this.form.proName = "";
      this.form.proId = null;
      this.form.resultType = "1";
      this.getDeptList();
      getlist().then((response) => {
        if (response.code == 200) {
          this.loading = false;
          // this.loading = false;
          this.projectOptions = [];
          const project = { proId: 0, proName: "主类目", children: [] };
          project.children = this.handleTree(response.data.list, "proId");
@@ -740,8 +807,8 @@
            this.open = true;
          } else if (this.treeDate.id) {
            if (this.treeDate.qf == "0") {
              this.form.proParentId = "0"
              this.form.deptId = this.treeDate.id
              this.form.proParentId = "0";
              this.form.deptId = this.treeDate.id;
            } else {
              this.form.proParentId = this.treeDate.id;
              this.projectOptions.forEach((item) => {
@@ -753,10 +820,9 @@
              });
            }
            this.open = true;
          } else {
            this.form.proParentId = "0"
            this.form.proParentId = "0";
            this.open = true;
          }
        }
@@ -810,7 +876,10 @@
      listSfxm(this.querycharge).then((response) => {
        this.sfxmList = response.rows;
        response.rows.forEach((item, index) => {
          item.newID = (this.querycharge.pageNum - 1) * this.querycharge.pageSize + index + 1;
          item.newID =
            (this.querycharge.pageNum - 1) * this.querycharge.pageSize +
            index +
            1;
        });
        this.total = response.total;
        this.loading = false;
@@ -836,7 +905,8 @@
      getListByXmId(this.queryParam).then((response) => {
        this.sfxmList = response.data.date;
        response.data.date.forEach((item, index) => {
          item.newID = (this.queryParam.page - 1) * this.queryParam.pageSize + index + 1;
          item.newID =
            (this.queryParam.page - 1) * this.queryParam.pageSize + index + 1;
        });
        this.total = response.data.total;
        this.loading = false;
@@ -867,16 +937,15 @@
        this.deptList = this.handleTree(response.data, "proId");
      });
    },
    getDeptTree() {
    /* getDeptTree() {
      return deptTree111().then((response) => {
        this.deptOptions = response.data;
        this.treeId.push(this.treeDate.id);
      });
    },
    }, */
    handleNodeClick(date) {
      this.treeDate = date;
      this.xiugaiList ={}
      this.xiugaiList = {};
      this.xiugais = date.qf === "0";
      let proId = date.id;
      getInfoByProId(proId).then((response) => {
@@ -891,8 +960,13 @@
      this.loading = true;
      getAllChildListById(data).then((response) => {
        if (response.code == 200) {
          this.projectList = response.data.list.length >= 1 ? this.handleTree(response.data.list, "proId") : [];
          this.ListId = this.projectList.length ? [this.projectList[0].proId] : [];
          this.projectList =
            response.data.list.length >= 1
              ? this.handleTree(response.data.list, "proId")
              : [];
          this.ListId = this.projectList.length
            ? [this.projectList[0].proId]
            : [];
          this.key = response.data.key;
          this.loading = false;
        }
@@ -946,7 +1020,7 @@
        tjStandardList: [],
        proStatus: "0",
        resultType: "1",
        proDelivery:'1'
        proDelivery: "1",
      };
      this.resetForm("form");
    },
@@ -1027,25 +1101,38 @@
      }
    },
    handleUpdate1() {
      this.form ={}
      this.form = this.xiugaiList;
      this.form.proStatus = this.form.proStatus.toString();
      this.form.sfcyyc = this.form.sfcyyc.toString();
      this.form.proDelivery = this.form.proDelivery.toString();
      // this.updateLoading = true;
      this.form = {};
      this.proParent = true;
      this.isPriceDisabled = true;
      getlist().then((response) => {
        if (response.code == 200) {
      // 先加载科室列表数据,再设置表单数据
      Promise.all([
        listDept(this.queryParams),
        getlist()
      ]).then(([deptResponse, listResponse]) => {
        // 先设置科室列表
        this.parentNameList = deptResponse.data;
        // 再设置表单数据
        this.form = this.xiugaiList;
        this.form.proStatus = this.form.proStatus.toString();
        this.form.sfcyyc = this.form.sfcyyc.toString();
        // 处理项目选项
        if (listResponse.code == 200) {
          this.loading = false;
          this.projectOptions = [];
          const project = { proId: 0, proName: "主类目", children: [] };
          project.children = this.handleTree(response.data.list, "proId");
          this.key = response.data.key;
          project.children = this.handleTree(listResponse.data.list, "proId");
          this.key = listResponse.data.key;
          this.projectOptions.push(project);
          console.log( this.projectOptions,11111)
        }
      });
      this.open = true;
        this.open = true;
      }).catch((error) => {
        this.$message.error("加载数据失败");
      })
    },
    handleUpdate(row) {
      this.reset();
@@ -1053,36 +1140,52 @@
      const proId = row.proId || this.ids;
      this.proParent = false;
      this.isPriceDisabled = false;
      getProject(proId).then((response) => {
        this.form = response.data;
        this.showPrise = this.form.proParentId === "0";
        this.showRentPrise = !this.showPrise;
        this.form.proStatus = this.form.proStatus.toString();
        this.form.sfcyyc = this.form.sfcyyc.toString();
        this.form.proDelivery =  this.form.proDelivery.toString()
        this.form.consumablesList = response.data.consumablesList;
        this.form.tjStandardList = response.data.tjStandardList;
        if (this.form.tjStandardList) {
          this.form.tjStandardList.forEach((item) => {
            item.tjSex = item.tjSex === "0" || item.tjSex === "男" ? "男" : (item.tjSex === "1" || item.tjSex === "女" ? "女" : null);
            item.tjType = {
              0: "婴儿", 1: "幼儿", 2: "儿童", 3: "少年", 4: "青年", 5: "中年", 6: "老年"
            }[item.tjType] || item.tjType;
          });
        }
        getlist().then((response) => {
          if (response.code == 200) {
            this.loading = false;
            this.projectOptions = [];
            const project = { proId: 0, proName: "主类目", children: [] };
            project.children = this.handleTree(response.data.list, "proId");
            this.key = response.data.key;
            this.projectOptions.push(project);
      listDept(this.queryParams).then((response) => {
        this.parentNameList = response.data;
        getProject(proId).then((response) => {
          this.form = response.data;
          this.showPrise = this.form.proParentId === "0";
          this.showRentPrise = !this.showPrise;
          this.form.proStatus = this.form.proStatus.toString();
          this.form.sfcyyc = this.form.sfcyyc.toString();
          this.form.proDelivery = this.form.proDelivery.toString();
          this.form.consumablesList = response.data.consumablesList;
          this.form.tjStandardList = response.data.tjStandardList;
          if (this.form.tjStandardList) {
            this.form.tjStandardList.forEach((item) => {
              item.tjSex =
                item.tjSex === "0" || item.tjSex === "男"
                  ? "男"
                  : item.tjSex === "1" || item.tjSex === "女"
                    ? "女"
                    : null;
              item.tjType =
                {
                  0: "婴儿",
                  1: "幼儿",
                  2: "儿童",
                  3: "少年",
                  4: "青年",
                  5: "中年",
                  6: "老年",
                }[item.tjType] || item.tjType;
            });
          }
          getlist().then((response) => {
            if (response.code == 200) {
              this.loading = false;
              this.projectOptions = [];
              const project = { proId: 0, proName: "主类目", children: [] };
              project.children = this.handleTree(response.data.list, "proId");
              this.key = response.data.key;
              this.projectOptions.push(project);
            }
          });
          this.open = true;
          this.title = "体检项目信息维护";
        });
        this.open = true;
        this.title = "体检项目信息维护";
      });
      })
    },
    getSelectValue(val) {
      this.form.consumablesList.forEach((formitem) => {
@@ -1099,15 +1202,28 @@
    },
    submitForm() {
      this.noclick = true;
      this.pageLoading = true;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          const isUpdate = this.form.proId != null;
          if (this.form.tjStandardList) {
            this.form.tjStandardList.forEach((item) => {
              item.tjSex = item.tjSex === "男" || item.tjSex === "0" ? "0" : (item.tjSex === "女" || item.tjSex === "1" ? "1" : null);
              item.tjType = {
                "婴儿": 0, "幼儿": 1, "儿童": 2, "少年": 3, "青年": 4, "中年": 5, "老年": 6
              }[item.tjType] || null;
              item.tjSex =
                item.tjSex === "男" || item.tjSex === "0"
                  ? "0"
                  : item.tjSex === "女" || item.tjSex === "1"
                    ? "1"
                    : null;
              item.tjType =
                {
                  婴儿: 0,
                  幼儿: 1,
                  儿童: 2,
                  少年: 3,
                  青年: 4,
                  中年: 5,
                  老年: 6,
                }[item.tjType] || null;
            });
          }
          this.form.lisXmbm = this.form.lisXmbm;
@@ -1148,7 +1264,24 @@
        }
      }
    },
    handleSuccess(isY) {
    async handleSuccess(isY) {
      this.cancel();
      if (this.proParent || isY) {
        // 等待左侧树加载和拼音处理
        await this.getDeptTree();
        this.precomputePinyin();
      }
      // 等待右侧表格刷新
      await this.getList();
      // 立即刷新当前项目数据,确保数据是最新的
      await this.refreshCurrentProjectData();
      this.pageLoading = false; // ✅ 统一加载状态控制
    },
    /* handleSuccess(isY) {
      this.cancel();
      this.getList();
      if (this.proParent || isY) {
@@ -1156,6 +1289,21 @@
          this.precomputePinyin();
        });
      }
    }, */
    // 刷新当前选中项目的数据
    async refreshCurrentProjectData() {
      if (this.id) {
        try {
          const response = await getInfoByProId(this.id);
          this.xiugaiList = response.data;
          return response.data;
        } catch (error) {
          this.$message.error("刷新项目数据失败");
          this.xiugaiList = null; // 刷新失败时重置为 null
          return null;
        }
      }
      return null;
    },
    submit() {
      this.ChangeList.forEach((item) => {
@@ -1166,6 +1314,10 @@
        this.sfxmId = parseInt(item.id);
      });
      this.dialogTableVisible = false;
      this.getDeptList();
      this.getDeptTree().then(() => {
        this.precomputePinyin();
      });
    },
    handleDelete(row) {
      const proIds = row.proId || this.ids;