Browse Source

时间空间

XWookey 2 years ago
parent
commit
d9c386be72

+ 2 - 2
app.js

@@ -5,10 +5,10 @@ App({
   globalData: {
    // postHeadAgreement: 'http://127.0.0.1:10301',
     // 测试
-    // postHeadAgreement: 'https://jqcs.pjnes.com/cloud/chargapi',
+    postHeadAgreement: 'https://jqcs.pjnes.com/cloud/chargapi',
 
     // 正式
-    postHeadAgreement: 'https://cdglyy.pjnes.com/cloud/chargapi',
+    // postHeadAgreement: 'https://cdglyy.pjnes.com/cloud/chargapi',
     helpPhoneNum: '4009608068',
     version:'2.0'
   },

+ 126 - 0
components/datePicker/datePicker.js

@@ -0,0 +1,126 @@
+const App = getApp();
+const dateTimePicker = require('../../utils/datePicker.js')
+Component({
+  options: {
+    addGlobalClass: true,
+  },
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    params: {
+        type: Object,
+        value:{
+          placeholder: '请选择时间', 
+          startDateTime: '', 
+          endDateTime: '', 
+          pText: ''
+        }
+    },
+  },
+
+  /**
+   * 组件的初始数据
+   */
+  data: {
+    dateTimeArray: null,
+    dateTime: null,
+    startDateTime: '',
+    endDateTime: '',
+    dateTimeWhole: '',
+  },
+  lifetimes: {
+    attached: function () {
+     this.setData({
+        startDateTime: this.data.params.startDateTime,
+        endDateTime: this.data.params.endDateTime
+      })
+      this.initData()
+    }
+  },
+  pageLifetimes: {
+    show: function() {
+      this.setData({
+        startDateTime: this.data.params.startDateTime,
+        endDateTime: this.data.params.endDateTime
+      })
+      this.initData()
+    },
+    hide: function() {
+      // 页面被隐藏
+    },
+    resize: function(size) {
+      // 页面尺寸变化
+    }
+  },
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    initData(date) {
+      // 获取完整的年月日 时分秒,以及默认显示的数组
+      this.data.unit = ['年', '月', '日', '时', '分']
+      this.data.dateTimePicker = dateTimePicker.newDateTimePicker(this.data.startDateTime, this.data.endDateTime, this.data.params.pText)
+      let obj = this.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])
+      }
+      this.data.dateTimeArray = lastArray
+      this.data.dateTime = lastTime
+      this.setData({
+        dateTimeArray: this.data.dateTimeArray,
+        dateTime: this.data.dateTime
+      })
+    },
+    changeDateTime(e) { 
+      this.data.dateTime = e.detail.value
+      const year = this.data.dateTimeArray[0][this.data.dateTime[0]].replace(/年/, '')
+      const month = this.data.dateTimeArray[1][this.data.dateTime[1]].replace(/月/, '')
+      const day = this.data.dateTimeArray[2][this.data.dateTime[2]].replace(/日/, '')
+      const hour = this.data.dateTimeArray[3][this.data.dateTime[3]].replace(/时/, '')
+      const minute = this.data.dateTimeArray[4][this.data.dateTime[4]].replace(/分/, '')
+      // const second = this.data.dateTimeArray[5][this.data.dateTime[4]].replace(/秒/, '')
+      this.data.dateTimeWhole = `${year}-${month}-${day} ${hour}:${minute}`
+      // this.data.dateTimeWhole = `${year}-${month}-${day}`
+      this.setData({
+        dateTimeWhole: this.data.dateTimeWhole,
+      })
+      // console.log(this.data.dateTimeWhole)
+      this.triggerEvent('getDateString', this.data.dateTimeWhole)
+    },
+    changeDateTimeColumn(e) {
+      const { column, value } = e.detail
+      // this.$set(this.data.dateTime, column, value)
+      let dateTimeTemp = 'dateTime['+column+']'
+      this.setData({
+        [dateTimeTemp]: value
+      })
+      this.data.dateTimePicker.setValue({ dateTimeArray: this.data.dateTimeArray, dateTime: this.data.dateTime })
+      for (let i = 1; i < this.data.dateTime.length; i++) {
+        if (column == i - 1) {
+          for (let j = i; j < this.data.dateTime.length; j++) {
+            // this.$set(this.data.dateTime, j, 0)
+            let temp = 'dateTime['+j+']'
+            this.setData({
+              [temp]: 0
+            })
+          }
+        }
+        let arr = this.data.dateTimePicker.dispatch(i).map(m => m + this.data.unit[i])
+        // this.$set(this.data.dateTimeArray, i, arr)
+        let temp1 = 'dateTimeArray['+i+']'
+        this.setData({
+          [temp1]: arr
+        })
+      }
+      this.setData({
+        dateTimeArray: this.data.dateTimeArray,
+        dateTime: this.data.dateTime
+      })
+    },
+
+
+  }
+})

