index.js 3.7 KB

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