From ab70c6eb4a181b282af0eb200275cd8a4d2ab172 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 13 十一月 2024 16:41:32 +0800
Subject: [PATCH] 2024.11.13
---
pages/mService/behaviors/bScheduleManager.js | 193 ++++++++++++++++++++++++++---------------------
1 files changed, 107 insertions(+), 86 deletions(-)
diff --git a/pages/mService/behaviors/bScheduleManager.js b/pages/mService/behaviors/bScheduleManager.js
index e19eeb9..156adee 100644
--- a/pages/mService/behaviors/bScheduleManager.js
+++ b/pages/mService/behaviors/bScheduleManager.js
@@ -1,9 +1,9 @@
-import scheduleservice from '../../../service/scheduleservice'
-import sysSchedules from '../../../data/schedules'
-import moment from '../../../utils/moment.min'
-import util from '../../../utils/util'
+import scheduleservice from '../../../service/scheduleservice';
+import sysSchedules from '../../../data/schedules';
+import moment from '../../../utils/moment.min';
+import util from '../../../utils/util';
-const app = getApp()
+const app = getApp();
/**
* 鐜繚鏃ョ▼绠$悊
@@ -12,125 +12,146 @@
// behaviors: [bLoadingStatus],
properties: {
ledgerCompleted: {
- type: Boolean,
+ type: Number,
observer(value) {
- this.checkScheduleComplete(0, value)
- }
+ this.checkScheduleComplete(1, value);
+ },
},
assessmentCompleted: {
- type: Boolean,
+ type: Number,
observer(value) {
- this.checkScheduleComplete(1, value)
- }
- }
+ this.checkScheduleComplete(2, value);
+ },
+ },
},
data: {
+ // 鍏ㄩ儴鐜繚鏃ョ▼
allSchedules: [],
+ // 褰撳墠鐢ㄦ埛鏈�涓磋繎鏈畬鎴愭棩绋�
thisSchedule: {},
- index: 0
+ // 褰撳墠鐢ㄦ埛鏈�涓磋繎鏈畬鎴愭棩绋嬬储寮�
+ index: 0,
+ // 鍙拌处鍜岃嚜璇勬湰鏈熷畬鎴愭儏鍐�
+ scheduleComplete: new Map(),
+ // 闇�瑕佸仛鏃ョ▼鏄惁瀹屾垚鍒ゆ柇鐨勬棩绋嬩釜鏁帮紙鍙拌处鍜岃嚜璇勶級
+ scheduleCount: 2,
},
lifetimes: {
attached: function () {
- this.getRecentSchedule()
- if (app.globalData.newUser) {
- this.nextSchedules()
- }
- // this.getAllSchedules()
- }
+ this.setData({
+ scheduleComplete: new Map(),
+ });
+ this.getAllSchedules().then(() => {
+ this.getRecentSchedule();
+ if (app.globalData.newUser) {
+ this.nextSchedules();
+ }
+ });
+ // this.getSchedules();
+ },
},
methods: {
+ // 鑾峰彇鏈�閭昏繎鐨勪竴涓幆淇濈郴缁熸棩绋�
+ getSchedules() {
+ let startTime = moment().format('YYYY-MM-DD');
+ let endTime = startTime;
+ const that = this;
+ scheduleservice.getSchedules(
+ { startTime, endTime, type: 0 },
+ {
+ success(res) {
+ if (res.data.length > 0) {
+ res.data.sort(
+ (a, b) => Math.abs(a.diffDays) - Math.abs(b.diffDays),
+ );
+ const schedule = res.data[0];
+ schedule.time = moment(schedule.time.split('T')[0]).format(
+ 'YYYY-MM-DD',
+ );
+ that.setData({
+ thisSchedule: schedule,
+ });
+ }
+ },
+ fail(e) {
+ console.log(e);
+ },
+ },
+ );
+ },
+
//鏌ユ壘鏈�涓磋繎鐨勬棩绋�
getRecentSchedule() {
//1. 浠庢帴鍙h幏鍙栫敤鎴蜂釜浜恒�佺敤鎴蜂紒涓氱被鍨嬬殑鐩稿叧鏈�涓磋繎鏃ョ▼
//2. 鎸夌収鏈湴閫昏緫锛屽緱鍑烘渶閭昏繎鏃ョ▼
- const schedules = sysSchedules()
+ const schedules = this.data.allSchedules;
//2.1 灏嗗彴璐︺�佽瘎浼般�佹壙璇轰笁椤笰PP鍔熻兘瀹氫箟涓烘棩绋�
- //2.2 閫夋嫨鏈�閭昏繎鐨勪簨椤逛綔涓哄綋鏃ョ殑鎻愰啋浜嬮」,
- let today = moment().hour(0).minute(0).second(0).millisecond(0)
- let diffDays = 999
- let schedule
- let index = 0
+ //2.2 閫夋嫨鏈�閭昏繎鐨勪簨椤逛綔涓哄綋鏃ョ殑鎻愰啋浜嬮」,
+ let today = moment().hour(0).minute(0).second(0).millisecond(0);
+ let diffDays = 999;
+ let schedule;
+ let index = 0;
for (let i = 0; i < schedules.length; i++) {
let s = schedules[i];
- let d = s.time.diff(today, 'days')
- s.diffDays = d
+ let d = s.diffDays;
+ // if (d == -8) {
if (Math.abs(d) < Math.abs(diffDays)) {
- let _index = i
+ let _index = i;
- schedule = s
- diffDays = d
- index = _index
+ schedule = s;
+ diffDays = d;
+ index = _index;
}
}
//2.3 鏃ョ▼鍦ㄦ椂闂寸淮搴︿笂鍒嗕负涓夌被鎻愰啋锛岄鍛娿�佸綋鏃ャ�佹湭瀹屾垚鐨勯�炬湡鎻愰啋
-
this.setData({
- allSchedules: schedules,
- thisSchedule: {
- date: schedule.time,
- time: schedule.time.format('YYYY-MM-DD dddd'),
- type: schedule.type,
- events: schedule.events,
- diffDays: schedule.diffDays,
- },
- index
- })
+ thisSchedule: schedule,
+ index,
+ });
},
//鑾峰彇鎵�鏈夋棩绋�
getAllSchedules() {
- console.log('getAllSchedules');
- scheduleservice.getAllSchedules(app.globalData.accessToken.userId, {
- success(res) {
- console.log('success');
- console.log(res);
- },
- fail(e) {
- console.log('fail');
- console.log(e);
- },
- complete(res) {
- console.log('complete');
- },
- })
+ return sysSchedules().then(res => {
+ this.setData({
+ allSchedules: res,
+ });
+ });
},
// 褰撳墠鏃ョ▼瀹屾垚锛岄『寤朵笅涓�涓棩绋�
nextSchedules() {
- let today = moment().hour(0).minute(0).second(0).millisecond(0)
let s = this.data.allSchedules[this.data.index + 1];
- let d = s.time.diff(today, 'days')
- s.diffDays = d
-
this.setData({
- thisSchedule: {
- date: s.time,
- time: s.time.format('YYYY-MM-DD dddd'),
- type: s.type,
- events: s.events,
- diffDays: s.diffDays,
- },
- index: this.data.index + 1
- })
+ thisSchedule: s,
+ index: this.data.index + 1,
+ });
},
- // 妫�鏌ュ綋鍓嶆棩绋嬫槸鍚﹀畬鎴�
- checkScheduleComplete(type, value) {
- debugger
+ // 妫�鏌ュ綋鍓嶆棩绋嬫槸鍚﹀畬鎴�(2023.8.24 鐩墠鍙秹鍙婂彴璐﹀拰鑷瘎涓ょ被鏃ョ▼)
+ checkScheduleComplete(scId, value) {
+ const { scheduleComplete, scheduleCount } = this.data;
+ scheduleComplete.set(scId, value);
+ // 鍙拌处鍜岃嚜璇勭殑缁撴灉鍏ㄩ儴浼犲叆鍚庡啀鍋氬垽鏂�
+ if (scheduleComplete.size < scheduleCount) return;
// 鏂扮敤鎴蜂笉鍋氬垽鏂�
- if (app.globalData.newUser) return
- // 鏃ョ▼绫诲瀷涓嶄竴鑷存棤闇�鍒ゆ柇
- if (this.data.thisSchedule.type != type) return
- // 鏃ョ▼涓嶅湪褰撴湀鐨勬棤闇�鍒ゆ柇
- const thisMonth = moment().month()
- const sTimeMonth = moment(this.data.thisSchedule.date).month()
- if (thisMonth != sTimeMonth) return
+ if (app.globalData.newUser) return;
- // 鏃ョ▼瀹屾垚鍒欓『寤朵笅涓棩绋�
- if (value) {
- this.nextSchedules()
- }
- }
- }
-})
\ No newline at end of file
+ let index = 0;
+ const thisMonth = moment().month();
+ do {
+ const { thisSchedule } = this.data;
+ // 鏃ョ▼涓嶅湪褰撴湀鐨勬棤闇�鍒ゆ柇
+ const sTimeMonth = moment(thisSchedule.time).month();
+ if (thisMonth != sTimeMonth) return;
+
+ // 鍒ゆ柇褰撴湀璇ユ棩绋嬫槸鍚﹀畬鎴愶紝瀹屾垚鍒欏皢褰撳墠鏃ョ▼椤哄欢鑷充笅涓�涓�
+ if (scheduleComplete.get(thisSchedule.id) == 2) {
+ this.nextSchedules();
+ }
+ index++
+ } while (index < scheduleCount);
+ },
+ },
+});
--
Gitblit v1.9.3