riku
2024-11-13 48145f787eda81815f653ad21161a60e89b6a303
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
const ledgerservice = require('../../../service/ledgerservice');
const moment = require('../../../utils/moment.min');
const app = getApp();
 
Page({
  /**
   * 页面的初始数据
   */
  data: {
    thisMonth: '',
    lastMonth: '',
 
    //提交期限
    deadline: '',
    //剩余提交天数
    leftday: 0,
 
    //本月汇总
    thisMonthInfo: {
      //必填项总数
      totalMust: 0,
      //必填项提交数
      finishedMust: 0,
      //选填项总数
      totalSelect: 0,
      //选填项提交数
      finishedSelect: 0,
      //提交情况
      status: '',
      //超时情况
      overtime: '',
      //建议
      suggestion: '',
    },
    //上月汇总
    lastMonthInfo: {
      totalMust: 0,
      finishedMust: 0,
      totalSelect: 0,
      finishedSelect: 0,
      status: '',
      overtime: '',
      suggestion: '',
    },
 
    //选项卡相关
    currentTab: 0,
    tabList: [],
    pageList: [],
    pageheight: '300px',
 
    //当前显示月份
    showThisMonth: true,
  },
 
  //每月台账提交期限日
  DEADLINEDAY: 10,
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let now = moment();
    let limitTime = moment().date(this.DEADLINEDAY);
    //如果是新注册用户不到一个月,则不提醒本月情况,直接提醒下个月的情况
    if (app.globalData.newUser) {
      limitTime.add(1, 'M');
    }
    let deadline = limitTime.format(`MM-${this.DEADLINEDAY}`);
    let leftday = limitTime.diff(now, 'days');
    let thisMonth = now.format('YYYY-MM');
    let lastMonth = now.add(-1, 'M').format('YYYY-MM');
    this.setData({
      deadline,
      leftday,
      thisMonth,
      lastMonth,
    });
 
    now = moment();
    this.getLedgerType(now.format('YYYY-MM-DD'), r => {
      this.setData({
        tabList: r[0],
        pageList: r[1],
        thisMonthInfo: r[2],
      });
      this.tabsHeight('.page0');
    }); //本月
    this.getLedgerType(
      now.add(-1, 'M').format('YYYY-MM-DD'),
      r => {
        this.setData({
          lastMonthInfo: r[2],
        });
      },
      true,
    ); //上月
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},
 
  getLedgerType(time, success, lastMonth) {
    var that = this;
    // var time = moment().format('YYYY-MM-DD')
    ledgerservice.getLedgerSummary(
      app.globalData.accessToken.userId,
      app.globalData.userInfo.extension2,
      time,
      {
        success(res) {
          let r = that.parseLedgerType(res, lastMonth);
          success(r);
        },
      },
    );
  },
 
  parseLedgerType(subtypes, lastMonth) {
    let monthInfo = {
      totalMust: 0,
      finishedMust: 0,
      totalSelect: 0,
      finishedSelect: 0,
      status: '',
      overtime: '',
      suggestion: '',
    };
    let map = new Map();
    subtypes.forEach(s => {
      //月度统计
      if (s.ledgerTypeId != -1 && s.needUpdate) {
        monthInfo.totalMust++;
        if (s.upLoad) {
          monthInfo.finishedMust++;
        }
      } else {
        monthInfo.totalSelect++;
        if (s.upLoad) {
          monthInfo.finishedSelect++;
        }
      }
 
      //选项卡
      if (s.upLoad) {
        s.tag = '/res/icons/round_check_fill.png';
        s.opacity = 0.7;
      } else if (s.ledgerFinished) {
        s.tag = '/res/icons/warning_yellow.png';
        s.opacity = 1;
      } else if (!s.needUpdate) {
        s.tag = '/res/icons/warning_selected.png';
        s.opacity = 0.8;
      } else {
        s.tag = '/res/icons/warning_red.png';
        s.opacity = 1;
      }
      if (!map.has(s.ledgerType)) {
        map.set(s.ledgerType, []);
      }
      map.get(s.ledgerType).push(s);
    });
 
    //
    if (monthInfo.finishedMust == 0) {
      monthInfo.status = '未提交';
      if (lastMonth) {
        monthInfo.suggestion =
          '建议:当期台账完全未提交,严重影响评估结果,后续请注意';
      } else {
        monthInfo.suggestion = '建议:请尽快提交台账';
      }
    } else if (monthInfo.finishedMust < monthInfo.totalMust) {
      monthInfo.status = '部分提交';
      if (lastMonth) {
        monthInfo.suggestion =
          '建议:当期台账部分未提交,会影响评估结果,后续请尽量提交所有台账';
      } else {
        monthInfo.suggestion = '建议:当前已提交部分台账,请补全剩余台账';
      }
    } else {
      monthInfo.status = '已提交';
      if (lastMonth) {
        monthInfo.suggestion = '当期台账已全部提交,请保持';
      } else {
        monthInfo.suggestion = '本期台账已全部提交';
      }
    }
    monthInfo.overtime = moment().date() - this.DEADLINEDAY;
    monthInfo.percent = Math.round(
      (monthInfo.finishedMust / monthInfo.totalMust) * 100,
    );
 
    //选项卡
    var t = [];
    var p = [];
    for (let item of map) {
      if (item[1][0].ledgerTypeId == -1) {
        continue;
      }
      let notUpload = 0;
      item[1].forEach(l => {
        if (l.needUpdate && !l.upLoad) {
          notUpload++;
        }
      });
      t.push({
        name: item[0],
        tag: notUpload,
        total: item[1].length,
      });
      p.push(item[1]);
    }
 
    return [t, p, monthInfo];
  },
 
  gotoLedgerDetail(e) {
    var i = e.currentTarget.dataset.index.split(',');
    var indexGroup = [parseInt(i[0]), parseInt(i[1])];
    var ledger = this.data.pageList[indexGroup[0]][indexGroup[1]];
 
    var that = this;
    wx.navigateTo({
      url: '/pages/mLedger/ledgerupload/ledgerupload',
      events: {
        uploadOver: function (data) {
          let i = data.indexGroup;
          let { pageList, tabList } = that.data;
          tabList[i[0]].tag--;
          pageList[i[0]][i[1]].upLoad = true;
          pageList[i[0]][i[1]].tag = '/res/icons/round_check_fill.png';
          pageList[i[0]][i[1]].opacity = 0.7;
          that.setData({
            pageList,
            tabList,
          });
        },
      },
      success: res => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          ledger: ledger,
          indexGroup: indexGroup,
          type: 0,
        });
      },
    });
  },
 
  gotoHistory() {
    let tabList = this.data.tabList;
    wx.navigateTo({
      url: '/pages/mLedger/ledgerhistory/ledgerhistory',
      success: res => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          tabList: tabList,
        });
      },
    });
  },
 
  //计算swiper高度方法(在切换的时候调用)
  tabsHeight(element) {
    let that = this;
    let query = wx.createSelectorQuery(); //必须要先创建一个查询
    query
      .select(element)
      .boundingClientRect(function (rect) {
        let pageheight = that.data.pageheight.split('px')[0];
        pageheight = parseInt(pageheight);
        if (rect.height > pageheight) {
          that.setData({
            pageheight: rect.height + 'px',
          });
        }
      })
      .exec();
  },
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
        navScrollLeft:
          e.target.dataset.current >= 3 ? e.target.dataset.current * 60 : 0, //判断当前选中的个数是否是第5个
      });
      // that.tabsHeight('.page' + e.target.dataset.current); //查询哪一个元素
    }
  },
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current,
      navScrollLeft: e.detail.current >= 3 ? e.detail.current * 60 : 0, //判断当前选中的个数是否是第5个
    });
    that.tabsHeight('.page' + e.detail.current); //查询哪一个元素
  },
 
  changeMonth() {
    let showThisMonth = !this.data.showThisMonth;
    this.setData({ showThisMonth });
  },
});