From b06a903d08d6f5432105d12686ccaf074b45323a Mon Sep 17 00:00:00 2001
From: lkk <364857242@qq.com>
Date: 星期四, 24 十月 2024 08:58:35 +0800
Subject: [PATCH] lkk 10.24

---
 src/views/sampling/sampling/index.vue |  490 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 445 insertions(+), 45 deletions(-)

diff --git a/src/views/sampling/sampling/index.vue b/src/views/sampling/sampling/index.vue
index 29cedaf..2d42182 100644
--- a/src/views/sampling/sampling/index.vue
+++ b/src/views/sampling/sampling/index.vue
@@ -67,13 +67,13 @@
           @click="handleQuery"
           >鏌ヨ</el-button
         >
-        <el-button
+        <!-- <el-button
           type="primary"
           icon="el-icon-thumb"
           size="mini" style="margin:0 15px;"
           @click="Confirmreceipt"
           >纭閲囨牱</el-button
-        >
+        > -->
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
           >閲嶇疆</el-button
         >
@@ -90,9 +90,43 @@
           <el-radio-button label="0">宸查噰鏍�</el-radio-button>
         </el-radio-group>
       </el-col>
-      <el-col :span="12" v-if="tableList.length > 1 && tjStatus == 0">
-        <el-button type="primary" plain v-hasPermi="['hosp:detail:add']"
-          >鍚堝苟鏍锋湰</el-button
+      <el-col
+        :span="12"
+        style="margin: 10px 15px"
+        v-if="samplingList.length > 0 && tjStatus == 1"
+      >
+        <el-button type="primary" @click="Merging">鍚堝苟椤圭洰</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-col>
+      <el-col
+        :span="12"
+        style="margin: 10px 15px"
+        v-show="samplingList.length > 0 && tjStatus == 0"
+      >
+        <el-button
+          type="primary"
+          :disabled="!selectList.length"
+          @click="Collection"
+          >琛ユ墦鏉$爜</el-button
+        >
+        <el-button type="primary" :disabled="!disabled" @click="Cancellation"
+          >鎾ら攢鍚堝苟</el-button
         >
       </el-col>
     </el-row>
@@ -101,7 +135,7 @@
       <div style="width: 40%; margin-right: 20px">
         <el-table
           id="ta"
-          v-loading="loading"
+          v-loading="loading1"
           ref="tb"
           :data="samplingList"
           @selection-change="handleSelectionChange"
@@ -113,19 +147,19 @@
           <el-table-column
             label="浣撴鍙�"
             align="center"
-            prop="customer.tjNumber"
+            prop="tjNumber"
             width="160px"
           />
           <el-table-column
             label="濮撳悕"
             align="center"
-            prop="customer.cusName"
+            prop="cusName"
             width="80px"
           />
           <el-table-column
             label="鎬у埆"
             align="center"
-            prop="customer.cusSex"
+            prop="cusSex"
             width="60px"
           >
             <!-- <template slot-scope="scope">
@@ -140,17 +174,17 @@
           <el-table-column
             label="鎵嬫満鍙�"
             align="center"
-            prop="customer.cusPhone"
+            prop="cusPhone"
             width="120px"
           />
           <el-table-column
             label="鐢宠鏃堕棿"
             align="center"
-            prop="customer.applicationTime"
+            prop="applicationTime"
             width="210"
           >
             <template slot-scope="scope">
-              <span>{{ parseTime(scope.row.customer.applicationTime) }}</span>
+              <span>{{ parseTime(scope.row.applicationTime) }}</span>
             </template>
           </el-table-column>
         </el-table>
@@ -180,34 +214,37 @@
             prop="specimenType"
             width="120"
           >
-            <template slot-scope="scope">
-              <dict-tag
-                :options="dict.type.sys_dict_specimen"
-                :value="scope.row.specimenType"
-              />
-            </template>
           </el-table-column>
-          <el-table-column label="椤圭洰鍚嶇О" align="center" prop="proName" />
           <el-table-column
+            label="閲囨牱缂栧彿"
+            align="center"
+            prop="jyxh"
+            :show-overflow-tooltip="true"
+            width="120"
+          />
+          <el-table-column label="椤圭洰鍚嶇О" align="center" prop="proName" />
+          <!-- <el-table-column
             label="鎬у埆"
             align="center"
             prop="proSex"
             width="90"
-          />
+          /> -->
           <el-table-column
-            label="绌鸿吂"
+            label="鏄惁鍚堝苟"
             align="center"
