Ver código fonte

时间修改

HW 3 anos atrás
pai
commit
3ca0f459f9

+ 1 - 1
src/app.config.js

@@ -2,8 +2,8 @@ export default {
   pages: [
     // 'pages/staffDistribution/index',//员工分布
     'pages/punchClock/index',//打卡
-    'pages/applyDepart/index',//申请公出
     'pages/examine/index',//审核
+    'pages/applyDepart/index',//申请公出
     'pages/egressDetails/index',//公出详情
     'pages/login/index',//登录
   ],

+ 0 - 247
src/components/common/DateTimePicker/index.jsx

@@ -1,247 +0,0 @@
-import React,{ Component } from 'react'
-import Taro from '@tarojs/taro';
-import dayjs from 'dayjs';
-import { AtIcon } from 'taro-ui';
-import { View, Text, PickerView, PickerViewColumn, } from '@tarojs/components';
-import { getPickerViewList, getDate, getArrWithTime, formatDate, getDayList } from './utils';
-import './index.scss';
-import {getUserWordTimes} from "../../../utils/tools";
-
-
-export default class DateTimePicker extends Component {
-    static externalClasses = ['wrap-class', 'select-item-class'];
-
-    state = {
-        yearList: [],   //年 -下拉
-        monthLsit: [], //月 -下拉
-        dayList: [], //日 -下拉
-        hourList: [], //时 -下拉
-        minuteList: [], //分 -下拉
-        selectIndexList: [1, 1, 1, 1, 1], //PickerViewColumn选择的索引
-        fmtInitValue: "", //初始值
-        current: '', //当前选择的数据
-        visible: false, //是否可见
-        hasChange: false, //是否更改
-        year: '',  //时间值
-        month: '',
-        day: '',
-        hour: '',
-        minute: '',
-      isPickend:true,
-    };
-    // 打开时间选择的模态框 - 根据当前时间初始化picker-view的数据
-    openModal = () => {
-        const { current, fmtInitValue } = this.state;
-        const selectIndexList = [];
-        const arr = getArrWithTime(current || fmtInitValue || getDate()); //优先当前选择的值,其次默认值,其次当前值
-        const { yearList, monthLsit, dayList, hourList, minuteList } = getPickerViewList();
-        const [year, month, day, hour, minute] = arr;
-
-        //根据arr  数据索引
-        selectIndexList[0] = yearList.indexOf(arr[0] + '年');
-        selectIndexList[1] = monthLsit.indexOf(arr[1] + '月');
-        selectIndexList[2] = dayList.indexOf(arr[2] + '日');
-        selectIndexList[3] = hourList.indexOf(arr[3] + '点');
-        selectIndexList[4] = minuteList.indexOf(arr[4] + '分');
-
-        this.setState({
-            selectIndexList,
-            visible: true,
-            yearList,
-            monthLsit,
-            dayList,
-            hourList,
-            minuteList,
-            year,
-            month,
-            day,
-            hour,
-            minute
-        });
-    };
-    // 取消
-    cancelHandel = () => {
-        this.setState({
-            visible: false,
-            hasChange: false,
-        });
-
-        const { year, month, day, hour, minute } = this.state;
-        const current = formatDate(year, month, day, hour, minute);
-
-        this.props.onCancel && this.props.onCancel({ current });
-    };
-    // 确定
-    okHandel = () => {
-        const { year, month, day, hour, minute } = this.state;
-        let current = formatDate(year, month, day, hour, minute);
-        let currentValue = formatDate(year, month, day, hour, minute);
-        const {start,restStart,restEnd,end} = getUserWordTimes();
-        let startArr = start.split(':');
-        let endArr = end.split(':');
-        let restEndArr = restEnd.split(':');
-
-        if(dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isBefore(dayjs(dayjs(current).format('YYYY-MM-DD')+start))){
-          currentValue = formatDate(year, month, day,parseInt(startArr[0]), parseInt(startArr[1]));
-        }else if(dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isAfter(dayjs(dayjs(current).format('YYYY-MM-DD')+end))){
-          currentValue = formatDate(year, month, day,parseInt(endArr[0]), parseInt(endArr[1]));
-        }else if(
-          dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isAfter(dayjs(dayjs(current).format('YYYY-MM-DD')+restStart))
-          &&
-          dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isBefore(dayjs(dayjs(current).format('YYYY-MM-DD')+restEnd))
-        ){
-          currentValue = formatDate(year, month, day,parseInt(restEndArr[0]), parseInt(restEndArr[1]));
-        }
-
-        this.setState({
-            current,
-            hasChange: false,
-            visible: false,
-        });
-        this.props.onOk && this.props.onOk({ current:currentValue });
-    };
-    // 切换
-    changeHandel = (e) => {
-        const selectIndexList = e.detail.value;
-        const [yearIndex, monthIndex, dayIndex, hourIndex, minuteIndex] = selectIndexList;
-        const { yearList, monthLsit, dayList, hourList, minuteList } = this.state;
-        const yearStr = yearList[yearIndex];
-        const monthStr = monthLsit[monthIndex];
-        const dayStr = dayList[dayIndex];
-        const hourStr = hourList[hourIndex];
-        const minuteStr = minuteList[minuteIndex];
-        const year = Number(yearStr.substr(0, yearStr.length - 1));
-        const month = Number(monthStr.substr(0, monthStr.length - 1));
-        const day = Number(dayStr.substr(0, dayStr.length - 1));
-        const hour = Number(hourStr.substr(0, hourStr.length - 1));
-        const minute = Number(minuteStr.substr(0, minuteStr.length - 1));
-
-        // 更新年、天数
-        const newDayList = getDayList(year, month);
-
-        this.setState({
-            dayList: newDayList,
-            year,
-            month,
-            day,
-            hour,
-            minute,
-            hasChange: true,
-            selectIndexList
-        });
-    };
-    // 清除数据
-    clear = () => {
-        this.setState({
-            current: ''
-        });
-        this.props.onClear && this.props.onClear({ current: '' });
-    };
-    // 设值
-    setInitialState(state) {
-      this.setState({
-        ...state
-      })
-    }
-
-  componentDidMount() {
-        const { initValue } = this.props;
-        const fmtInitValue = getDate(initValue);
-        this.setState({ fmtInitValue });
-    }
-
-    render() {
-        const { visible, current, yearList, monthLsit, dayList, hourList, minuteList, selectIndexList } = this.state;
-        const { placeholder = '请选择时间' } = this.props;
-        return (
-            <View className='datetime-picker-wrap wrap-class'>
-                <View className='selector-wrap'>
-                    <View className='select-item select-item-class' onClick={this.openModal}>
-                        {current || placeholder}
-                    </View>
-                    {
-                        current && <View className='clear-icon'>
-                            <AtIcon value='close-circle' size='20' onClick={this.clear} />
-                        </View>
-                    }
-                </View>
-                {visible
-                && <View className='wrapper'>
-                    {/*日期模态框 */}
-                    <View className='model-box-bg'></View>
-                    <View className='model-box'>
-                        <View className='model-picker'>
-                            <View className='button-model'>
-                                <Text class='btn-txt' onClick={this.cancelHandel}>取消</Text>
-                                <Text class='btn-txt' onClick={()=>{
-                                  if(!this.state.isPickend){return;}
-                                  this.okHandel()
-                                }} style={{color:this.state.isPickend ? '#007aff' : '#a1a2a3'}}>确定</Text>
-                            </View>
-                            <View className='cont_model'>
-                                <PickerView
-                                  className='pick-view'
-                                  indicatorStyle='height: 50px;'
-                                  value={selectIndexList}
-                                  onChange={this.changeHandel}
-                                  onPickstart={()=>{
-                                    this.setState({
-                                      isPickend:false
-                                    })
-                                  }}
-                                  onPickend={()=>{
-                                  this.setState({
-                                    isPickend:true
-                                  })
-                                }}>
-                                    {/*年*/}
-                                    <PickerViewColumn className='picker-view-column'>
-                                        {
-                                            yearList.length && yearList.map((item, index) =>
-                                                <View key={String(index)} className='pick-view-column-item'>{item}</View>)
-                                        }
-                                    </PickerViewColumn>
-                                    {/*月*/}
-                                    <PickerViewColumn className='picker-view-column'>
-                                        {
-                                            monthLsit.length && monthLsit.map((item, index) =>
-                                                <View key={String(index)} className='pick-view-column-item'>{item}</View>)
-                                        }
-                                    </PickerViewColumn>
-                                    {/*日*/}
-                                    <PickerViewColumn className='picker-view-column'>
-                                        {
-                                            dayList.length && dayList.map((item, index) =>
-                                                <View key={String(index)} className='pick-view-column-item'>{item}</View>)
-                                        }
-                                    </PickerViewColumn>
-                                    {/*时*/}
-                                    <PickerViewColumn className='picker-view-column'>
-                                        {
-                                            hourList.length && hourList.map((item, index) =>
-                                                <View key={String(index)} className='pick-view-column-item'>{item}</View>)
-                                        }
-                                    </PickerViewColumn>
-                                    {/*分*/}
-                                    <PickerViewColumn className='picker-view-column'>
-                                        {
-                                            minuteList.length && minuteList.map((item, index) =>
-                                                <View key={String(index)} className='pick-view-column-item'>{item}</View>)
-                                        }
-                                    </PickerViewColumn>
-                                </PickerView>
-                            </View>
-                        </View>
-                    </View>
-                </View>}
-            </View>
-        );
-    }
-}
-
-// DateTimePicker.prototype = {
-//     initValue: PropTypes.string, //初始化时间
-//     onClear: PropTypes.func, //清除选择的时间触发
-//     onCancel: PropTypes.func, //时间picker 取消时触发
-//     onOk: PropTypes.func, //时间picker 确定时触发
-// };

+ 0 - 76
src/components/common/DateTimePicker/index.scss

@@ -1,76 +0,0 @@
-.datetime-picker-wrap {
-    width: 100%;
-    .selector-wrap {
-        display: flex;
-        align-items: center;
-        background: #FFFFFF;
-        color: #9BA0AA;
-        padding: 0;
-        .select-item {
-            flex: 1;
-            font-size: 30px;
-            padding: 12px 0;
-            //text-align: center;
-        }
-    }
-    .wrapper {
-        .model-box-bg {
-            position: fixed;
-            top: 0;
-            left: 0;
-            z-index: 10000;
-            width: 100%;
-            height: 100%;
-            background: #000;
-            opacity: 0.3;
-        }
-        .model-box {
-            position: fixed;
-            bottom: 0;
-            left: 0;
-            z-index: 999999;
-            width: 100%;
-            background: #fff;
-        }
-
-        .model-picker {
-            position: relative;
-            .button-model {
-                height: 80px;
-                width: 100%;
-                background: #fff;
-                position: relative;
-                border-bottom: 1px solid #d9d9d9;
-                .btn-txt {
-                    color: #007aff;
-                    position: absolute;
-                    background: transparent;
-                    border: none;
-                    line-height: 80px;
-                    &:first-child {
-                        left: 32px;
-                    }
-                    &:last-child {
-                        right: 32px;
-                    }
-                }
-            }
-            .pick-view {
-                width: 100%;
-                height: 600px;
-                .picker-view-column {
-                    text-align: center;
-                    .pick-view-column-item {
-                        line-height: 50PX;
-                    }
-                }
-            }
-
-        }
-    }
-}
-
-
-
-
-

+ 0 - 85
src/components/common/DateTimePicker/utils.js

@@ -1,85 +0,0 @@
-function addZero(num) {
-    return Number(num) < 10 ? `0${num}` : num;
-}
-
-export const formatDate = (year, month, day, hour, minute) => {
-    const newmonth = addZero(month);
-    const newday = addZero(day);
-    const newhour = addZero(hour);
-    const newminute = addZero(minute);
-
-    return year + '-' + newmonth + '-' + newday + ' ' + newhour + ":" + newminute;
-};
-
-// 获取当前时间
-export const getDate = (value) => {
-    let date = '';
-    if (value) {
-        date = new Date(value);
-    } else {
-        date = new Date();
-    }
-    const y = date.getFullYear(),
-        m = date.getMonth() + 1,
-        d = date.getDate(),
-        h = date.getHours(), //获取当前小时数(0-23)
-        f = date.getMinutes();
-    return formatDate(y, m, d, h, f);
-};
-
-// 获取对应年份月份的天数
-export const getMonthDay = (year, month) => {
-    var d = new Date(year, month, 0);
-    return d.getDate();
-};
-
-//根据时间2019-01-02 09:12  得到 ['2019','1','2','9','12']
-export const getArrWithTime = (str) => {
-    let arr1 = str.split(' ');
-    let arr2 = (arr1[0]).split('-');
-    let arr3 = arr1[1].split(':');
-    let arr = arr2.concat(arr3);
-    arr[1] = arr[1].startsWith('0') ? arr[1].substr(1, arr[1].length) : arr[1];
-    arr[2] = arr[2].startsWith('0') ? arr[2].substr(1, arr[2].length) : arr[2];
-    arr[3] = arr[3].startsWith('0') ? arr[3].substr(1, arr[3].length) : arr[3];
-    arr[4] = arr[4].startsWith('0') ? arr[4].substr(1, arr[4].length) : arr[4];
-    return arr;
-};
-
-// 获取月份天数
-export const getDayList = (year, month) => {
-    const dayList = [];
-    var d = new Date(year, month, 0);
-    for (let i = 1; i <= d.getDate(); i++) {
-        dayList.push(i + "日");
-    }
-
-    return dayList;
-};
-
-// 获取最近的年、月、日、时、分的集合
-export const getPickerViewList = () => {
-    const now = new Date();
-    const year = now.getFullYear();
-    const month = now.getMonth() + 1;
-    const yearList = [];
-    const monthLsit = [];
-    const dayList = getDayList(year, month);
-    const hourList = [];
-    const minuteList = [];
-
-    for (let i = 1970; i <= 2070; i++) {
-        yearList.push(i + "年");
-    }
-    for (let i = 1; i <= 12; i++) {
-        monthLsit.push(i + "月");
-    }
-
-    for (let i = 0; i <= 23; i++) {
-        hourList.push(i + "点");
-    }
-    for (let i = 0; i <= 59; i++) {
-        minuteList.push(i + "分");
-    }
-    return { yearList, monthLsit, dayList, hourList, minuteList };
-};

+ 612 - 0
src/components/common/timePicker/timePicker.js

@@ -0,0 +1,612 @@
+import dayjs from "dayjs";
+import {getUserWordTimes,formatDate} from "../../../utils/tools";
+Component({
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    isPartition:{
+      type: Boolean,
+    },
+    pickerShow: {
+      type: Boolean,
+      observer:function(val){   //弹出动画
+        if(val){
+          let animation = wx.createAnimation({
+            duration: 500,
+            timingFunction: "ease"
+          });
+          let animationOpacity = wx.createAnimation({
+            duration: 500,
+            timingFunction: "ease"
+          });
+          setTimeout(() => {
+            animation.bottom(0).step();
+            animationOpacity.opacity(0.7).step();
+            this.setData({
+              animationOpacity: animationOpacity.export(),
+              animationData: animation.export()
+            })
+          }, 0);
+        }else{
+          let animation = wx.createAnimation({
+            duration: 100,
+            timingFunction: "ease"
+          });
+          let animationOpacity = wx.createAnimation({
+            duration: 500,
+            timingFunction: "ease"
+          });
+          animation.bottom(-320).step();
+          animationOpacity.opacity(0).step();
+          this.setData({
+            animationOpacity: animationOpacity.export(),
+            animationData: animation.export()
+          });
+        }
+
+        // 在picker滚动未停止前点确定,会使startValue数组各项归零,发生错误,这里判断并重新初始化
+        // 微信新增了picker滚动的回调函数,已进行兼容
+        if(this.data.startValue&&this.data.endValue){
+          let s = 0, e = 0;
+          let conf = this.data.config;
+
+          this.data.startValue.map(val => {
+            if (val == 0) {
+              s++
+            }
+          })
+          this.data.endValue.map(val => {
+            if (val == 0) {
+              e++;
+            }
+          });
+          let tmp={
+            hour:4,
+            minute:5,
+            second:6
+          }
+          let n = tmp[conf.column];
+          if (s>=n || e>=n) {
+            this.initPick(this.data.config);
+            this.setData({
+              startValue: this.data.startValue,
+              endValue: this.data.endValue,
+            });
+          }
+        }
+      }
+    },
+    config: Object,
+  },
+
+  /**
+   * 组件的初始数据
+   */
+  data: {
+    // pickerShow:true
+    // limitStartTime: new Date().getTime()-1000*60*60*24*30,
+    // limitEndTime: new Date().getTime(),
+    // yearStart:2000,
+    // yearEnd:2100
+  },
+  detached: function() {
+    console.log("dele");
+  },
+  attached: function() {},
+  ready: function() {
+    this.readConfig();
+    this.initPick(this.data.config || {});
+    this.setData({
+      startValue: this.data.startValue,
+      endValue: this.data.endValue,
+    });
+
+
+
+
+  },
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    //阻止滑动事件
+    onCatchTouchMove(e) {
+
+    },
+    //读取配置项
+    readConfig() {
+      let limitEndTime = new Date().getTime();
+      let limitStartTime = new Date().getTime() - 1000 * 60 * 60 * 24 * 30;
+      if (this.data.config) {
+        let conf = this.data.config;
+
+        if (typeof conf.dateLimit == "number") {
+          limitStartTime =
+            new Date().getTime() - 1000 * 60 * 60 * 24 * conf.dateLimit;
+        }
+        if(conf.limitStartTime){
+
+          limitStartTime = new Date(conf.limitStartTime.replace(/-/g,'/')).getTime();
+        }
+
+        if (conf.limitEndTime) {
+          limitEndTime = new Date(conf.limitEndTime.replace(/-/g, '/')).getTime();
+        }
+
+        this.setData({
+          yearStart: conf.yearStart || 2000,
+          yearEnd: conf.yearEnd || 2100,
+          endDate: conf.endDate || false,
+          dateLimit: conf.dateLimit || false,
+          hourColumn:
+            conf.column == "hour" ||
+            conf.column == "minute" ||
+            conf.column == "second",
+          minColumn: conf.column == "minute" || conf.column == "second",
+          secColumn: conf.column == "second"
+        });
+      }
+
+      let limitStartTimeArr = formatTime(limitStartTime);
+      let limitEndTimeArr = formatTime(limitEndTime);
+
+      this.setData({
+        limitStartTime,
+        limitStartTimeArr,
+        limitEndTime,
+        limitEndTimeArr
+      });
+    },
+    //滚动开始
+    handlePickStart:function(e){
+      this.setData({
+        isPicking:true
+      })
+    },
+    //滚动结束
+    handlePickEnd:function(e){
+      this.setData({
+        isPicking:false
+      })
+    },
+    partitionTimeHandle(time){
+      let year = dayjs(time).year();
+      let month = dayjs(time).month()+1;
+      let day = dayjs(time).date();
+      let hour = dayjs(time).hour();
+      let minute = dayjs(time).minute();
+
+      let current = formatDate(year, month, day, hour, minute);
+      const {start,restStart,restEnd,end} = getUserWordTimes();
+      let startArr = start.split(':');
+      let endArr = end.split(':');
+      let restEndArr = restEnd.split(':');
+
+      if(dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isBefore(dayjs(dayjs(current).format('YYYY-MM-DD')+start))){
+        current = formatDate(year, month, day,parseInt(startArr[0]), parseInt(startArr[1]));
+      }else if(dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isAfter(dayjs(dayjs(current).format('YYYY-MM-DD')+end))){
+        current = formatDate(year, month, day,parseInt(endArr[0]), parseInt(endArr[1]));
+      }else if(
+        dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isAfter(dayjs(dayjs(current).format('YYYY-MM-DD')+restStart))
+        &&
+        dayjs(dayjs(current).format('YYYY-MM-DD HH:mm')).isBefore(dayjs(dayjs(current).format('YYYY-MM-DD')+restEnd))
+      ){
+        current = formatDate(year, month, day,parseInt(restEndArr[0]), parseInt(restEndArr[1]));
+      }
+      return current;
+    },
+    onConfirm: function() {
+      //滚动未结束时不能确认
+      if(this.data.isPicking){return}
+      let startTime = new Date(this.data.startPickTime.replace(/-/g, "/"));
+      let endTime = new Date(this.data.endPickTime.replace(/-/g, "/"));
+      let lv = true;
+      this.triggerEvent("conditionaljudgment", {
+        startTime,
+        endTime,
+        setLv:(v)=>{lv = v}
+      });//条件判断
+      wx.nextTick(() => {
+        if(!lv){return}
+        if (startTime <= endTime || !this.data.endDate) {
+          this.setData({
+            startTime,
+            endTime
+          });
+          let startArr = formatTime(startTime).arr;
+          let endArr = formatTime(endTime).arr;
+          let format0 = function(num){
+            return num<10?'0'+num:num
+          }
+
+          let startTimeBack =
+            startArr[0] +
+            "-" +
+            format0(startArr[1]) +
+            "-" +
+            format0(startArr[2]) +
+            " " +
+            (this.data.hourColumn ? format0(startArr[3]) : "00") +
+            ":" +
+            (this.data.minColumn ? format0(startArr[4]) : "00") +
+            ":" +
+            (this.data.secColumn ? format0(startArr[5]) : "00");
+
+          let endTimeBack =
+            endArr[0] +
+            "-" +
+            format0(endArr[1]) +
+            "-" +
+            format0(endArr[2]) +
+            " " +
+            (this.data.hourColumn ? format0(endArr[3]) : "00") +
+            ":" +
+            (this.data.minColumn ? format0(endArr[4]) : "00") +
+            ":" +
+            (this.data.secColumn ? format0(endArr[5]) : "00");
+
+          let time = {
+            startTime: startTimeBack,
+            endTime: endTimeBack
+          };
+          //触发自定义事件
+          //isPartition是否按地区判断工作开始结束时间
+          if(this.data.isPartition){
+            let startTimeInfor = this.partitionTimeHandle(time.startTime);
+            let endTimeInfor = this.partitionTimeHandle(time.endTime);
+            time.selectStartTime = time.startTime;
+            time.selectEndTime = time.endTime;
+            time.startTime = dayjs(startTimeInfor).format('YYYY-MM-DD HH:mm:ss');
+            time.endTime = dayjs(endTimeInfor).format('YYYY-MM-DD HH:mm:ss');
+            this.triggerEvent("setpickertime", time);
+          }else{
+            this.triggerEvent("setpickertime", time);
+          }
+          this.triggerEvent("hidepicker", {},{});
+        } else {
+          wx.showToast({
+            icon: "none",
+            title: "结束时间不能小于开始时间"
+          });
+        }
+      })
+    },
+    hideModal: function(e) {
+      this.triggerEvent("hidepicker",  e.detail,{});
+    },
+    changeStartDateTime: function(e) {
+      let val = e.detail.value;
+
+      this.compareTime(val, "start");
+    },
+
+    changeEndDateTime: function(e) {
+      let val = e.detail.value;
+      this.compareTime(val, "end");
+    },
+    //比较时间是否在范围内
+    compareTime(val_, type) {
+      const val = val_.map(it=>it.toString());
+      let h = val[3] ? this.data.HourList[val[3]] : "00";
+      let m = val[4] ? this.data.MinuteList[val[4]] : "00";
+      let s = val[5] ? this.data.SecondList[val[5]] : "00";
+      let time =
+        this.data.YearList[val[0]] +
+        "-" +
+        this.data.MonthList[val[1]] +
+        "-" +
+        this.data.DayList[val[2]] +
+        " " +
+        h +
+        ":" +
+        m +
+        ":" +
+        s;
+
+      let start = this.data.limitStartTime;
+      let end = this.data.limitEndTime;
+      let timeNum = new Date(time.replace(/-/g, '/')).getTime();
+      let year, month, day, hour, min, sec, limitDate;
+      let tempArr = []
+
+      if (!this.data.dateLimit){
+        limitDate = [
+          this.data.YearList[val[0]],
+          this.data.MonthList[val[1]],
+          this.data.DayList[val[2]],
+          this.data.HourList[val[3]],
+          this.data.MinuteList[val[4]],
+          this.data.SecondList[val[5]]]
+      } else if (type == "start" && timeNum > new Date(this.data.endPickTime.replace(/-/g, '/')) && this.data.config.endDate) {
+        limitDate = formatTime(this.data.endPickTime).arr;
+
+      } else if (type == "end" && timeNum < new Date(this.data.startPickTime.replace(/-/g, '/'))) {
+        limitDate = formatTime(this.data.startPickTime).arr;
+
+      } else if (timeNum < start) {
+        limitDate = this.data.limitStartTimeArr.arr;
+
+      } else if (timeNum > end) {
+        limitDate = this.data.limitEndTimeArr.arr;
+
+      } else {
+        limitDate = [
+          this.data.YearList[val[0]],
+        this.data.MonthList[val[1]],
+        this.data.DayList[val[2]],
+        this.data.HourList[val[3]],
+        this.data.MinuteList[val[4]],
+       this.data.SecondList[val[5]]
+        ]
+
+      }
+
+      year = limitDate[0];
+      month = limitDate[1];
+      day = limitDate[2];
+      hour = limitDate[3];
+      min = limitDate[4];
+      sec = limitDate[5];
+
+      if (type == "start") {
+        this.setStartDate(year, month, day, hour, min, sec);
+      } else if (type == "end") {
+        this.setEndDate(year, month, day, hour, min, sec);
+      }
+    },
+    getDays: function(year, month) {
+      let daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+      if (month === 2) {
+        return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0
+          ? 29
+          : 28;
+      } else {
+        return daysInMonth[month - 1];
+      }
+    },
+    initPick: function(initData) {
+      const date = initData.initStartTime ? new Date(initData.initStartTime.replace(/-/g, '/')): new Date();
+      const endDate = initData.initEndTime ? new Date(initData.initEndTime.replace(/-/g, '/')) : new Date();
+      // const startDate = new Date(date.getTime() - 1000 * 60 * 60 * 24);
+      const startDate = date;
+      const startYear = date.getFullYear();
+      const startMonth = date.getMonth() + 1;
+      const startDay = date.getDate();
+      const startHour = date.getHours();
+      const startMinute = date.getMinutes();
+      const startSecond = date.getSeconds();
+
+      const endYear = endDate.getFullYear();
+      const endMonth = endDate.getMonth() + 1;
+      const endDay = endDate.getDate();
+      const endHour = endDate.getHours();
+      const endMinute = endDate.getMinutes();
+      const endSecond = endDate.getSeconds();
+
+      let YearList = [];
+      let MonthList = [];
+      let DayList = [];
+      let HourList = [];
+      let MinuteList = [];
+      let SecondList = [];
+
+      //设置年份列表
+      for (let i = this.data.yearStart; i <= this.data.yearEnd; i++) {
+        YearList.push(i);
+      }
+
+      // 设置月份列表
+      for (let i = 1; i <= 12; i++) {
+        MonthList.push(i);
+      }
+      // 设置日期列表
+      for (let i = 1; i <= 31; i++) {
+        DayList.push(i);
+      }
+      // 设置时列表
+      for (let i = 0; i <= 23; i++) {
+        if (0 <= i && i < 10) {
+          i = "0" + i;
+        }
+        HourList.push(i);
+      }
+      // 分|秒
+      for (let i = 0; i <= 59; i++) {
+        if (0 <= i && i < 10) {
+          i = "0" + i;
+        }
+        MinuteList.push(i);
+        SecondList.push(i);
+      }
+
+      this.setData({
+        YearList,
+        MonthList,
+        DayList,
+        HourList,
+        MinuteList,
+        SecondList
+      });
+
+      this.setStartDate(startYear, startMonth, startDay, startHour, startMinute, startSecond);
+      this.setEndDate(endYear, endMonth, endDay, endHour, endMinute, endSecond);
+
+      //!!!
+      // setTimeout(() => {
+      //   this.setStartDate(nowYear, nowMonth, nowDay, nowHour, nowMinute)
+      //   this.setEndDate(nowYear, nowMonth, nowDay, nowHour, nowMinute)
+      // }, 0);
+    },
+    setPickerDateArr(type, year, month, day, hour, minute, second) {
+      let yearIdx = 0;
+      let monthIdx = 0;
+      let dayIdx = 0;
+      let hourIdx = 0;
+      let minuteIdx = 0;
+      let secondIdx = 0;
+
+      this.data.YearList.map((v, idx) => {
+        if (parseInt(v) === year) {
+          yearIdx = idx;
+        }
+      });
+
+      this.data.MonthList.map((v, idx) => {
+        if (parseInt(v) === month) {
+          monthIdx = idx;
+        }
+      });
+
+      // 重新设置日期列表
+      let DayList = [];
+      for (let i = 1; i <= this.getDays(year, month); i++) {
+        DayList.push(i);
+      }
+
+      DayList.map((v, idx) => {
+        if (parseInt(v) === day) {
+          dayIdx = idx;
+        }
+      });
+      if (type == "start") {
+        this.setData({ startDayList: DayList });
+      } else if (type == "end") {
+        this.setData({ endDayList: DayList });
+      }
+
+      this.data.HourList.map((v, idx) => {
+        if (parseInt(v) === parseInt(hour)) {
+          hourIdx = idx;
+        }
+      });
+
+      this.data.MinuteList.map((v, idx) => {
+        if (parseInt(v) === parseInt(minute)) {
+          minuteIdx = idx;
+        }
+      });
+      this.data.SecondList.map((v, idx) => {
+        if (parseInt(v) === parseInt(second)) {
+          secondIdx = idx;
+        }
+      });
+
+      return {
+        yearIdx,
+        monthIdx,
+        dayIdx,
+        hourIdx,
+        minuteIdx,
+        secondIdx
+      };
+    },
+    setStartDate: function(year, month, day, hour, minute, second) {
+      let pickerDateArr = this.setPickerDateArr(
+        "start",
+        year,
+        month,
+        day,
+        hour,
+        minute,
+        second
+      );
+      this.setData({
+        startYearList: this.data.YearList,
+        startMonthList: this.data.MonthList,
+        // startDayList: this.data.DayList,
+        startHourList: this.data.HourList,
+        startMinuteList: this.data.MinuteList,
+        startSecondList: this.data.SecondList,
+        startValue: [
+          pickerDateArr.yearIdx,
+          pickerDateArr.monthIdx,
+          pickerDateArr.dayIdx,
+          pickerDateArr.hourIdx,
+          pickerDateArr.minuteIdx,
+          pickerDateArr.secondIdx
+        ],
+        startPickTime:
+          this.data.YearList[pickerDateArr.yearIdx] +
+          "-" +
+          this.data.MonthList[pickerDateArr.monthIdx] +
+          "-" +
+          this.data.DayList[pickerDateArr.dayIdx] +
+          " " +
+          this.data.HourList[pickerDateArr.hourIdx] +
+          ":" +
+          this.data.MinuteList[pickerDateArr.minuteIdx] +
+          ":" +
+          this.data.SecondList[pickerDateArr.secondIdx]
+      });
+    },
+    setEndDate: function(year, month, day, hour, minute, second) {
+      let pickerDateArr = this.setPickerDateArr(
+        "end",
+        year,
+        month,
+        day,
+        hour,
+        minute,
+        second
+      );
+
+      this.setData({
+        endYearList: this.data.YearList,
+        endMonthList: this.data.MonthList,
+        // endDayList: this.data.DayList,
+        endHourList: this.data.HourList,
+        endMinuteList: this.data.MinuteList,
+        endSecondList: this.data.SecondList,
+        endValue: [
+          pickerDateArr.yearIdx,
+          pickerDateArr.monthIdx,
+          pickerDateArr.dayIdx,
+          pickerDateArr.hourIdx,
+          pickerDateArr.minuteIdx,
+          pickerDateArr.secondIdx
+        ],
+        endPickTime:
+          this.data.YearList[pickerDateArr.yearIdx] +
+          "-" +
+          this.data.MonthList[pickerDateArr.monthIdx] +
+          "-" +
+          this.data.DayList[pickerDateArr.dayIdx] +
+          " " +
+          this.data.HourList[pickerDateArr.hourIdx] +
+          ":" +
+          this.data.MinuteList[pickerDateArr.minuteIdx] +
+          ":" +
+          this.data.SecondList[pickerDateArr.secondIdx]
+      });
+    },
+  }
+});
+
+
+function formatTime(date) {
+
+  if (typeof date == 'string' || 'number') {
+    try {
+      date = date.replace(/-/g, '/')//兼容ios
+    } catch (error) {
+    }
+    date = new Date(date)
+  }
+
+  const year = date.getFullYear()
+  const month = date.getMonth() + 1
+  const day = date.getDate()
+  const hour = date.getHours()
+  const minute = date.getMinutes()
+  const second = date.getSeconds()
+
+  return {
+    str: [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':'),
+    arr: [year, month, day, hour, minute, second]
+  }
+}
+function formatNumber(n) {
+  n = n.toString()
+  return n[1] ? n : '0' + n
+}

