12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- const App = getApp();
- const dateTimePicker = require('../../utils/datePicker');
- const moment = require("../../utils/moment.min");
- Component({
- options: { addGlobalClass: true },
- properties: {
- datetime: { type: String, value: '' },
- name: { type: String, value: '' }
- },
- data: {
- // 时间列表
- dateTimeArray: null,
- // 默认显示时间
- valueDateTime: null,
- // 开始时间
- startDateTime: '',
- // 结束时间
- endDateTime: '',
- },
- pageLifetimes: {
- show: function () {
- const that = this;
- that.search();
-
- },
- hide: function () { },
- resize: function (size) { }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- search: function () {
- const that = this;
- // 计算时间区间
- let startDateTime = moment().format('YYYY-MM-DD HH:mm');
- let endDateTime = moment().add(100, 'years').format('YYYY-MM-DD HH:mm');
- that.setData({ startDateTime: startDateTime, endDateTime: endDateTime })
- // 获取完整的年月日 时分秒,以及默认显示的数组
- that.data.unit = ['年', '月', '日', '时', '分']
- that.data.dateTimePicker = dateTimePicker.newDateTimePicker(startDateTime, endDateTime)
- let obj = that.data.dateTimePicker.render();
- let lastArray = obj.dateTimeArray;
- let lastTime = obj.dateTime;
- for (let i = 0; i < lastArray.length; i++) {
- lastArray[i] = lastArray[i].map(m => m + this.data.unit[i])
- }
- that.setData({ dateTimeArray: lastArray, valueDateTime: lastTime })
- },
- // 确认选择
- change(e) {
- const that = this;
- const valueDateTime = that.data.valueDateTime;
- const year = that.data.dateTimeArray[0][valueDateTime[0]].replace(/年/, '')
- const month = that.data.dateTimeArray[1][valueDateTime[1]].replace(/月/, '')
- const day = that.data.dateTimeArray[2][valueDateTime[2]].replace(/日/, '')
- const hour = that.data.dateTimeArray[3][valueDateTime[3]].replace(/时/, '')
- const minute = that.data.dateTimeArray[4][valueDateTime[4]].replace(/分/, '')
- let dateTimeWhole = `${year}-${month}-${day} ${hour}:${minute}`;
- that.triggerEvent('datetimeChange', { datetime: dateTimeWhole, name: that.properties.name })
- },
- // 选择时间
- columnChange: function (e) {
- const that = this;
- // 时间列表
- const dateTimeArray = that.data.dateTimeArray;
- const { column, value } = e.detail
- let dateTimeTemp = 'valueDateTime[' + column + ']'
- that.setData({ [dateTimeTemp]: value })
- // 当前选择的值
- const valueDateTime = that.data.valueDateTime;
- that.data.dateTimePicker.setValue({ dateTimeArray: dateTimeArray, dateTime: valueDateTime })
- for (let i = 1; i < valueDateTime.length; i++) {
- if (column == i - 1) {
- for (let j = i; j < valueDateTime.length; j++) {
- let temp = 'valueDateTime[' + j + ']'
- that.setData({ [temp]: 0 })
- }
- }
- let arr = that.data.dateTimePicker.dispatch(i).map(m => m + that.data.unit[i])
- let temp1 = 'dateTimeArray[' + i + ']';
- that.setData({ [temp1]: arr })
- }
- that.setData({ dateTimeArray: dateTimeArray, valueDateTime: valueDateTime })
- },
- }
- })
|