小程序六列级联,年月日时分秒

小程序六列级联,年月日时分秒_第1张图片

 
 
              
                
              
            
//page  data
 timeMultiArray: [],
    timeMultiIndex: [],
page ononload function

 //时间
    let timeMultiArray = this.data.timeMultiArray;
    let timeMultiIndex = this.data.timeMultiIndex;
    const sratYear = 1900;
    let localDate = new Date();
    const localYear = localDate.getFullYear();//获取完整的年份(4位,1970-????)
    const localMonth = localDate.getMonth() + 1;//获取当前月份(0-11,0代表1月)
    let localNewMonth = localMonth < 10 ? "0" + localMonth : localMonth;
    const localDays = new Date(localYear, parseInt(localNewMonth), 0).getDate();//获取当前日(1-31)
    const localHour = localDate.getHours();       //获取当前小时数(0-23)
    const localMinute = localDate.getMinutes();     //获取当前分钟数(0-59)
    const localSecond = localDate.getSeconds();     //获取当前秒数(0-59)
    timeMultiArray[0] = that.iteratorNumber(sratYear, localYear + 3);
    timeMultiIndex[0] = localYear - sratYear;
    timeMultiArray[1] = that.iteratorNumber(1, 12);
    timeMultiIndex[1] = parseInt(localNewMonth)-1;
    timeMultiArray[2] = that.iteratorNumber(1, localDays);
    timeMultiIndex[2] = parseInt(localDate.getDate()) - 1;
    timeMultiArray[3] = that.iteratorNumber(0, 23);
    timeMultiIndex[3] = localHour;
    timeMultiArray[4] = that.iteratorNumber(0, 59);
    timeMultiIndex[4] = localMinute;
    timeMultiArray[5] = that.iteratorNumber(0, 59);
    timeMultiIndex[5] = localSecond;
    that.setData({
      timeMultiArray:timeMultiArray,
      timeMultiIndex:timeMultiIndex
    })
iteratorNumber:function(begin,end){
     let resultArray = [];
     for(let i=0;i<=(end-begin);i++){
       let current = begin + i;
       resultArray.push(current < 10 ? "0" + current : "" + current);
     }
    return resultArray;
  },
 //时间选择
  bindMultiPickerChange: function (e) {
    let that = this;
    that.setData({
      timeMultiIndex: e.detail.value
    })
  },
  //时间列改变
  bindMultiPickerColumnChange: function (e) {
    let that = this;
    if (e.detail.column == 0 || e.detail.column == 1){
      let timeMultiArray = that.data.timeMultiArray;
      let timeMultiIndex = that.data.timeMultiIndex;
      if (e.detail.column == 0){
        const localDays = new Date(e.detail.value, timeMultiArray[1][timeMultiIndex[1]], 0).getDate();//获取当前日(1-31)
        timeMultiArray[2] = that.iteratorNumber(1, localDays);
        //下标越界处理
        if (localDays < timeMultiArray[2][timeMultiIndex[2]]){
          timeMultiIndex[2] = 0;
        }
        timeMultiIndex[0] = e.detail.value;
      }
      if (e.detail.column == 1) {
        const localDays = new Date(timeMultiArray[0][timeMultiIndex[0]], e.detail.value+1, 0).getDate();//获取当前日(1-31)
        timeMultiArray[2] = that.iteratorNumber(1, localDays);
        //下标越界处理
        if (localDays < timeMultiArray[2][timeMultiIndex[2]]) {
          timeMultiIndex[2] = 0;
        }
        timeMultiIndex[1] = e.detail.value;
      }
      console.log('修改的列为', e.detail.column, ',值为', e.detail.value, ',timeMultiIndex', timeMultiIndex);
      that.setData({
        timeMultiArray: timeMultiArray,
        timeMultiIndex: timeMultiIndex
      })
    }
  }

你可能感兴趣的:(小程序)