+ 4 - 0
components/datePicker/datePicker.json

@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 7 - 0
components/datePicker/datePicker.wxml

@@ -0,0 +1,7 @@
+<!--pages/components/datePicker/datePicker.wxml-->
+<picker class="dateTimePicker"  mode="multiSelector" value="{{dateTime}}" bindchange="changeDateTime" bindcolumnchange="changeDateTimeColumn" range="{{dateTimeArray}}" style="width: 100%;">
+  <view class="tui-picker-detail wrap column-center" style="text-align: right;">
+    <text style="color:{{(dateTimeWhole||params.pText)?'#333333':'#999999'}}">{{dateTimeWhole || params.pText || params.placeholder ||"请选择时间"}}</text>
+    <!-- <image class="icon" src="/static/mine/meArrowRight.png" mode=""></image> -->
+  </view>
+</picker>

+ 13 - 0
components/datePicker/datePicker.wxss

@@ -0,0 +1,13 @@
+/* pages/components/datePicker/datePicker.wxss */
+.dateTimePicker {
+  text-align: left;
+  width: 300rpx;
+}
+.tui-picker-detail {
+  border-radius: 10rpx;
+  font-size: 32rpx;
+}
+.icon {
+  width: 16rpx;
+  height: 32rpx;
+}

+ 1 - 1
pages/index/index.js

