index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // pages/clock/clock-tongji/index.js
  2. import {
  3. monthTotalSettlement,
  4. currentSettlement,
  5. daySettlement
  6. } from '../../../services/index.js'
  7. import {
  8. imgServerUrl
  9. } from '../../../config/config.js'
  10. let selected = ''
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. wsPunchClockList: [],
  17. currentSettlement: {},
  18. imgServerUrl,
  19. next: `${imgServerUrl}/images/clock/clock-arrow-righr-disabled.png`,
  20. last: `${imgServerUrl}/images/clock/clock-arrow-left.png`,
  21. text: '',
  22. currentDuration: 0,
  23. punckClockList: [],
  24. nextMoney: 0,
  25. clockCount: 0,
  26. defaultDate: ''
  27. },
  28. toList() {
  29. wx.navigateTo({
  30. url: './list?date=' + this.data.defaultDate,
  31. })
  32. },
  33. getList(month_type) {
  34. monthTotalSettlement({ month_type }).then(data => {
  35. this.setData({
  36. wsPunchClockList: data.data.wsPunchClockList
  37. })
  38. })
  39. },
  40. getCurrent() {
  41. currentSettlement().then(data => {
  42. const date = new Date(data.data.currentSettlement.date.replace(/'-'/g, '/'))
  43. // const month = Number(data.data.currentSettlement.date.split('-')[1])
  44. let year = date.getFullYear()
  45. let month = date.getMonth() + 1
  46. let day = date.getDate()
  47. this.selectComponent('.calendar').init(date)
  48. this.setData({
  49. currentSettlement: data.data.currentSettlement,
  50. text: month,
  51. mouth: month,
  52. year,
  53. defaultDate: data.data.currentSettlement.date.replace(/'-'/g, '/')
  54. })
  55. const search_date = [year, month, day].map(val => {
  56. const number = val.toString()
  57. return number[1] ? number : '0' + number
  58. }).join('-')
  59. this.getDay(search_date)
  60. })
  61. },
  62. next() {
  63. if (this.data.text !== this.data.mouth) {
  64. this.selectComponent('.calendar').next()
  65. this.getList(1)
  66. this.setData({
  67. text: this.data.mouth,
  68. next: `${imgServerUrl}/images/clock/clock-arrow-righr-disabled.png`,
  69. last: `${imgServerUrl}/images/clock/clock-arrow-left.png`,
  70. })
  71. }
  72. },
  73. last() {
  74. if (this.data.text === this.data.mouth) {
  75. this.selectComponent('.calendar').last()
  76. this.getList(2)
  77. if (this.data.mouth - 1 <= 0) {
  78. this.setData({
  79. text: 12,
  80. })
  81. } else {
  82. this.setData({
  83. text: this.data.mouth - 1
  84. })
  85. }
  86. this.setData({
  87. next: `${imgServerUrl}/images/clock/clock-arrow-righr.png`,
  88. last: `${imgServerUrl}/images/clock/clock-arrow-left-disabled.png`,
  89. })
  90. }
  91. },
  92. getDay(search_date) {
  93. daySettlement({ search_date }).then(data => {
  94. this.setData({
  95. punckClockList: data.data.punckClockList,
  96. nextMoney: data.data.nextMoney,
  97. clockCount: data.data.clockCount,
  98. currentDuration: data.data.currentDuration,
  99. })
  100. })
  101. },
  102. day(e) {
  103. let { year, month, date } = e.detail
  104. const search_date = [year, month, date].map(val => {
  105. const number = val.toString()
  106. return number[1] ? number : '0' + number
  107. }).join('-')
  108. this.getDay(search_date)
  109. },
  110. /**
  111. * 生命周期函数--监听页面加载
  112. */
  113. onLoad: function (options) {
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面显示
  122. */
  123. onShow: function () {
  124. this.getList(1)
  125. this.getCurrent()
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function () {
  136. },
  137. /**
  138. * 页面相关事件处理函数--监听用户下拉动作
  139. */
  140. onPullDownRefresh: function () {
  141. },
  142. /**
  143. * 页面上拉触底事件的处理函数
  144. */
  145. onReachBottom: function () {
  146. },
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function () {
  151. }
  152. })