1
lkk
2025-04-08 2f0e1ee5a74344f6a108df4559beed0423b9639d
src/components/public/index.vue
@@ -1,6 +1,11 @@
<template>
  <div>
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <h3 v-if="fList.proResult">检测项目 :{{ fList.project.proName }}</h3>
      <h3 v-if="fList.proResult">
        检测结果 :{{ fList.proResult }}{{ fList.project.proMetering }}
@@ -39,50 +44,86 @@
            >搜索</el-button
          >
        </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="320px
        "
      >
        <el-table-column type="selection" width="40" align="center" />
        <el-table-column label="序号" type="index" width="80px" />
        <!-- <el-table-column label="规则" align="center" prop="ruleStr" /> -->
        <el-table-column label="检查结论" align="center" prop="ruleStr" />
        <el-table-column label="检查所见" align="center" prop="yxbx" />
      </el-table>
      <div class="pag">
        <div class="pag1">
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
      <div style="display: flex; width: 100%">
        <div style="width: 50%; margin-right: 30px">
          <el-table
            :data="dataList"
            ref="multipleTable"
            v-loading="loading"
            @selection-change="handleSelectionChange"
            border
            height="420px"
          >
            <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="ruleStr" />
            <el-table-column label="检查所见" align="center" prop="yxbx" />
          </el-table>
          <div class="pag">
            <div class="pag1" style="margin-left: 600px">
              <pagination
                small
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </div>
          </div>
        </div>
        <div style="width: 100%; height: 610px">
          <!-- <h3 style="margin-top: -30px;">已选项目</h3> -->
          <el-form
            :model="form"
            ref="queryForm"
            size="small"
            label-width="68px"
          >
          <!--  :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>
      <h3>已选项目</h3>
      <el-form
        :model="form"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="68px"
      >
        <el-form-item>
          <el-input
            type="textarea"
            v-model="form.desc"
            style="width: 560px"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <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>
@@ -92,34 +133,38 @@
  
