selectDate.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. typeFlag:{
  26. type:Boolean,
  27. default: false
  28. },
  29. toTop:{
  30. type:Number,
  31. value: -360
  32. }
  33. },
  34. /**
  35. * 组件的初始数据
  36. */
  37. data: {
  38. beginDate: '2020-01-01',
  39. endDate: '2021-02-02',
  40. initDate: '2020-01-01',
  41. lastDate: '',
  42. yFlag: false,
  43. animationBox: {},
  44. animationBg: {},
  45. typeArr:['全部','已预约','排队中'],
  46. typeIndex: 0,
  47. str:{}
  48. },
  49. /**
  50. * 组件的方法列表
  51. */
  52. methods: {
  53. bindBeginDateChange: function (e) {
  54. if (e.detail.value > this.data.endDate) {
  55. this.setData({
  56. beginDate: this.data.endDate
  57. })
  58. } else {
  59. this.setData({
  60. beginDate: e.detail.value
  61. })
  62. }
  63. },
  64. bindEndDateChange: function (e) {
  65. if (e.detail.value > this.data.endDate) {
  66. this.setData({
  67. endDate: this.data.lastDate
  68. })
  69. } else {
  70. this.setData({
  71. endDate: e.detail.value
  72. })
  73. }
  74. },
  75. resetDate: function () {
  76. this.setData({
  77. beginDate: this.data.initDate,
  78. endDate: this.data.lastDate,
  79. typeIndex: 0
  80. })
  81. const date = new Date()
  82. const dateArr = [date.getFullYear()+"-01"+"-01", this.data.lastDate];
  83. this.triggerEvent("getDates", dateArr);
  84. this.showSelect()
  85. },
  86. submitDate: function () {
  87. const dateArr = [this.data.beginDate, this.data.endDate];
  88. this.triggerEvent("getDates", dateArr);
  89. this.showSelect()
  90. },
  91. showSelect: function () {
  92. var animation = wx.createAnimation({
  93. timingFunction: 'linear',
  94. })
  95. this.animation = animation
  96. var num = 0
  97. var opacity = 0
  98. if (this.data.yFlag == false) {
  99. num = Math.abs(this.data.toTop) / 2 + 30
  100. opacity = 0.4
  101. this.setData({
  102. yFlag: true
  103. })
  104. } else {
  105. num = this.data.toTop
  106. opacity = 0
  107. this.setData({
  108. yFlag: false
  109. })
  110. }
  111. animation.translateY(num).step()
  112. this.setData({
  113. animationBox: animation.export()
  114. })
  115. var animation2 = wx.createAnimation({
  116. timingFunction: 'linear',
  117. })
  118. this.animation2 = animation2
  119. animation2.opacity(opacity).step()
  120. this.setData({
  121. animationBg: animation2.export()
  122. })
  123. },
  124. bindPickerChange:function(e){
  125. const typeIndex = e.detail.value
  126. const name = this.data.typeArr[typeIndex]
  127. const str = {
  128. typeIndex,
  129. name
  130. }
  131. this.setData({
  132. str,
  133. typeIndex
  134. })
  135. // this.triggerEvent("changeType",str)
  136. },
  137. }
  138. })