diff --git a/weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.js b/weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.js index a5cb997..19d984a 100644 --- a/weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.js +++ b/weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.js @@ -123,28 +123,49 @@ Page({ this.inspectedPoints = inspectedPoints; // 今日待检分布 - // let needInspectPoints = []; - // subSystemPatrol.dayPatrolPlan.forEach((plan) => { - // const unit = plan.frequency.split('/')[1]; - // const frequency = plan.frequency.split('/')[0]; - // let record = [...patrolRecord]; - // switch (unit) { - // case '周': - // record = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day')); - // break; - // case '天': - // record = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day')); - // break; - // default: - // break; - // } - // }) + let needInspectPoints = []; + subSystemPatrol.dayPatrolPlan.forEach((plan) => { + const unit = plan.frequency.split('/')[1]; + const frequency = Number(plan.frequency.split('次')[0]); + let record = patrolRecord.filter(r => + moment(r.inspectionTime).isBefore(moment(this.day).endOf('day')) // 当前选定日期及之前的巡检记录 + && r.patrolPlanId === plan.id // 关联当前计划的记录 + ); + switch (unit) { + case '月': + record = record.filter(r => moment(r.inspectionTime).isSame(this.day, 'month ')); + break; + case '周': + record = record.filter(r => moment(r.inspectionTime).isSame(this.day, 'isoWeek')); + break; + case '天': + record = record.filter(r => moment(r.inspectionTime).isSame(this.day, 'day')); + break; + default: + break; + } + plan.points.forEach(p => { + const index = needInspectPoints.findIndex(n => n.name === p.name) + if (index === -1) { + needInspectPoints.push({ name: p.name, value: frequency }); + } else { + needInspectPoints[index].value += frequency; + } + }) + record.forEach(r => { + const index = needInspectPoints.findIndex(n => n.name === r.points.itemData.name); + if (index !== -1 && needInspectPoints[index].value > 0) { + needInspectPoints[index].value -= 1; + } + }) + }) + this.initNeedChart(needInspectPoints) this.initAlreadyChart(inspectedPoints) this.setData({ dayIssues: nextDayIssues, + needInspectCount: needInspectPoints.reduce((accumulator, currentValue) => accumulator + currentValue.value, 0), inspectedCount: inspectedPoints.reduce((accumulator, currentValue) => accumulator + currentValue.value, 0), - }) }) }, @@ -158,15 +179,6 @@ Page({ this.day = options.day; this.subType = options.subType; this.getData(); - setTimeout(() => { - this.initNeedChart([ - { value: 1048, name: '点位1' }, - { value: 735, name: '点位2' }, - { value: 580, name: '点位3' }, - { value: 580, name: '点位4' }, - { value: 580, name: '点位5' }, - ]) - }, 1000) }, /**