YZProjectCloud/yanzhu-ui-app/miniprogram/pages/components/voucher-datetime/index.js

141 lines
2.8 KiB
JavaScript
Raw Normal View History

2024-10-13 11:24:45 +08:00
// pages/components/voucher-select/index.js
2025-08-02 15:44:20 +08:00
import fmt from '../../../utils/date.js'
2024-10-13 11:24:45 +08:00
Component({
/**
* 组件的属性列表
*/
properties: {
2025-08-02 15:44:20 +08:00
width: {
type: String
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
counts: {
type: Number
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
placeholder: {
type: String
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
time: {
type: String
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
maxDate: {
type: Number,
value: new Date().getTime()
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
value: {
type: String,
value: ''
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
currentDate: {
type: Number
2024-10-13 11:24:45 +08:00
}
},
/**数据监听 */
observers: {
counts: function (val) {
this.setData({
2025-08-02 15:44:20 +08:00
item: val[0],
2024-10-13 11:24:45 +08:00
})
},
2025-08-02 15:44:20 +08:00
time: function (val) {
2024-10-13 11:24:45 +08:00
var that = this
that.setData({
2025-08-02 15:44:20 +08:00
value: val,
2024-10-13 11:24:45 +08:00
// date:val
})
// that.onConfirm()
}
},
lifetimes: {
2025-08-02 15:44:20 +08:00
created: function () {
2024-10-13 11:24:45 +08:00
//在组件实例刚刚被创建时执行,注意此时不能调用 setData
},
attached: function () {
2025-08-02 15:44:20 +08:00
//在组件实例进入页面节点树时执行
2024-10-13 11:24:45 +08:00
},
ready: function () {
2025-08-02 15:44:20 +08:00
// 在组件在视图层布局完成后执行
2024-10-13 11:24:45 +08:00
},
detached: function () {
2025-08-02 15:44:20 +08:00
// 在组件实例被从页面节点树移除时执行
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
2024-10-13 11:24:45 +08:00
},
/**
* 组件的初始数据
*/
data: {
show: false,
2025-08-02 15:44:20 +08:00
date: '',
currDate: 0,
minDate: new Date(2022, 1, 1).getTime(),
counts: '5',
2024-10-13 11:24:45 +08:00
formatter(type, value) {
if (type === 'year') {
return `${value}`;
}
if (type === 'month') {
return `${value}`;
}
return value;
},
},
/**
* 组件的方法列表
*/
methods: {
showPopup() {
2025-08-02 15:44:20 +08:00
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,
});
},
2024-10-13 11:24:45 +08:00
},
2025-08-02 15:44:20 +08:00
2024-10-13 11:24:45 +08:00
})