qx
2025-06-05 93452e1aad484102f15234d1a6f76764bd18a5ca
src/components/public/index.vue
@@ -1,349 +1,389 @@
<template>
    <div>
      <el-dialog
        :title="title"
        :visible.sync="open"
        width="1080px"
        append-to-body
      >
        <h3 v-if="fList.proResult">检测项目 :{{ fList.project.proName }}</h3>
        <h3 v-if="fList.proResult">
          检测结果 :{{ fList.proResult }}{{ fList.project.proMetering }}
        </h3>
        <!-- <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="68px"
        > -->
          <!-- <el-form-item label="病种名称" prop="bingzhong">
            <el-input
              v-model="queryParams.bingzhong"
              placeholder="请输入简称"
              clearable
              @keyup.enter.native="handleQuery"
              style="width: 120px"
            />
          </el-form-item>
          <el-form-item label="拼音码" prop="bzPinyin">
            <el-input
              v-model="queryParams.bzPinyin"
              placeholder="请输入拼音码"
              clearable
              @keyup.enter.native="handleQuery"
              style="width: 130px"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
          </el-form-item> -->
          <!-- <el-form-item>
            <h3 >{{ queryParams.proName  || '暂无项目名称'  }}</h3>
          </el-form-item> -->
          <!-- <el-form-item>
            <h3 style="margin-left: 160px">已选项目</h3>
          </el-form-item> -->
        <!-- </el-form> -->
        <h2 style="text-align: center;margin-top: -30px;">{{ queryParams.proName  || '暂无项目名称'  }}</h2>
        <div style="display: flex; width: 100%">
          <div style="width: 50%; margin-right: 40px">
            <el-table
              :data="dataList"
              ref="multipleTable"
              v-loading="loading"
              row-key="aid"
              @selection-change="handleSelectionChange"
              :reserve-selection="false"
              border
              height="420px"
            >
              <el-table-column type="selection" width="40" align="center" />
              <el-table-column
                label="序号"
                type="index"
                align="center"
                width="50px"
  <div>
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1080px"
      append-to-body
    >
      <h3 v-if="fList.proResult">检测项目 :{{ fList.project.proName }}</h3>
      <h3 v-if="fList.proResult">
        检测结果 :{{ fList.proResult }}{{ fList.project.proMetering }}
      </h3>
      <h2 style="text-align: center">{{ proName || "暂无项目名称" }}</h2>
      <div style="display: flex; width: 100%">
        <div style="width: 50%; margin-right: 40px">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            label-width="68px"
          >
            <!-- <el-form-item label="病种名称" prop="bingzhong">
          <el-input
            v-model="queryParams.bingzhong"
            placeholder="请输入简称"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 120px"
          />
        </el-form-item>-->
            <el-form-item label="检查结论" prop="ruleStr">
              <el-input
                v-model="queryParams.ruleStr"
                placeholder="请输入检查结论"
                clearable
                @keyup.enter.native="getList"
                style="width: 130px"
              />
              <!-- <el-table-column label="规则" align="center" prop="ruleStr" /> -->
              <el-table-column label="检查所见" align="center" prop="yxbx" />
              <el-table-column label="检查结论" align="center" prop="ruleStr" />
            </el-table>
            <div class="pag">
              <div class="pag1" style="margin-left: 630px">
                <pagination
                  small
                  v-show="total > 0"
                  :total="total"
                  :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getList"
                />
              </div>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="getList"
                >搜索</el-button
              >
            </el-form-item>
            <!-- <el-form-item>
          <h3 >{{ queryParams.proName  || '暂无项目名称'  }}</h3>
        </el-form-item> -->
            <!-- <el-form-item>
          <h3 style="margin-left: 160px">已选项目</h3>
        </el-form-item> -->
          </el-form>
          <el-table
            :data="dataList"
            ref="multipleTable"
            v-loading="loading"
            @selection-change="handleSelectionChange"
            border
            height="480px"
          >
            <el-table-column type="selection" width="40" align="center" />
            <el-table-column
              label="序号"
              type="index"
              align="center"
              width="50px"
            />
            <!-- <el-table-column label="规则" align="center" prop="ruleStr" /> -->
            <el-table-column label="检查所见" align="center" prop="yxbx" />
            <el-table-column label="检查结论" align="center" prop="ruleStr" />
          </el-table>
          <div class="pag">
            <div class="pag1" style="margin-left: 630px">
              <pagination
                small
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </div>
          </div>
          <div style="width: 100%; height: 600px">
            <!-- <h3 style="margin-top: -30px;">已选项目</h3> -->
            <el-form
              :model="form"
              ref="queryForm"
              size="small"
              label-width="68px"
              :inline="true"
            >
              <!--  :inline="true" -->
              <!-- <el-form-item>
                <el-input
                  type="textarea"
                  v-model="form.desc"
                  style="width: 560px"
                ></el-input>
              </el-form-item> -->
              <el-form-item label="检查所见" prop="jcsj">
                <el-input
                  v-model="form.jcsj"
                  clearable
                  type="textarea"
                  :autosize="{ minRows: 8 }"
                  style="width: 380px"
                />
              </el-form-item>
              <el-form-item label="检查结论" prop="conclusion">
                <el-input
                  v-model="form.desc"
                  clearable
                  type="textarea"
                  :autosize="{ minRows: 8 }"
                  style="width: 380px"
                />
              </el-form-item>
            </el-form>
          </div>
        </div>
        <span slot="footer" class="dialog-footer" style="margin-top: -120px">
          <el-button @click="open = false">取 消</el-button>
          <el-button type="primary" @click="handleOk">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </template>
  <script>
  import { getlist, getlistByRuleStr } from "@/api/doctor/check";
  import { getYxJcXxJg } from "@/api/picture/picture";
  export default {
    name: "Public",
    props: {
      checkStatus: {
        type: String,
        default: "0",
        validator: (value) => ["0", "1"].includes(value),
      },
      proResult: {
        type: String,
        default: "",
      },
      conclusion: {
        type: String,
        default: "",
      },
      projectList: {
        type: Array,
        default: () => [],
      },
        <div class="jianc">
          <!-- <h3 style="margin-top: -30px;">已选项目</h3> -->
          <el-form
            :model="form"
            ref="queryForm"
            size="small"
            label-width="68px"
            :label-position="labelPosition"
          >
            <!--  :inline="true" -->
            <!-- <el-form-item>
              <el-input
                type="textarea"
                v-model="form.desc"
                style="width: 560px"
              ></el-input>
            </el-form-item> -->
            <el-form-item label="检查所见" prop="jcsj">
              <el-input
                v-model="form.jcsj"
                clearable
                type="textarea"
                :autosize="{ minRows: 7 }"
                style="width: 380px"
              />
            </el-form-item>
            <el-form-item label="检查结论" prop="desc">
              <el-input
                v-model="form.desc"
                clearable
                type="textarea"
                :autosize="{ minRows: 7 }"
                style="width: 380px"
              />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <span slot="footer" class="dialog-footer" style="margin-top: -20px">
        <el-button @click="callcolos">取 消</el-button>
        <el-button type="primary" @click="handleOk">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getlist, getlistByRuleStr } from "@/api/doctor/check";
import { getYxJcXxJg } from "@/api/picture/picture";
export default {
  name: "Public",
  props: {
    checkStatus: {
      type: String,
      default: "0",
      validator: (value) => ["0", "1"].includes(value),
    },
    data() {
      return {
        open: false,
        // 弹出层标题
        title: "",
        yxbx: "",
        proName:'',
        //   lastDesc: "",
        total: 0,
        dataList: [],
        // 遮罩层
        loading: false,
        form: {
          desc: "",
          jcsj: "",
        },
        queryParams: {
          bingzhong: "",
          bzPinyin: "",
          proId:"",
        //   proName:"",
          pageNum: 1,
          pageSize: 10,
        },
        list: [],
        fList: {},
        selectedItems: [],
        searchDebounce: null,
      };
    proResult: {
      type: String,
      default: "",
    },
    watch: {
      checkStatus(newValue) {
        if (newValue === "1") {
          this.updateData(this.proResult, this.conclusion);
    conclusion: {
      type: String,
      default: "",
    },
    projectList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      open: false,
      labelPosition: "top",
      // 弹出层标题
      title: "",
      yxbx: "",
      proName: "",
      //   lastDesc: "",
      total: 0,
      dataList: [],
      // 遮罩层
      loading: false,
      form: {
        desc: "",
        jcsj: "",
      },
      queryParams: {
        ruleStr: "",
        pageNum: 1,
        pageSize: 10,
      },
      list: [],
      fList: {},
      selectedItems: [],
      searchDebounce: null,
    };
  },
  watch: {
    checkStatus(newValue) {
      console.log(565658);
      if (newValue === "1") {
        this.updateData(this.proResult, this.conclusion);
      }
    },
    projectList: {
      immediate: true,
      deep: true,
      handler(newVal) {
        console.log("收到的项目数据:", newVal);
        // 你可以在这里处理数据,比如保存到 data 或做逻辑判断
        if (newVal && newVal.length > 0) {
          const firstProject = newVal[0]; // 你也可以遍历所有项目,看你业务需求
          this.queryParams.proId = firstProject.proId; // 假设项目中叫 id
          //this.queryParams.proName = firstProject.proName; // 假设叫 proName
          this.proName = firstProject.proName;
        }
      },
      projectList: {
        immediate: true,
        deep: true,
        handler(newVal) {
          console.log("收到的项目数据:", newVal);
          // 你可以在这里处理数据,比如保存到 data 或做逻辑判断
          if (newVal && newVal.length > 0) {
            const firstProject = newVal[0]; // 你也可以遍历所有项目,看你业务需求
            this.queryParams.proId = firstProject.proId; // 假设项目中叫 id
            // this.queryParams.proName = firstProject.proName;
            this.proName = firstProject.proName
          }
        },
      },
    },
    mounted() {},
    created() {},
    methods: {
      async getList() {
        try {
          this.loading = true; // 添加加载状态
          const res = await getlist(this.queryParams);
          this.dataList = res.data.rows;
  },
  mounted() {},
  created() {},
  methods: {
    async getList() {
      try {
        this.loading = true; // 添加加载状态
        const res = await getlist(this.queryParams);
        this.dataList = res.data.rows;
        if (res.data.total) {
          this.total = res.data.total;
          // 如果需要选中操作,将其封装为独立方法
          await this.handleAutoSelection();
        } catch (error) {
          console.error("获取数据失败:", error);
          this.$message.error("获取数据失败");
        } finally {
          this.loading = false;
        }
      },
      // 封装选中逻辑
      async handleAutoSelection() {
        if (!this.fList?.rulesList?.length) return;
        await this.$nextTick();
        // 先清除所有选择
        this.$refs.multipleTable?.clearSelection();
        // 再进行选择
        this.dataList.forEach((item) => {
          const shouldSelect = this.fList.rulesList.some(
            (rule) => rule.aid === item.aid
          );
          if (shouldSelect) {
            this.$refs.multipleTable?.toggleRowSelection(item, true);
        this.updateData(this.proResult, this.conclusion);
        // 如果需要选中操作,将其封装为独立方法
        await this.handleAutoSelection();
      } catch (error) {
        console.error("获取数据失败:", error);
        this.$message.error("获取数据失败");
      } finally {
        this.loading = false;
      }
    },
    // 封装选中逻辑
    async handleAutoSelection() {
      if (!this.fList?.rulesList?.length) return;
      await this.$nextTick();
      this.dataList.forEach((item) => {
        const shouldSelect = this.fList.rulesList.some(
          (rule) => rule.aid === item.aid
        );
        if (shouldSelect) {
          this.$refs.multipleTable?.toggleRowSelection(item, true);
        }
      });
    },
    handleQuery() {
      if (this.searchDebounce) clearTimeout(this.searchDebounce);
      this.searchDebounce = setTimeout(() => {
        this.queryParams.pageNum = 1; // 重置页码
        this.getList();
      }, 300);
    },
    updateData(proResult, conclusion) {
      console.log(proResult, conclusion, 5658);
      if (this.checkStatus == 1) {
        this.form.jcsj = proResult; // 更新检查所见
        this.form.desc = conclusion; // 更新检查结论
      } else {
        this.form.desc = "";
        this.form.jcsj = "";
      }
      if (this.list.length != 0) {
        let desc = "";
        desc += this.list
          .map((item) => item.bingzhong || item.ruleStr)
          .filter(Boolean)
          .join(",");
        let jcsj = "";
        jcsj += this.list
          .map((item) => item.yxbx)
          .filter(Boolean)
          .join(",");
        this.form.jcsj = this.form.jcsj + jcsj; // 更新检查所见
        this.form.desc = this.form.desc + desc;
      }
    },
    handleSelectionChange(selection) {
      this.list = selection;
      this.updateFormContent(selection);
    },
    updateFormContent(selection) {
      // if (!selection.length) return;
      this.updateData(this.proResult, this.conclusion);
      // 如果处于检查状态,使用传入的值
      // if (this.checkStatus === "1") {
      //   this.updateData(this.proResult, this.conclusion);
      //   return;
      // }
      // 重置表单内容
      // this.form.desc = "";
      // this.form.jcsj = "";
      // console.log(22222);
      // // 使用map和join替代forEach和字符串拼接
      // this.form.desc = selection
      //   .map((item) => item.bingzhong || item.ruleStr)
      //   .filter(Boolean)
      //   .join(",");
      // this.form.jcsj = selection
      //   .map((item) => item.yxbx)
      //   .filter(Boolean)
      //   .join(",");
    },
    handleOk() {
      if (!this.form.desc && !this.form.jcsj) {
        this.$message.warning("请选择数据");
        return;
      } else {
        const desc = this.form.desc?.trim();
        const jcsj = this.form.jcsj?.trim();
        // 如果没有选中表格项
        if (!this.list || this.list.length === 0) {
          if (!desc && !jcsj) {
            this.$message.warning(
              "请填写有效的检查所见和检查结论,或选择表格数据"
            );
            return;
          }
        });
      },
      handleQuery() {
        if (this.searchDebounce) clearTimeout(this.searchDebounce);
        this.searchDebounce = setTimeout(() => {
          this.queryParams.pageNum = 1; // 重置页码
          this.getList();
        }, 300);
      },
      updateData(proResult, conclusion) {
        if (this.checkStatus === "1") {
          this.form.jcsj = proResult; // 更新检查所见
          this.form.desc = conclusion; // 更新检查结论
          // console.log(proResult, conclusion);
        }
      },
      handleSelectionChange(selection) {
        console.log('Selection changed:', selection);
        this.list = [...selection]; // 使用展开运算符创建新数组
        this.updateFormContent(selection);
      },
      updateFormContent(selection) {
        // 如果处于检查状态,使用传入的值
        if (this.checkStatus === "1") {
          this.updateData(this.proResult, this.conclusion);
          return;
        }
        // 重置表单内容
        this.form.desc = "";
        this.form.jcsj = "";
        // 只有在有选中项时才进行拼接
        if (selection.length > 0) {
          // 使用map和join替代forEach和字符串拼接
          this.form.desc = selection
            .map((item) => item.bingzhong || item.ruleStr)
            .filter(Boolean)
            .join(",");
          this.form.jcsj = selection
            .map((item) => item.yxbx)
            .filter(Boolean)
            .join(",");
        }
      },
      handleOk() {
        if (!this.form.desc && !this.form.jcsj) {
          this.$message.warning("请选择数据");
          return;
        }
        try {
          this.$emit("add", this.form.desc, this.form.jcsj);
          this.resetForm();
          this.open = false;
        } catch (error) {
          console.error("处理数据失败:", error);
          this.$message.error("操作失败");
        }
      },
      resetForm() {
        this.form.desc = "";
        this.form.jcsj = "";
        this.list = [];
        if (this.$refs.multipleTable) {
          this.$refs.multipleTable.clearSelection();
        }
      },
      }
      try {
        this.$emit("add", this.form.desc, this.form.jcsj);
        this.resetForm();
        this.open = false;
      } catch (error) {
        console.error("处理数据失败:", error);
        this.$message.error("操作失败");
      }
    },
    computed: {
      isCheckMode() {
        return this.checkStatus === "1";
      },
      hasSelectedItems() {
        return this.list.length > 0;
      },
    resetForm() {
      this.form.desc = "";
      this.form.jcsj = "";
      this.list = [];
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
      }
    },
  };
  </script>
  <style scoped>
  .el-dialog__body {
    padding: 10px 20px;
  }
  ::v-deep .el-dialog__footer {
    padding: 0 !important;
    padding-bottom: 40px !important;
  }
  </style>
    callcolos() {
      this.open = false;
    },
  },
  computed: {
    isCheckMode() {
      return this.checkStatus === "1";
    },
    hasSelectedItems() {
      return this.list.length > 0;
    },
  },
};
</script>
<style scoped>
.el-dialog__body {
  padding: 0px 20px;
}
::v-deep .el-dialog__header {
  padding: 0px !important;
  padding-bottom: 0px !important;
}
::v-deep .el-dialog__footer {
  padding: 0 !important;
  padding-bottom: 40px !important;
}
.jianc {
  width: 100%;
  height: 600px;
  padding-top: 40px;
}
</style>