JhHardwareWRS/pages/reportResult/reportResult.js
2026-06-24 15:19:14 +08:00

111 lines
4.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const api = require('../../utils/api')
Page({
data: {
report: null,
},
async onLoad(options) {
try {
const report = await api.getReport(options.reportId)
this.setData({
report: {
...report,
itemResults: this.buildItemResults(report),
},
})
} catch (error) {
wx.showToast({ title: error.message, icon: 'none' })
}
},
round1(value) {
return Math.round(Number(value || 0) * 10) / 10
},
round2(value) {
return Math.round(Number(value || 0) * 100) / 100
},
buildCompareText(rate, fastLabel, slowLabel) {
return `${rate > 0 ? slowLabel : fastLabel}${Math.abs(this.round1(rate))}%`
},
buildWorkloadText(rate) {
return `${rate >= 0 ? '工作量大于标准工作量' : '工作量小于标准工作量'}${Math.abs(this.round1(rate))}%`
},
buildItemResults(report) {
return (report.items || []).map((item, index) => {
if (item.isMisc) {
return {
key: `${item.id || index}`,
title: '处理杂活',
subtitle: `考勤点 ${item.attendancePointName || report.attendancePointName || '-'} · 工序 ${item.process || '-'} · 冲压方式 ${item.stampingMethod || '-'}`,
goodQty: 0,
defectQty: 0,
workTimeText: item.workTimeText || '-',
resultText: '处理杂活工时已提交管理员审核,杂活事项由管理员备注留痕',
goodResult: true,
isMisc: true,
isMultiPerson: !!item.isMultiPerson,
isContinuousDie: !!item.isContinuousDie,
changeoverCount: item.changeoverCount || 0,
}
}
if (item.isCleaning) {
return {
key: `${item.id || index}`,
title: `清洗 · ${item.displayName || item.productName || '-'}`,
subtitle: `考勤点 ${item.attendancePointName || report.attendancePointName || '-'} · 项目 ${item.projectNo || '-'} · 工序 ${item.process || '-'} · 冲压方式 ${item.stampingMethod || '-'}`,
goodQty: this.round2(item.goodQty || 0),
defectQty: 0,
resultText: `清洗数量 ${this.round2(item.goodQty || 0)},已提交管理员审核`,
goodResult: true,
isCleaning: true,
isMultiPerson: !!item.isMultiPerson,
isContinuousDie: !!item.isContinuousDie,
changeoverCount: item.changeoverCount || 0,
}
}
const goodQty = Number(item.goodQty || 0)
const defectQty = Number(item.defectQty || 0)
const outputQty = goodQty + defectQty
const actualBeat = outputQty > 0 ? Number(item.allocatedMinutes || 0) * 60 / outputQty : 0
const standardBeat = Number(item.standardBeat || 0)
const standardWorkload = api.calculateStandardWorkload(item.allocatedMinutes, standardBeat) || Number(item.standardWorkload || 0)
const paceRate = standardBeat > 0 ? (actualBeat - standardBeat) / standardBeat * 100 : 0
const workloadRate = standardWorkload > 0 ? (goodQty - standardWorkload) / standardWorkload * 100 : 0
const paceText = this.buildCompareText(paceRate, '节拍快于标准节拍', '节拍慢于标准节拍')
const workloadText = this.buildWorkloadText(workloadRate)
const overStandardAbnormal = paceRate < -30 || workloadRate > 30
const underStandardAbnormal = paceRate > 0 || workloadRate < 0
const abnormal = overStandardAbnormal || underStandardAbnormal
const goodResult = !abnormal
const suffix = overStandardAbnormal
? '数据明显超出标准,请自我核对一下是不是报工时填错。'
: (goodResult ? '今天真的很棒呢!' : '后续需要加油喽!')
return {
key: `${item.id || index}`,
title: `${item.deviceNo || '-'} · ${item.displayName || item.productName || '-'}`,
subtitle: `考勤点 ${item.attendancePointName || report.attendancePointName || '-'} · 项目 ${item.projectNo || '-'} · 工序 ${item.process || '-'} · 冲压方式 ${item.stampingMethod || '-'}`,
actualBeat: this.round2(actualBeat),
standardBeat: this.round2(standardBeat),
goodQty: this.round2(goodQty),
defectQty: this.round2(defectQty),
standardWorkload: this.round1(standardWorkload),
resultText: `今日${paceText},今日${workloadText}${suffix}`,
goodResult,
overStandardAbnormal: abnormal,
isMultiPerson: !!item.isMultiPerson,
isContinuousDie: !!item.isContinuousDie,
changeoverCount: item.changeoverCount || 0,
}
})
},
goRecords() {
wx.redirectTo({
url: '/pages/records/records',
})
},
goHome() {
wx.reLaunch({
url: '/pages/index/index',
})
},
})