| | |
| | | <el-date-picker style="margin-left: 10px;" v-model="timeRange" type="daterange" format="YYYY/MM/DD" |
| | | value-format="YYYY-MM-DD" :start-placeholder="$t('reportmanage.starttime')" |
| | | :end-placeholder="$t('reportmanage.endtime')" :default-time="defaultTime" /> |
| | | <el-input v-model="report.targetSlot" style="margin-left: 15px;width: 150px" placeholder="请输入格子号" /> |
| | | <el-input v-model="report.width" style="margin-left: 15px;width: 150px" placeholder="请输入宽" /> |
| | | <el-input v-model="report.height" style="margin-left: 15px;width: 150px" placeholder="请输入高" /> |
| | | <el-input v-model="report.targetSlot" style="margin-left: 15px;width: 150px" :placeholder="$t('rework.gridNumberEnter')"/> |
| | | <el-input v-model="report.width" style="margin-left: 15px;width: 150px" :placeholder="$t('searchOrder.inwidth')"/> |
| | | <el-input v-model="report.height" style="margin-left: 15px;width: 150px" :placeholder="$t('searchOrder.inheight')"/> |
| | | <!-- <el-select v-model="report.taskType" :placeholder="$t('reportmanage.ctype')" style="margin-left: 10px;"> |
| | | <el-option :label="$t('reportmanage.all')" value="0"></el-option> |
| | | <el-option :label="$t('reportmanage.go')" value="1"></el-option> |
| | | <el-option :label="$t('reportmanage.nogo')" value="2"></el-option> |
| | | </el-select> --> |
| | | <el-select v-model="report.taskState" :placeholder="$t('reportmanage.cstate')" style="margin-left: 10px;"> |
| | | <el-select v-model="report.taskState" :placeholder="$t('reportmanage.cstate')" style="margin-left: 10px;width: 100px;"> |
| | | <el-option :label="$t('reportmanage.all')" value="-1"></el-option> |
| | | <el-option :label="$t('reportmanage.scan')" value="0"></el-option> |
| | | <el-option :label="$t('reportmanage.feeding')" value="1"></el-option> |
| | |
| | | <el-option :label="$t('reportmanage.car')" value="3"></el-option> |
| | | <el-option :label="$t('reportmanage.cage')" value="4"></el-option> |
| | | </el-select> |
| | | <el-select v-model="report.line" :placeholder="$t('reportmanage.cprocess')" style="margin-left: 10px;"> |
| | | <el-select v-model="report.line" :placeholder="$t('reportmanage.cprocess')" style="margin-left: 10px;width: 100px;"> |
| | | <el-option :label="$t('reportmanage.all')" value="0"></el-option> |
| | | <el-option :label="$t('reportmanage.oneline')" value="2001"></el-option> |
| | | <el-option :label="$t('reportmanage.twoline')" value="2002"></el-option> |
| | | </el-select> |
| | | |
| | | <el-input v-model="timeInterval" style="margin-left: 15px;width: 100px" :placeholder="$t('reportmanage.timeInterval')"/> |
| | | <el-button type="primary" style="margin-left: 10px;" @click="selectReportData()">{{ $t('reportmanage.inquire') |
| | | }}</el-button> |
| | | </div> |
| | |
| | | <div id="dt" style="font-size: 15px;"> |
| | | <el-form-item :label="$t('reportmanage.totalTakes')" style="width: 14vw"> |
| | | {{ totalTakes }} |
| | | </el-form-item> |
| | | </div> |
| | | </el-col> |
| | | <el-col :span="3"> |
| | | <div id="dt" style="font-size: 15px;"> |
| | | <el-form-item :label="$t('reportmanage.workMinutes')" style="width: 14vw"> |
| | | {{ totalMinutes }} min |
| | | </el-form-item> |
| | | </div> |
| | | </el-col> |
| | |
| | | taskState: '-1', |
| | | line: '0', |
| | | width: '', |
| | | height: '' |
| | | height: '', |
| | | }); |
| | | const timeInterval= ref(120) |
| | | const reportData = ref([]) |
| | | const endDate = new Date(); |
| | | const startDate = new Date(); |
| | | startDate.setDate(endDate.getDate() - 100); // 获取一个星期前的时间 |
| | | startDate.setDate(endDate.getDate()); // 获取一个星期前的时间 |
| | | // 格式化为 "YYYY-MM-DD" 格式 |
| | | const formatDate = (date) => { |
| | | const year = date.getFullYear(); |
| | |
| | | const totalAreas = ref(0); |
| | | const totalDamages = ref(0); |
| | | const totalTakes = ref(0); |
| | | |
| | | const workHours = ref(0); |
| | | const totalMinutes = ref(0); |
| | | |
| | | // 查询数据 |
| | | const selectReportData = async () => { |
| | |
| | | totalDamages.value = totalDamage; |
| | | totalTakes.value = totalTake; |
| | | ElMessage.success(response.message); |
| | | const workTime = calculateWorkTime(response.data); |
| | | console.log(workTime); |
| | | workHours.value = workTime.totalHours; |
| | | totalMinutes.value =workTime.totalMinutes; |
| | | } else { |
| | | ElMessage.error(response.message); |
| | | } |
| | | |
| | | }; |
| | | |
| | | const calculateWorkTime = (tasks) =>{ |
| | | // 处理空数据或非数组情况 |
| | | if (!tasks || !Array.isArray(tasks) || tasks.length === 0) { |
| | | return { |
| | | totalSeconds: 0, |
| | | totalMinutes: 0, |
| | | totalHours: 0, // 确保初始化 |
| | | periods: [] |
| | | }; |
| | | } |
| | | |
| | | // 按时间排序任务 |
| | | const sorted = [...tasks].sort((a, b) => new Date(a.createTime) - new Date(b.createTime)); |
| | | |
| | | // 初始化变量 |
| | | const periods = []; |
| | | let start = new Date(sorted[0].createTime); |
| | | let end = start; |
| | | |
| | | // 遍历计算连续时段 |
| | | for (let i = 1; i < sorted.length; i++) { |
| | | const prev = new Date(sorted[i - 1].createTime); |
| | | const curr = new Date(sorted[i].createTime); |
| | | const gap = (curr - prev) / 1000; // 间隔秒数 |
| | | // alert(timeInterval.value) |
| | | if (gap <= timeInterval.value) { |
| | | end = curr; |
| | | } else { |
| | | periods.push({ |
| | | start: new Date(start), |
| | | end: new Date(end), |
| | | duration: Math.round((end - start) / 1000) |
| | | }); |
| | | start = curr; |
| | | end = curr; |
| | | } |
| | | } |
| | | |
| | | // 添加最后一个时段 |
| | | periods.push({ |
| | | start: new Date(start), |
| | | end: new Date(end), |
| | | duration: Math.round((end - start) / 1000) |
| | | }); |
| | | |
| | | // 计算总时长 |
| | | const totalSeconds = periods.reduce((sum, p) => sum + (p.duration > 0 ? p.duration : 0), 0); |
| | | |
| | | // 确保所有时间字段都被定义 |
| | | return { |
| | | totalSeconds: totalSeconds, |
| | | totalMinutes: Math.floor(totalSeconds / 60), |
| | | totalHours: (totalSeconds / 3600).toFixed(1), // 保留1位小数 |
| | | periods: periods.map(p => ({ |
| | | start: p.start.toLocaleString(), |
| | | end: p.end.toLocaleString(), |
| | | durationSeconds: p.duration, |
| | | durationMinutes: Math.floor(p.duration / 60) |
| | | })) |
| | | }; |
| | | } |
| | | </script> |