+ 4 - 0
src/components/common/timePicker/timePicker.json

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

+ 68 - 0
src/components/common/timePicker/timePicker.wxml

@@ -0,0 +1,68 @@
+<!--components/timePicker/timePicker.wxml-->
+<!-- 自定义时间筛选器 -->
+<view hidden="{{!pickerShow}}">
+  <view class="picker-container {{pickerShow?'show_picker':'hide_picker'}}" animation="{{animationData}}">
+
+    <view class="btn-box" catchtouchmove="onCatchTouchMove">
+      <view class="pick_btn" bindtap="hideModal">取消</view>
+      <view class='pick_btn' style="color: #19f" bindtap="onConfirm">确定</view>
+    </view>
+
+    <view>
+      <picker-view class='sensorTypePicker' indicator-style='height: 35px;' bindchange="changeStartDateTime"
+        value="{{startValue}}" style="height: {{endDate?'120px':'250px'}};" bindpickstart="handlePickStart" bindpickend="handlePickEnd">
+        <picker-view-column style="min-width: 70px;flex-shrink: 0">
+          <view class='picker-item' wx:for="{{startYearList}}" wx:key='*this'>{{item}}年</view>
+        </picker-view-column>
+        <picker-view-column>
+          <view class='picker-item' wx:for="{{startMonthList}}" wx:key='*this'>{{item}}月</view>
+        </picker-view-column>
+        <picker-view-column>
+          <view class='picker-item' wx:for="{{startDayList}}" wx:key='*this'>{{item}}日</view>
+        </picker-view-column>
+        <picker-view-column hidden="{{!hourColumn}}">
+          <view class='picker-item' wx:for="{{startHourList}}" wx:key='*this'>{{item}}时</view>
+        </picker-view-column>
+        <picker-view-column hidden="{{!minColumn}}">
+          <view class='picker-item' wx:for="{{startMinuteList}}" wx:key='*this'>{{item}}分</view>
+        </picker-view-column>
+        <picker-view-column hidden="{{!secColumn}}">
+          <view class='picker-item' wx:for="{{startSecondList}}" wx:key='*this'>{{item}}秒</view>
+        </picker-view-column>
+      </picker-view>
+    </view>
+
+    <view wx:if="{{endDate}}">
+      <view class='to' style='margin-top: 4px;margin-bottom: 4px;'>至</view>
+        <picker-view class='sensorTypePicker' indicator-style='height: 35px;' bindchange="changeEndDateTime" bindpickstart="handlePickStart" bindpickend="handlePickEnd"
+          value="{{endValue}}">
+          <picker-view-column style="min-width: 70px;flex-shrink: 0">
+            <view class='picker-item' wx:for="{{endYearList}}" wx:key='*this' style="min-width: 70px;">{{item}}年</view>
+          </picker-view-column>
+          <picker-view-column>
+            <view class='picker-item' wx:for="{{endMonthList}}" wx:key='*this'>{{item}}月</view>
+          </picker-view-column>
+          <picker-view-column>
+            <view class='picker-item' wx:for="{{endDayList}}" wx:key='*this'>{{item}}日</view>
+          </picker-view-column>
+          <picker-view-column hidden="{{!hourColumn}}" >
+            <view class='picker-item' wx:for="{{endHourList}}" wx:key='*this'>{{item}}时</view>
+          </picker-view-column>
+          <picker-view-column hidden="{{!minColumn}}">
+            <view class='picker-item' wx:for="{{endMinuteList}}" wx:key='*this'>{{item}}分</view>
+          </picker-view-column>
+          <picker-view-column hidden="{{!secColumn}}">
+            <view class='picker-item' wx:for="{{startSecondList}}" wx:key='*this'>{{item}}秒</view>
+          </picker-view-column>
+
+
+        </picker-view>
+    </view>
+
+
+    <!-- <view class='sure' bindtap="onConfirm">确定</view> -->
+
+  </view>
+  <!-- 遮罩 -->
+  <view class="sensorType-screen" bindtap="hideModal" catchtouchmove="onCatchTouchMove" animation="{{animationOpacity}}"/>
+</view>

