index.js 4.3 KB

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