| | |
| | | >(最多{{ remainingReturnQuantity }}台)</span |
| | | > |
| | | <span |
| | | style="color: #ff4d4f; font-size: 12px; margin-left: 8px" |
| | | style="color: #67c23a; font-size: 12px; margin-left: 8px" |
| | | v-else |
| | | >(已全部归还)</span |
| | | > |
| | | <!-- 归还完成提示 --> |
| | | <div |
| | | v-if="remainingReturnQuantity > 0 && form.returnQuantity === remainingReturnQuantity" |
| | | style="color: #67c23a; font-size: 12px; margin-top: 4px" |
| | | > |
| | | 💡 提示:本次归还后将完成全部归还 |
| | | </div> |
| | | </el-form-item> |
| | | <!-- 使用开始时间 - 只在非归还模式显示 --> |
| | | <el-form-item label="使用开始时间" prop="usageStartTime" v-if="!isReturnMode"> |
| | |
| | | |
| | | <script setup> |
| | | import { ref, watch, computed, onMounted } from "vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import { ElMessage, ElMessageBox } from "element-plus"; |
| | | import { getEquipmentList } from "@/api/publicApi/index.js"; |
| | | import { addOrEditUsageRecord } from "@/api/equipment/requisition/index.js"; |
| | | |
| | |
| | | } |
| | | |
| | | function handleSubmit() { |
| | | formRef.value.validate((valid) => { |
| | | formRef.value.validate(async (valid) => { |
| | | if (!valid) return; |
| | | |
| | | let submitData = { ...form.value }; |
| | |
| | | const alreadyReturnedQuantity = props.formData.totalReturnNo || 0; |
| | | const newTotalReturnedQuantity = alreadyReturnedQuantity + currentReturnQuantity; |
| | | |
| | | // 判断是否全部归还完成 |
| | | let equipmentStatus = 2; // 默认为部分归还 |
| | | let isFullyReturned = newTotalReturnedQuantity >= totalUsageQuantity; |
| | | |
| | | if (isFullyReturned) { |
| | | equipmentStatus = 3; // 全部归还完成 |
| | | |
| | | // 全部归还时的确认提示 |
| | | try { |
| | | await ElMessageBox.confirm( |
| | | `确认将设备"${props.formData.equipmentName || '未知设备'}"全部归还吗?归还后设备状态将变为"已归还"。`, |
| | | '确认全部归还', |
| | | { |
| | | confirmButtonText: '确认归还', |
| | | cancelButtonText: '取消', |
| | | type: 'success', |
| | | } |
| | | ); |
| | | } catch (error) { |
| | | if (error === 'cancel') { |
| | | ElMessage.info('已取消归还操作'); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | console.log('设备归还完成:', { |
| | | 设备名称: props.formData.equipmentName, |
| | | 总使用数量: totalUsageQuantity, |
| | | 新的归还总数: newTotalReturnedQuantity, |
| | | 状态: '已全部归还' |
| | | }); |
| | | } else { |
| | | console.log('设备部分归还:', { |
| | | 设备名称: props.formData.equipmentName, |
| | | 总使用数量: totalUsageQuantity, |
| | | 已归还数量: newTotalReturnedQuantity, |
| | | 剩余未归还: totalUsageQuantity - newTotalReturnedQuantity, |
| | | 状态: '部分归还' |
| | | }); |
| | | } |
| | | |
| | | submitData = { |
| | | ...props.formData, |
| | | totalReturnNo: newTotalReturnedQuantity, |
| | | returnQuantity: currentReturnQuantity, |
| | | returnTime: form.value.returnTime, |
| | | equipmentStatus: 2, |
| | | equipmentStatus: equipmentStatus, |
| | | remarks: form.value.remarks, |
| | | usageQuantity: totalUsageQuantity |
| | | }; |
| | | } |
| | | |
| | | addOrEditUsageRecord(submitData); |
| | | try { |
| | | let {code,data} = await addOrEditUsageRecord(submitData); |
| | | if (code !== 200) { |
| | | ElMessage.error(data.msg || "操作失败"); |
| | | return; |
| | | } |
| | | if(code == 200 && data == 1){ |
| | | // 根据归还状态给出不同的成功提示 |
| | | if (isReturnMode.value && submitData.equipmentStatus === 3) { |
| | | ElMessage.success("设备已全部归还完成!"); |
| | | } else if (isReturnMode.value && submitData.equipmentStatus === 2) { |
| | | ElMessage.success("设备部分归还成功!"); |
| | | } else { |
| | | ElMessage.success("操作成功!"); |
| | | } |
| | | |
| | | emit("submit", submitData); |
| | | } |
| | | handleClose(); |
| | | } catch (error) { |
| | | console.error('提交失败:', error); |
| | | ElMessage.error("操作失败,请稍后再试"); |
| | | } |
| | | }); |
| | | } |
| | | </script> |