lkk
2024-12-04 d747406e0eb22d47726916be55e85376c4aa2729
src/views/sampling/sampling/index.vue
@@ -96,23 +96,18 @@
        v-if="samplingList.length > 0 && tjStatus == 1"
      >
        <el-button type="primary" @click="Merging">合并项目</el-button>
        <el-button
        <!-- <el-button
          type="primary"
          icon="el-icon-thumb"
          style="margin: 0 15px"
          v-hasPermi="['hosp:detail:add']"
          @click="Confirmreceipt"
          >确认采样</el-button
        >
        > -->
        <el-button type="primary" :disabled="!disabled" @click="Cancellation"
          >撤销合并</el-button
        >
        <el-button
          type="primary"
          :disabled="!selectList.length"
          @click="Collection"
          >采样打码</el-button
        >
        <el-button type="primary" @click="Confirmreceipt">采样打码</el-button>
      </el-col>
      <el-col
        :span="12"
@@ -190,15 +185,21 @@
        </el-table>
      </div>
      <div style="width: 50%">
        <!-- :default-sort="{ prop: 'specimenType', order: 'ascending' }"  :default-sort="{ prop: 'specimenType', order: 'ascending' }"
          @sort-change="handleSortChange"
          :span-method="objectSpanMethod"
          @selection-change="handleChange" ref="tab1"
          :row-class-name="tableRowClassName"-->
        <el-table
          v-loading="loading"
          :data="tableList"
          :span-method="objectSpanMethod"
          @sort-change="handleSortChange"
          @selection-change="handleChange"
          border
          height="520px"
          :span-method="objectSpanMethod"
          ref="tab1"
          :row-class-name="tableRowClassName"
          border
          height="520px"
        >
          <el-table-column type="selection" width="40" align="center" />
          <!--  :selectable="selectEnable" -->
@@ -274,12 +275,14 @@
        <!-- 动态生成多个条形码的容器 -->
        <div v-for="(item, index) in selectList" :key="index">
          <svg :id="'barcode' + index"></svg>
          <!-- <div class="name">{{ item.proName }}</div>
          <div class="name1">{{ item.proName }}</div> -->
          <div class="name">{{ getTruncatedName(item.proName).truncated }}</div>
          <div class="name1">
            {{ getTruncatedName(item.proName).remaining }}
          </div>
          <!-- <div class="name">{{ item.proName.slice(0, msg) }}</div>
          <div class="name1">
            {{ item.proName.slice(msg) }}
          </div> -->
          <div class="last">
            <p>{{ item.cusName }}</p>
            <div>
@@ -289,7 +292,9 @@
          </div>
          <div class="tj">
            <span>体检中心</span>
            <span>{{ item.cardId.substring(0, 14) }}</span>
            <!-- <span>{{ item.cardId.slice(0, 14) }}</span> -->
            <!-- <span>{{ item.cardId }}</span> -->
            <span>{{ item.cardId ? item.cardId.substring(0, 14) : "" }}</span>
          </div>
          <div class="tj">
            <span>{{ item.jyxh }}</span>
