index.js 4.2 KB

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