@@ -309,7 +309,7 @@ Page({
                       address: item.address,
                       width: "46rpx",
                       height: "67rpx",
-                      chargfeatures: chargfeatures , 
+                      chargfeatures: item.chargfeatures , 
                       iconPath: iconPath,
                       id: item.id,
                       callout: {},

+ 2 - 2
pages/index/index.wxml

@@ -4,8 +4,8 @@
       <image src='/images/search.png'></image>
       <text>{{keywords}}</text>
     </view>
-    <view class='city_select'>{{city==null?'北京市':city}}</view>
-    <view class='down'>
+    <view style="display: none;" class='city_select'>{{city==null?'北京市':city}}</view>
+    <view style="display: none;"  class='down'>
       <image src='/images/down.png'></image>
     </view>
   </view>

+ 4 - 2
pages/ucenter/myworksheet/myworksheet.wxml

@@ -23,8 +23,10 @@
       <text wx:if="{{item.workBigclass==null}}">工单大类:未知</text>
       <text wx:if="{{item.workBigclass==1}}">工单大类:售后服务</text>
       <text wx:if="{{item.workBigclass==2}}">工单大类:工程实施</text>
-      <text>预计完成时间:{{item.exceptTime}}</text>
-      <text>工单创建时间:{{item.workCreatetime}}</text>
+      <text wx:if="{{item.exceptTime!==null}}">预计完成时间:{{item.exceptTime}}</text>
+      <text wx:if="{{item.exceptTime==null}}">预计完成时间:未知</text>
+      <text wx:if="{{item.workCreatetime!==null}}">工单创建时间:{{item.workCreatetime}}</text>
+      <text wx:if="{{item.workCreatetime==null}}">工单创建时间:未知</text>
       <view id="{{item.id}}" class='detail' bindtap="getRoute">详情
         <image src='/images/detail.png'></image>
       </view>

+ 62 - 22
pages/worksheetinfo/addworksheetinfo.js

@@ -1,5 +1,5 @@
 // pages/worksheetinfo/worksheetinfo.js
-
+let Util = require("../../utils/util");
 Page({
 
   /**
@@ -88,6 +88,19 @@ Page({
     breakdownTypeindex: 0,
     exceptdate: null,
     excepttime: '00:00',
+    exceptparams:{
+      placeholder: '请选择时间', 
+      startDateTime: '2020-01-01 00:00',
+      endDateTime: '2040-01-01 00:00',
+      pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
+    },
+    finishparams:{
+      placeholder: '请选择时间', 
+      startDateTime: '2020-01-01 00:00',
+      endDateTime: '2040-01-01 00:00',
+      // pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
+      pText: '0000-00-00 00:00' //'2022-04-30 00:00'
+    },
     finishdate: null,
     finishtime: '00:00',
     accendantids: [],
@@ -165,16 +178,16 @@ Page({
       url
     });
   },
-  bindExceptdateChange(e) {
-    this.setData({
-      exceptdate: e.detail.value
-    })
-  },
-  bindExcepttimeChange(e) {
-    this.setData({
-      excepttime: e.detail.value
-    })
-  },
+  // bindExceptdateChange(e) {
+  //   this.setData({
+  //     exceptdate: e.detail.value
+  //   })
+  // },
+  // bindExcepttimeChange(e) {
+  //   this.setData({
+  //     excepttime: e.detail.value
+  //   })
+  // },
   bindFinishdateChange(e) {
     this.setData({
       finishdate: e.detail.value
@@ -205,15 +218,22 @@ Page({
     let worksheetinfo = this.data.worksheetinfo;
     worksheetinfo.operatorName = this.data.userNames.length>0?this.data.userNames[0]:"";
     worksheetinfo.pams = this.data.accendantids;
-    worksheetinfo.accendant = null;
-    if (this.data.exceptdate ) {
-    // if (this.data.exceptdate && this.data.excepttime) {
-      worksheetinfo.exceptTime = this.data.exceptdate + " " + this.data.excepttime + ":00";
-    }
-    if (this.data.finishdate){
-    // if (this.data.finishdate && this.data.finishtime){
-      worksheetinfo.finishTime = this.data.finishdate + " " + this.data.finishtime + ":00";
-    }
+    console.info(this.data.accendantids)
+    // worksheetinfo.accendant = null;
+    // if (this.data.exceptdate ) {
+    // // if (this.data.exceptdate && this.data.excepttime) {
+    //   worksheetinfo.exceptTime = this.data.exceptdate + " " + this.data.excepttime + ":00";
+    // }
+    worksheetinfo.exceptTime = this.data.exceptparams.pText + ":00";
+    // if (this.data.finishdate){
+    // // if (this.data.finishdate && this.data.finishtime){
+    //   worksheetinfo.finishTime = this.data.finishdate + " " + this.data.finishtime + ":00";
+    // }
+    worksheetinfo.workEndtime = this.data.finishparams.pText + ":00";
+
+    console.info(worksheetinfo.exceptTime + ":00")
+    console.info(worksheetinfo.finishTime + ":00")
+
     let images = this.data.images;
     var imgString = [];
     
@@ -448,13 +468,33 @@ Page({
   },
 
   clear_chargStationName(e){
+    let worksheetinfo = this.data.worksheetinfo;
+    worksheetinfo.chargStationId = 0;
+    worksheetinfo.pams = [];
+    worksheetinfo.accendant =  '';
+    worksheetinfo.mainLocation =  '';
     this.setData({
-      worksheetinfo:{chargStationId: 0,pams:[]},
+      worksheetinfo,
       chargStationNameClearFlag: true
-
     });
   },
+  bindFinishparamsChange(e){
+    let finishparams =  this.data.finishparams;
+    finishparams.pText = e.detail
+    this.setData({
+      finishparams:finishparams
+    })
+    console.info("finishparams " + finishparams.pText)
+  },
 
+  bindExceptparamsChange(e){
+    let exceptparams =  this.data.exceptparams;
+    exceptparams.pText = e.detail
+    this.setData({
+      exceptparams:exceptparams
+    })
+    console.info("exceptparams " + exceptparams.pText)
+  },
   /**
    * 生命周期函数--监听页面加载
    */

+ 3 - 1
pages/worksheetinfo/addworksheetinfo.json

@@ -1,5 +1,7 @@
 {
   "navigationBarTitleText": "新增工单",
   "navigationBarBackgroundColor": "#2483c0",
-  "usingComponents": {}
+  "usingComponents": {
+    "datepicker": "/components/datePicker/datePicker"
+  }
 }

+ 6 - 4
pages/worksheetinfo/addworksheetinfo.wxml

@@ -60,22 +60,24 @@
   </view>
   <view class="context">
     <text>预计完成时间</text>
-    <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{exceptdate}}" bindchange="bindExceptdateChange">
+    <!-- <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{exceptdate}}" bindchange="bindExceptdateChange">
       <text>{{exceptdate==null?'0000-00-00':exceptdate}}</text>
     </picker>
     <picker class="picker2" disabled="{{worksheetinfo.workStatus==6}}" mode="time" value="{{excepttime}}" bindchange="bindExcepttimeChange">
       <text>{{excepttime==null?'00:00':excepttime}}:00</text>
-    </picker>
+    </picker> -->
+    <datepicker params="{{exceptparams}}" bind:getDateString="bindExceptparamsChange" style="width: 100%;"/>
     <!-- <input class='input' type='text' value='{{worksheetinfo.exceptTime}}'></input> -->
   </view>
   <view class="context">
     <text>工作完成截止时间</text>
-    <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{finishdate}}" bindchange="bindFinishdateChange">
+    <!-- <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{finishdate}}" bindchange="bindFinishdateChange">
       <text>{{finishdate==null?'0000-00-00':finishdate}}</text>
     </picker>
     <picker class="picker2" disabled="{{worksheetinfo.workStatus==6}}" mode="time" value="{{finishtime}}" bindchange="bindFinishtimeChange">
       <text>{{finishtime==null?'00:00':finishtime}}:00</text>
