riku
2023-02-24 5d8e52e398bff7bc8f83e8f5b8a387175b958c98
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
// pages/promise/promise.js
const moment = require('../../../utils/moment.min')
const promiseservice = require("../../../service/promiseservice")
const app = getApp()
 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    text1: "已开启!请及时完成承诺",
    text3: "去承诺",
    status: 0,
 
    promise: [{
      period: '承诺周期:2021年1月~2021年12月',
      time: '2021年1月6日完成',
      picPath: [],
      pdfPath: ''
    }],
    deadline: "承诺截止时间:----年--月--日",
  },
 
  promiseHistory: [],
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._initPlanYear()
    // this.getCommitment()
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log("promise: onshow");
    this.getCommitment()
  },
 
  /**
   * 初始化年份
   */
  _initPlanYear() {
    var now = moment()
    var year = now.year()
    var period = `${now.year()}/${now.month()+1}-${now.month()+1}`
    var deadline = now.endOf('year').format("YYYY年MM月DD日")
    this.setData({
      year: year,
      // deadline: `承诺截止时间:${deadline}`
      deadline: ''
    })
  },
 
  /**
   * 判断当前周期内的承诺是否完成
   */
  checkStatus() {
    if (this.promiseHistory.length > 0) {
      var first = this.promiseHistory[0]
      var cTime = moment(first.cmCreateTime)
      let leftDays = cTime.add(1, 'years').diff(moment(), 'days')
      // that.setData({
      //   promsieInfo: {
      //     leftDays: leftDays
      //   }
      // })
      if (leftDays > 0) {
        var deadline = cTime.format("YYYY-MM-DD")
        this.setData({
          text1: "本次承诺已完成",
          text3: "查看承诺",
          status: 1,
          deadline: `承诺有效时间:剩余${leftDays}天`
        })
      } else {
        this.setData({
          text1: "请及时完成承诺",
          text3: "去承诺",
          status: 0,
        })
        this._initPlanYear()
      }
    }
  },
 
  /**
   * 获取历史记录
   */
  getCommitment() {
    var that = this
    promiseservice.getCommitment(app.globalData.accessToken.userId, {
      success(data) {
        that.promiseHistory = data
        let promise = []
        data.forEach(d => {
          const time = moment(d.cmCreateTime)
          promise.push({
            period: `承诺周期:${time.year()}年1月~${time.year()}年12月`,
            time: `${time.format('YYYY年MM月DD日')}完成`,
            picPath: d.cmUrl,
            pdfPath: d.cmPdfUrl
          })
        });
        that.setData({
          promise
        })
 
        that.checkStatus()
      }
    })
  },
 
  /**
   * 跳转至去承诺
   */
  gotoPromise(e) {
    var status = e.currentTarget.dataset.status
    if (status == 0) {
      wx.navigateTo({
        url: '/pages/mPromise/promiseinfo/promiseinfo'
      })
    } else {
      this.gotoResult(0)
    }
  },
 
  /**
   * 跳转至承诺详情
   */
  gotoDetail(e) {
    var i = e.currentTarget.dataset.index
    this.gotoResult(i)
  },
 
  gotoResult(i) {
    var p = this.data.promise[i]
    wx.navigateTo({
      url: '/pages/mPromise/promiseresult/promiseresult',
      success: function (res) {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          promise: {
            picPath: p.picPath,
            pdfPath: p.pdfPath
          }
        })
      }
    })
  },
 
  /**
   * 跳转至历史记录
   */
  gotoHistory() {
 
  }
})