qx
wwl
2025-02-08 00865e5de8d4bc31caa931de063b71acdbb26266
src/views/sampling/sampling/index.vue
@@ -1,46 +1,24 @@
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="体检号" prop="tjNumber">
        <el-input
          ref="inputName"
          v-model="queryParams.tjNumber"
          placeholder="请输入体检号"
          clearable
          @keyup.enter.native="handleQuery"
          @blur="hb"
          style="width: 170px"
        />
        <el-input ref="inputName" v-model="queryParams.tjNumber" placeholder="请输入体检号" clearable
          @keyup.enter.native="handleQuery" @blur="hb" style="width: 170px" />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
          style="width: 110px"
        />
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery"
          style="width: 110px" />
      </el-form-item>
      <el-form-item label="申请时间" prop="applicationTime">
        <el-date-picker
          v-model="createTimeList"
          @change="dateChangebirthday1"
          :default-time="['00:00:00', '23:00:00']"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
        ></el-date-picker>
        <el-date-picker v-model="createTimeList" @change="dateChangebirthday1" :default-time="['00:00:00', '23:00:00']"
          format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>
      <el-form-item label="单位名称" prop="tjCompName" style="margin-left: 20px; margin-right: 500px">
        <el-select :remote-method="getRemoteData" v-model="queryParams.tjCompName" value-key="drugManufacturerId"
          style="width: 200px" remote filterable placeholder="请选择单位名称" clearable @change="searchSelect">
          <el-option v-for="dict in CompanyList" :key="dict.drugManufacturerId" :label="dict.cnName" :value="dict" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="是否采样" prop="isSignFor">
                    <el-select style="width:100px" v-model="queryParams.isSignFor" placeholder="是否采样">
@@ -60,13 +38,7 @@
                <el-input v-model="queryParams.proName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" style="width: 140px;"/>
            </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >查询</el-button
        >
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <!-- <el-button
          type="primary"
          icon="el-icon-thumb"
@@ -74,31 +46,17 @@
          @click="Confirmreceipt"
          >确认采样</el-button
        > -->
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="10">
        <el-radio-group
          v-model="tjStatus"
          @input="radioChange"
          style="margin: 10px 15px"
        >
          <el-radio-button label="1" :disabled="qiehuan && disabledId === 0"
            >未采样</el-radio-button
          >
          <el-radio-button label="0" :disabled="qiehuan && disabledId === 1"
            >已采样</el-radio-button
          >
        <el-radio-group v-model="tjStatus" @input="radioChange" style="margin: 10px 15px">
          <el-radio-button label="1" :disabled="qiehuan && disabledId === 0">未采样</el-radio-button>
          <el-radio-button label="0" :disabled="qiehuan && disabledId === 1">已采样</el-radio-button>
        </el-radio-group>
      </el-col>
      <el-col
        :span="12"
        style="margin: 10px 15px"
        v-if="samplingList.length > 0 && tjStatus == 1"
      >
      <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"
@@ -108,59 +66,25 @@
          @click="Confirmreceipt"
          >确认采样</el-button
        > -->
        <el-button type="primary" :disabled="!disabled" @click="Cancellation"
          >撤销合并</el-button
        >
        <el-button type="primary" :disabled="!disabled" @click="Cancellation">撤销合并</el-button>
        <el-button type="primary" @click="Confirmreceipt" :disabled="!selectList.length">采样打码</el-button>
        <el-button type="primary" @click="piliangPrint" :disabled="!isAllSelected">批量打印</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 :span="12" style="margin: 10px 15px" v-show="samplingList.length > 0 && tjStatus == 0">
        <el-button type="primary" :disabled="!selectList.length" @click="buda">补打条码</el-button>
        <!-- @click="Collection" -->
        <el-button type="primary" :disabled="!disabled" @click="Cancellation">撤销合并</el-button>
      </el-col>
    </el-row>
    <div style="width: 100%; margin-left: 10px; display: flex">
      <div style="width: 40%; margin-right: 20px">
        <el-table
          id="ta"
          v-loading="loading1"
          ref="tb"
          :data="samplingList"
          @selection-change="handleSelectionChange"
          border
          height="520px"
          :row-class-name="tableRowClassName"
        >
          <el-table-column type="selection" width="40" align="center" />
          <el-table-column
            label="体检号"
            align="center"
            prop="tjNumber"
            width="160px"
          />
          <el-table-column
            label="姓名"
            align="center"
            prop="cusName"
            width="80px"
          />
          <el-table-column
            label="性别"
            align="center"
            prop="cusSex"
            width="60px"
          >
        <el-table id="ta" v-loading="loading1" ref="tb" :data="samplingList" @selection-change="handleSelectionChange"
          border height="520px" :row-class-name="tableRowClassName">
          <el-table-column type="selection" width="40" align="center" :selectable="selectable" />
          <el-table-column label="体检号" align="center" prop="tjNumber" width="160px" />
          <el-table-column label="姓名" align="center" prop="cusName" width="80px" />
          <el-table-column label="性别" align="center" prop="cusSex" width="60px">
            <!-- <template slot-scope="scope">
              {{ scope.row.customer.cusSex === 0 ? "男" : "女" }}
            </template> -->