+ 96 - 0
src/components/common/timePicker/timePicker.wxss

@@ -0,0 +1,96 @@
+/* components/timePicker/timePicker.wxss */
+
+.picker-item{
+  line-height: 100rpx;  
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+
+/* 自定义时间 */
+.picker-container {
+  display: flex;
+  flex-direction: column;
+  /* justify-content: center; */
+  align-items: center;
+
+  width: 100%;
+  overflow: hidden;
+  position: fixed;
+  bottom: -640rpx;
+  left: 0;
+  /* height: 0; */
+  transition: height 0.5s;
+  z-index: 2000;
+  background: white;
+  border-top: 1px solid #EFEFF4;
+}
+.sensorType-screen{
+  width: 100vw;
+  /* height:400rpx; */
+  position: fixed;
+  top: 0;
+  right: 0;
+  bottom: 0;
+  left: 0;
+  background: #000;
+  opacity: 0;
+  overflow: hidden;
+  z-index: 1999;
+  color: #fff;
+}
+.sensorTypePicker{
+  width: 690rpx;
+  height: 240rpx;
+  /* padding: 45px 0; */
+}
+.picker-item{
+  line-height: 100rpx;  
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  font-size: 32rpx;
+  /* overflow: hidden; */
+}
+.box{
+   padding: 0 20rpx; 
+}
+
+/* 至 */
+.to{
+  width:100%;
+  display: flex;
+  justify-content: center;align-items: center;
+  color:rgb(138,138,138);
+  /* font-size:30rpx; */
+}
+
+/* 确定 */
+.sure{
+  width:100%;
+  height:90rpx;
+  border-top: 2rpx solid #EFEFF4;
+  display: flex;justify-content: center;align-items: center;
+  color: rgb(36,123,255);
+  font-size:16px;
+}
+
+.btn-box{
+  width: 100%;
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  border-bottom: 2rpx solid #eee;
+}
+.pick_btn{
+  padding: 14rpx 30rpx;
+  color: #ccc;
+  /* background-color: #159; */
+}
+
+.show_picker{
+  /* height: 320px; */
+}
+.hide_picker{
+  /* height: 0; */
+}

+ 3 - 0
src/pages/applyDepart/index.config.js

@@ -1,3 +1,6 @@
 export default {
   navigationBarTitleText: '申请公出',
+  usingComponents: {
+    timePicker: '../../components/common/timePicker/timePicker'
+  }
 }

+ 85 - 104
src/pages/applyDepart/publicContent.jsx

@@ -3,7 +3,6 @@ import Taro from '@tarojs/taro';
 import {Text, View} from '@tarojs/components'
 import dayjs from 'dayjs';
 import './index.less';
-import DateTimePicker from '../../components/common/DateTimePicker';
 
 import ImagePicker from '../../components/common/imagePicker'
 
@@ -38,17 +37,20 @@ class PublicContent extends Component{
       loading:false,
       workTypeList:[],
       workType:0,
+
+      isPickerRender:false,
     }
     this.onSubmit = this.onSubmit.bind(this);
     this.selectArrder = this.selectArrder.bind(this);
     this.onChange = this.onChange.bind(this);
     this.getWorkingHoursList = this.getWorkingHoursList.bind(this);
+    this.onPickerHide = this.onPickerHide.bind(this);
+    this.onSetPickerTime = this.onSetPickerTime.bind(this);
+    this.getNumHourse = this.getNumHourse.bind(this);
   }
 
   componentDidMount() {
     Taro.eventCenter.on('result', () => {
-      this.rangeEndRef && this.rangeEndRef.clear();
-      this.rangeStartRef && this.rangeStartRef.clear();
       this.imagePickerRef && this.imagePickerRef.clear();
       this.setState({
         rangeStartVal:'',
@@ -74,11 +76,11 @@ class PublicContent extends Component{
 
   onSubmit(){
     if(!this.state.rangeStartMinuteVal){
-      Taro.showToast({title:'请选择公出开始时间',icon:'none'})
+      Taro.showToast({title:'请选择公出时间',icon:'none'})
       return ;
     }
     if(!this.state.rangeEndMinuteVal){
-      Taro.showToast({title:'请选择公出结束时间',icon:'none'})
+      Taro.showToast({title:'请选择公出时间',icon:'none'})
       return ;
     }
     if(!(this.props.selectArrderLocation.longitude && this.props.selectArrderLocation.latitude)){
@@ -169,6 +171,41 @@ class PublicContent extends Component{
     })
   }
 
+  onPickerHide(){
+    this.setState({
+      isPickerRender: false,
+    });
+  }
+
+  onSetPickerTime(val){
+    let data = val.detail;
+    this.setState({
+      rangeStartMinuteVal: data.selectStartTime,
+      rangeEndMinuteVal: data.selectEndTime
+    });
+
+    let arr = [];
+    if(data.startTime && data.endTime){
+      let a = dayjs(data.startTime);
+      let b = dayjs(data.endTime);
+      let num = b.diff(a, 'day')+1;
+      let strAdd = data.startTime;
+      for(let i = 0;i<num;i++){
+        let time = dayjs(strAdd).add(i, 'days').format('YYYY-MM-DD');
+        arr.push({value:time});
+      }
+    }
+    this.setState({
+      rangeEndVal:dayjs(data.endTime).format('YYYY-MM-DD'),
+      rangeStartVal:dayjs(data.startTime).format('YYYY-MM-DD'),
+      validDates:arr,
+    },()=>{
+      let a1 = dayjs(dayjs(data.endTime).format('YYYY-MM-DD HH:mm:ss'));
+      let b1 = dayjs(dayjs(data.startTime).format('YYYY-MM-DD  HH:mm:ss'));
+      this.getNumHourse(b1,a1)
+    })
+  }
+
   render() {
     return (
       <View className='publicContent'>
@@ -187,11 +224,11 @@ class PublicContent extends Component{
                 let obj = Taro.getStorageSync('userInfor');
                 obj.workTimeInfor = this.state.workTypeList[e.detail.value];
                 Taro.setStorageSync('userInfor', obj);
-                this.rangeEndRef.clear();
-                this.rangeStartRef.clear();
                 this.setState({
                   rangeStartVal:'',
                   rangeStartMinuteVal: '',
+                  rangeEndMinuteVal:'',
+                  rangeEndVal:'',
                   validDates:[],
                   totalDuration:0
                 })
@@ -205,107 +242,51 @@ class PublicContent extends Component{
           </View>
         </View>
         <View className='formItem'>
-          <View className='formName'>公出开始时间:</View>
+          <View className='formName'>公出时间:</View>
           <View className='formValue'>
-            <DateTimePicker ref={ref=>this.rangeStartRef = ref} onOk={(current)=>{
-              let arr = [];
-              if(this.state.rangeEndVal){
-                if(dayjs(current.current).isAfter(dayjs(this.state.rangeEndMinuteVal))){
-                  Taro.showToast({title:'开始时间不能在结束时间之后',icon:'none'})
-                  this.rangeStartRef.clear();
-                  this.setState({
-                    rangeStartVal:'',
-                    rangeStartMinuteVal: '',
-                    validDates:[],
-                    totalDuration:0
-                  })
-                  return;
-                }
-              }
-              if(this.state.rangeEndVal){
-                let str = dayjs(current.current).format('YYYY-MM-DD');
-                arr.push({value:str});
-                let a = dayjs(this.state.rangeEndVal);
-                let b = dayjs(str);
-                let num = a.diff(b, 'days');
-                let strAdd = str;
-                for(let i = 0;i<num;i++){
-                  let time = dayjs(strAdd).add(1, 'days').format('YYYY-MM-DD');
-                  strAdd = time
-                  arr.push({value:time});
-                }
-              }
+            <View className='time' onClick={()=>{
               this.setState({
-                rangeStartVal:dayjs(current.current).format('YYYY-MM-DD'),
-                rangeStartMinuteVal: dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'),
-                validDates:arr
-              },()=>{
-                if(this.state.rangeEndVal){
-                  let a1 = dayjs(dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'));
-                  let b1 = dayjs(dayjs(this.state.rangeEndMinuteVal).format('YYYY-MM-DD  HH:mm:ss'));
-                  this.getNumHourse(a1,b1)
-                }
-              })
-            }} onClear={()=>{
-              this.setState({
-                rangeStartVal:'',
-                rangeStartMinuteVal: '',
-                validDates:[],
-                totalDuration:0
+                isPickerRender:true
               })
-            }} initValue={dayjs()} wrap-class="my-class"  select-item-class="mySelector" />
-          </View>
-        </View>
-        <View className='formItem'>
-          <View className='formName'>公出结束时间:</View>
-          <View className='formValue'>
-            <DateTimePicker ref={ref=>this.rangeEndRef = ref} onOk={(current)=>{
-              let arr = [];
-              if(this.state.rangeStartVal){
-                if(dayjs(current.current).isBefore(dayjs(this.state.rangeStartMinuteVal))){
-                  Taro.showToast({title:'结束时间不能在开始时间之前',icon:'none'})
-                  this.rangeEndRef.clear();
-                  this.setState({
-                    rangeEndVal:'',
-                    rangeEndMinuteVal: '',
-                    validDates:[],
-                    totalDuration:0
-                  })
-                  return;
-                }
+            }}>
+              {
+                this.state.rangeStartMinuteVal && this.state.rangeEndMinuteVal ? <View className='timeContent'>
+                  <View>
+                    开始时间:{this.state.rangeStartMinuteVal}
+                  </View>
+                  <View>
+                    结束时间:{this.state.rangeEndMinuteVal}
+                  </View>
+                </View>: '请选择公出时间'
               }
-              if(this.state.rangeStartVal){
-                let str = dayjs(current.current).format('YYYY-MM-DD');
-                arr.push({value:this.state.rangeStartVal});
-                let a = dayjs(this.state.rangeStartVal);
-                let b = dayjs(str);
-                let num = b.diff(a, 'days');
-                let strAdd = this.state.rangeStartVal;
-                for(let i = 0;i<num;i++){
-                  let time = dayjs(strAdd).add(1, 'days').format('YYYY-MM-DD');
-                  strAdd = time
-                  arr.push({value:time});
-                }
-              }
-              this.setState({
-                rangeEndVal:dayjs(current.current).format('YYYY-MM-DD'),
-                rangeEndMinuteVal: dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'),
-                validDates:arr,
-              },()=>{
-                if(this.state.rangeStartVal){
-                  let a1 = dayjs(dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'));
-                  let b1 = dayjs(dayjs(this.state.rangeStartMinuteVal).format('YYYY-MM-DD  HH:mm:ss'));
-                  this.getNumHourse(b1,a1)
+            </View>
+            <timePicker
+              config={{
+                endDate: true,
+                column: "minute",
+                dateLimit: false,
+                // initStartTime: "2019-01-01 12:32:44", //默认开始时间
+                // initEndTime: "2019-12-01 12:32:44",   //默认结束时间
+                limitStartTime: dayjs().subtract(3,'year').format('YYYY-MM-DD HH:mm:ss'),
+                limitEndTime: dayjs().add(3,'year').format('YYYY-MM-DD HH:mm:ss')
+              }}
+              isPartition
+              pickerShow={this.state.isPickerRender}
+              onconditionaljudgment={(v)=>{
+                if(!dayjs(v.detail.endTime).isAfter(dayjs())){
+                  Taro.showToast({
+                    title:'结束时间不能小于当前时间',
+                    icon:'none'
+                  })
+                  v.detail.setLv(false);
                 }
-              })
-            }} onClear={()=>{
-              this.setState({
-                rangeEndVal:'',
-                rangeEndMinuteVal: '',
-                validDates:[],
-                totalDuration:0
-              })
-            }} initValue={dayjs()} wrap-class="my-class"  select-item-class="mySelector" />
+              }}
+              onhidepicker={()=>{
+                this.onPickerHide()
+              }}
+              onsetpickertime={(v)=>{
+                this.onSetPickerTime(v)
+              }}/>
           </View>
         </View>
         <View className='formItem'>
@@ -384,7 +365,7 @@ class PublicContent extends Component{
           <View className='formName'>附件:</View>
           <View className='formValue' style={{paddingTop:'10px',textAlign:'left'}}>
             <ImagePicker
-              showAddBtn={true}
+              showAddBtn
               ref={ref => this.imagePickerRef = ref}
               url='/api/admin/release/upload'
               onChange={this.onChange}

+ 11 - 0
src/pages/applyDepart/publicContent.less

@@ -20,6 +20,17 @@
       flex-flow: row nowrap;
       align-items: center;
       justify-content: flex-end;
+      .time{
+        flex:1;
+        font-size: 30px;
+        color: #bfbdbd;
+        .timeContent{
+          display: flex;
+          flex-flow: column nowrap;
+          align-items: flex-end;
+          justify-content: center;
+        }
+      }
       .formValueText{
         display: block;
         width: 452px;

+ 3 - 0
src/pages/egressDetails/index.config.js

@@ -1,3 +1,6 @@
 export default {
   navigationBarTitleText: '详情',
+  usingComponents: {
+    timePicker: '../../components/common/timePicker/timePicker'
+  }
 }

+ 86 - 106
src/pages/egressDetails/publicContent.jsx

@@ -1,9 +1,8 @@
 import React,{Component} from 'react';
-import Taro,{getCurrentInstance } from '@tarojs/taro';
+import Taro from '@tarojs/taro';
 import {Text, View} from '@tarojs/components'
 import dayjs from 'dayjs';
 import './index.less';
-import DateTimePicker from '../../components/common/DateTimePicker';
 
 import ImagePicker from '../../components/common/imagePicker'
 import {resourceAddress} from '../../utils/config';
@@ -40,16 +39,20 @@ class PublicContent extends Component{
 
       workTypeList:[],
       workType:0,
+
+      isPickerRender:false,
     }
     this.onSubmit = this.onSubmit.bind(this);
     this.selectArrder = this.selectArrder.bind(this);
     this.onChange = this.onChange.bind(this);
     this.getWorkingHoursList = this.getWorkingHoursList.bind(this);
+
+    this.onPickerHide = this.onPickerHide.bind(this);
+    this.onSetPickerTime = this.onSetPickerTime.bind(this);
+    this.getNumHourse = this.getNumHourse.bind(this);
   }
 
   componentDidMount() {
-    this.rangeStartRef.setInitialState({current:this.props.dtails.releaseStarts})
-    this.rangeEndRef.setInitialState({current:this.props.dtails.releaseEnds});
     let arr = [];
     for(let i of this.props.dtails.annexUrl){
       arr.push(i.url.split(resourceAddress).join(""))
@@ -68,8 +71,6 @@ class PublicContent extends Component{
   }
 
   componentWillUnmount() {
-    this.rangeEndRef && this.rangeEndRef.clear();
-    this.rangeStartRef && this.rangeStartRef.clear();
     this.imagePickerRef && this.imagePickerRef.clear();
     this.setState({
       rangeStartVal:'',
@@ -115,11 +116,11 @@ class PublicContent extends Component{
 
   onSubmit(){
     if(!this.state.rangeStartMinuteVal){
-      Taro.showToast({title:'请选择公出开始时间',icon:'none'})
+      Taro.showToast({title:'请选择公出时间',icon:'none'})
       return ;
     }
     if(!this.state.rangeEndMinuteVal){
-      Taro.showToast({title:'请选择公出结束时间',icon:'none'})
+      Taro.showToast({title:'请选择公出时间',icon:'none'})
       return ;
     }
     if(!(this.props.locationInfor.longitude && this.props.locationInfor.latitude)){
@@ -200,6 +201,41 @@ class PublicContent extends Component{
     })
   }
 
+  onPickerHide(){
+    this.setState({
+      isPickerRender: false,
+    });
+  }
+
+  onSetPickerTime(val){
+    let data = val.detail;
+    this.setState({
+      rangeStartMinuteVal: data.selectStartTime,
+      rangeEndMinuteVal: data.selectEndTime
+    });
+
+    let arr = [];
+    if(data.startTime && data.endTime){
+      let a = dayjs(data.startTime);
+      let b = dayjs(data.endTime);
+      let num = b.diff(a, 'day')+1;
+      let strAdd = data.startTime;
+      for(let i = 0;i<num;i++){
+        let time = dayjs(strAdd).add(i, 'days').format('YYYY-MM-DD');
+        arr.push({value:time});
+      }
+    }
+    this.setState({
+      rangeEndVal:dayjs(data.endTime).format('YYYY-MM-DD'),
+      rangeStartVal:dayjs(data.startTime).format('YYYY-MM-DD'),
+      validDates:arr,
+    },()=>{
+      let a1 = dayjs(dayjs(data.endTime).format('YYYY-MM-DD HH:mm:ss'));
+      let b1 = dayjs(dayjs(data.startTime).format('YYYY-MM-DD  HH:mm:ss'));
+      this.getNumHourse(b1,a1)
+    })
+  }
+
   render() {
     const {dtails} = this.props;
     return (
@@ -219,11 +255,11 @@ class PublicContent extends Component{
                 let obj = Taro.getStorageSync('userInfor');
                 obj.workTimeInfor = this.state.workTypeList[e.detail.value];
                 Taro.setStorageSync('userInfor', obj);
-                this.rangeEndRef.clear();
-                this.rangeStartRef.clear();
                 this.setState({
                   rangeStartVal:'',
                   rangeStartMinuteVal: '',
+                  rangeEndMinuteVal:'',
+                  rangeEndVal:'',
                   validDates:[],
                   totalDuration:0
                 })
@@ -237,107 +273,51 @@ class PublicContent extends Component{
           </View>
         </View>
         <View className='formItem'>
-          <View className='formName'>公出开始时间:</View>
+          <View className='formName'>公出时间:</View>
           <View className='formValue'>
-            <DateTimePicker ref={ref=>this.rangeStartRef = ref} onOk={(current)=>{
-              let arr = [];
-              if(this.state.rangeEndVal){
-                if(dayjs(current.current).isAfter(dayjs(this.state.rangeEndMinuteVal))){
-                  Taro.showToast({title:'开始时间不能在结束时间之后',icon:'none'})
-                  this.rangeStartRef.clear();
-                  this.setState({
-                    rangeStartVal:'',
-                    rangeStartMinuteVal: '',
-                    validDates:[],
-                    totalDuration:0
-                  })
-                  return;
-                }
-              }
-              if(this.state.rangeEndVal){
-                let str = dayjs(current.current).format('YYYY-MM-DD');
-                arr.push({value:str});
-                let a = dayjs(this.state.rangeEndVal);
-                let b = dayjs(str);
-                let num = a.diff(b, 'days');
-                let strAdd = str;
-                for(let i = 0;i<num;i++){
-                  let time = dayjs(strAdd).add(1, 'days').format('YYYY-MM-DD');
-                  strAdd = time
-                  arr.push({value:time});
-                }
-              }
-              this.setState({
-                rangeStartVal:dayjs(current.current).format('YYYY-MM-DD'),
-                rangeStartMinuteVal: dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'),
-                validDates:arr
-              },()=>{
-                if(this.state.rangeEndVal){
-                  let a1 = dayjs(dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'));
-                  let b1 = dayjs(dayjs(this.state.rangeEndMinuteVal).format('YYYY-MM-DD  HH:mm:ss'));
-                  this.getNumHourse(a1,b1)
-                }
-              })
-            }} onClear={()=>{
+            <View className='time' onClick={()=>{
               this.setState({
-                rangeStartVal:'',
-                rangeStartMinuteVal: '',
-                validDates:[],
-                totalDuration:0
+                isPickerRender:true
               })
-            }} initValue={dayjs()} wrap-class="my-class"  select-item-class="mySelector" />
-          </View>
-        </View>
-        <View className='formItem'>
-          <View className='formName'>公出结束时间:</View>
-          <View className='formValue'>
-            <DateTimePicker ref={ref=>this.rangeEndRef = ref} onOk={(current)=>{
-              let arr = [];
-              if(this.state.rangeStartVal) {
-                if (dayjs(current.current).isBefore(dayjs(this.state.rangeStartMinuteVal))) {
-                  Taro.showToast({title: '结束时间不能在开始时间之前', icon: 'none'})
-                  this.rangeEndRef.clear();
-                  this.setState({
-                    rangeEndVal: '',
-                    rangeEndMinuteVal: '',
-                    validDates: [],
-                    totalDuration: 0
-                  })
-                  return;
-                }
+            }}>
+              {
+                this.state.rangeStartMinuteVal && this.state.rangeEndMinuteVal ? <View className='timeContent'>
+                  <View>
+                    开始时间:{this.state.rangeStartMinuteVal}
+                  </View>
+                  <View>
+                    结束时间:{this.state.rangeEndMinuteVal}
+                  </View>
+                </View>: '请选择公出时间'
               }
-              if(this.state.rangeStartVal){
-                let str = dayjs(current.current).format('YYYY-MM-DD');
-                arr.push({value:this.state.rangeStartVal});
-                let a = dayjs(this.state.rangeStartVal);
-                let b = dayjs(str);
-                let num = b.diff(a, 'days');
-                let strAdd = this.state.rangeStartVal;
-                for(let i = 0;i<num;i++){
-                  let time = dayjs(strAdd).add(1, 'days').format('YYYY-MM-DD');
-                  strAdd = time
-                  arr.push({value:time});
-                }
-              }
-              this.setState({
-                rangeEndVal:dayjs(current.current).format('YYYY-MM-DD'),
-                rangeEndMinuteVal: dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'),
-                validDates:arr,
-              },()=>{
-                if(this.state.rangeStartVal){
-                  let a1 = dayjs(dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'));
-                  let b1 = dayjs(dayjs(this.state.rangeStartMinuteVal).format('YYYY-MM-DD  HH:mm:ss'));
-                  this.getNumHourse(b1,a1)
+            </View>
+            <timePicker
+              config={{
+                endDate: true,
+                column: "minute",
+                dateLimit: false,
+                initStartTime: this.state.rangeStartMinuteVal, //默认开始时间
+                initEndTime: this.state.rangeEndMinuteVal,   //默认结束时间
+                limitStartTime: dayjs().subtract(3,'year').format('YYYY-MM-DD HH:mm:ss'),
+                limitEndTime: dayjs().add(3,'year').format('YYYY-MM-DD HH:mm:ss')
+              }}
+              isPartition
+              pickerShow={this.state.isPickerRender}
+              onconditionaljudgment={(v)=>{
+                if(!dayjs(v.detail.endTime).isAfter(dayjs())){
+                  Taro.showToast({
+                    title:'结束时间不能小于当前时间',
+                    icon:'none'
+                  })
+                  v.detail.setLv(false);
                 }
-              })
-            }} onClear={()=>{
-              this.setState({
-                rangeEndVal:'',
-                rangeEndMinuteVal: '',
-                validDates:[],
-                totalDuration:0
-              })
-            }} initValue={dayjs()} wrap-class="my-class"  select-item-class="mySelector" />
+              }}
+              onhidepicker={()=>{
+                this.onPickerHide()
+              }}
+              onsetpickertime={(v)=>{
+                this.onSetPickerTime(v)
+              }}/>
           </View>
         </View>
         <View className='formItem'>

+ 0 - 6
src/pages/examine/index.jsx

@@ -6,12 +6,8 @@ import {
   AtSearchBar,
   AtTabs,
   AtTabsPane,
-  AtActionSheet,
-  AtActionSheetItem,
-  AtIcon,
   AtList,
   AtListItem,
-  AtButton
 } from 'taro-ui';
 import {clockState} from '../../utils/tools/config';
 
@@ -25,8 +21,6 @@ import "taro-ui/dist/style/components/list.scss";
 
 import MyList from './myList';
 import MessageNoticebar from "../../components/common/messageNoticebar";
-import dayjs from "dayjs";
-import DateTimePicker from "../../components/common/DateTimePicker";
 
 class Examine extends Component {
 

+ 3 - 3
src/pages/punchClock/punchClocks.jsx

@@ -429,7 +429,7 @@ class PunchClocks extends Component {
             <View className='content'>
               <View className='punchClockContent'  onClick={this.publicReleaseClockIn} style={{
                 boxShadow:  '1px 1px 15px 1px #acb8ad',
-                background: '#acb8ad',
+                background: '#828e83',
                 marginTop: '85px',
               }}>
                 <View className='punchClockTitle'>公出打卡</View>
@@ -507,14 +507,14 @@ class PunchClocks extends Component {
                     && this.state.distance <=this.wxConfig.clockInRange && this.state.distance >= 0 &&
                     !(dayjs().isBefore(this.state.dtails.releaseStarts) || dayjs().isAfter(this.state.dtails.releaseEnds)) &&
                     dtails.status !== 3
-                      ? (dtails.clockIn === 1 ? '1px 1px 15px 1px #3f82e8' : '1px 1px 15px 1px #659268') : '1px 1px 15px 1px #acb8ad',
+                      ? (dtails.clockIn === 1 ? '1px 1px 15px 1px #3f82e8' : '1px 1px 15px 1px #659268') : '1px 1px 15px 1px #828e83',
                   background: (!isNaN(parseInt(this.state.distance)))
                   &&
                   this.state.distance <=this.wxConfig.clockInRange &&
                   this.state.distance >= 0 &&
                   !(dayjs().isBefore(this.state.dtails.releaseStarts) || dayjs().isAfter(this.state.dtails.releaseEnds))&&
                   dtails.status !== 3
-                    ? (dtails.clockIn === 1 ? '#3f82e8' : '#72cb78') : '#acb8ad'
+                    ? (dtails.clockIn === 1 ? '#3f82e8' : '#72cb78') : '#828e83'
                 }}>
                   <View className='punchClockTitle'>
                     {

+ 2 - 2
src/utils/servers/baseUrl.js

@@ -2,10 +2,10 @@ const getBaseUrl = (url) => {
   let BASE_URL = '';
   if (process.env.NODE_ENV === 'development') {
     //开发环境 - 根据请求不同返回不同的BASE_URL
-    BASE_URL = 'https://bm.jishutao.com'
+    BASE_URL = 'https://uat.jishutao.com'
   } else {
     // 生产环境
-    BASE_URL = 'https://bm.jishutao.com'
+    BASE_URL = 'https://uat.jishutao.com'
   }
   return BASE_URL
 }

+ 16 - 0
src/utils/tools/index.js

@@ -102,3 +102,19 @@ export const getNumHourse = (startTimeValue,endTimeValue,days) =>{
     return a+b+c;
   }
 }
+
+function addZero(num) {
+  return Number(num) < 10 ? `0${num}` : num;
+}
+
+export const formatDate = (year, month, day, hour, minute) => {
+  const newmonth = addZero(month);
+  const newday = addZero(day);
+  const newhour = addZero(hour);
+  const newminute = addZero(minute);
+
+  return year + '-' + newmonth + '-' + newday + ' ' + newhour + ":" + newminute;
+};
+
+
+