@@ -369,6 +374,8 @@
  name: "Sampling",
  data() {
    return {
      msg: "",
      getNumbr: null,
      list: [],
      selectList: [],
      selectedRows: [],
@@ -452,7 +459,9 @@
  },
  created() {
    // this.getNowTime();
    getTxmmccd().then((res) => {
      this.msg = Number(res.msg);
    });
    this.getdate();
  },
  mounted() {
@@ -470,73 +479,48 @@
  },
  methods: {
    async getTruncatedName(proName) {
      try {
        const res = await getTxmmccd(); // 确保使用 async/await
        console.log(res, 4545);
    handleSortChange({ prop, order }) {
      if (order === null) return; // 无排序时不处理
        // 去掉所有空格
        const trimmedProName = proName.replace(/\s+/g, "");
        // 检查 res 是否有效
        if (res && res.msg) {
          const number = Number(res.msg);
          console.log(number, 4444);
          const truncated =
            trimmedProName.length > number
              ? trimmedProName.slice(0, number)
              : trimmedProName;
          const remaining =
            trimmedProName.length > number ? trimmedProName.slice(number) : "";
          return { truncated, remaining }; // 返回结果
        } else {
          // 如果 res 无效,使用默认值
          const truncated =
            trimmedProName.length > 35
              ? trimmedProName.slice(0, 35)
              : trimmedProName;
          const remaining =
            trimmedProName.length > 35 ? trimmedProName.slice(35) : "";
          return { truncated, remaining }; // 确保返回
      this.tableList.sort((a, b) => {
        // 如果标本类型相同,继续按照采样编号排序
        if (a.jyxh !== b.jyxh) {
          return order === "ascending" ? a.jyxh - b.jyxh : b.jyxh - a.jyxh;
        }
      } catch (error) {
        console.error("Error fetching data:", error);
        return { truncated: "", remaining: "" }; // 捕获错误时的返回值
      }
        return 0;
      });
    },
    /* getTruncatedName(proName) {
      getTxmmccd().then((res) => {
        console.log(res, 4545);
        const number = Number(res.msg);
        console.log(number, 4444);
        if (res) {
          const trimmedProName = proName.replace(/\s+/g, ""); // 去掉所有空格
          const truncated =
            trimmedProName.length > res.msg
              ? trimmedProName.slice(0, res.msg)
              : trimmedProName;
          const remaining =
            trimmedProName.length > res.msg
              ? trimmedProName.slice(res.msg)
              : "";
          return { truncated, remaining };
        } else {
          res.msg == "35";
        }
      }); */
    getTruncatedName(proName) {
      // 去掉所有空格
      const trimmedProName = proName.replace(/\s+/g, "");
    /* const trimmedProName = proName.replace(/\s+/g, ""); // 去掉所有空格
        const truncated =
          trimmedProName.length > 35
            ? trimmedProName.slice(0, 35)
            : trimmedProName;
        const remaining =
          trimmedProName.length > 35 ? trimmedProName.slice(35) : "";
        return { truncated, remaining }; */
    // },
      const number = this.msg;
      const truncated =
        trimmedProName.length > number
          ? trimmedProName.slice(0, number)
          : trimmedProName;
      let remaining =
        trimmedProName.length > number ? trimmedProName.slice(number) : "";
      if (remaining.length > number) {
        remaining = remaining.slice(0, number) + "...";
      }
      return { truncated, remaining }; // 返回结果
    },
    /* getTruncatedName(proName) {
      const trimmedProName = proName.replace(/\s+/g, ""); // 去掉所有空格
      const truncated =
        trimmedProName.length > 35
          ? trimmedProName.slice(0, 35)
          : trimmedProName;
      const remaining =
        trimmedProName.length > 35 ? trimmedProName.slice(35) : "";
      return { truncated, remaining };
    }, */
    // 示例的日期格式化方法
    formatDate(date) {
      const options = { year: "numeric", month: "2-digit", day: "2-digit" };
@@ -612,7 +596,7 @@
            return;
          } else {
            this.samplingList = response.data.list;
            console.log(this.samplingList, 888);
            // console.log(this.samplingList, 888);
            // 判断是否需要刷新右边表格
            this.$nextTick(() => {
              this.$refs.tb.toggleRowSelection(this.samplingList[0], true);
@@ -682,7 +666,6 @@
      this.resetForm("form");
    },
    hb() {
      // console.log(this.queryParams.tjNum);
      if (this.queryParams.tjNum != null) {
        this.handleQuery();
      }
@@ -750,13 +733,12 @@
    fetchData(cusId) {
      this.loading = true; // 显示加载状态
      console.log(this.tjStatus, 999);
      getCusCyList(cusId, this.tjStatus) // 调用API获取数据
        .then((response) => {
          if (response.data) {
            console.log(response, 2525);
            this.tableList = response.data; // 确认 list 存在后再进行赋值
            console.log(this.tableList, 123);
          } else {
            // 如果没有数据或 list 为空,清空表格并提示
            this.tableList = [];
@@ -770,35 +752,6 @@
        });
    },
    /* 点击合并按钮 */
    /* Merging() {
      // 检查是否选中了数据
      if (this.selectedRows.length === 0) {
        this.$message.error("至少选中一个人");
        return;
      }
      if (this.selectList.length === 0) {
        this.$message.error("请选择要合并项目");
        return;
      }
      // 获取 tableList 第一行的 specimenTypeCode 作为基准
      const baseSpecimenTypeCode = this.selectList[0].specimenTypeCode;
      // 检查 specimenTypeCode 是否一致
      const canMergeBySpecimenTypeCode = this.selectList.every(
        (row) => row.specimenTypeCode === baseSpecimenTypeCode
      );
      // 根据 canMergeBySpecimenTypeCode 判断是否合并
      if (canMergeBySpecimenTypeCode) {
        this.$message.success("合并成功。");
        console.log("合并的行:", this.selectedRows);
      } else {
        this.$message.error("项目的 不一致,无法合并!");
      }
    }, */
    /* 点击合并按钮 */
    Merging() {
      // 检查是否选中了数据
@@ -824,7 +777,7 @@
          mergeCaiYang(data).then((response) => {
            this.$message.success("合并成功。");
            console.log("合并的行:", this.selectedRows);
            // console.log("合并的行:", this.selectedRows);
            // this.getList();
            this.fetchData(this.selectedRows[0].cusId);
          });
@@ -846,7 +799,7 @@
        return;
      }
      console.log("撤销的已合并项目ID:", data);
      // console.log("撤销的已合并项目ID:", data);
      // 调用撤销采样的接口
      chexiaoCaiYang(data)
@@ -870,11 +823,9 @@
      try {
        // 请求接口并获取宽度值
        const widthResponse = await getTxmkd();
        console.log("从 getTxmkd 返回的响应:", widthResponse); // 打印后端返回值
        const barcodeWidth = `${Number(widthResponse.msg)}%` || "70%"; // 获取宽度值,默认使用 70%
        const jyxh = this.selectList.map((item) => item.jyxh);
        console.log(this.selectList, 999);
        await this.$nextTick(); // 确保 DOM 更新
@@ -923,6 +874,10 @@
                padding: 0; /* 重置所有元素的 margin 和 padding */
                box-sizing: border-box; /* 使内边距和边框包含在元素的总宽度和高度内 */
              }
              .name, .name1, .last, .tj, .last div span, .last p, .tj span {
                font-family: Arial, sans-serif !important; /* 重新指定字体 */
                font-weight: bold !important; /* 强制加粗 */
              }
              body {
                margin: 0;
                padding: 0;
@@ -935,6 +890,7 @@
                padding: 0;
                font-size: 18px;
                width: 70%;
                font-family: "Arial Black", sans-serif; /* 设置黑体 */
              }
              p {
                margin: 0;
@@ -952,20 +908,31 @@
                display: flex;
                font-size: 19px;
                justify-content: space-between;
                 font-family: "Arial Black", sans-serif; /* 设置黑体 */
                // font-weight: bold;
                // font-family: "Arial Black", sans-serif !important;
              }
              .last div span {
              // font-weight: bold;
                margin-left: 10px;
                // font-family: "Arial Black", sans-serif !important;
              }
              .last p {
                margin-left: 10px;
              // font-weight: bold;
                margin-left: 10px;
                // font-family: "Arial Black", sans-serif !important;
              }
                p {
                margin-left: 10px;
                // font-weight: bold;
                // font-family: "Arial Black", sans-serif !important;
              }
              .tj {
                width: 70%;
                display: flex;
                font-size: 19px;
                justify-content: space-between;
                 font-family: "Arial Black", sans-serif; /* 设置黑体 */
                // font-weight: bold;
                 font-family: "Arial Black", sans-serif !important;
              }
              .tj span {
                margin-left: 10px;
@@ -985,129 +952,6 @@
      }
    },
    // Collection() {
    // const jyxh = this.selectList.map((item) => item.jyxh);
    // const selectedData = this.selectList.map((item) => ({
    //   jyxh: item.jyxh,
    // }));
    // console.log(this.selectList, 999);
    // console.log(selectedData, 888);
    /* this.$nextTick(() => {
        jyxh.forEach((number, index) => {
          const barcodeContent = number; // 确保 jyxh 是有效的
          if (barcodeContent && barcodeContent !== "未提供体检号") {
            JsBarcode(`#barcode${index}`, barcodeContent, {
              format: "CODE128",
              width: 2,
              height: 50,
              displayValue: false,
            });
          } else {
            console.log(`条形码内容无效: ${barcodeContent}`); // 调试输出
          }
        });
      }); */
    /* this.$nextTick(() => {
        const barcodeElement = document.querySelector("#barcode");
        // const barcodeElements = selectedData.map((_, index) =>
        //   document.querySelector(`#barcode${index}`)
        // );
        if (barcodeElement) {
          barcodeElement.forEach((element) => {
            if (element) {
              console.log(element.innerHTML); // 打印条形码的内容,看看是否生成成功
            }
          });
        } else {
          console.log("条形码元素未找到");
        }
        const newWindow = window.open("", "_blank", "width=800,height=600");
        const printContents = document.getElementById("printSection").innerHTML;
        console.log(printContents); */
    // newWindow.document.write(`
    //  <html>
    //   <head>
    //     <title>Print Barcode</title>
    //     <style>
    //       @media print {
    //        * {
    //            margin: 0;
    //            padding: 0; /* 重置所有元素的 margin 和 padding */
    //            box-sizing: border-box; /* 使内边距和边框包含在元素的总宽度和高度内 */
    //          }
    //          body {
    //             margin: 0;
    //             padding: 0;
    //           }
    //           .barcode-container {
    //             // width: 100%; /* 根据需要调整 */
    //             // text-align: center; /* 确保条形码居中 */
    //           }
    //           .name,.name1 {
    //             padding: 0;
    //             // margin: -5px auto 0;
    //             // padding-left: 20px;
    //             font-size: 18px;
    //             width: 70%;
    //             // max-height: 3.6em;
    //             // display: -webkit-box;
    //             // -webkit-box-orient: vertical;
    //             // -webkit-line-clamp: 2;
    //             // overflow: hidden;
    //             // white-space: normal;
    //           }
    //           p {
    //             margin: 0;
    //             padding: 0;
    //           }
    //           svg {
    //             display: block;
    //             width: 70%;
    //             margin-left: 10mm;
    //             // margin: 0 auto;
    //             height: auto;
    //             margin-bottom: 0;
    //           }
    //           .last {
    //             width: 66%;
    //             display: flex;
    //             font-size: 19px;
    //             // margin-left: 20px;
    //             justify-content: space-between;
    //           }
    //           .last div span{
    //             margin-left: 10px
    //             }
    //             .last p{
    //             margin-left: 10px
    //             }
    //           .tj{
    //             width: 70%;
    //             display: flex;
    //             font-size: 19px;
    //             // margin-left: 10px;
    //             justify-content: space-between;
    //           }
    //           .tj span{
    //             margin-left:10px;
    //           }
    //       }
    //     </style>
    //   </head>
    //   <body>${printContents}</body>
    // </html>
    //   `);
    //     newWindow.document.close();
    //     newWindow.focus();
    //     newWindow.print();
    //     newWindow.close();
    //   });
    // },
    tableRowClassName({ row, rowIndex }) {
      for (let i = 0; i < this.selectList.length; i++) {
        if (row === this.selectList[i]) {
@@ -1117,7 +961,7 @@
    },
    handleChange(selection) {
      console.log(selection);
      // console.log(selection);
      this.selectList = selection;
@@ -1139,15 +983,30 @@
    // 确认采样
    Confirmreceipt() {
      let data = this.ids;
      if (data.length === 0) {
        // 如果没有已合并的项目,给出提示信息
        this.$message.error("没有已合并的项目可以撤销!");
        return;
      }
      confirmSampling(data).then((res) => {
        this.$modal.msgSuccess("采样成功");
        this.getList();
      console.log(this.ids, 999);
      const loadingInstance = this.$loading({
        lock: true, // 锁定屏幕
        text: "加载中...", // 加载文本
        spinner: "el-icon-loading", // 自定义加载图标
        background: "rgba(255, 255, 255, 0.7)", // 背景颜色
      });
      confirmSampling(this.ids)
        .then((res) => {
          if (res.code === 200) {
            this.$modal.msgSuccess("采样成功");
            this.Collection();
          }else{
            this.$message.error(res.msg)
          }
          // this.getList();
        })
        .catch((error) => {
          this.$message.error(res.msg);
        })
        .finally(() => {
          loadingInstance.close();
        });
    },
    // 单选按钮
@@ -1215,5 +1074,6 @@
.el-table .warning-row {
  background-color: #e5f3ff !important;
  /* font-weight: bold; */
}
</style>