lkk
2024-10-29 3f0a509bba98151a08f5abd057c7a6f77064f5bc
2024.10.29
3个文件已修改
394 ■■■■ 已修改文件
dist.zip 补丁 | 查看 | 原始文档 | blame | 历史
src/api/sampling/sampling.js 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/sampling/sampling/index.vue 382 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dist.zip
Binary files differ
src/api/sampling/sampling.js
@@ -36,7 +36,19 @@
    })
}
export function getTxmmccd() {
    return request({
        url: '/system/config/configKey/txmmccd',
        method: 'get',
    })
}
export function getTxmkd() {
    return request({
        url: '/system/config/configKey/txmkd',
        method: 'get',
    })
}
// 确认采样接口
export function confirmSampling(data) {
    return request({
src/views/sampling/sampling/index.vue
@@ -274,7 +274,12 @@
        <!-- 动态生成多个条形码的容器 -->
        <div v-for="(item, index) in selectList" :key="index">
          <svg :id="'barcode' + index"></svg>
          <div class="name">{{ item.proName }}</div>
          <!-- <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="last">
            <p>{{ item.cusName }}</p>
            <div>
@@ -347,10 +352,11 @@
  getCusCyList,
  mergeCaiYang,
  chexiaoCaiYang,
  getTxmmccd,
  getTxmkd,
} from "@/api/sampling/sampling";
import { getNewDateList } from "@/api/hosp/order";
import moment from "moment";
import ItemVue from "../../../layout/components/Sidebar/Item.vue";
export default {
  dicts: [
@@ -462,7 +468,80 @@
      );
    },
  },
  methods: {
    async getTruncatedName(proName) {
      try {
        const res = await getTxmmccd(); // 确保使用 async/await
        console.log(res, 4545);
        // 去掉所有空格
        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 }; // 确保返回
        }
      } catch (error) {
        console.error("Error fetching data:", error);
        return { truncated: "", remaining: "" }; // 捕获错误时的返回值
      }
    },
    /* 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";
        }
      }); */
    /* 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" };
      return new Date(date).toLocaleDateString(undefined, options);
    },
    getdate() {
      getNewDateList().then((res) => {
        this.createTimeList = [
@@ -784,20 +863,21 @@
        .catch((error) => {
          this.$message.error("请求失败,请重试!");
        });
      // chexiaoCaiYang(data).then((res) => {});
    },
    /** 点击补打条码按钮 **/
    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);
    async Collection() {
      try {
        // 请求接口并获取宽度值
        const widthResponse = await getTxmkd();
        console.log("从 getTxmkd 返回的响应:", widthResponse); // 打印后端返回值
        const barcodeWidth = `${Number(widthResponse.msg)}%` || "70%"; // 获取宽度值,默认使用 70%
      this.$nextTick(() => {
        const jyxh = this.selectList.map((item) => item.jyxh);
        console.log(this.selectList, 999);
        await this.$nextTick(); // 确保 DOM 更新
        jyxh.forEach((number, index) => {
          const barcodeContent = number; // 确保 jyxh 是有效的
          if (barcodeContent && barcodeContent !== "未提供体检号") {
@@ -811,9 +891,125 @@
            console.log(`条形码内容无效: ${barcodeContent}`); // 调试输出
          }
        });
      });
      this.$nextTick(() => {
        await this.$nextTick(); // 确保条形码生成完成
        const barcodeElements = jyxh.map((_, index) =>
          document.querySelector(`#barcode${index}`)
        );
        if (barcodeElements) {
          barcodeElements.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;
                font-size: 18px;
                width: 70%;
              }
              p {
                margin: 0;
                padding: 0;
              }
              svg {
                display: block;
                width: ${barcodeWidth}; /* 使用从接口获取的宽度 */
                margin-left: 10mm;
                height: auto;
                margin-bottom: 0;
              }
              .last {
                width: 66%;
                display: flex;
                font-size: 19px;
                justify-content: space-between;
                 font-family: "Arial Black", sans-serif; /* 设置黑体 */
              }
              .last div span {
                margin-left: 10px;
              }
              .last p {
                margin-left: 10px;
              }
              .tj {
                width: 70%;
                display: flex;
                font-size: 19px;
                justify-content: space-between;
                 font-family: "Arial Black", sans-serif; /* 设置黑体 */
              }
              .tj span {
                margin-left: 10px;
              }
            }
          </style>
        </head>
        <body>${printContents}</body>
      </html>
    `);
        newWindow.document.close();
        newWindow.focus();
        newWindow.print();
        newWindow.close();
      } catch (error) {
        console.error("获取宽度时出错:", error); // 捕获错误
      }
    },
    // 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}`)
@@ -831,81 +1027,86 @@
        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 {
                  padding: 0;
                  margin: -5px auto 0;
                  padding-left: 20px;
                  font-size: 18px;
                  width: 90%;
                  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: 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
                  }
                .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();
      });
    },
        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++) {
@@ -917,7 +1118,7 @@
    handleChange(selection) {
      console.log(selection);
      this.selectList = selection;
      this.ids = selection.map((item) => item.id);
@@ -1015,5 +1216,4 @@
.el-table .warning-row {
  background-color: #e5f3ff !important;
}
</style>