-            prop="proCheckMethod"
+            prop="isMerge"
             width="90"
-          />
-          <el-table-column
-            label="閲囨牱缂栧彿"
-            align="center"
-            prop="samplingNumber"
-            :show-overflow-tooltip="true"
-            width="120"
-          />
-          <el-table-column
+          >
+            <template slot-scope="scope">
+              <span
+                :style="{ color: scope.row.isMerge === 0 ? '' : '#409EFF' }"
+              >
+                {{ scope.row.isMerge === 0 ? "鏈悎骞�" : "宸插悎骞�" }}
+              </span>
+            </template>
+          </el-table-column>
+
+          <!-- <el-table-column
             label="閲囨牱鐘舵��"
             align="center"
             prop="isSignFor"
@@ -219,7 +256,7 @@
                 :value="scope.row.isSignFor"
               />
             </template>
-          </el-table-column>
+          </el-table-column> -->
           <!-- <el-table-column label="鎿嶄綔" align="center" class-name="small-padding fixed-width">
                 <template slot-scope="scope">
                     <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
@@ -231,6 +268,29 @@
                 </template>
             </el-table-column> -->
         </el-table>
+      </div>
+
+      <div id="printSection" style="display: none">
+        <!-- 鍔ㄦ�佺敓鎴愬涓潯褰㈢爜鐨勫鍣� -->
+        <div v-for="(item, index) in selectList" :key="index">
+          <svg :id="'barcode' + index"></svg>
+          <div class="name">{{ item.proName }}</div>
+          <div class="last">
+            <p>{{ item.cusName }}</p>
+            <div>
+              <span>{{ item.customer.cusSex == 0 ? "鐢�" : "濂�" }}</span>
+              <span>{{ item.customer.age }}</span>
+            </div>
+          </div>
+          <div class="tj">
+            <span>浣撴涓績</span>
+            <span>{{ item.cardId.substring(0, 14) }}</span>
+          </div>
+          <div class="tj">
+            <span>{{ item.jyxh }}</span>
+            <span>{{ formatDate(item.applicationTime) }}</span>
+          </div>
+        </div>
       </div>
     </div>
     <!-- 
@@ -284,9 +344,13 @@
   addSampling,
   updateSampling,
   confirmSampling,
