riku
2022-08-23 8fbd6b8d09e70494d920cc0b77812e9643be3196
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
// pages/module_ledger/ledgerHistory/ledgerhistory.js
const ledgerservice = require("../../../service/ledgerservice")
const moment = require('../../../utils/moment.min')
const app = getApp()
 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    year: 2000,
    maxYear: 2000,
 
    months: [{
      month: 1,
      hasData: true
    }, {
      month: 2,
      hasData: true
    }, {
      month: 3,
      hasData: true
    }, {
      month: 4,
      hasData: true
    }, {
      month: 5,
      hasData: true
    }, {
      month: 6,
      hasData: true
    }, {
      month: 7,
      hasData: true
    }, {
      month: 8,
      hasData: true
    }, {
      month: 9,
      hasData: true
    }, {
      month: 10,
      hasData: true
    }, {
      month: 11,
      hasData: true
    }, {
      month: 12,
      hasData: true
    }],
    selectedMonIndex: 0,
 
    recordList: []
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    this.initTime()
    this.getRecord()
    this.getOpenerEventChannel().on('acceptDataFromOpenerPage', function (data) {
      let ledgerMap = new Map()
      data.tabList.forEach(t => {
        ledgerMap.set(t.name, {
          notUpload: t.tag,
          total: t.total,
          ledgers: []
        })
      });
      that.setData({
        ledgerMap
      })
    })
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  onShow(){
    if (this.data.marginTop == undefined) {
      this.topHeight('.page__hd')
    }
  },
 
  initTime(year) {
    var date = new Date()
    let maxYear = date.getFullYear()
    var thisMonth = date.getMonth()
    if (year == undefined) {
      year = maxYear + '年'
    }
    this.setData({
      year: year,
      maxYear: maxYear,
    })
    this.setData({
      selectedMonIndex: thisMonth
    })
  },
 
  bindYearChange(e) {
    let y = e.detail.value
    this.setData({
      year: `${y}年`
    })
    this.getRecord()
  },
 
  selectMonth(e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      selectedMonIndex: index
    })
    this.getRecord()
  },
 
  getRecord() {
    var that = this
    var userId = app.globalData.accessToken.userId
    var sceneType = app.globalData.userInfo.extension2
    let month = this.data.months[this.data.selectedMonIndex].month
    let year = parseInt(this.data.year.split("年")[0])
    var time = moment().year(year).month(month - 1).format('YYYY-MM-DD')
    wx.showLoading({
      title: '加载中',
      mask: true,
      success: (res) => {},
      fail: (res) => {},
      complete: (res) => {},
    })
    setTimeout(() => {
      wx.hideLoading()
    }, 20000);
    ledgerservice.getLedgerDetail(userId, undefined, sceneType, time, {
      success(res) {
        let ledgerMap = that.data.ledgerMap
        ledgerMap.forEach((e, key) => {
          e.ledgers = []
        });
        res.forEach(r => {
          let t = ledgerMap.get(r.ledgerType)
          t.ledgers.push(r)
        });
        let recordList = []
        ledgerMap.forEach((e, key) => {
          recordList.push({
            ledgerType: key,
            total: e.total,
            notUpload: e.notUpload,
            ledgers: e.ledgers
          })
        });
        // for (const key in ledgerMap) {
        //   const e = ledgerMap.get(key);
 
        // }
        that.setData({
          ledgerMap: ledgerMap,
          recordList: recordList
        })
        console.log(recordList);
      },
      complete(res) {
        wx.hideLoading()
      }
    })
  },
 
  topHeight(element) {
    let that = this;
    let query = wx.createSelectorQuery(); //必须要先创建一个查询
    query.select(element).boundingClientRect(function (rect) {
      that.setData({
        marginTop: rect.height + 'px'
      });
    }).exec();
  },
 
  gotoLedgerDetail(e) {
    var i = e.currentTarget.dataset.index.split(',')
    var indexGroup = [parseInt(i[0]), parseInt(i[1])]
    var ledger = this.data.recordList[indexGroup[0]].ledgers[indexGroup[1]]
    console.log(ledger);
    wx.navigateTo({
      url: '/pages/module_ledger/ledgerupload/ledgerupload',
      success: (res) => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          ledger: ledger,
          indexGroup: indexGroup,
          barTitle: '历史台账'
        })
      },
    })
  },
})