// pages/components/voucher-select/index.js import fmt from '../../../utils/date.js' Component({ /** * 组件的属性列表 */ properties: { width: { type: String }, counts: { type: Number }, placeholder: { type: String }, time: { type: String }, maxDate: { type: Number, value: new Date().getTime() }, value: { type: String, value: '' }, currentDate: { type: Number } }, /**数据监听 */ observers: { counts: function (val) { this.setData({ item: val[0], }) }, time: function (val) { var that = this that.setData({ value: val, // date:val }) // that.onConfirm() } }, lifetimes: { created: function () { //在组件实例刚刚被创建时执行,注意此时不能调用 setData }, attached: function () { //在组件实例进入页面节点树时执行 }, ready: function () { // 在组件在视图层布局完成后执行 }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, /** * 组件的初始数据 */ data: { show: false, date: '', currDate: 0, minDate: new Date(2022, 1, 1).getTime(), counts: '5', formatter(type, value) { if (type === 'year') { return `${value}`; } if (type === 'month') { return `${value}`; } return value; }, }, /** * 组件的方法列表 */ methods: { showPopup() { debugger let cDate = this.properties.currentDate ? this.properties.currentDate : this.properties.value ? +fmt(this.properties.value) : +(new Date()) this.setData({ currDate: cDate, show: true }); }, onClose() { this.setData({ show: false }); }, onConfirm() { this.setData({ value: this.data.date }) this.triggerEvent('change', this.data.date) this.setData({ show: false }); }, formatter(type, value) { if (type === 'year') { return `${value}`; } if (type === 'month') { return `${value}`; } return value; }, /** * 组件的方法列表 */ onInput(event) { let date = new Date(event.detail) let Y = date.getFullYear(); let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ''; let H = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ''; let I = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ''; var lot = Y + '-' + M + '-' + D + ' ' + H + ':' + I + ':00'; this.setData({ date: lot, }); }, }, })