From b4ac09eb2e493aab92557628e0436189337e2939 Mon Sep 17 00:00:00 2001 From: 董国庆 <364620639@qq.com> Date: 星期二, 20 五月 2025 16:44:32 +0800 Subject: [PATCH] 样品管理大模块85% --- laboratory/src/views/dataManagement/sampleManage/addSample.vue | 677 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 436 insertions(+), 241 deletions(-) diff --git a/laboratory/src/views/dataManagement/sampleManage/addSample.vue b/laboratory/src/views/dataManagement/sampleManage/addSample.vue index b345928..99460d5 100644 --- a/laboratory/src/views/dataManagement/sampleManage/addSample.vue +++ b/laboratory/src/views/dataManagement/sampleManage/addSample.vue @@ -3,19 +3,26 @@ <div class="header-title-left"> <img src="@/assets/public/headercard.png" /> <div>所属实验调度</div> - <el-button v-if="isEngineer" @click="showScheduling = true" class="el-icon-plus" type="primary"> + <el-button v-if="isEngineer && pageType !== 'detail'" @click="showScheduling = true" class="el-icon-plus" type="primary"> 选择实验调度</el-button> </div> <Table :data="schedulingData" :total="schedulingTotal" :height="null"> <template> - <el-table-column prop="planCode" label="所属项目课题方案"></el-table-column> - <el-table-column prop="planName" label="实验编号"></el-table-column> - <el-table-column prop="planName" label="实验名称"></el-table-column> - <el-table-column prop="stage" label="通知时间"></el-table-column> - <el-table-column prop="stage" label="实验开始时间"></el-table-column> - <el-table-column prop="stage" label="实验结束时间"></el-table-column> - <el-table-column prop="stage" label="参加人员"></el-table-column> - <el-table-column prop="creator" label="状态"></el-table-column> + <el-table-column type="index" label="序号" width="80"></el-table-column> + <el-table-column prop="projectName" label="所属项目课题方案"></el-table-column> + <el-table-column prop="experimentCode" label="实验编号"></el-table-column> + <el-table-column prop="experimentName" label="实验名称"></el-table-column> + <el-table-column prop="experimentDate" label="通知时间"></el-table-column> + <el-table-column prop="experimentStartTime" label="实验开始时间"></el-table-column> + <el-table-column prop="experimentEndTime" label="实验结束时间"></el-table-column> + <el-table-column prop="participantsName" label="参加人员"></el-table-column> + <el-table-column prop="status" label="状态"> + <template slot-scope="scope"> + <el-tag :type="getStatusType(scope.row.status)"> + {{ getStatusText(scope.row.status) }} + </el-tag> + </template> + </el-table-column> </template> </Table> @@ -38,28 +45,63 @@ <!-- 待收样列表 --> <div class="pending-samples"> <div class="sub-title">待收样列表</div> - <el-button type="primary" class="batch-receive" @click="handleBatchReceive">批量接收</el-button> - <Table :data="pendingSamples" :total="pendingSamplesTotal" :height="null" - @selection-change="handleSelectionChange"> + <el-button + type="primary" + class="batch-receive" + @click="handleBatchReceive" + :disabled="selectedSamples.length == 0" + >批量接收</el-button> + <Table ref="pendingTable" + :data="pendingSamples" + :total="pendingSamplesTotal" + :height="null" + :row-key="row => row.id" + @selection-change="handlePendingSelectionChange"> <template> - <el-table-column type="selection" width="55"></el-table-column> - <el-table-column prop="index" label="序号" width="80"></el-table-column> - <el-table-column prop="sampleName" label="取样名称"></el-table-column> - <el-table-column prop="sampleCode" label="取样样品编号"></el-table-column> - <el-table-column prop="ph" label="PH"></el-table-column> - <el-table-column prop="sampleAmount" label="取样量"></el-table-column> - <el-table-column prop="sendTime" label="送样时间"></el-table-column> - <el-table-column prop="sender" label="送样人"></el-table-column> - <el-table-column prop="status" label="状态"></el-table-column> + <el-table-column + type="selection" + width="55" + fixed="left" > + </el-table-column> + <el-table-column type="index" label="序号" width="80"></el-table-column> + <el-table-column prop="samplingName" label="取样名称" width="150"></el-table-column> + <el-table-column prop="sampleCode" label="取样样品编号" width="150"></el-table-column> + <el-table-column prop="temperature" label="温度" width="150"></el-table-column> + <el-table-column prop="samplePh" label="PH" width="150"></el-table-column> + <el-table-column prop="waterAddition" label="加水量" width="150"></el-table-column> <template v-if="showPendingColumns"> - <el-table-column prop="temperature" label="温度" width="150"></el-table-column> - <el-table-column prop="waterAmount" label="加水量" width="150"></el-table-column> - <el-table-column prop="additive1" label="加辅1" width="150"></el-table-column> - <el-table-column prop="additive2" label="加辅2" width="150"></el-table-column> - <el-table-column prop="additive3" label="加辅3" width="150"></el-table-column> - <el-table-column prop="additive4" label="加辅4" width="150"></el-table-column> - <el-table-column prop="additive5" label="加辅5" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryOne" label="加辅1" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryTwo" label="加辅2" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryThree" label="加辅3" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryFour" label="加辅4" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryFive" label="加辅5" width="150"></el-table-column> + <el-table-column prop="addAuxiliarySix" label="加辅6" width="150"></el-table-column> + <el-table-column prop="addAuxiliarySeven" label="加辅7" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryEight" label="加辅8" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryNine" label="加辅9" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryTen" label="加辅10" width="150"></el-table-column> </template> + <el-table-column prop="sampleAmount" label="取样量" width="150"></el-table-column> + <el-table-column prop="pictures" label="拍照" width="150"> + <template slot-scope="scope"> + <template v-if="scope.row.pictures"> + <el-image + v-for="(url, index) in scope.row.pictures.split(',')" + :key="index" + src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" + :preview-src-list="[url]" + style="width: 50px; height: 50px;" + /> + </template> + <span v-else>-</span> + </template> + </el-table-column> + <el-table-column prop="handlePersonName" label="操作人员" width="150"></el-table-column> + <el-table-column label="状态" prop="status" width="100" fixed="right"> + <template slot-scope="scope"> + <span>{{ scope.row.status == '2' ? '待接收' : '已接收' }}</span> + </template> + </el-table-column> <el-table-column label="操作" width="100" fixed="right"> <template slot-scope="scope"> <el-button type="text" @click="handleReceive(scope.row)">接收</el-button> @@ -68,31 +110,52 @@ </template> </Table> </div> - <!-- 已收样列表 --> <div class="received-samples"> <div class="sub-title">已收样列表</div> - <Table :data="receivedSamples" :total="receivedSamplesTotal" :height="null"> + <Table ref="receivedTable" :data="receivedSamples" :total="receivedSamplesTotal" :height="null"> <template> - <el-table-column prop="index" label="序号" width="80"></el-table-column> - <el-table-column prop="sampleName" label="取样名称"></el-table-column> - <el-table-column prop="sampleCode" label="取样样品编号"></el-table-column> + <el-table-column type="index" label="序号" width="80"></el-table-column> + <el-table-column prop="samplingName" label="取样名称" width="150"></el-table-column> + <el-table-column prop="sampleCode" label="取样样品编号" width="150"></el-table-column> <el-table-column prop="temperature" label="温度" width="150"></el-table-column> - <el-table-column prop="waterAmount" label="加水量" width="150"></el-table-column> - <el-table-column prop="ph" label="PH"></el-table-column> + <el-table-column prop="samplePh" label="PH" width="150"></el-table-column> + <el-table-column prop="waterAddition" label="加水量" width="150"></el-table-column> <template v-if="showReceivedColumns"> - <el-table-column prop="additive1" label="加辅1" width="150"></el-table-column> - <el-table-column prop="additive2" label="加辅2" width="150"></el-table-column> - <el-table-column prop="additive3" label="加辅3" width="150"></el-table-column> - <el-table-column prop="additive4" label="加辅4" width="150"></el-table-column> - <el-table-column prop="additive5" label="加辅5" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryOne" label="加辅1" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryTwo" label="加辅2" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryThree" label="加辅3" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryFour" label="加辅4" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryFive" label="加辅5" width="150"></el-table-column> + <el-table-column prop="addAuxiliarySix" label="加辅6" width="150"></el-table-column> + <el-table-column prop="addAuxiliarySeven" label="加辅7" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryEight" label="加辅8" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryNine" label="加辅9" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryTen" label="加辅10" width="150"></el-table-column> </template> - <el-table-column prop="sampleAmount" label="取样量"></el-table-column> - <el-table-column prop="sendTime" label="送样时间"></el-table-column> - <el-table-column prop="sender" label="送样人"></el-table-column> - <el-table-column prop="receiveTime" label="收样时间"></el-table-column> - <el-table-column prop="receiver" label="收样人"></el-table-column> - <el-table-column prop="status" label="状态" fixed="right"></el-table-column> + <el-table-column prop="sampleAmount" label="取样量" width="150"></el-table-column> + <el-table-column prop="pictures" label="拍照" width="150"> + <template slot-scope="scope"> + <template v-if="scope.row.pictures"> + <el-image + v-for="(url, index) in scope.row.pictures.split(',')" + :key="index" + src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" + :preview-src-list="[url]" + style="width: 50px; height: 50px;" + /> + </template> + <span v-else>-</span> + </template> + </el-table-column> + <el-table-column prop="handlePersonName" label="操作人员" width="150"></el-table-column> + <el-table-column prop="receiveTime" label="收样时间" width="150"></el-table-column> + <el-table-column prop="receiver" label="收样人" width="150"></el-table-column> + <el-table-column label="状态" prop="status" width="100" fixed="right"> + <template slot-scope="scope"> + <span>{{ scope.row.status == '3' ? '已接收' : '待接收' }}</span> + </template> + </el-table-column> </template> </Table> </div> @@ -104,55 +167,79 @@ <img src="@/assets/public/headercard.png" /> <span>基础信息</span> </div> - <el-form ref="form" :model="form" :rules="rules" inline label-position="top"> + <el-form ref="form" :model="form" :rules="rules" inline label-position="top" v-if="pageType !== 'detail'"> <el-form-item label="取样单编号" prop="sampleCode"> <el-input v-model="form.sampleCode" :disabled="true" placeholder="自动生成" /> </el-form-item> </el-form> + <div>取样单编号:{{ form.sampleCode }}</div> <div class="header-title-left" style="margin-top: 38px"> <img src="@/assets/public/headercard.png" /> <span>取样操作记录</span> - <el-button type="primary" class="el-icon-plus" @click="showAddTime = true"> + <el-button v-if="isEngineer && pageType !== 'detail'" type="primary" class="el-icon-plus" @click="showAddTime = true"> 新增工艺时间 </el-button> <el-button type="primary" class="el-icon-plus" @click="showAdditives = !showAdditives"> {{ showAdditives ? "收起辅料详情" : "展开辅料详情" }} </el-button> </div> - <Table :data="sampleData" :total="sampleTotal" :height="null"> + <Table ref="sampleTable" :data="sampleData" :total="sampleTotal" :height="null"> <template> <el-table-column prop="index" label="序号" width="80"></el-table-column> <el-table-column prop="processTime" label="工艺时间" width="150"></el-table-column> - <el-table-column prop="sampleName" label="取样名称" width="150"></el-table-column> + <el-table-column prop="samplingName" label="取样名称" width="150"></el-table-column> <el-table-column prop="sampleCode" label="取样样品编号" width="150"></el-table-column> <el-table-column prop="temperature" label="温度" width="150"></el-table-column> - <el-table-column prop="ph" label="PH" width="150"></el-table-column> - <el-table-column prop="waterAmount" label="加水量" width="150"></el-table-column> + <el-table-column prop="samplePh" label="PH" width="150"></el-table-column> + <el-table-column prop="waterAddition" label="加水量" width="150"></el-table-column> <template v-if="showAdditives"> - <el-table-column prop="additive1" label="加辅1" width="150"></el-table-column> - <el-table-column prop="additive2" label="加辅2" width="150"></el-table-column> - <el-table-column prop="additive3" label="加辅3" width="150"></el-table-column> - <el-table-column prop="additive4" label="加辅4" width="150"></el-table-column> - <el-table-column prop="additive5" label="加辅5" width="150"></el-table-column> - <el-table-column prop="additive6" label="加辅6" width="150"></el-table-column> - <el-table-column prop="additive7" label="加辅7" width="150"></el-table-column> - <el-table-column prop="additive8" label="加辅8" width="150"></el-table-column> - <el-table-column prop="additive9" label="加辅9" width="150"></el-table-column> - <el-table-column prop="additive10" label="加辅10" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryOne" label="加辅1" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryTwo" label="加辅2" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryThree" label="加辅3" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryFour" label="加辅4" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryFive" label="加辅5" width="150"></el-table-column> + <el-table-column prop="addAuxiliarySix" label="加辅6" width="150"></el-table-column> + <el-table-column prop="addAuxiliarySeven" label="加辅7" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryEight" label="加辅8" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryNine" label="加辅9" width="150"></el-table-column> + <el-table-column prop="addAuxiliaryTen" label="加辅10" width="150"></el-table-column> </template> <el-table-column prop="sampleAmount" label="取样量" width="150"></el-table-column> - <el-table-column prop="sampleTime" label="取样时间" width="150"></el-table-column> - <el-table-column prop="remark" label="拍照" width="150"></el-table-column> - <el-table-column prop="operator" label="操作人员" width="150"></el-table-column> + <el-table-column prop="pictures" label="拍照" width="150"> + <template slot-scope="scope"> + <template v-if="scope.row.pictures"> + <el-image + v-for="(url, index) in scope.row.pictures.split(',')" + :key="index" + :src="url" + :preview-src-list="[url]" + style="width: 50px; height: 50px;" + /> + </template> + <span v-else>-</span> + </template> + </el-table-column> + <el-table-column prop="handlePersonName" label="操作人员" width="150"></el-table-column> </template> </Table> - <div class="add-project-footer"> + <div v-if="pageType == 'detail'" style="margin-top: 38px">备注:</div> + <el-input + v-if="pageType == 'detail'" + type="textarea" + + v-model="form.remark" + placeholder="请输入内容" + style="margin-top: 10px" + :disabled="true" + /> + + <div class="add-project-footer" v-if="isEngineer && pageType !== 'detail'"> <el-button type="primary" class="save-btn" @click="handleSave">保存</el-button> - <el-button>存草稿</el-button> + <el-button @click="handleSaveDraft">存草稿</el-button> </div> </div> - <experimentalScheduling :show="showScheduling" /> + <experimentalScheduling :show="showScheduling" @close="handleSchedulingClose" @submit="handleSchedulingSubmit" /> <addTime :show.sync="showAddTime" @confirm="handleAddTime" /> <receive-confirm-dialog :visible.sync="showReceiveConfirm" :sample-count="selectedSamples.length" @confirm="confirmReceive" /> @@ -163,6 +250,7 @@ import experimentalScheduling from "./components/experimental-scheduling.vue"; import addTime from "./components/addTime.vue"; import ReceiveConfirmDialog from "./components/receiveConfirmDialog.vue"; +import { add, getDetail, update, batchCollectSamples } from "./service"; export default { name: "AddSample", @@ -181,224 +269,331 @@ showReceivedColumns: true, schedulingData: [], schedulingTotal: 0, - sampleData: [ - { - index: 1, - processTime: "2h", - sampleName: "样品A", - sampleCode: "SP001", - temperature: "25℃", - ph: "7.0", - waterAmount: "500ml", - additive1: "10g", - additive2: "5g", - additive3: "3g", - additive4: "", - additive5: "", - additive6: "", - additive7: "", - additive8: "", - additive9: "", - additive10: "", - sampleAmount: "100ml", - sampleTime: "2024-03-20 10:00:00", - remark: "", - operator: "张三", - }, - { - index: 2, - processTime: "4min", - sampleName: "样品B", - sampleCode: "SP002", - temperature: "30℃", - ph: "6.5", - waterAmount: "300ml", - additive1: "8g", - additive2: "4g", - additive3: "", - additive4: "", - additive5: "", - additive6: "", - additive7: "", - additive8: "", - additive9: "", - additive10: "", - sampleAmount: "50ml", - sampleTime: "2024-03-20 10:30:00", - remark: "", - operator: "李四", - }, - ], - sampleTotal: 2, + sampleData: [], + sampleTotal: 0, form: { sampleCode: "", + dispatchId: "", // 实验调度id + samplingCode: "", // 取样单编号 + status: 1, // 状态:1=已发送待提交 + samplingRecordOperations: [], // 取样操作记录集合 + remark: "", // 备注,json存储 }, rules: { - sampleCode: [ - { required: true, message: "请输入取样单编号", trigger: "blur" }, - ], }, - userRole: "assayer", // engineer默认设置为工程师assayer化验师 + userRole: '', // 修改初始值为空字符串 // 化验师相关数据 - pendingSamples: [ - { - index: 1, - sampleName: "名称名称名称", - sampleCode: "314234321", - ph: "5", - sampleAmount: "34", - sendTime: "2025-1-9 15:26:08", - sender: "李四", - status: "待接收", - }, - { - index: 2, - sampleName: "名称名称名称", - sampleCode: "314234321", - ph: "6", - sampleAmount: "23", - sendTime: "2025-1-9 15:26:08", - sender: "李四", - status: "待接收", - }, - { - index: 3, - sampleName: "名称名称名称", - sampleCode: "314234321", - ph: "7", - sampleAmount: "23", - sendTime: "2025-1-13 16:38:17", - sender: "李四", - status: "待接收", - }, - ], - pendingSamplesTotal: 3, - receivedSamples: [ - { - index: 1, - sampleName: "名称名称名称", - sampleCode: "314234321", - ph: "5", - sampleAmount: "34", - sendTime: "2025-1-9 15:26:08", - sender: "李四", - receiveTime: "2025-1-15 14:00:50", - receiver: "段向蒙", - status: "已接收", - }, - { - index: 2, - sampleName: "名称名称名称", - sampleCode: "314234321", - ph: "6", - sampleAmount: "23", - sendTime: "2025-1-9 15:26:08", - sender: "李四", - receiveTime: "2025-1-15 14:00:50", - receiver: "傅彦涛", - status: "已接收", - }, - { - index: 3, - sampleName: "名称名称名称", - sampleCode: "314234321", - ph: "7", - sampleAmount: "23", - sendTime: "2025-1-13 16:38:17", - sender: "李四", - receiveTime: "2025-1-15 14:00:50", - receiver: "王乐康", - status: "已接收", - }, - ], - receivedSamplesTotal: 3, + pendingSamples: [], + pendingSamplesTotal: 0, + receivedSamples: [], + receivedSamplesTotal: 0, selectedSamples: [], + // 状态映射表 + statusTypeMap: { + "-1": "info", + "1": "warning", + "2": "success", + "3": "info" + }, + statusTextMap: { + "-1": "草稿箱", + "1": "待确认", + "2": "已确认", + "3": "已封存" + }, + // 页面类型:add-新增,edit-编辑,detail-详情 + pageType: 'add', }; + }, + created() { + const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}'); + this.userRole = userInfo.roleType || ''; + + // 获取路由参数 + const { id, type } = this.$route.query; + if (id) { + this.pageType = type || 'detail'; + this.getDetailData(id); + } }, computed: { isEngineer() { - return this.userRole === "engineer"; + return this.userRole == '3'; // 工艺工程师 }, isAssayer() { - return this.userRole === "assayer"; + return this.userRole == '4'; // 化验师 }, }, methods: { + // 获取详情数据 + async getDetailData(id) { + try { + const res = await getDetail({ id }); + if (res) { + const detail = res; + console.log('获取到的详情数据:', detail); + + // 设置表单数据 + this.form = { + ...this.form, + ...detail, + dispatchId: detail.dispatchId, + sampleCode: detail.samplingCode, + }; + + // 设置实验调度数据 + if (detail.experimentDispatch) { + this.schedulingData = [detail.experimentDispatch]; + } + + // 设置取样操作记录 + if (detail.samplingRecordOperations && detail.samplingRecordOperations.length > 0) { + console.log('原始取样操作记录:', detail.samplingRecordOperations); + + // 如果是化验师角色,需要将数据分为待接收和已接收 + if (this.isAssayer) { + // 确保status是字符串类型 + this.pendingSamples = detail.samplingRecordOperations + .filter(item => { + const status = String(item.status); + console.log('过滤待接收样品:', item.id, status); + return status === '2'; + }) + .map(item => ({ + ...item, + status: String(item.status) + })); + console.log('处理后的待接收样品:', this.pendingSamples); + this.pendingSamplesTotal = this.pendingSamples.length; + + this.receivedSamples = detail.samplingRecordOperations + .filter(item => String(item.status) === '3') + .map(item => ({ + ...item, + status: String(item.status) + })); + this.receivedSamplesTotal = this.receivedSamples.length; + } else { + // 工程师角色保持原有逻辑 + this.sampleData = detail.samplingRecordOperations.map((item, index) => ({ + ...item, + index: index + 1, + status: String(item.status) + })); + } + } + + // 如果是详情模式,禁用所有输入 + if (this.pageType == 'detail') { + this.$nextTick(() => { + const inputs = document.querySelectorAll('input, textarea, select'); + inputs.forEach(input => { + input.disabled = true; + }); + }); + } + } + } catch (error) { + console.error('获取详情失败:', error); + this.$message.error('获取详情失败,请重试'); + } + }, handleAddTime(processTime) { const newRow = { index: this.sampleData.length + 1, processTime, - sampleName: "", + samplingName: "", sampleCode: "", temperature: "", - ph: "", - waterAmount: "", - additive1: "", - additive2: "", - additive3: "", - additive4: "", - additive5: "", - additive6: "", - additive7: "", - additive8: "", - additive9: "", - additive10: "", + samplePh: "", + waterAddition: "", + addAuxiliaryOne: "", + addAuxiliaryTwo: "", + addAuxiliaryThree: "", + addAuxiliaryFour: "", + addAuxiliaryFive: "", + addAuxiliarySix: "", + addAuxiliarySeven: "", + addAuxiliaryEight: "", + addAuxiliaryNine: "", + addAuxiliaryTen: "", sampleAmount: "", - sampleTime: "", - remark: "", - operator: "", + pictures: "", + handlePersonId: "", + status: 1 // 1=待发送 }; this.sampleData.push(newRow); this.$message.success("添加工艺时间成功"); }, handleSave() { - this.submitForm(); + // 验证是否选择了实验调度 + if (!this.schedulingData || this.schedulingData.length == 0) { + this.$message.warning('请选择所属实验调度'); + return; + } + + // 验证是否有取样操作记录 + if (!this.sampleData || this.sampleData.length == 0) { + this.$message.warning('请至少添加一条取样操作记录'); + return; + } + + this.$refs.form.validate(async (valid) => { + if (valid) { + try { + // 获取当前用户信息 + const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}'); + + // 构建提交数据 + const submitData = { + ...this.form, + dispatchId: this.schedulingData[0].id, + status: 1, // 正常保存状态为1 + samplingRecordOperations: this.sampleData.map(item => ({ + ...item, + handlePersonId: userInfo.userId, + status: 1 // 1=待发送 + })), + remark: this.form.remark, + samplingCode: this.form.sampleCode, + id: this.form.id, + }; + + // 打印提交数据 + console.log('保存提交数据:',submitData); + + let res; + if (this.pageType == 'edit') { + // 编辑模式调用update接口 + res = await update(submitData); + } else { + // 新增模式调用add接口 + res = await add(submitData); + } + + if (res.code == 200) { + this.$message.success(this.pageType == 'edit' ? '编辑成功' : '保存成功'); + this.$router.go(-1); + } else { + this.$message.error(res.msg || (this.pageType == 'edit' ? '编辑失败' : '保存失败')); + } + } catch (error) { + console.error(this.pageType == 'edit' ? '编辑失败:' : '保存失败:', error); + this.$message.error(this.pageType == 'edit' ? '编辑失败,请重试' : '保存失败,请重试'); + } + } + }); }, - submitForm() { - // 在这里实现表单提交逻辑 - console.log("提交表单数据"); - this.$message.success("保存成功"); + // 添加存草稿方法 + async handleSaveDraft() { + try { + // 获取当前用户信息 + const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}'); + + // 构建提交数据 + const submitData = { + dispatchId: this.schedulingData?.[0]?.id || '', + status: -1, // 存草稿状态为-1 + samplingRecordOperations: (this.sampleData || []).map(item => ({ + ...item, + handlePersonId: userInfo.userId, + status: 1 // 1=待发送 + })), + remark: this.form.remark, + samplingCode: this.form.sampleCode, + id: this.form.id, + }; + + // 打印提交数据 + console.log('草稿提交数据:', submitData); + + let res; + if (this.pageType == 'edit') { + // 编辑模式调用update接口 + res = await update(submitData); + } else { + // 新增模式调用add接口 + res = await add(submitData); + } + + if (res.code == 200) { + this.$message.success(this.pageType == 'edit' ? '草稿保存成功' : '存草稿成功'); + this.$router.go(-1); + } else { + this.$message.error(res.msg || (this.pageType == 'edit' ? '草稿保存失败' : '存草稿失败')); + } + } catch (error) { + console.error(this.pageType == 'edit' ? '草稿保存失败:' : '存草稿失败:', error); + this.$message.error(this.pageType == 'edit' ? '草稿保存失败,请重试' : '存草稿失败,请重试'); + } }, - handleSelectionChange(selection) { + handlePendingSelectionChange(selection) { + console.log("pending selection change:", selection); + console.log("pending samples data:", this.pendingSamples); this.selectedSamples = selection; + // 强制更新视图 + this.$nextTick(() => { + this.$forceUpdate(); + }); }, handleReceive(row) { + // 清空之前的选择 + this.selectedSamples = []; + // 设置当前行为选中状态 this.selectedSamples = [row]; this.showReceiveConfirm = true; }, handleBatchReceive() { - if (this.selectedSamples.length === 0) { + if (this.selectedSamples.length == 0) { this.$message.warning("请先选择要接收的样品"); return; } this.showReceiveConfirm = true; }, confirmReceive(signature) { - // 这里处理接收确认逻辑 - const sampleIds = this.selectedSamples.map((item) => item.id); - console.log("接收样品", { sampleIds, signature }); - - // 模拟接收成功 - this.$message.success(`成功接收 ${this.selectedSamples.length} 个样品`); - - // 更新数据 - this.selectedSamples.forEach((sample) => { - const index = this.pendingSamples.findIndex( - (item) => item.id === sample.id - ); - if (index > -1) { - this.pendingSamples.splice(index, 1); - this.receivedSamples.unshift({ - ...sample, - receiveTime: new Date().toLocaleString(), - receiver: "当前用户", - status: "已接收", - }); + // 获取选中样品的ID并拼接 + const recordOperationIds = this.selectedSamples.map(item => item.id).join(','); + + // 调用批量收样接口 + batchCollectSamples({ + receiptsSign: signature, + recordOperationId: recordOperationIds + }).then(res => { + if (res.code == 200) { + this.$message.success(`成功接收 ${this.selectedSamples.length} 个样品`); + // 重新获取详情数据 + this.getDetailData(this.form.id); + } else { + this.$message.error(res.msg || '收样失败'); } + }).catch(error => { + console.error('收样失败:', error); + this.$message.error('收样失败,请重试'); + }).finally(() => { + // 清空选择并关闭弹窗 + this.selectedSamples = []; + this.showReceiveConfirm = false; }); - - // 清空选择 - this.selectedSamples = []; + }, + getStatusType(status) { + return this.statusTypeMap[status] || 'info'; + }, + getStatusText(status) { + return this.statusTextMap[status] || '未知状态'; + }, + handleSchedulingClose() { + this.showScheduling = false; + }, + handleSchedulingSubmit(data) { + this.schedulingData = data || []; + + }, + isSelectable(row) { + console.log('isSelectable row:', row); + console.log('row status:', row.status, typeof row.status); + const result = String(row.status) === '2'; + console.log('isSelectable result:', result); + return result; }, }, }; -- Gitblit v1.7.1