selectDate.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 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 dateArr = [this.data.initDate, this.data.lastDate];
  70. this.triggerEvent("getDates", dateArr);
  71. this.showSelect()
  72. },
  73. submitDate: function () {
  74. const dateArr = [this.data.beginDate, this.data.endDate];
  75. this.triggerEvent("getDates", dateArr);
  76. this.showSelect()
  77. },
  78. showSelect: function () {
  79. var animation = wx.createAnimation({
  80. timingFunction: 'linear',
  81. })
  82. this.animation = animation
  83. var num = 0
  84. var opacity = 0
  85. if (this.data.yFlag == false) {
  86. num = 180
  87. opacity = 0.4
  88. this.setData({
  89. yFlag: true
  90. })
  91. } else {
  92. num = -360
  93. opacity = 0
  94. this.setData({
  95. yFlag: false
  96. })
  97. }
  98. animation.translateY(num).step()
  99. this.setData({
  100. animationBox: animation.export()
  101. })
  102. var animation2 = wx.createAnimation({
  103. timingFunction: 'linear',
  104. })
  105. this.animation2 = animation2
  106. animation2.opacity(opacity).step()
  107. this.setData({
  108. animationBg: animation2.export()
  109. })
  110. },
  111. }
  112. })