123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- // pages/in/in.js
- var date = new Date();
- var currentHours = date.getHours();
- var currentMinute = date.getMinutes();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- startDate: "请选择日期",
- multiArray: [['今天', '明天', '3-2', '3-3', '3-4', '3-5'], [0, 1, 2, 3, 4, 5, 6], [0, 10, 20]],
- multiIndex: [0, 0, 0],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- },
- pickerTap:function() {
- date = new Date();
- var monthDay = ['今天','明天'];
- var hours = [];
- var minute = [];
-
- currentHours = date.getHours();
- currentMinute = date.getMinutes();
- // 月-日
- for (var i = 2; i <= 28; i++) {
- var date1 = new Date(date);
- date1.setDate(date.getDate() + i);
- var md = (date1.getMonth() + 1) + "-" + date1.getDate();
- monthDay.push(md);
- }
- var data = {
- multiArray: this.data.multiArray,
- multiIndex: this.data.multiIndex
- };
- if(data.multiIndex[0] === 0) {
- if(data.multiIndex[1] === 0) {
- this.loadData(hours, minute);
- } else {
- this.loadMinute(hours, minute);
- }
- } else {
- this.loadHoursMinute(hours, minute);
- }
- data.multiArray[0] = monthDay;
- data.multiArray[1] = hours;
- data.multiArray[2] = minute;
- this.setData(data);
- },
- bindMultiPickerColumnChange:function(e) {
- date = new Date();
- var that = this;
- var monthDay = ['今天', '明天'];
- var hours = [];
- var minute = [];
- currentHours = date.getHours();
- currentMinute = date.getMinutes();
- 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) {
- that.loadData(hours, minute);
-
- } else {
- that.loadHoursMinute(hours, minute);
- }
- data.multiIndex[1] = 0;
- data.multiIndex[2] = 0;
- // 如果是第2列改变
- } else if (e.detail.column === 1) {
- // 如果第一列为今天
- if (data.multiIndex[0] === 0) {
- if (e.detail.value === 0) {
- that.loadData(hours, minute);
- } else {
- that.loadMinute(hours, minute);
- }
- // 第一列不为今天
- } else {
- that.loadHoursMinute(hours, minute);
- }
- data.multiIndex[2] = 0;
- // 如果是第3列改变
- } else {
- // 如果第一列为'今天'
- if (data.multiIndex[0] === 0) {
- // 如果第一列为 '今天'并且第二列为当前时间
- if(data.multiIndex[1] === 0) {
- that.loadData(hours, minute);
- } else {
- that.loadMinute(hours, minute);
- }
- } else {
- that.loadHoursMinute(hours, minute);
- }
- }
- data.multiArray[1] = hours;
- data.multiArray[2] = minute;
- this.setData(data);
- },
- loadData: function (hours, minute) {
- var minuteIndex;
- if (currentMinute > 0 && currentMinute <= 10) {
- minuteIndex = 10;
- } else if (currentMinute > 10 && currentMinute <= 20) {
- minuteIndex = 20;
- } else if (currentMinute > 20 && currentMinute <= 30) {
- minuteIndex = 30;
- } else if (currentMinute > 30 && currentMinute <= 40) {
- minuteIndex = 40;
- } else if (currentMinute > 40 && currentMinute <= 50) {
- minuteIndex = 50;
- } else {
- minuteIndex = 60;
- }
- if (minuteIndex == 60) {
- // 时
- for (var i = currentHours + 1; i < 24; i++) {
- hours.push(i);
- }
- // 分
- for (var i = 0; i < 60; i += 10) {
- minute.push(i);
- }
- } else {
- // 时
- for (var i = currentHours; i < 24; i++) {
- hours.push(i);
- }
- // 分
- for (var i = minuteIndex; i < 60; i += 10) {
- minute.push(i);
- }
- }
- },
- loadHoursMinute: function (hours, minute){
- // 时
- for (var i = 0; i < 24; i++) {
- hours.push(i);
- }
- // 分
- for (var i = 0; i < 60; i += 10) {
- minute.push(i);
- }
- },
- loadMinute: function (hours, minute) {
- var minuteIndex;
- if (currentMinute > 0 && currentMinute <= 10) {
- minuteIndex = 10;
- } else if (currentMinute > 10 && currentMinute <= 20) {
- minuteIndex = 20;
- } else if (currentMinute > 20 && currentMinute <= 30) {
- minuteIndex = 30;
- } else if (currentMinute > 30 && currentMinute <= 40) {
- minuteIndex = 40;
- } else if (currentMinute > 40 && currentMinute <= 50) {
- minuteIndex = 50;
- } else {
- minuteIndex = 60;
- }
- if (minuteIndex == 60) {
- // 时
- for (var i = currentHours + 1; i < 24; i++) {
- hours.push(i);
- }
- } else {
- // 时
- for (var i = currentHours; i < 24; i++) {
- hours.push(i);
- }
- }
- // 分
- for (var i = 0; i < 60; i += 10) {
- minute.push(i);
- }
- },
- bindStartMultiPickerChange: function (e) {
- var that = this;
- var monthDay = that.data.multiArray[0][e.detail.value[0]];
- var hours = that.data.multiArray[1][e.detail.value[1]];
- var minute = that.data.multiArray[2][e.detail.value[2]];
- if (monthDay === "今天") {
- var month = date.getMonth()+1;
- var day = date.getDate();
- monthDay = month + "月" + day + "日";
- } else if (monthDay === "明天") {
- var date1 = new Date(date);
- date1.setDate(date.getDate() + 1);
- monthDay = (date1.getMonth() + 1) + "月" + date1.getDate() + "日";
- } else {
- var month = monthDay.split("-")[0]; // 返回月
- var day = monthDay.split("-")[1]; // 返回日
- monthDay = month + "月" + day + "日";
- }
- var startDate = monthDay + " " + hours + ":" + minute;
- that.setData({
- startDate: startDate
- })
- },
- })
|