// pages/Components/selectDate/selectDate.js const util = require('../../../utils/util') Component({ lifetimes: { attached: function () { var date = new Date() const year = date.getFullYear() const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1 const day = date.getDate() + 1 < 10 ? '0' + date.getDate() : date.getDate() let now = new Date(); let edd = new Date(now.setDate(now.getDate() + 7)); let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-') this.setData({ endDate: year + '-' + month + '-' + day, lastDate: year + '-' + month + '-' + day, initChangeDate: ed }) } }, /** * 组件的属性列表 */ properties: { beginDate: { type: String }, endDate: { type: String }, typeFlag:{ type:Boolean, default: false }, toTop:{ type:Number, value: -360 }, title:{ type:String, value: '筛选' } }, /** * 组件的初始数据 */ data: { beginDate: '2020-01-01', endDate: '2021-02-02', initDate: '2020-01-01', lastDate: '', yFlag: false, animationBox: {}, animationBg: {}, typeArr:['全部','已预约','排队中'], typeIndex: 0, str:{} }, /** * 组件的方法列表 */ methods: { bindBeginDateChange: function (e) { if (e.detail.value > this.data.endDate) { this.setData({ beginDate: this.data.endDate }) } else { this.setData({ beginDate: e.detail.value }) } }, bindEndDateChange: function (e) { if (e.detail.value > this.data.initChangeDate) { this.setData({ endDate: this.data.initChangeDate }) } else { this.setData({ endDate: e.detail.value }) } }, resetDate: function () { this.setData({ beginDate: this.data.initDate, endDate: this.data.initChangeDate, typeIndex: 0 }) const date = new Date() const dateArr = [date.getFullYear()+"-01"+"-01", this.data.initChangeDate]; const typeIndex = this.data.typeIndex this.triggerEvent("getDates", {dateArr,typeIndex}); this.showSelect() }, submitDate: function () { const dateArr = [this.data.beginDate, this.data.endDate]; const typeIndex = this.data.typeIndex this.triggerEvent("getDates", {dateArr,typeIndex}); this.showSelect() }, showSelect: function () { var animation = wx.createAnimation({ timingFunction: 'linear', }) this.animation = animation var num = 0 var opacity = 0 if (this.data.yFlag == false) { num = Math.abs(this.data.toTop) / 2 + 30 opacity = 0.4 this.setData({ yFlag: true }) } else { num = this.data.toTop opacity = 0 this.setData({ yFlag: false }) } animation.translateY(num).step() this.setData({ animationBox: animation.export() }) var animation2 = wx.createAnimation({ timingFunction: 'linear', }) this.animation2 = animation2 animation2.opacity(opacity).step() this.setData({ animationBg: animation2.export() }) }, bindPickerChange:function(e){ const typeIndex = e.detail.value this.setData({ typeIndex }) // this.triggerEvent("changeType",str) }, } })