riku
2026-01-19 068be2757aa2d51e3f6604dae54287683160ad0e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import scheduleservice from '../../../service/scheduleservice';
import moment from '../../../utils/moment.min';
import { animation1 } from '../../../utils/animation';
import $f from "../../../service/baserequest";
 
Component({
  properties: {},
 
  data: {
    icon_calendar: $f.baseIconUrl + 'res/calendar.jpg',
    schedules: [],
    expand: false,
    unfinishedCount: 0,
  },
  lifetimes: {
    attached: function () {
      this.getTodaySchedules();
    },
  },
  methods: {
    initAnimation() {
      this.animation = animation1({
        content: this,
        selector: '.schedule-card__item',
        size: this.data.schedules.length,
        margin: 1,
      });
    },
 
    getTodaySchedules() {
      let startTime = moment().format('YYYY-MM-DD');
      let endTime = startTime;
      const that = this;
      scheduleservice.getSchedules(
        { startTime, endTime, type: 1 },
        {
          success(res) {
            const schedules = [];
            let unfinishedCount = 0;
            res.data.forEach(r => {
              r.time = moment(r.time.split('T')[0]).format('YYYY-MM-DD dddd');
              schedules.push(r);
              if (!r.finished) unfinishedCount++;
            });
            schedules.sort((a, b) => {
              return a.finished - b.finished;
            });
            that.setData({ schedules, unfinishedCount });
            that.initAnimation();
          },
          fail(e) {
            console.log(e);
          },
        },
      );
    },
 
    onCardClick() {
      if (this.data.expand) {
        this.setData({ expand: !this.data.expand });
        this.animation.collapse();
      } else {
        this.animation.expand(() => {
          this.setData({ expand: !this.data.expand });
        });
      }
    },
 
    onComplete(e) {
      const { index } = e.currentTarget.dataset;
      const s = this.data.schedules[index];
      this.setData({
        [`schedules[${index}].loading`]: true,
      });
      const that = this;
      scheduleservice.completeSchedule(
        { id: s.id },
        {
          success(res) {
            that.setData({
              [`schedules[${index}].loading`]: false,
              [`schedules[${index}].recordId`]: res.data.srId,
            });
            that.completeAnimation(index);
          },
          fail(e) {
            that.setData({
              [`schedules[${index}].loading`]: false,
            });
          },
          complete() {},
        },
      );
    },
 
    onRevoke(e) {
      const { index } = e.currentTarget.dataset;
      const s = this.data.schedules[index];
      this.setData({
        [`schedules[${index}].loading`]: true,
      });
      const that = this;
      scheduleservice.revokeSchedule(
        { recordId: s.recordId },
        {
          success(res) {
            that.setData({
              [`schedules[${index}].loading`]: false,
            });
            that.completeAnimation(index);
          },
          fail(e) {
            that.setData({
              [`schedules[${index}].loading`]: false,
            });
          },
          complete() {},
        },
      );
    },
 
    completeAnimation(index) {
      const { schedules } = this.data;
      const s = schedules[index];
      schedules.splice(index, 1);
      let nextIndex = index;
      if (s.finished) {
        schedules.unshift(s);
        nextIndex = 0;
      } else {
        schedules.push(s);
        nextIndex = schedules.length - 1;
      }
      s.finished = !s.finished;
      this.checkFinishedCount(s.finished);
      this.animation.slideOut(index, () => {
        this.setData({
          schedules,
        });
        this.animation.slideIn(nextIndex, () => {});
      });
    },
 
    checkFinishedCount(finished) {
      let { unfinishedCount } = this.data;
      unfinishedCount += finished ? -1 : 1;
      this.setData({ unfinishedCount });
    },
  },
});