From caef1ff213da160e818342eceb3d77fac0db280d Mon Sep 17 00:00:00 2001 From: qx <1084500556@qq.com> Date: 星期五, 30 五月 2025 16:41:29 +0800 Subject: [PATCH] qx --- src/views/sampling/sampling/index.vue | 228 +++++++++++++++++++++++++++++++++----------------------- 1 files changed, 133 insertions(+), 95 deletions(-) diff --git a/src/views/sampling/sampling/index.vue b/src/views/sampling/sampling/index.vue index 0327f4e..8157f73 100644 --- a/src/views/sampling/sampling/index.vue +++ b/src/views/sampling/sampling/index.vue @@ -21,10 +21,10 @@ </el-select> </el-form-item> <!-- <el-form-item label="鏄惁閲囨牱" prop="isSignFor"> - <el-select style="width:100px" v-model="queryParams.isSignFor" placeholder="鏄惁閲囨牱"> + <el-select1 style="width:100px" v-model="queryParams.isSignFor" placeholder="鏄惁閲囨牱"> <el-option v-for="dict in dict.type.sampling_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option> - </el-select> + </el-select1> </el-form-item> --> <!-- <el-form-item label="浣撴鏃堕棿" prop="tjTime"> <el-date-picker clearable v-model="queryParams.tjTime" type="date" value-format="yyyy-MM-dd" @@ -105,8 +105,9 @@ </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"> + <el-table :key="tableKey" :row-key="getRowKey" v-if="tableList.length > 0" 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" /> --> @@ -197,7 +198,7 @@ :limit.sync="queryParams.pageSize" @pagination="getList" /> </div> --> - <div style="margin-right: 70%"> + <div style="margin-right: 50%"> <!-- <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> --> @@ -249,7 +250,7 @@ piliangList: [], msg: "", getNumbr: null, - valueUrl: "ws://192.168.1.138:6789/websocket", + valueUrl: "ws://127.0.0.1:6789/websocket", webSocket: null, list: [], selectList: [], @@ -331,6 +332,7 @@ }, // 琛ㄥ崟鍙傛暟 form: {}, + tableKey: "", // 琛ㄥ崟鏍¢獙 rules: {}, // rightTabShow: false @@ -393,6 +395,12 @@ } }, async piliangPrint() { + // 妫�鏌ユ槸鍚︽湁閫変腑鐨勬暟鎹� + if (this.piliangList.length === 0) { + this.$message.warning('璇峰厛閫夋嫨瑕佹墦鍗扮殑鏁版嵁'); + return; + } + const loadingInstance = this.$loading({ lock: true, text: '鎵撳嵃涓�...', @@ -406,15 +414,29 @@ // 鑾峰彇鏁版嵁锛屽苟绛夊緟鏁版嵁鏇存柊瀹屾垚 const tableList = await this.fetchData(item.tjNumber); - // 鍙繚鐣欐渶鏂颁袱涓厓绱� - if (tableList.length > 0) { - this.selectList = tableList.slice(0, 2); - } else { - this.selectList = []; // 濡傛灉娌℃湁鏁版嵁锛屾竻绌簊electList + // 妫�鏌� tableList 鏄惁鏈夋暟鎹� + if (!tableList || tableList.length === 0) { + console.error(`浣撴鍙� ${item.tjNumber} 鏃犵浉鍏虫暟鎹甡); + continue; } - // 浣跨敤鏇存柊鍚庣殑tableList鑾峰彇ids + // 鐩存帴浣跨敤鎵�鏈夋暟鎹� + this.selectList = tableList; + + // 妫�鏌� selectList 鏄惁鏈夋暟鎹� + if (this.selectList.length === 0) { + console.error(`浣撴鍙� ${item.tjNumber} 鐨� selectList 涓虹┖锛岃烦杩� WebSocket 鎿嶄綔`); + continue; + } + + // 浣跨敤鏇存柊鍚庣殑 tableList 鑾峰彇 ids let ids = this.selectList.map(row => row.id); + if (ids.length === 0) { + console.error(`浣撴鍙� ${item.tjNumber} 鏃犳湁鏁� ID`); + continue; + } + + // 纭閲囨牱 await this.Confirmreceipt1(ids); // 绛夊緟涓�娈垫椂闂� @@ -424,8 +446,8 @@ } } } finally { - this.ids = []; // 娓呯┖ids - this.selectList = []; // 娓呯┖selectList + this.ids = []; // 娓呯┖ ids + this.selectList = []; // 娓呯┖ selectList loadingInstance.close(); } }, @@ -512,6 +534,7 @@ return ""; // 濡傛灉 applicationTime 鏃犳晥锛岃繑鍥炵┖瀛楃涓� }, /** 鏌ヨ浣撴閲囨牱绠$悊鍒楄〃 */ + /** 鏌ヨ浣撴閲囨牱绠$悊鍒楄〃 */ getList() { this.queryParams.compId = this.CheckBox.drugManufacturerId; this.loading1 = true; @@ -520,68 +543,40 @@ if (this.createTimeList) { this.queryParams.beginTime = this.createTimeList[0]; this.queryParams.endTime = this.createTimeList[1]; - } else if (this.createTimeList == null) { + } else { this.queryParams.beginTime = 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; - // 鍒ゆ柇鏄惁闇�瑕佸埛鏂板彸杈硅〃鏍� - this.$nextTick(() => { - this.$refs.tb.toggleRowSelection(this.samplingList[0], true); - // 妫�鏌ユ槸鍚﹀叏閫� - if (this.samplingList.length === this.selectedRows.length) { - this.disableSelections = true; - } else { - this.disableSelections = false; - } - }); - } + if (response.data && response.data.list && response.data.list.length > 0) { + this.samplingList = response.data.list; this.total = response.data.total; - this.loading1 = false; - } else { - this.samplingList = []; - this.tableList = []; - this.loading1 = false; - } - }); + this.$nextTick(() => { + if (this.$refs.tb) { - /* getList(this.queryParams).then((response) => { - if (response.data) { - if (response.data.list == null) { - this.samplingList = []; - this.tableList = []; - this.loading = false; - } else { - this.samplingList = response.data.list; - console.log(this.samplingList,888); - - this.loading = false; - if (this.samplingList.length != 0) { - this.$nextTick(() => { - this.$refs.tb.toggleRowSelection(this.samplingList[0], true); - }); - } else { - this.$refs.tb.clearSelection(); + const headerCheckbox = this.$refs.tb.$el.querySelector('.el-table__header .el-checkbox'); + if (headerCheckbox) headerCheckbox.style.display = 'none'; + } - } - this.total = response.data.total; - this.loading = false; + }); + // 绉婚櫎榛樿閫変腑绗竴琛岀殑閫昏緫 + // this.$nextTick(() => { + // this.$refs.tb.toggleRowSelection(this.samplingList[0], true); // 榛樿閫変腑绗竴琛� + // this.fetchData(this.samplingList[0].tjNumber); // 鍒锋柊鍙充晶琛ㄦ牸 + // }); } else { this.samplingList = []; this.tableList = []; - this.loading = false; + this.selectList = []; // 娓呯┖ selectList + this.ids = []; // 娓呯┖ ids + if (this.$refs.tab1) { + this.$refs.tab1.clearSelection(); // 娓呯┖鍙充晶琛ㄦ牸閫変腑鐘舵�� + } } - }); */ + this.loading1 = false; + }); }, // 鍙栨秷鎸夐挳 cancel() { @@ -619,8 +614,19 @@ }, /** 閲嶇疆鎸夐挳鎿嶄綔 */ resetQuery() { - this.createTimeList = []; - this.handleQuery(); + this.createTimeList = []; // 娓呯┖鏃ユ湡鑼冨洿 + this.queryParams.tjNumber = null; // 娓呯┖浣撴鍙� + this.queryParams.name = null; // 娓呯┖濮撳悕 + this.queryParams.tjCompName = null; // 娓呯┖鍗曚綅鍚嶇О + this.selectList = []; // 娓呯┖鍙充晶閫変腑椤� + this.selectedRows = []; // 娓呯┖宸︿晶閫変腑椤� + this.tableList = []; // 娓呯┖鍙充晶琛ㄦ牸鏁版嵁 + this.ids = []; // 娓呯┖閫変腑鐨� ID + this.$refs.tb.clearSelection(); // 娓呯┖宸︿晶琛ㄦ牸閫変腑鐘舵�� + if (this.$refs.tab1) { + this.$refs.tab1.clearSelection(); // 娓呯┖鍙充晶琛ㄦ牸閫変腑鐘舵�� + } + this.handleQuery(); // 閲嶆柊鏌ヨ }, handleSelectionChange(selection) { @@ -628,11 +634,14 @@ const selectedCount = selection.length; const totalCount = this.samplingList.length; - // 濡傛灉鍙湁涓�鏉℃暟鎹紝涓嶈绂佺敤閫夋嫨 - if (selectedCount === 1 && totalCount === 1) { + // 濡傛灉鍙湁涓�鏉℃暟鎹紝涓嶈绂佺敤閫夋嫨锛屽苟灞曠ず鍙充晶鍒楄〃 + if (selectedCount === 1) { this.disableSelections = false; - - } else if (selectedCount === totalCount && selectedCount > 0) { + const selectedPerson = selection[0]; + const tjNumber = selectedPerson.tjNumber; + console.log(`閫変腑鐨勪綋妫�鍙�: ${tjNumber}`); + this.fetchData(tjNumber); + } else if (selectedCount === totalCount && selectedCount > 1) { // 鍏ㄩ�夋椂绂佺敤閫夋嫨鏂拌 this.disableSelections = true; this.tableList = []; @@ -640,13 +649,7 @@ } else { // 闈炲叏閫夋椂鍚敤閫夋嫨 this.disableSelections = false; - - if (selectedCount === 1) { - const selectedPerson = selection[0]; - const tjNumber = selectedPerson.tjNumber; - console.log(`閫変腑鐨勪綋妫�鍙�: ${tjNumber}`); - this.fetchData(tjNumber); - } else if (selectedCount > 1) { + if (selectedCount > 1) { // 淇濈暀鍗曢�夊姛鑳斤紝鍙栨秷澶氶�� let del_row = selection.shift(); this.$refs.tb.toggleRowSelection(del_row, false); @@ -669,6 +672,10 @@ console.log(`鏄惁绂佺敤閫夋嫨: ${this.disableSelections}`); }, + getRowKey(row) { + return row.id; // 蹇呴』鍞竴涓旂ǔ瀹� + }, + fetchData(tjNumber) { return new Promise((resolve, reject) => { this.loading = true; @@ -676,9 +683,24 @@ .then((response) => { if (response.data) { this.tableList = response.data; + this.tableKey = Date.now() + this.$nextTick(() => { + if (this.$refs.tab1) { + this.$refs.tab1.doLayout(); // 淇敼涓烘纭殑 ref 鍚嶇О + this.$refs.tab1.clearSelection(); // 娓呯┖閫変腑鐘舵�� + const headerCheckbox = this.$refs.tab1.$el.querySelector('.el-table__header .el-checkbox'); + if (headerCheckbox) headerCheckbox.style.display = 'inline'; + } + }); resolve(this.tableList); + this.loading = false; } else { this.tableList = []; + this.selectList = []; + this.ids = []; + if (this.$refs.tab1) { + this.$refs.tab1.clearSelection(); + } resolve([]); } }) @@ -899,10 +921,7 @@ }, handleChange(selection) { - // console.log(selection); - this.selectList = selection; - console.log(this.selectList, 9977); var array = selection; this.ids = array.map((item) => item.id); }, @@ -922,6 +941,7 @@ }; websocket.onopen = () => { this.websocket = websocket; + console.log(this.selectList, "this.selectList") this.dayinData = this.selectList.map((item) => ({ jyxh: item.jyxh, proName: item.proName, @@ -931,6 +951,8 @@ cardId: item.cardId, tjTime: item.createTime, })); + + // 杩炴帴璁惧 this.jsonObj = { type: "3", @@ -939,7 +961,12 @@ }, }; var jStr = JSON.stringify(this.jsonObj); + console.log(jStr, "jStr"); + this.websocket.send(jStr); + this.$refs.tab1.clearSelection(); // 娓呴櫎鍙充晶琛ㄦ牸鐨勯�変腑鐘舵�� + this.selectList = []; // 娓呯┖ selectList + this.ids = []; // 娓呯┖ ids this.jsonObj = {}; // this.dialogVisible = false; }; @@ -948,23 +975,24 @@ // 纭閲囨牱 Confirmreceipt() { const loadingInstance = this.$loading({ - lock: true, // 閿佸畾灞忓箷 - text: "鍔犺浇涓�...", // 鍔犺浇鏂囨湰 - spinner: "el-icon-loading", // 鑷畾涔夊姞杞藉浘鏍� - background: "rgba(255, 255, 255, 0.7)", // 鑳屾櫙棰滆壊 + lock: true, + text: "鍔犺浇涓�...", + spinner: "el-icon-loading", + background: "rgba(255, 255, 255, 0.7)", }); confirmSampling(this.ids) .then((res) => { - console.log(this.selectList, 2222); - if (res.code === 200) { - this.buda(); - this.getList(); + this.buda(); // 鎵撳嵃鏉$爜 + + this.getList(); // 鍒锋柊宸︿晶琛ㄦ牸 + console.log("閲囨牱鍚� - selectList:", this.selectList, "qiehuan:", this.qiehuan); } else { this.$message.error(res.msg); } }) .catch((error) => { + console.error("閲囨牱澶辫触:", error); }) .finally(() => { loadingInstance.close(); @@ -987,6 +1015,7 @@ }); }, // 鍗曢�夋寜閽� + // 鍗曢�夋寜閽� radioChange(value) { this.loading = true; this.queryParams.isSignFor = value; @@ -998,14 +1027,23 @@ this.loading = false; } else { this.samplingList = response.data.list; - this.loading = false; - if (this.samplingList.length != 0) { - this.$nextTick(() => { - this.$refs.tb.toggleRowSelection(this.samplingList[0], true); - }); - } else { - this.$refs.tb.clearSelection(); + this.$nextTick(() => { + if (this.$refs.tb) { + + const headerCheckbox = this.$refs.tb.$el.querySelector('.el-table__header .el-checkbox'); + if (headerCheckbox) headerCheckbox.style.display = 'none'; + } + }); + this.loading = false; + // 绉婚櫎榛樿閫変腑绗竴琛岀殑閫昏緫 + // if (this.samplingList.length != 0) { + // this.$nextTick(() => { + // this.$refs.tb.toggleRowSelection(this.samplingList[0], true); + // }); + // } else { + // this.$refs.tb.clearSelection(); + // } } this.total = response.data.total; this.loading = false; -- Gitblit v1.8.0