|
@@ -1,24 +1,25 @@
|
|
|
import { PickerView, PickerViewColumn, View, Text } from "@tarojs/components";
|
|
import { PickerView, PickerViewColumn, View, Text } from "@tarojs/components";
|
|
|
-import { useEffect, useState } from "react";
|
|
|
|
|
-
|
|
|
|
|
-export default function Component(props: { limit: number, onChange: Function, onCancel: Function,isRealTime?:boolean,limitDay?:number,time?:number }) {
|
|
|
|
|
|
|
+import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
|
|
|
+import './LimitPickers.scss'
|
|
|
|
|
+// export default function Component(props: { limit: number, onChange: Function, onCancel: Function,isRealTime?:boolean,limitDay?:number,time?:number,ref?:any }) {
|
|
|
|
|
+const Component = forwardRef((props: { limit: number, onChange: Function, onCancel: Function, isRealTime?: boolean, limitDay?: number, time?: number }, ref) => {
|
|
|
const days: string[] = [];
|
|
const days: string[] = [];
|
|
|
const today = new Date();
|
|
const today = new Date();
|
|
|
- const [values, setValues] = useState([props.limitDay?props.limitDay-1:6, today.getHours(), today.getMinutes()])
|
|
|
|
|
|
|
+ const [values, setValues] = useState([props.limitDay ? props.limitDay - 1 : 6, today.getHours(), today.getMinutes()])
|
|
|
|
|
|
|
|
|
|
|
|
|
- useEffect(()=>{
|
|
|
|
|
- if(props.time){
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (props.time) {
|
|
|
var date = new Date(props.time)
|
|
var date = new Date(props.time)
|
|
|
- setValues([(props.limitDay?props.limitDay-1:6) - getDaysDiff(date), date.getHours(), date.getMinutes()])
|
|
|
|
|
|
|
+ setValues([(props.limitDay ? props.limitDay - 1 : 6) - getDaysDiff(date), date.getHours(), date.getMinutes()])
|
|
|
}
|
|
}
|
|
|
- },[])
|
|
|
|
|
|
|
+ }, [])
|
|
|
// useEffect(() => {
|
|
// useEffect(() => {
|
|
|
// setValues([6, today.getHours(), today.getMinutes()])
|
|
// setValues([6, today.getHours(), today.getMinutes()])
|
|
|
// }, [props.limit])
|
|
// }, [props.limit])
|
|
|
|
|
|
|
|
|
|
|
|
|
- for (let i = props.limitDay?props.limitDay-1:7; i >= 0; i--) {
|
|
|
|
|
|
|
+ for (let i = props.limitDay ? props.limitDay - 1 : 7; i >= 0; i--) {
|
|
|
const date = new Date();
|
|
const date = new Date();
|
|
|
date.setDate(today.getDate() - i);
|
|
date.setDate(today.getDate() - i);
|
|
|
|
|
|
|
@@ -75,7 +76,7 @@ export default function Component(props: { limit: number, onChange: Function, on
|
|
|
var list = e.detail.value
|
|
var list = e.detail.value
|
|
|
|
|
|
|
|
const date = new Date();
|
|
const date = new Date();
|
|
|
- date.setDate(today.getDate() - ((props.limitDay?props.limitDay-1:6) - list[0]));
|
|
|
|
|
|
|
+ date.setDate(today.getDate() - ((props.limitDay ? props.limitDay - 1 : 6) - list[0]));
|
|
|
const year = date.getFullYear();
|
|
const year = date.getFullYear();
|
|
|
const month = date.getMonth() + 1;
|
|
const month = date.getMonth() + 1;
|
|
|
const day = date.getDate();
|
|
const day = date.getDate();
|
|
@@ -96,7 +97,7 @@ export default function Component(props: { limit: number, onChange: Function, on
|
|
|
// const time = `${year}-${expandZero(month)}-${expandZero(day)}T${expandZero(hours[list[1]])}:${expandZero(minutes[list[2]])}:59`;
|
|
// const time = `${year}-${expandZero(month)}-${expandZero(day)}T${expandZero(hours[list[1]])}:${expandZero(minutes[list[2]])}:59`;
|
|
|
if (getTimestamp(time) < props.limit) {
|
|
if (getTimestamp(time) < props.limit) {
|
|
|
// console.log(6 - getDaysDiff(limitDate))
|
|
// console.log(6 - getDaysDiff(limitDate))
|
|
|
- setValues([(props.limitDay?props.limitDay-1:6) - getDaysDiff(limitDate), limitDate.getHours(), limitDate.getMinutes()])
|
|
|
|
|
|
|
+ setValues([(props.limitDay ? props.limitDay - 1 : 6) - getDaysDiff(limitDate), limitDate.getHours(), limitDate.getMinutes()])
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -113,23 +114,43 @@ export default function Component(props: { limit: number, onChange: Function, on
|
|
|
props.onCancel()
|
|
props.onCancel()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function confirm() {
|
|
|
|
|
|
|
+ // function confirm() {
|
|
|
|
|
+ // var date = new Date();
|
|
|
|
|
+ // if (!props.isRealTime) {
|
|
|
|
|
+ // date = new Date(global.set_time);
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // date.setDate(today.getDate() - ((props.limitDay ? props.limitDay - 1 : 6) - values[0]));
|
|
|
|
|
+ // date.setHours(values[1])
|
|
|
|
|
+ // date.setMinutes(values[2])
|
|
|
|
|
+ // props.onChange(date.getTime())
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ function getConfirmData(){
|
|
|
var date = new Date();
|
|
var date = new Date();
|
|
|
if (!props.isRealTime) {
|
|
if (!props.isRealTime) {
|
|
|
date = new Date(global.set_time);
|
|
date = new Date(global.set_time);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- date.setDate(today.getDate() - ((props.limitDay?props.limitDay-1:6) - values[0]));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ date.setDate(today.getDate() - ((props.limitDay ? props.limitDay - 1 : 6) - values[0]));
|
|
|
date.setHours(values[1])
|
|
date.setHours(values[1])
|
|
|
date.setMinutes(values[2])
|
|
date.setMinutes(values[2])
|
|
|
- props.onChange(date.getTime())
|
|
|
|
|
|
|
+ return date.getTime()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return <View style={{ backgroundColor: '#fff', color: '#000', position: 'relative' }}>
|
|
|
|
|
|
|
+ useImperativeHandle(ref, () => ({
|
|
|
|
|
+ getConfirmData:getConfirmData
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return <View style={{ backgroundColor: 'transparent', position: 'relative' }}>
|
|
|
<PickerView value={values}
|
|
<PickerView value={values}
|
|
|
|
|
+ className="picker"
|
|
|
|
|
+ maskClass="picker-mask"
|
|
|
onChange={onPickerChange}
|
|
onChange={onPickerChange}
|
|
|
immediateChange={true}
|
|
immediateChange={true}
|
|
|
- indicatorStyle='height: 50px;' style='width: 100%; height: 300px;'>
|
|
|
|
|
|
|
+ indicatorStyle='height: 50px;'>
|
|
|
<PickerViewColumn style='flex:0 0 45%'>
|
|
<PickerViewColumn style='flex:0 0 45%'>
|
|
|
{days.map(item => {
|
|
{days.map(item => {
|
|
|
return (
|
|
return (
|
|
@@ -159,10 +180,7 @@ export default function Component(props: { limit: number, onChange: Function, on
|
|
|
}}>
|
|
}}>
|
|
|
<Text style={{ color: '#000', fontSize: 16, fontWeight: 'bold' }}>:</Text>
|
|
<Text style={{ color: '#000', fontSize: 16, fontWeight: 'bold' }}>:</Text>
|
|
|
</View>
|
|
</View>
|
|
|
-
|
|
|
|
|
- <View style={{ marginBottom: 20,marginTop:20, display: 'flex', flexDirection: 'row', width: '100%' }}>
|
|
|
|
|
- <Text style={{ flex: 1, textAlign: 'center',height:50 }} onClick={cancel}>取消</Text>
|
|
|
|
|
- <Text style={{ flex: 1, textAlign: 'center',height:50 }} onClick={confirm}>确认</Text>
|
|
|
|
|
- </View>
|
|
|
|
|
</View>
|
|
</View>
|
|
|
-}
|
|
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+export default Component;
|