selectDate.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // pages/Components/selectDate/selectDate.js
  2. Component({
  3. lifetimes: {
  4. attached: function () {
  5. var date = new Date()
  6. const year = date.getFullYear()
  7. const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  8. const day = date.getDate() + 1 < 10 ? '0' + date.getDate() : date.getDate()
  9. this.setData({
  10. endDate: year + '-' + month + '-' + day,
  11. lastDate: year + '-' + month + '-' + day
  12. })
  13. }
  14. },
  15. /**
  16. * 组件的属性列表
  17. */
  18. properties: {
  19. beginDate: {
  20. type: String
  21. },
  22. endDate: {
  23. type: String
  24. }
  25. },
  26. /**
  27. * 组件的初始数据
  28. */
  29. data: {
  30. beginDate: '2020-01-01',
  31. endDate: '2021-02-02',
  32. initDate: '2020-01-01',
  33. lastDate: '',
  34. yFlag: false,
  35. animationBox: {},
  36. animationBg: {},
  37. },
  38. /**
  39. * 组件的方法列表
  40. */
  41. methods: {
  42. bindBeginDateChange: function (e) {
  43. if (e.detail.value > this.data.endDate) {
  44. this.setData({
  45. beginDate: this.data.endDate
  46. })
  47. } else {
  48. this.setData({
  49. beginDate: e.detail.value
  50. })
  51. }
  52. },
  53. bindEndDateChange: function (e) {
  54. if (e.detail.value > this.data.endDate) {
  55. this.setData({
  56. endDate: this.data.lastDate
  57. })
  58. } else {
  59. this.setData({
  60. endDate: e.detail.value
  61. })
  62. }
  63. },
  64. resetDate: function () {
  65. this.setData({
  66. beginDate: this.data.initDate,
  67. endDate: this.data.lastDate
  68. })
  69. const date = new Date()
  70. const dateArr = [date.getFullYear()+"-01"+"-01", this.data.lastDate];
  71. this.triggerEvent("getDates", dateArr);
  72. this.showSelect()
  73. },
  74. submitDate: function () {
  75. const dateArr = [this.data.beginDate, this.data.endDate];
  76. this.triggerEvent("getDates", dateArr);
  77. this.showSelect()
  78. },
  79. showSelect: function () {
  80. var animation = wx.createAnimation({
  81. timingFunction: 'linear',
  82. })
  83. this.animation = animation
  84. var num = 0
  85. var opacity = 0
  86. if (this.data.yFlag == false) {
  87. num = 180
  88. opacity = 0.4
  89. this.setData({
  90. yFlag: true
  91. })
  92. } else {
  93. num = -360
  94. opacity = 0
  95. this.setData({
  96. yFlag: false
  97. })
  98. }
  99. animation.translateY(num).step()
  100. this.setData({
  101. animationBox: animation.export()
  102. })
  103. var animation2 = wx.createAnimation({
  104. timingFunction: 'linear',
  105. })
  106. this.animation2 = animation2
  107. animation2.opacity(opacity).step()
  108. this.setData({
  109. animationBg: animation2.export()
  110. })
  111. },
  112. }
  113. })