@@ -170,36 +94,19 @@
              <span v-if="scope.row.cusSex == '2'">未知</span>
            </template>
          </el-table-column>
          <el-table-column
            label="手机号"
            align="center"
            prop="cusPhone"
            width="120px"
          />
          <el-table-column
            label="申请时间"
            align="center"
            prop="applicationTime"
            width="210"
          >
          <el-table-column label="手机号" align="center" prop="cusPhone" width="120px" />
          <el-table-column label="单位名称" align="center" prop="firmName" width="120px" />
          <el-table-column label="申请时间" align="center" prop="applicationTime" width="210">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.applicationTime) }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div style="width: 50%" v-if="this.rightTabShow">
        <el-table
          v-loading="loading"
          :data="tableList"
          @selection-change="handleChange"
          :span-method="objectSpanMethod"
          ref="tab1"
          :row-class-name="tableRowClassName"
          border
          height="520px"
        >
      <div style="width: 50%">
        <!-- v-if="this.rightTabShow" -->
        <el-table v-loading="loading" :data="tableList" @selection-change="handleChange" :span-method="objectSpanMethod"
          ref="tab1" :row-class-name="tableRowClassName" border height="520px">
          <el-table-column type="selection" width="40" align="center" />
          <!--  :selectable="selectEnable" -->
          <!-- <el-table-column label="是否签收" align="center" prop="isSignFor" /> -->
