selectDate.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // pages/Components/selectDate/selectDate.js
  2. const util = require('../../../utils/util')
  3. Component({
  4. lifetimes: {
  5. attached: function () {
  6. var date = new Date()
  7. const year = date.getFullYear()
  8. const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  9. const day = date.getDate() + 1 < 10 ? '0' + date.getDate() : date.getDate()
  10. let now = new Date();
  11. let edd = new Date(now.setDate(now.getDate() + 7));
  12. let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
  13. this.setData({
  14. endDate: year + '-' + month + '-' + day,
  15. lastDate: year + '-' + month + '-' + day,
  16. initChangeDate: ed
  17. })
  18. }
  19. },
  20. /**
  21. * 组件的属性列表
  22. */
  23. properties: {
  24. beginDate: {
  25. type: String
  26. },
  27. endDate: {
  28. type: String
  29. },
  30. typeFlag:{
  31. type:Boolean,
  32. default: false
  33. },
  34. toTop:{
  35. type:Number,
  36. value: -360
  37. },
  38. title:{
  39. type:String,
  40. value: '筛选'
  41. }
  42. },
  43. /**
  44. * 组件的初始数据
  45. */
  46. data: {
  47. beginDate: '2020-01-01',
  48. endDate: '2021-02-02',
  49. initDate: '2020-01-01',
  50. lastDate: '',
  51. yFlag: false,
  52. animationBox: {},
  53. animationBg: {},
  54. typeArr:['全部','已预约','排队中'],
  55. typeIndex: 0,
  56. str:{}
  57. },
  58. /**
  59. * 组件的方法列表
  60. */
  61. methods: {
  62. bindBeginDateChange: function (e) {
  63. if (e.detail.value > this.data.endDate) {
  64. this.setData({
  65. beginDate: this.data.endDate
  66. })
  67. } else {
  68. this.setData({
  69. beginDate: e.detail.value
  70. })
  71. }
  72. },
  73. bindEndDateChange: function (e) {
  74. if (e.detail.value > this.data.initChangeDate) {
  75. this.setData({
  76. endDate: this.data.initChangeDate
  77. })
  78. } else {
  79. this.setData({
  80. endDate: e.detail.value
  81. })
  82. }
  83. },
  84. resetDate: function () {
  85. this.setData({
  86. beginDate: this.data.initDate,
  87. endDate: this.data.initChangeDate,
  88. typeIndex: 0
  89. })
  90. const date = new Date()
  91. const dateArr = [date.getFullYear()+"-01"+"-01", this.data.initChangeDate];
  92. const typeIndex = this.data.typeIndex
  93. this.triggerEvent("getDates", {dateArr,typeIndex});
  94. this.showSelect()
  95. },
  96. submitDate: function () {
  97. const dateArr = [this.data.beginDate, this.data.endDate];
  98. const typeIndex = this.data.typeIndex
  99. this.triggerEvent("getDates", {dateArr,typeIndex});
  100. this.showSelect()
  101. },
  102. showSelect: function () {
  103. var animation = wx.createAnimation({
  104. timingFunction: 'linear',
  105. })
  106. this.animation = animation
  107. var num = 0
  108. var opacity = 0
  109. if (this.data.yFlag == false) {
  110. num = Math.abs(this.data.toTop) / 2 + 30
  111. opacity = 0.4
  112. this.setData({
  113. yFlag: true
  114. })
  115. } else {
  116. num = this.data.toTop
  117. opacity = 0
  118. this.setData({
  119. yFlag: false
  120. })
  121. }
  122. animation.translateY(num).step()
  123. this.setData({
  124. animationBox: animation.export()
  125. })
  126. var animation2 = wx.createAnimation({
  127. timingFunction: 'linear',
  128. })
  129. this.animation2 = animation2
  130. animation2.opacity(opacity).step()
  131. this.setData({
  132. animationBg: animation2.export()
  133. })
  134. },
  135. bindPickerChange:function(e){
  136. const typeIndex = e.detail.value
  137. this.setData({
  138. typeIndex
  139. })
  140. // this.triggerEvent("changeType",str)
  141. },
  142. }
  143. })