selectDate.js 2.5 KB

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