-    </picker>
+    </picker> -->
+    <datepicker params="{{finishparams}}"  bind:getDateString="bindFinishparamsChange" style="width: 100%;"/>
     <!-- <input class='input' type='text' value='{{worksheetinfo.finishTime}}'></input> -->
   </view>
   

+ 5 - 1
pages/worksheetinfo/findstation.js

@@ -70,10 +70,14 @@ Page({
       let chargStationName = keywords.chargStationName
       worksheetinfo.chargStationId =  keywords.id;
       worksheetinfo.mainLocation =  keywords.address;
+      worksheetinfo.accendant =  '';
+      worksheetinfo.pams =  [];
       prevPage.setData({
         chargStationName,
         chargStationNameClearFlag:false,
-        worksheetinfo
+        worksheetinfo,
+        accendantids:[],
+        
       });
     }
     //let url = `/pages/index/index`;

+ 69 - 14
pages/worksheetinfo/worksheetinfo.js

@@ -1,4 +1,6 @@
 // pages/worksheetinfo/worksheetinfo.js
+let Util = require("../../utils/util");
+
 Page({
 
   /**
@@ -88,10 +90,22 @@ Page({
     excepttime: '00:00',
     finishdate: null,
     finishtime: '00:00',
+    exceptparams:{
+      placeholder: '请选择时间', 
+      startDateTime: '2020-01-01 00:00',
+      endDateTime: '2040-01-01 00:00',
+      pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
+    },
+    finishparams:{
+      placeholder: '请选择时间', 
+      startDateTime: '2020-01-01 00:00',
+      endDateTime: '2040-01-01 00:00',
+      pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
+    },
     accendantids: [],
     userNames:[],
     chargStationName:'',
-    chargStationNameClearFlag: true
+    chargStationNameClearFlag: false
 
 
 
@@ -205,12 +219,14 @@ Page({
     worksheetinfo.operatorName = this.data.userNames.length>0?this.data.userNames[0]:"";
     worksheetinfo.pams = this.data.accendantids;
     worksheetinfo.accendant = null;
-    if (this.data.exceptdate && this.data.excepttime) {
-      worksheetinfo.exceptTime = this.data.exceptdate + " " + this.data.excepttime + ":00";
-    }
-    if (this.data.finishdate && this.data.finishtime){
-      worksheetinfo.finishTime = this.data.finishdate + " " + this.data.finishtime + ":00";
-    }
+    // if (this.data.exceptdate && this.data.excepttime) {
+    //   worksheetinfo.exceptTime = this.data.exceptdate + " " + this.data.excepttime + ":00";
+    // }
+    worksheetinfo.exceptTime = this.data.exceptparams.pText + ":00";
+    // if (this.data.finishdate && this.data.finishtime){
+    //   worksheetinfo.finishTime = this.data.finishdate + " " + this.data.finishtime + ":00";
+    // }
+    worksheetinfo.finishTime = this.data.finishparams.pText + ":00";
     let images = this.data.images;
     var imgString = [];
     
@@ -442,12 +458,33 @@ Page({
   },
 
   clear_chargStationName(e){
+    let worksheetinfo = this.data.worksheetinfo;
+    worksheetinfo.chargStationId = 0;
+    worksheetinfo.pams = [];
+    worksheetinfo.accendant =  '';
+    worksheetinfo.mainLocation =  '';
     this.setData({
-      worksheetinfo:{chargStationId: 0,pams:[]},
+      worksheetinfo,
       chargStationNameClearFlag: true
     });
   },
+  bindFinishparamsChange(e){
+    let finishparams =  this.data.finishparams;
+    finishparams.pText = e.detail
+    this.setData({
+      finishparams:finishparams
+    })
+    console.info("finishparams " + finishparams.pText)
+  },
 
+  bindExceptparamsChange(e){
+    let exceptparams =  this.data.exceptparams;
+    exceptparams.pText = e.detail
+    this.setData({
+      exceptparams:exceptparams
+    })
+    console.info("exceptparams " + exceptparams.pText)
+  },
   /**
    * 生命周期函数--监听页面加载
    */
@@ -484,17 +521,29 @@ Page({
       }
     });
     if (worksheetinfo.exceptTime) {
-      let datetime = worksheetinfo.exceptTime.split(" ");
+      // let datetime = worksheetinfo.exceptTime.split(" ");
+      // this.setData({
+      //   exceptdate: datetime[0],
+      //   excepttime: datetime[1].substr(0, 5)
+      // });
+      let exceptparams = this.data.exceptparams;
+      exceptparams['pText'] = worksheetinfo.exceptTime.substr(0,16)
+      console.info(exceptparams['pText'])
       this.setData({
-        exceptdate: datetime[0],
-        excepttime: datetime[1].substr(0, 5)
+        exceptparams: exceptparams
       });
     }
     if (worksheetinfo.finishTime) {
-      let datetime = worksheetinfo.finishTime.split(" ");
+      // let datetime = worksheetinfo.finishTime.split(" ");
+      // this.setData({
+      //   finishdate: datetime[0],
+      //   finishtime: datetime[1].substr(0, 5)
+      // });
+      let finishparams = this.data.finishparams;
+      finishparams['pText'] = worksheetinfo.finishTime.substr(0,16)
+      console.info(finishparams['pText'])
       this.setData({
-        finishdate: datetime[0],
-        finishtime: datetime[1].substr(0, 5)
+        finishparams: finishparams
       });
     }
     this.data.breakdownType.forEach((item, index) => {
@@ -533,6 +582,12 @@ Page({
         chargStationName:worksheetinfo.chargStationName,
         worksheetinfo 
       });
+      console.info(worksheetinfo.chargStationName)
+      if(!worksheetinfo.chargStationName){
+        that.setData({
+          chargStationNameClearFlag:true,
+        });
+      }
     }
     wx.request({
       url: getApp().globalData.postHeadAgreement + '/restapi/wechat/getuserworksheet',

+ 3 - 1
pages/worksheetinfo/worksheetinfo.json

@@ -1,5 +1,7 @@
 {
   "navigationBarTitleText": "编辑工单",
   "navigationBarBackgroundColor": "#2483c0",
-  "usingComponents": {}
+  "usingComponents": {
+    "datepicker": "/components/datePicker/datePicker"
+  }
 }

+ 6 - 4
pages/worksheetinfo/worksheetinfo.wxml

@@ -61,22 +61,24 @@
   </view>
   <view class="context">
     <text>预计完成时间</text>
-    <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{exceptdate}}" bindchange="bindExceptdateChange">
+    <!-- <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{exceptdate}}" bindchange="bindExceptdateChange">
       <text>{{exceptdate==null?'0000-00-00':exceptdate}}</text>
     </picker>
     <picker class="picker2" disabled="{{worksheetinfo.workStatus==6}}" mode="time" value="{{excepttime}}" bindchange="bindExcepttimeChange">
       <text>{{excepttime==null?'00:00':excepttime}}:00</text>
-    </picker>
+    </picker> -->
+    <datepicker params="{{exceptparams}}" bind:getDateString="bindExceptparamsChange" style="width: 100%;"/>
     <!-- <input class='input' type='text' value='{{worksheetinfo.exceptTime}}'></input> -->
   </view>
   <view class="context">
     <text>实际完成时间</text>
-    <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{finishdate}}" bindchange="bindFinishdateChange">
+    <!-- <picker class="picker1" disabled="{{worksheetinfo.workStatus==6}}" mode="date" value="{{finishdate}}" bindchange="bindFinishdateChange">
       <text>{{finishdate==null?'0000-00-00':finishdate}}</text>
     </picker>
     <picker class="picker2" disabled="{{worksheetinfo.workStatus==6}}" mode="time" value="{{finishtime}}" bindchange="bindFinishtimeChange">
       <text>{{finishtime==null?'00:00':finishtime}}:00</text>
-    </picker>
+    </picker> -->
+    <datepicker params="{{finishparams}}" bind:getDateString="bindFinishparamsChange" style="width: 100%;"/>
     <!-- <input class='input' type='text' value='{{worksheetinfo.finishTime}}'></input> -->
   </view>
   

+ 265 - 0
utils/datePicker.js

@@ -0,0 +1,265 @@
+class BaseInfo {
+  constructor() {
+    this.newDate = new Date();
+  }
+  withData(param) {
+    return parseInt(param) < 10 ? '0' + param : '' + param;
+  }
+  getLoopArray(start, end) {
+    var start = start || 0;
+    var end = end || 0;
+    var array = [];
+    for (var i = start; i <= end; i++) {
+      array.push(this.withData(i));
+    }
+    return array;
+  }
+  formatArr(dateString) {
+    return [...dateString.split(' ')[0].split('-'), ...dateString.split(' ')[1].split(':')]
+    //return [...dateString.split(' ')[0].split('-')]
+  }
+  beforeDateArr(disYear) {
+    /*
+     * 处理前
+     * 获取当前时间
+     */
+    let year = this.newDate.getFullYear() - (disYear || 0)
+    let month = this.newDate.getMonth() + 1
+    let day = this.newDate.getDate()
+    let hour = this.newDate.getHours()
+    let minute = this.newDate.getMinutes()
+    return [year, month, day, hour, minute]
+  }
+  afterDateArr() {
+    /*
+     * 处理后
+     * 获取当前时间
+     */
+    let year = this.withData(this.newDate.getFullYear())
+    let mont = this.withData(this.newDate.getMonth() + 1)
+    let date = this.withData(this.newDate.getDate())
+    let hour = this.withData(this.newDate.getHours())
+    let minu = this.withData(this.newDate.getMinutes())
+    return [year, mont, date, hour, minu];
+  }
+}
+
+// 实现
+class dateTimePicker extends BaseInfo {
+  constructor(startDate, endDate, defaultDate) {
+    super();
+    this.dateTimeArray = null
+    this.dateTime = null
+    this.startDate = super.formatArr(startDate); // 开始时间
+    this.endDate = endDate ? super.formatArr(endDate) : super.afterDateArr(); // 结束时间
+    this.defaultDate = defaultDate ? super.formatArr(defaultDate) : this.startDate;
+  }
+  setValue(obj) {
+    for (let key in obj) {
+      this[key] = obj[key]
+    }
+  }
+  /* 获取当前切换选择的日期值*/
+  getCurDateInfo() {
+    return this.dateTime && this.dateTimeArray ? {
+      year: this.dateTimeArray[0][this.dateTime[0]],
+      month: this.dateTimeArray[1][this.dateTime[1]],
+      day: this.dateTimeArray[2][this.dateTime[2]],
+      hour: this.dateTimeArray[3][this.dateTime[3]],
+      second: this.dateTimeArray[4][this.dateTime[4]],
+    } : {}
+  }
+  /* 获取月数组*/
+  getMonths() {
+    let array = []
+    const year = (this.getCurDateInfo().year || this.defaultDate[0]).replace(/年/, '');
+    if (this.startDate[0] == this.endDate[0]) {
+      /* 
+       * 开始的年和结束的年相同
+       * 就取(开始月,结束月)
+       */
+      array = super.getLoopArray(parseInt(this.startDate[1]), parseInt(this.endDate[1]))
+    } else {
+      switch (year) {
+        case this.startDate[0]:
+          /* 开始年 */
+          array = super.getLoopArray(parseInt(this.startDate[1]), 12)
+          break;
+        case this.endDate[0]:
+          /* 结束年 */
+          array = super.getLoopArray(1, parseInt(this.endDate[1]))
+          break;
+        default:
+          array = super.getLoopArray(1, 12)
+          break;
+      }
+    }
+
+    return array;
+  }
+  /* 获取日数组*/
+  getDays() {
+    let array = []
+    let lastDay = null
+    const year = (this.getCurDateInfo().year || this.defaultDate[0]).replace(/年/, '');
+    const month = (this.getCurDateInfo().month || this.defaultDate[1]).replace(/月/, '');
+    const flag = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
+    switch (month) {
+      case '01':
+      case '03':
+      case '05':
+      case '07':
+      case '08':
+      case '10':
+      case '12':
+        lastDay = 31
+        break;
+      case '04':
+      case '06':
+      case '09':
+      case '11':
+        lastDay = 30
+        break;
+      case '02':
+        lastDay = flag ? 29 : 28
+        break;
+      default:
+        array = '月份格式不正确,请重新输入!'
+    }
+    const afterDateArr = super.afterDateArr()
+    const _start = year == this.startDate[0] && month == this.startDate[1]
+    const _end = year == this.endDate[0] && month == this.endDate[1]
+    if (this.startDate[0] == this.endDate[0] && this.startDate[1] == this.endDate[1]) {
+      /*
+       * 开始的年和结束的年相同,开始月和结束月相同
+       * 就取(开始日,结束日)
+       */
+      array = super.getLoopArray(parseInt(this.startDate[2]), parseInt(this.endDate[2]))
+    } else {
+      if (_start) { // 开始年月
+        array = super.getLoopArray(parseInt(this.startDate[2]), lastDay)
+      } else if (_end) { // 结束年月
+        array = super.getLoopArray(1, parseInt(this.endDate[2]))
+      } else {
+        array = super.getLoopArray(1, lastDay)
+      }
+    }
+
+    return array;
+  }
+
+  /* 获取小时数组*/
+  getHours() {
+    let array = []
+    const year = (this.getCurDateInfo().year || this.defaultDate[0]).replace(/年/, '');
+    const month = (this.getCurDateInfo().month || this.defaultDate[1]).replace(/月/, '');
+    const day = (this.getCurDateInfo().day || this.defaultDate[2]).replace(/日/, '');
+    const _start = year == this.startDate[0] && month == this.startDate[1] && day == this.startDate[2]
+    const _end = year == this.endDate[0] && month == this.endDate[1] && day == this.endDate[2]
+    const _equal = this.startDate[0] == this.endDate[0] && this.startDate[1] == this.endDate[1] && this.startDate[
+      2] == this.endDate[2]
+    if (_equal) {
+      /*
+       * 开始的年月日和结束的年月日都相同
+       * 就取(开始小时,结束小时)
+       */
+      array = super.getLoopArray(parseInt(this.startDate[3]), parseInt(this.endDate[3]))
+    } else {
+      if (_start) { // 开始年月日
+        array = super.getLoopArray(parseInt(this.startDate[3]), 23)
+      } else if (_end) { // 结尾年月日
+        array = super.getLoopArray(0, parseInt(this.endDate[3]))
+      } else {
+        array = super.getLoopArray(0, 23)
+      }
+    }
+    return array;
+  }
+  /* 获取分钟数组*/
+  getMinutes(years, months, days, hours) {
+    let array = []
+    const year = (this.getCurDateInfo().year || this.defaultDate[0]).replace(/年/, '');
+    const month = (this.getCurDateInfo().month || this.defaultDate[1]).replace(/月/, '');
+    const day = (this.getCurDateInfo().day || this.defaultDate[2]).replace(/日/, '');
+    const hour = (this.getCurDateInfo().hour || this.defaultDate[3]).replace(/时/, '');
+    const _start = year == this.startDate[0] && month == this.startDate[1] && day == this.startDate[2] && hour == this
+      .startDate[3]
+    const _end = year == this.endDate[0] && month == this.endDate[1] && day == this.endDate[2] && hour == this
+      .endDate[3]
+    const _equal = this.startDate[0] == this.endDate[0] && this.startDate[1] == this.endDate[1] && this.startDate[
+      2] == this.endDate[2] && this.startDate[3] == this.endDate[3]
+    if (_equal) {
+      /*
+       * 开始的年月日时和结束的年月日时都相同
+       * 就取(开始小时,结束小时)
+       */
+      array = super.getLoopArray(parseInt(this.startDate[4]), parseInt(this.endDate[4]))
+    } else {
+      if (_start) { // 开始年月日
+        array = super.getLoopArray(parseInt(this.startDate[4]), 59)
+      } else if (_end) { // 结尾年月日
+        array = super.getLoopArray(0, parseInt(this.endDate[4]))
+      } else {
+        array = super.getLoopArray(0, 59)
+      }
+    }
+    return array;
+  }
+  /*  */
+  dispatch(index) {
+    let arr = []
+    switch (index) {
+      case 0:
+        arr = super.getLoopArray(this.startDate[0], this.endDate[0]);
+        break;
+      case 1:
+        arr = this.getMonths();
+        break;
+      case 2:
+        arr = this.getDays();
+        break;
+      case 3:
+        arr = this.getHours();
+        break;
+      case 4:
+        arr = this.getMinutes();
+        break;
+      default:
+        break;
+    }
+    return arr
+  }
+
+  /* 初始默认数据 */
+  render() {
+    const dateTime = []
+    const dateTimeArray = [
+      [],
+      [],
+      [],
+      [],
+      []
+    ];
+    /*年月日 时分秒*/
+    for (let i = 0; i < dateTimeArray.length; i++) {
+      dateTimeArray[i] = this.dispatch(i)
+    }
+    dateTimeArray.forEach((current, index) => { 
+      const _index = current.indexOf(this.defaultDate[index])
+      dateTime.push(_index == -1 ? 0 : _index);
+    });
+
+    return {
+      dateTimeArray,
+      dateTime
+    }
+  }
+}
+
+function newDateTimePicker(startDateTime, endDateTime, pText){
+  let newDateTimePicker = new dateTimePicker(startDateTime, endDateTime, pText)
+  return newDateTimePicker
+}
+module.exports = {
+  newDateTimePicker: newDateTimePicker,
+}

+ 15 - 0
utils/util.js

@@ -20,6 +20,21 @@ class Util {
 
     return [year, month, day].map(this.formatNumber).join('/') + ' ' + [hour, minute, second].map(this.formatNumber).join(':');
   };
+
+
+  static formatTimePicker(date) {
+    let year = date.getFullYear();
+    let month = date.getMonth() + 1;
+    let day = date.getDate();
+
+    let hour = date.getHours();
+    let minute = date.getMinutes();
+    let second = date.getSeconds();
+
+    return [year, month, day].map(this.formatNumber).join('-') + ' ' + [hour, minute].map(this.formatNumber).join(':');
+  };
+
+
   static formatNumber(n) {
     n = n.toString();
     return n[1] ? n : '0' + n;