Pārlūkot izejas kodu

时间添加时分秒

Luolei 6 gadi atpakaļ
vecāks
revīzija
322bcfb47e

+ 15 - 3
src/components/AddInspect/SlideSelect/index.jsx

@@ -10,10 +10,19 @@ import close from '../img/close.png';
 class SlideSelect extends Component {
   constructor(props) {
     super(props);
+    const date = new Date();
     this.state = {
       show:false,
       activeInd:false,
-      activeName:''
+      activeName:'',
+      timeLis: {
+        year: date.getFullYear(),
+        month: date.getMonth() + 1,
+        day: date.getDate(),
+        hour: '00',
+        minute: '00',
+        second: '00'
+      },
     };
     this.toTime = this.toTime.bind(this)
     this.handleSlide = this.handleSlide.bind(this)
@@ -61,9 +70,12 @@ class SlideSelect extends Component {
       activeName:''
     })
   }
+  timeSure(date){
+    console.log(date)
+  }
   render() {
     const {getInfomation,handleConfirm,changeActivePart,handleDelClick,getItemList,date,item,idx,handleFillShow,showDetails,handleLabelSub,showFill,changeShowFill,handlePush,dateTime,currentIdx,currentData,fillActive,handleShowDate,handleChangeDate,showToast} = this.props;
-    const {show,activeInd,activeName} = this.state;
+    const {show,activeInd,activeName,timeLis} = this.state;
     let numPlus = 0,numPlus1 = 0;
     return (
       <li key={item.questionId} className={styles.slideLi}> 
@@ -171,7 +183,7 @@ class SlideSelect extends Component {
                             </p>
                             <div style={{display:date?"block":"none",position:"relative"}}>
                                 {/* 日期组件 */}
-                                <Calendar isShow={true} handleChange={handleChangeDate}></Calendar>
+                                <Calendar timeLis={timeLis} isShow={true} timeSure={this.timeSure} needTime={true} sure={true} handleChange={handleChangeDate}></Calendar>
                             </div>
                         </div>
                             {/* 填写单内容显示 */}

+ 1 - 11
src/components/AddInspect/index.jsx

@@ -30,7 +30,6 @@ class Inspect extends React.Component {
     }
     this.handleChangeDate = this.handleChangeDate.bind(this)
     this.handleShowDate = this.handleShowDate.bind(this)
-    this.getCurrentDate = this.getCurrentDate.bind(this)
     this.getItemList = this.getItemList.bind(this)
     this.getSearchList = this.getSearchList.bind(this)
     this.getCommonList = this.getCommonList.bind(this)
@@ -124,7 +123,7 @@ class Inspect extends React.Component {
   handleChangeDate(info) {
     let date = info.year+'-'+info.month.toString().padStart(2,'0')+'-'+info.day.toString().padStart(2,'0')
     // let date = info.year+'-'+info.month.toString().padStart(2,'0')+'-'+info.day.toString().padStart(2,'0')+' '+h.toString().padStart(2,'0')+m.toString().padStart(2,'0')+s.toString().padStart(2,'0');
-    this.setState({ dateTime: date, date: false })
+    // this.setState({ dateTime: date, date: false })
   }
   handleSearchShow(e) {
     let tmpShow = this.state.show;
@@ -147,15 +146,6 @@ class Inspect extends React.Component {
       date: !this.state.date
     })
   }
-  getCurrentDate() {
-    let myDate = new Date();
-    let year = myDate.getFullYear();       //获取完整的年份(4位,1970-????)
-    let mon = myDate.getMonth() - 0 + 1;       //获取当前月份(0-11,0代表1月)
-    let day = myDate.getDate();            //获取当前日(1-31)
-    let date = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day);
-    this.setState({ dateTime: date })
-    return date;
-  }
   changeActivePart(idx, val, clear) {
     let nums = this.state.num;
     let fillActive;

+ 0 - 1
src/store/reducers/inspect.js

@@ -51,7 +51,6 @@ export default (state = initSearchList, action) => {
           lisExcelRes:[],
           messages:[]
         }
-
         for(let i = 0;i < tmpGroup.length;i++){
           let tmpObj = {//excelDataLis.lisExcelRes[0]
             menus:'',

+ 2 - 1
src/utils/tools.js

@@ -875,8 +875,9 @@ function dateParser(timestamp,link = '-'){
   let date = time.getDate();
   let hour = time.getHours().toString().padStart(2,'0');
   let minute = time.getMinutes().toString().padStart(2,'0');
+  let second = time.getSeconds().toString().padStart(2,'0');
   // let result = year+link+month+link+date;
-  let result = year+link+(month<10?"0"+month:month)+link+(date<10?"0"+date:date)+' '+hour+':'+minute;
+  let result = year+link+(month<10?"0"+month:month)+link+(date<10?"0"+date:date)+' '+hour+':'+minute+':'+second;
   return result;
 }