<script>
import { getlist, getlistByRuleStr } from "@/api/doctor/check";
import { getYxJcXxJg } from "@/api/picture/picture";
export default {
  name: "Public",
  /*  props: {
    row: {
      type: Object,
    },
  }, */
  props: {
    lastDesc: {
    checkStatus: {
      type: String,
      default: "",
      default: "0",
      validator: value => ["0", "1"].includes(value)
    },
    proResult: {
      type: String,
      default: ''
    },
    conclusion: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      open: false,
      // 弹出层标题
      title: "",
      yxbx:"",
      yxbx: "",
      //   lastDesc: "",
      total: 0,
      dataList: [],
      // 遮罩层
      loading: false,
      form: {
        // desc: "",
        desc: this.lastDesc,
        desc: "",
        jcsj: "",
      },
      queryParams: {
        bingzhong: "",
@@ -130,181 +175,142 @@
      list: [],
      fList: {},
      selectedItems: [],
      searchDebounce: null,
    };
  },
  watch: {
    row(val, newVla) {
      // console.log(val,newVla)
      //   this.fList = val;
      // if (this.fList) {
      //     this.getList()
      // }
    },
    lastDesc(newVal) {
      this.form.desc = newVal; // 更新 form.desc
      console.log(newVal, 666);
    checkStatus(newValue) {
      console.log( newValue,9988);
      if (newValue === "1") {
        this.updateData(this.proResult, this.conclusion);
      }
    },
  },
  mounted() {},
  created() {},
  methods: {
    getList(row, date) {
      let data = {
        //   proId: fList.proId,
        // ruleStr: fList.proResult,
      };
      getlist(data).then((res) => {
    async getList() {
      try {
        this.loading = true; // 添加加载状态
        const res = await getlist(this.queryParams);
        this.dataList = res.rows;
        this.$nextTick(() => {
          /* this.dataList.forEach((item) => {
            this.fList.rulesList.forEach((item1) => {
              if (item.aid === item1.aid) {
                this.$refs.multipleTable.toggleRowSelection(item, true);
              }
            });
          }); */
        });
      });
    },
    /* getList(row, date) {
      if (row.proId) {
        let fList = row;
        // if (this.fList.proResult == "") {
        let data = {
        //   proId: fList.proId,
          // ruleStr: fList.proResult,
        };
        getlist(data).then((res) => {
          this.dataList = res.rows;
          this.$nextTick(() => {
            this.dataList.forEach((item) => {
              this.fList.rulesList.forEach((item1) => {
                if (item.aid == item1.aid) {
                  this.$refs.multipleTable.toggleRowSelection(item, true);
                }
              });
            });
          });
        });
        // }else{
        //     let data = {
        //         proId: this.fList.proId,
        //         bingzhong: this.queryParams.bingzhong,
        //         ruleStr: this.fList.proResult,
        //     }
        //     getlistByRuleStr(data).then(res => {
        //         this.dataList = res.rows
        //         this.$nextTick(() => {
        //             this.dataList.forEach(item => {
        //                 this.fList.rulesList.forEach(item1 => {
        //                     if (item.aid == item1.aid) {
        //                         this.$refs.multipleTable.toggleRowSelection(item, true);
        //                     }
        //                 })
        //             })
        //         })
        //     })
        // }
      } else {
        let data = {
        //   proId: row,
        };
        getlist(data).then((res) => {
          this.dataList = res.rows;
          console.log(res,888);
          // this.$nextTick(() => {
          //     this.dataList.forEach(item => {
          //         this.fList.rulesList.forEach(item1 => {
          //             if (item.aid == item1.aid) {
          //                 this.$refs.multipleTable.toggleRowSelection(item, true);
          //             }
          //         })
          //     })
          // })
        });
      }
    }, */
    handleQuery() {
      let data = {
        proId: this.fList.proId,
        bingzhong: this.queryParams.bingzhong,
        bzPinyin: this.queryParams.bzPinyin,
      };
      getlist(data).then((res) => {
        this.dataList = res.rows;
        this.$nextTick(() => {
          this.dataList.forEach((item) => {
            this.fList.rulesList.forEach((item1) => {
              if (item.aid == item1.aid) {
                this.$refs.multipleTable.toggleRowSelection(item, true);
              }
            });
          });
        });
      });
    },
    handleSelectionChange(selection) {
        console.log(selection[0].yxbx,123);
        this.total = res.total;
        
      this.list = [];
      this.list = selection;
      this.yxbx = selection[0].yxbx
        // 如果需要选中操作,将其封装为独立方法
        await this.handleAutoSelection();
      } catch (error) {
        console.error('获取数据失败:', error);
        this.$message.error('获取数据失败');
      } finally {
        this.loading = false;
      }
    },
      //   this.form.desc = "";
      this.list.forEach((element) => {
        if (element.bingzhong) {
          this.form.desc += element.bingzhong + ",";
        } else {
          this.form.desc += element.ruleStr + ",";
    // 封装选中逻辑
    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);
        }
      });
    },
    /* handleSelectionChange(selection) {
      // 当前选中的项
        const newSelection = selection;
    handleQuery() {
      if (this.searchDebounce) clearTimeout(this.searchDebounce);
      this.searchDebounce = setTimeout(() => {
        this.queryParams.pageNum = 1; // 重置页码
        this.getList();
      }, 300);
    },
      // 1. 处理取消选中的项
      const removedItems = this.selectedItems.filter(
        (item) => !newSelection.includes(item)
      );
      // 从 form.desc 中移除取消选中的数据
      removedItems.forEach((item) => {
        const itemToRemove = item.bingzhong || item.ruleStr;
        this.form.desc = this.form.desc.replace(
          new RegExp(itemToRemove + ",?", "g"), // 使用正则确保移除所有重复项
          ""
        );
      });
      // 2. 更新已选中的数据列表
      this.selectedItems = newSelection;
      // 3. 添加新选中的项到 form.desc
      newSelection.forEach((element) => {
        const itemToAdd = element.bingzhong || element.ruleStr;
        if (!this.form.desc.includes(itemToAdd)) {
          this.form.desc += itemToAdd + ",";
        }
      });
    }, */
    handleOk() {
      this.open = false;
      if (this.form.desc) {
        // this.$emit("add", this.form.desc, this.list);
        this.$emit("add", this.form.desc,this.yxbx);
        // this.lastDesc = this.form.desc;
    updateData(proResult, conclusion) {
      if (this.checkStatus === "1") {
        this.form.jcsj = proResult; // 更新检查所见
        this.form.desc = conclusion; // 更新检查结论
        // console.log(proResult, conclusion);
      }
      //   this.form.desc = "";
    },
    handleSelectionChange(selection) {
      this.list = selection;
      this.updateFormContent(selection);
    },
    updateFormContent(selection) {
      if (!selection.length) return;
      // 如果处于检查状态,使用传入的值
      if (this.checkStatus === "1") {
        this.updateData(this.proResult, this.conclusion);
        return;
      }
      // 重置表单内容
      this.form.desc = '';
      this.form.jcsj = '';
      // 使用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();
      }
    },
  },
  computed: {
    isCheckMode() {
      return this.checkStatus === "1";
    },
    hasSelectedItems() {
      return this.list.length > 0;
    }
  }
};
</script>
  
<style scoped></style>
<style scoped>
.el-dialog__body{
  padding: 10px 20px;
}
::v-deep .el-dialog__footer {
  padding: 0 !important;
  padding-bottom: 40px !important;
}
</style>