+  getCusCyList,
+  mergeCaiYang,
+  chexiaoCaiYang,
 } 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: [
@@ -300,10 +364,12 @@
   data() {
     return {
       list: [],
-      selectList: "",
+      selectList: [],
+      selectedRows: [],
       createTimeList: [],
       // 閬僵灞�
       loading: true,
+      loading1: true,
       // 閫変腑鏁扮粍
       ids: [],
       // 缁戝畾鍗曢�夋寜閽�
@@ -380,13 +446,21 @@
   },
   created() {
     // this.getNowTime();
-   
+
     this.getdate();
   },
   mounted() {
     this.$nextTick(() => {
       this.$refs.inputName.focus();
     });
+  },
+  computed: {
+    disabled() {
+      return (
+        this.selectList.length > 0 &&
+        this.selectList[this.selectList.length - 1].isMerge === 1
+      );
+    },
   },
   methods: {
     getdate() {
@@ -429,19 +503,53 @@
     dateChangebirthday1(val) {
       this.createTimeList = val;
     },
+    formatDate(applicationTime) {
+      // 纭繚 applicationTime 鏄湁鏁堢殑瀛楃涓�
+      if (applicationTime) {
+        return applicationTime.split(" ")[0]; // 閫氳繃绌烘牸鍒嗛殧鏃ユ湡鍜屾椂闂达紝鍙繑鍥炴棩鏈熼儴鍒�
+      }
+      return ""; // 濡傛灉 applicationTime 鏃犳晥锛岃繑鍥炵┖瀛楃涓�
+    },
     /** 鏌ヨ浣撴閲囨牱绠$悊鍒楄〃 */
     getList() {
-      this.loading = true;
+      this.loading1 = true;
       this.queryParams.isSignFor = this.tjStatus;
-      if(this.createTimeList){
+
+      if (this.createTimeList) {
         this.queryParams.beginTime = this.createTimeList[0];
-      this.queryParams.endTime = this.createTimeList[1];
-      }else if(this.createTimeList == null){
+        this.queryParams.endTime = this.createTimeList[1];
+      } else if (this.createTimeList == null) {
         this.queryParams.beginTime = null;
-      this.queryParams.endTime = null;
+        this.queryParams.endTime = null;
       }
-     
       getList(this.queryParams).then((response) => {
+        this.loading1 = false;
+        if (response.data) {
+          if (!response.data.list || response.data.list.length === 0) {
+            this.samplingList = [];
+            this.tableList = [];
+            this.loading1 = false;
+            this.loading = false;
+            return;
+          } else {
+            this.samplingList = response.data.list;
+            console.log(this.samplingList, 888);
+            // 鍒ゆ柇鏄惁闇�瑕佸埛鏂板彸杈硅〃鏍�
+            this.$nextTick(() => {
+              this.$refs.tb.toggleRowSelection(this.samplingList[0], true);
+              this.fetchData(this.samplingList[0].cusId);
+            });
+          }
+          this.total = response.data.total;
+          this.loading1 = false;
+        } else {
+          this.samplingList = [];
+          this.tableList = [];
+          this.loading1 = false;
+        }
+      });
+
+      /* getList(this.queryParams).then((response) => {
         if (response.data) {
           if (response.data.list == null) {
             this.samplingList = [];
@@ -449,6 +557,8 @@
             this.loading = false;
           } else {
             this.samplingList = response.data.list;
+            console.log(this.samplingList,888);
+            
             this.loading = false;
             if (this.samplingList.length != 0) {
               this.$nextTick(() => {
@@ -465,9 +575,8 @@
           this.tableList = [];
           this.loading = false;
         }
-      });
+      }); */
     },
-
     // 鍙栨秷鎸夐挳
     cancel() {
       this.open = false;
@@ -506,15 +615,17 @@
     },
     /** 閲嶇疆鎸夐挳鎿嶄綔 */
     resetQuery() {
-      this.createTimeList=[]
+      this.createTimeList = [];
       this.resetForm("queryForm");
       this.handleQuery();
     },
     // 鍗曢�夋閫変腑鏁版嵁
-    handleSelectionChange(selection) {
+    /* handleSelectionChange(selection) {
       this.selectList = selection;
       selection.forEach((element) => {
         this.tableList = element.list;
+        console.log(this.tableList, 111);
+
         if (this.tableList.length != 0) {
           this.$nextTick(() => {
             this.$refs.tab1.toggleAllSelection(this.tableList, true);
@@ -530,7 +641,272 @@
       }
       this.single = selection.length !== 1;
       this.multiple = !selection.length;
+    }, */
+
+    handleSelectionChange(selection) {
+      // 娓呯┖鍙充晶琛ㄦ牸鐨勬暟鎹�
+      this.tableList = [];
+
+      // 鍙湁涓�涓汉琚�変腑鏃惰繘琛屾搷浣�
+      if (selection.length === 1) {
+        const selectedPerson = selection[0]; // 鑾峰彇閫変腑鐨勯偅涓汉
+        const cusId = selectedPerson.cusId; // 鍋囪cusId鍦ㄩ�変腑鐨勫璞′腑
+
+        this.fetchData(cusId);
+      } else {
+        // 濡傛灉閫変腑澶氫汉锛屽垯鍙栨秷閫変腑
+        if (selection.length > 1) {
+          let del_row = selection.shift();
+          this.$refs.tb.toggleRowSelection(del_row, false); // 璁剧疆杩欎竴琛屽彇娑堥�変腑
+        }
+      }
+
+      // 鏇存柊閫夋嫨鐘舵��
+      this.single = selection.length === 1;
+      this.multiple = selection.length === 0;
+
+      this.selectedRows = selection;
     },
+
+    fetchData(cusId) {
+      this.loading = true; // 鏄剧ず鍔犺浇鐘舵��
+
+      console.log(this.tjStatus, 999);
+
+      getCusCyList(cusId, this.tjStatus) // 璋冪敤API鑾峰彇鏁版嵁
+        .then((response) => {
+          if (response.data) {
+            this.tableList = response.data; // 纭 list 瀛樺湪鍚庡啀杩涜璧嬪��
+            console.log(this.tableList, 123);
+          } else {
+            // 濡傛灉娌℃湁鏁版嵁鎴� list 涓虹┖锛屾竻绌鸿〃鏍煎苟鎻愮ず
+            this.tableList = [];
+          }
+        })
+        .catch((error) => {
+          console.error("Error fetching data:", error);
+        })
+        .finally(() => {
+          this.loading = false; // 闅愯棌鍔犺浇鐘舵��
+        });
+    },
+
+    /* 鐐瑰嚮鍚堝苟鎸夐挳 */
+    /* 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() {
+      // 妫�鏌ユ槸鍚﹂�変腑浜嗘暟鎹�
+      if (this.selectedRows.length === 0) {
+        this.$message.error("鑷冲皯閫変腑涓�涓汉");
+        return;
+      }
+      if (this.selectList.length === 0) {
+        this.$message.error("璇烽�夋嫨瑕佸悎骞堕」鐩�");
+        return;
+      }
+      if (this.selectList.every((item) => item.isMerge === 0)) {
+        const baseSpecimenTypeCode = this.selectList[0].specimenTypeCode;
+
+        // 妫�鏌� specimenTypeCode 鏄惁涓�鑷�
+        const canMergeBySpecimenTypeCode = this.selectList.every(
+          (row) => row.specimenTypeCode === baseSpecimenTypeCode
+        );
+
+        // 鏍规嵁 canMergeBySpecimenTypeCode 鍒ゆ柇鏄惁鍚堝苟
+        if (canMergeBySpecimenTypeCode) {
+          let data = this.ids;
+
+          mergeCaiYang(data).then((response) => {
+            this.$message.success("鍚堝苟鎴愬姛銆�");
+            console.log("鍚堝苟鐨勮:", this.selectedRows);
+            // this.getList();
+            this.fetchData(this.selectedRows[0].cusId);
+          });
+        } else {
+          this.$message.error("鏍囨湰绫诲瀷涓嶄竴鑷达紝鏃犳硶鍚堝苟锛�");
+        }
+      } else {
+        this.$message.error("璇ラ」鐩凡鍚堝苟");
+      }
+    },
+
+    /** 鐐瑰嚮鎾ら攢鎸夐挳 **/
+    Cancellation() {
+      let data = this.ids;
+      console.log("鎾ら攢");
+      if (data.length === 0) {
+        // 濡傛灉娌℃湁宸插悎骞剁殑椤圭洰锛岀粰鍑烘彁绀轰俊鎭�
+        this.$message.error("娌℃湁宸插悎骞剁殑椤圭洰鍙互鎾ら攢锛�");
+        return;
+      }
+
+      console.log("鎾ら攢鐨勫凡鍚堝苟椤圭洰ID:", data);
+
+      // 璋冪敤鎾ら攢閲囨牱鐨勬帴鍙�
+      chexiaoCaiYang(data)
+        .then((res) => {
+          if (res && res.code === 200) {
+            this.$message.success("鎾ら攢鎴愬姛锛�");
+            // 鍒锋柊鏁版嵁鍒楄〃鎴栬繘琛屽叾浠栨搷浣�
+            // this.getList();
+            this.fetchData(this.selectedRows[0].cusId);
+          } else {
+            this.$message.error(res.msg || "鎾ら攢澶辫触锛岃閲嶈瘯锛�");
+          }
+        })
+        .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);
+
+      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 {
+                  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();
+      });
+    },
+
     tableRowClassName({ row, rowIndex }) {
       for (let i = 0; i < this.selectList.length; i++) {
         if (row === this.selectList[i]) {
@@ -540,7 +916,16 @@
     },
 
     handleChange(selection) {
+      console.log(selection);
+      selection.forEach((item, index) => {
+        if (item.cusSex == 0) {
+          item.cusSex = "鐢�";
+        } else if (item.cusSex == 1) {
+          item.cusSex = "濂�";
+        }
+      });
       this.selectList = selection;
+
       this.ids = selection.map((item) => item.id);
     },
 
@@ -559,6 +944,11 @@
     // 纭閲囨牱
     Confirmreceipt() {
       let data = this.ids;
+      if (data.length === 0) {
+        // 濡傛灉娌℃湁宸插悎骞剁殑椤圭洰锛岀粰鍑烘彁绀轰俊鎭�
+        this.$message.error("娌℃湁宸插悎骞剁殑椤圭洰鍙互鎾ら攢锛�");
+        return;
+      }
       confirmSampling(data).then((res) => {
         this.$modal.msgSuccess("閲囨牱鎴愬姛");
         this.getList();
@@ -629,6 +1019,16 @@
 }
 
 .el-table .warning-row {
-  background: #e5f3ff !important;
+  background-color: #e5f3ff !important;
 }
+/* .last {
+  display: flex;
+  justify-content: space-around;
+  justify-content: space-evenly;
+  background-color:aqua
+} */
+/* .last p:nth-child(2) {
+  margin: 20px;
+  font-size: 16px;
+} */
 </style>

--
Gitblit v1.8.0