@@ -208,20 +115,9 @@
                    <span>{{ parseTime(scope.row.tjTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column> -->
          <el-table-column
            label="标本类型"
            align="center"
            prop="specimenType"
            width="120"
          >
          <el-table-column label="标本类型" align="center" prop="specimenType" width="120">
          </el-table-column>
          <el-table-column
            label="采样编号"
            align="center"
            prop="jyxh"
            :show-overflow-tooltip="true"
            width="120"
          />
          <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="性别"
@@ -229,16 +125,9 @@
            prop="proSex"
            width="90"
          /> -->
          <el-table-column
            label="是否合并"
            align="center"
            prop="isMerge"
            width="90"
          >
          <el-table-column label="是否合并" align="center" prop="isMerge" width="90">
            <template slot-scope="scope">
              <span
                :style="{ color: scope.row.isMerge === 0 ? '' : '#409EFF' }"
              >
              <span :style="{ color: scope.row.isMerge === 0 ? '' : '#409EFF' }">
                {{ scope.row.isMerge === 0 ? "未合并" : "已合并" }}
              </span>
            </template>
@@ -312,35 +201,11 @@
      <!-- <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :pager-count="5" :current-page.sync="currentPage1" :current-page="page"
                :page-sizes="pageSize" :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination> -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 添加或修改体检采样管理对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="申请时间" prop="applicationTime">
                    <el-date-picker clearable v-model="form.applicationTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择申请时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="项目id父项" prop="proId">
                    <el-input v-model="form.proId" placeholder="请输入项目id父项" />
                </el-form-item>
                <el-form-item label="项目名称" prop="proName">
                    <el-input v-model="form.proName" placeholder="请输入项目名称" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog> -->
  </div>
</template>
@@ -361,7 +226,12 @@
} from "@/api/sampling/sampling";
import { getNewDateList } from "@/api/hosp/order";
import moment from "moment";
import {
  SubmitCompany,
  getCompany,
  queryCompany,
  addbatch,
} from "@/api/team/tuanti";
export default {
  dicts: [
    "sys_user_sex",
@@ -373,8 +243,14 @@
  name: "Sampling",
  data() {
    return {
      CheckBox: {},
      CompanyList: [],
      piliangList: [],
      msg: "",
      getNumbr: null,
      valueUrl: "ws://192.168.1.138:6789/websocket",
      webSocket: null,
      list: [],
      selectList: [],
      selectedRows: [],
@@ -386,6 +262,9 @@
      ids: [],
      // 绑定单选按钮
      tjStatus: "1",
      dayinData: [],
      jsonObj: {},
      // 非单个禁用
      single: true,
      // 非多个禁用
@@ -454,15 +333,21 @@
      form: {},
      // 表单校验
      rules: {},
      rightTabShow: false
      // rightTabShow: false
      allSelected: false,
      disableSelections: false, // 控制选择禁用状态
    };
  },
  created() {
    // this.getNowTime();
    getTxmmccd().then((res) => {
      this.msg = Number(res.msg);
      console.log(res,444);
      console.log(res, 444);
    });
    getCompany(this.queryParams).then((response) => {
      this.CompanyList = response.data;
      this.loading = false;
    });
    this.getdate();
  },
@@ -470,7 +355,6 @@
    this.$nextTick(() => {
      this.$refs.inputName.focus();
    });
  },
  computed: {
    disabled() {
@@ -485,9 +369,53 @@
    disabledId() {
      return this.tjStatus == "1" ? 1 : 0;
    },
    isAllSelected() {
      return this.samplingList.length > 0 && this.selectedRows.length === this.samplingList.length;
    },
  },
  methods: {
    // 选框数据
    searchSelect(val) {
      this.CheckBox = val;
      this.queryParams.dw = this.CheckBox.cnName;
      console.log(this.CheckBox, 9999);
    },
    getRemoteData(query) {
      if (query) {
        let compName = query;
        queryCompany(compName).then((response) => {
          this.CompanyList = response.data;
          this.CompanyList.forEach((item) => {
            this.queryParams = item;
          });
        });
      }
    },
    async piliangPrint() {
      for (const item of this.piliangList) {
        try {
          // 获取数据,并等待数据更新完成
          const tableList = await this.fetchData(item.tjNumber);
          // 只保留最新两个元素
          if (tableList.length > 0) {
            this.selectList = tableList.slice(0, 2);
          } else {
            this.selectList = []; // 如果没有数据,清空selectList
          }
          // 使用更新后的tableList获取ids
          let ids = this.selectList.map(row => row.id);
          await this.Confirmreceipt1(ids);
          // 等待一段时间
          await new Promise(resolve => setTimeout(resolve, 5000));
        } catch (error) {
          console.error(`处理体检号 ${item.tjNumber} 时出错:`, error);
        }
      }
    },
    getTruncatedName(proName) {
      // 去掉所有空格
      const trimmedProName = proName.replace(/\s+/g, "");
@@ -572,6 +500,7 @@
    },
    /** 查询体检采样管理列表 */
    getList() {
      this.queryParams.compId = this.CheckBox.drugManufacturerId;
      this.loading1 = true;
      this.queryParams.isSignFor = this.tjStatus;
@@ -593,15 +522,16 @@
            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].tjNumber);
              // ddddddddddddddd
              this.rightTabShow = true
              // 检查是否全选
              if (this.samplingList.length === this.selectedRows.length) {
                this.disableSelections = true;
              } else {
                this.disableSelections = false;
              }
            });
          }
          this.total = response.data.total;
          this.loading1 = false;
@@ -679,76 +609,74 @@
      this.createTimeList = [];
      this.handleQuery();
    },
    // 单选框选中数据
    /* 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);
          });
        } else {
          this.$refs.tab1.clearSelection();
        }
      });
      // this.ids = selection.map(item => item.id)
      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;
    }, */
    handleSelectionChange(selection) {
      // 清空右侧表格的数据
      this.tableList = [];
      this.piliangList = selection;
      const selectedCount = selection.length;
      const totalCount = this.samplingList.length;
      // 只有一个人被选中时进行操作
      if (selection.length === 1) {
        const selectedPerson = selection[0]; // 获取选中的那个人
        const tjNumber = selectedPerson.tjNumber;
        console.log(selectedPerson.tjNumber, 6363);
      // 如果只有一条数据,不要禁用选择
      if (selectedCount === 1 && totalCount === 1) {
        this.disableSelections = false;
        this.fetchData(tjNumber);
      } else if (selectedCount === totalCount && selectedCount > 0) {
        // 全选时禁用选择新行
        this.disableSelections = true;
        this.tableList = [];
        this.$message.info('已全选所有行');
      } else {
        // 如果选中多人,则取消选中
        if (selection.length > 1) {
        // 非全选时启用选择
        this.disableSelections = false;
        if (selectedCount === 1) {
          const selectedPerson = selection[0];
          const tjNumber = selectedPerson.tjNumber;
          console.log(`选中的体检号: ${tjNumber}`);
          this.fetchData(tjNumber);
        } else if (selectedCount > 1) {
          // 保留单选功能,取消多选
          let del_row = selection.shift();
          this.$refs.tb.toggleRowSelection(del_row, false); // 设置这一行取消选中
          this.$refs.tb.toggleRowSelection(del_row, false);
        }
      }
      // 更新选择状态
      this.single = selection.length === 1;
      this.multiple = selection.length === 0;
      if (selectedCount === 0) {
        this.tableList = [];
      }
      // 更新单选和多选状态
      this.single = selectedCount === 1;
      this.multiple = selectedCount === 0;
      // 更新选中的行
      this.selectedRows = selection;
      // 调试日志
      console.log(`当前选中数量: ${selectedCount}`);
      console.log(`是否禁用选择: ${this.disableSelections}`);
    },
    fetchData(tjNumber) {
      this.loading = true; // 显示加载状态
      getCusCyList(tjNumber, this.tjStatus) // 调用API获取数据
        .then((response) => {
          if (response.data) {
            console.log(response, 2525);
            this.tableList = response.data; // 确认 list 存在后再进行赋值
          } else {
            // 如果没有数据或 list 为空,清空表格并提示
            this.tableList = [];
          }
        })
        .catch((error) => {
          console.error("Error fetching data:", error);
        })
        .finally(() => {
          this.loading = false; // 隐藏加载状态
        });
      return new Promise((resolve, reject) => {
        this.loading = true;
        getCusCyList(tjNumber, this.tjStatus)
          .then((response) => {
            if (response.data) {
              this.tableList = response.data;
              resolve(this.tableList);
            } else {
              this.tableList = [];
              resolve([]);
            }
          })
          .catch((error) => {
            console.error("Error fetching data:", error);
            reject(error);
          })
          .finally(() => {
            this.loading = false;
          });
      });
    },
    /* 点击合并按钮 */
@@ -819,17 +747,12 @@
    /** 点击补打条码按钮 **/
    async Collection() {
      // console.log("selectList:", this.selectList);
      const jyxh = this.selectList.map((item) => item.jyxh);
      console.log("jyxh:", jyxh);
      try {
        // 请求接口并获取宽度值
        const widthResponse = await getTxmkd();
        const barcodeWidth = `${Number(widthResponse.msg)}%` || "70%"; // 获取宽度值,默认使用 70%
        // const jyxh = this.selectList.map((item) => item.jyxh);
        // await this.$nextTick(); // 确保 DOM 更新
        jyxh.forEach((number, index) => {
          const barcodeContent = number; // 确保 jyxh 是有效的
@@ -864,7 +787,7 @@
        const newWindow = window.open("", "_blank", "width=800,height=600");
        const printContents = document.getElementById("printSection").innerHTML;
        // console.log(printContents);
        console.log(printContents);
        newWindow.document.write(`
      <html>
        <head>
@@ -920,11 +843,11 @@
              }
              .last p {
              // font-weight: bold;
                margin-left: 10px;
                margin-left: 1px;
                // font-family: "Arial Black", sans-serif !important; 
              }
                p {
                margin-left: 10px;
                margin-left: 1px;
                // font-weight: bold;
                // font-family: "Arial Black", sans-serif !important;  
              }
@@ -937,7 +860,7 @@
                 font-family: "Arial Black", sans-serif !important; 
              }
              .tj span {
                margin-left: 10px;
                margin-left: 1px;
              }
            }
          </style>
@@ -966,29 +889,51 @@
      // console.log(selection);
      this.selectList = selection;
      // console.log(this.selectList, 5555);
      console.log(this.selectList, 9977);
      var array = selection;
      this.ids = array.map((item) => item.id);
    },
    // 禁选
    // selectEnable(row, rowIndex) {
    //     if(row.isSignFor === "0"){
    //         return false
    //     }else{
    //         return true
    //     }
    // },
    // 确定按钮
    submitForm() {},
    buda() {
      var websocket = null;
      var url = this.valueUrl;
      if ("WebSocket" in window) {
        websocket = new WebSocket(url);
      } else if ("MozWebSocket" in window) {
        websocket = new MozWebSocket(url);
      }
      if (websocket == null) {
        alert("创建WebSocket对象失败");
      }
      websocket.onerror = function () {
        alert("请检查读卡器连接是否正常");
      };
      websocket.onopen = () => {
        this.websocket = websocket;
        this.dayinData = this.selectList.map((item) => ({
          jyxh: item.jyxh,
          proName: item.proName,
          cusName: item.cusName,
          cusSex: item.customer.cusSex,
          age: item.customer.age,
          cardId: item.cardId,
          tjTime: item.createTime,
        }));
        // 连接设备
        this.jsonObj = {
          type: "3",
          array: {
            data: this.dayinData,
          },
        };
        var jStr = JSON.stringify(this.jsonObj);
        this.websocket.send(jStr);
        this.jsonObj = {};
        // this.dialogVisible = false;
      };
      // this.getList();
    },
    // 确认采样
    Confirmreceipt() {
      let data = this.ids;
      console.log(this.ids, 999);
      const loadingInstance = this.$loading({
        lock: true, // 锁定屏幕
        text: "加载中...", // 加载文本
@@ -997,24 +942,37 @@
      });
      confirmSampling(this.ids)
        .then((res) => {
          if (res.code === 200) {
            // this.$modal.msgSuccess("采样成功");
          console.log(this.selectList, 2222);
            this.Collection();
          if (res.code === 200) {
            this.buda();
            this.getList();
          } else {
            this.$message.error(res.msg);
          }
          // this.getList();
        })
        .catch((error) => {
          // this.$message.error("采样失败");
        })
        .finally(() => {
          loadingInstance.close();
        });
    },
    Confirmreceipt1(ids) {
      confirmSampling(ids)
        .then((res) => {
          if (res.code === 200) {
            this.buda();
            this.getList();
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
        })
        .finally(() => {
          loadingInstance.close();
        });
    },
    // 单选按钮
    radioChange(value) {
      this.loading = true;
@@ -1068,14 +1026,35 @@
    },
    // 导出
    handleExport() {},
    handleExport() { },
    /** 控制行是否可选 */
    selectable(row, index) {
      if (this.disableSelections) {
        // 仅允许取消已选中的行
        return this.selectedRows.some(selectedRow => selectedRow.id === row.id);
      }
      return true; // 允许选择所有行
    },
    resetSelection() {
      this.$refs.tb.clearSelection();
      this.disableSelections = false;
      this.selectedRows = [];
      this.single = false;
      this.multiple = true;
      this.tableList = [];
      // 调试日志
      console.log(`重置选择,是否禁用选择: ${this.disableSelections}`);
    },
  },
};
</script>
<style>
#ta .el-table__header-wrapper .el-checkbox {
  display: none;
  /* display: none; */
}
.el-table .warning-row {