data: {
// 声明一个二维数组用来保存日期和时间。
multiArray: [['今天', '明天', '3-2', '3-3', '3-4', '3-5'], [0, 1, 2, 3, 4, 5, 6]],
// 日期和时间的角标。
multiIndex: [0,0],
},
/*
* 获取并整理日期和时间格式
*/
pickerTap: function () {
var date = new Date();
var monthDay = ['今天'];
var hours = [];
// 月-日
for (var i = 1; i <= 6; i++) {
var date1 = new Date(date);
date1.setDate(date.getDate() + i);
var md = (date1.getMonth() + 1) + "月" + date1.getDate() + "日";
(md);
}
// 时
if (this.data.multiIndex[0] == 0 ) {
var nowHour = date.getHours()
if ( nowHour < 7) {
nowHour = 7
}
for (var i = nowHour; i < this.data.maxTime; i++) {
(i + ":00 - " + (i + 1) + ":00");
}
} else {
for (var i = this.data.minTime; i < this.data.maxTime; i++) {
(i + ":00 - " + (i + 1) + ":00");
}
}
var data = {
multiArray: this.data.multiArray,
multiIndex: this.data.multiIndex
};
data.multiArray[0] = monthDay;
data.multiArray[1] = hours;
(data);
},
bindMultiPickerColumnChange: function (e) {
var date = new Date();
var that = this;
var monthDay = ['今天'];
var hours = [];
var currentHours = date.getHours();
var data = {
multiArray: this.data.multiArray,
multiIndex: this.data.multiIndex
};
// 把选择的对应值赋值给 multiIndex
data.multiIndex[e.detail.column] = e.detail.value;
// 然后再判断当前改变的是哪一列,如果是第1列改变
if (e.detail.column === 0) {
// 如果第一列滚动到第一行
if (e.detail.value === 0) {
(hours);
} else {
(hours);
}
data.multiIndex[1] = 0;
// 如果是第2列改变
} else if (e.detail.column === 1) {
// 如果第一列为今天
if (data.multiIndex[0] === 0) {
if (e.detail.value === 0) {
(hours);
} else {
(hours);
}
// 第一列不为今天
} else {
(hours);
}
}
data.multiArray[1] = hours;
(data);
},
loadData: function (hours) {
var currentHours = (new Date()).getHours();
for (var i = currentHours; i < this.data.maxTime; i++) {
(i + ":00 - " + (i + 1) + ":00");
}
},
loadHoursMinute: function (hours) {
// 时
for (var i = this.data.minTime; i < this.data.maxTime; i++) {
(i + ":00 - " + (i + 1) + ":00");
}
},
最后向后台传参的格式是:
expire_solve_time = { "date": that.data.multiArray[0][that.data.multiIndex[0]], "hour": that.data.multiArray[1][that.data.multiIndex[1]] }
expire_solve_time 变量传到后台。