|
|
@@ -10,6 +10,8 @@ import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
import Modal from "@/components/layout/Modal.weapp";
|
|
|
import TimePicker from "@/features/common/TimePicker";
|
|
|
import showAlert from "@/components/basic/Alert";
|
|
|
+import { IconAdd } from "@/components/basic/Icons";
|
|
|
+import AddLabel from "../components/add_label";
|
|
|
|
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
|
@@ -35,11 +37,13 @@ export default function Schedules() {
|
|
|
}
|
|
|
const [list, setList] = useState<any>([])
|
|
|
const [labels, setLabels] = useState<any>([])
|
|
|
+ const [showAutoSave, setShowAutoSave] = useState(false)
|
|
|
const [errors, setErrors] = useState<any>(router.params.errors ? JSON.parse(router.params.errors) : [])
|
|
|
const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
const health = useSelector((state: any) => state.health);
|
|
|
const [selItem, setSelItem] = useState<any>(null)
|
|
|
const [selIndex, setSelIndex] = useState(-1)
|
|
|
+ const [showModal, setShowModal] = useState(false)
|
|
|
const selMode = router.params.mode;
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -56,6 +60,10 @@ export default function Schedules() {
|
|
|
schedules()
|
|
|
}
|
|
|
|
|
|
+ global.tempRefresh = () => {
|
|
|
+ schedules()
|
|
|
+ }
|
|
|
+
|
|
|
function schedules() {
|
|
|
let windows = ''
|
|
|
switch (selMode) {
|
|
|
@@ -139,6 +147,7 @@ export default function Schedules() {
|
|
|
|
|
|
|
|
|
if ((res as any).result) {
|
|
|
+ setShowAutoSave(true)
|
|
|
setErrors([])
|
|
|
setList((res as any).schedules)
|
|
|
global.refreshWindow()
|
|
|
@@ -150,43 +159,104 @@ export default function Schedules() {
|
|
|
// }
|
|
|
}
|
|
|
else {
|
|
|
- var array = (res as any).conflict_windows;
|
|
|
- var showMore = false;
|
|
|
- if (array.length > 2) {
|
|
|
- showMore = true;
|
|
|
- }
|
|
|
- else if (array.length == 1) {
|
|
|
- showMore = false;
|
|
|
- }
|
|
|
- else {
|
|
|
- // 判断是否同时存在 FAST 和 EAT
|
|
|
- const containsFastAndEat = array.includes('FAST') && array.includes('EAT');
|
|
|
+ setShowAutoSave(false)
|
|
|
+ setList((res as any).schedules)
|
|
|
+ setErrors((res as any).error_messages ? (res as any).error_messages : [])
|
|
|
+ // var array = (res as any).conflict_windows;
|
|
|
+ // var showMore = false;
|
|
|
+ // if (array.length > 2) {
|
|
|
+ // showMore = true;
|
|
|
+ // }
|
|
|
+ // else if (array.length == 1) {
|
|
|
+ // showMore = false;
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // // 判断是否同时存在 FAST 和 EAT
|
|
|
+ // const containsFastAndEat = array.includes('FAST') && array.includes('EAT');
|
|
|
|
|
|
- // 判断是否同时存在 SLEEP 和 ACTIVE
|
|
|
- const containsSleepAndActive = array.includes('SLEEP') && array.includes('ACTIVE');
|
|
|
+ // // 判断是否同时存在 SLEEP 和 ACTIVE
|
|
|
+ // const containsSleepAndActive = array.includes('SLEEP') && array.includes('ACTIVE');
|
|
|
|
|
|
- // 最终结果
|
|
|
- const result = containsFastAndEat || containsSleepAndActive;
|
|
|
- showMore = !result;
|
|
|
- }
|
|
|
- if (selMode != '' && showMore) {
|
|
|
- showAlert({
|
|
|
- title: '弹窗标题',
|
|
|
- content: '冲突描述',
|
|
|
- showCancel: false,
|
|
|
- confirm: () => {
|
|
|
- jumpPage(`./schedules?mode=&schedules=${JSON.stringify((res as any).schedules)}&errors=${JSON.stringify((res as any).error_messages)}`)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- else {
|
|
|
- setList((res as any).schedules)
|
|
|
- setErrors((res as any).error_messages ? (res as any).error_messages : [])
|
|
|
- }
|
|
|
+ // // 最终结果
|
|
|
+ // const result = containsFastAndEat || containsSleepAndActive;
|
|
|
+ // showMore = !result;
|
|
|
+ // }
|
|
|
+ // if (selMode != '' && showMore) {
|
|
|
+ // showAlert({
|
|
|
+ // title: '弹窗标题',
|
|
|
+ // content: '冲突描述',
|
|
|
+ // showCancel: false,
|
|
|
+ // confirm: () => {
|
|
|
+ // jumpPage(`./schedules?mode=&schedules=${JSON.stringify((res as any).schedules)}&errors=${JSON.stringify((res as any).error_messages)}`)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // setList((res as any).schedules)
|
|
|
+ // setErrors((res as any).error_messages ? (res as any).error_messages : [])
|
|
|
+ // }
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ function add() {
|
|
|
+ var isMax = false
|
|
|
+ if (selMode == 'FAST' || selMode == 'EAT') {
|
|
|
+ const countFastWindows = list.filter(item => item.window === 'EAT').length;
|
|
|
+ if (countFastWindows >= 4) {
|
|
|
+ isMax = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ const countFastWindows = list.filter(item => item.window === 'ACTIVE').length;
|
|
|
+ if (countFastWindows >= 4) {
|
|
|
+ isMax = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isMax) {
|
|
|
+ showAlert({
|
|
|
+ title: '会员',
|
|
|
+ content: '会员desc',
|
|
|
+ showCancel: true,
|
|
|
+ confirm: () => {
|
|
|
+ jumpPage('/pages/store/product_list', 'ProductList', navigation)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ setShowModal(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ function getAddColor() {
|
|
|
+ if (selMode == 'FAST' || selMode == 'EAT') {
|
|
|
+ return getThemeColor('EAT')
|
|
|
+ }
|
|
|
+ return getThemeColor('ACTIVE')
|
|
|
+ }
|
|
|
+
|
|
|
+ function tapEdit() {
|
|
|
+ jumpPage('./schedules_edit?mode=' + selMode)
|
|
|
+ }
|
|
|
+
|
|
|
+ function itemStyle(obj) {
|
|
|
+ if (obj.is_conflict) {
|
|
|
+ return {
|
|
|
+ backgroundColor: '#FF00001A',
|
|
|
+ color: '#FF0000'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (errors.length > 0) {
|
|
|
+ return {
|
|
|
+ backgroundColor: '#B2B2B21A',
|
|
|
+ color: '#000'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ backgroundColor: obj.window == selMode ? getThemeColor(selMode) + '1A' : '#B2B2B21A',
|
|
|
+ color: obj.window == selMode ? getThemeColor(selMode) : '#000'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
return <View>
|
|
|
<View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
@@ -196,9 +266,9 @@ export default function Schedules() {
|
|
|
return <View key={index} className='error_tip'>{item}</View>
|
|
|
})
|
|
|
}
|
|
|
- {/* {
|
|
|
- errors.length == 0 && <View className='success_tip'>时间冲突已解决,并保存</View>
|
|
|
- } */}
|
|
|
+ {
|
|
|
+ showAutoSave && <View className='success_tip'>已自动保存</View>
|
|
|
+ }
|
|
|
<View style={{ backgroundColor: '#fff' }}>
|
|
|
{
|
|
|
list.map((obj, i) => {
|
|
|
@@ -217,15 +287,15 @@ export default function Schedules() {
|
|
|
{
|
|
|
obj.is_conflict && <Text className="conflict_tip">时间冲突,请调整</Text>
|
|
|
}
|
|
|
+ {
|
|
|
+ !obj.is_all_day && !obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
|
|
|
+ }
|
|
|
{
|
|
|
!obj.is_all_day && <View className='edit_item_time' onClick={() => {
|
|
|
setSelIndex(i)
|
|
|
setSelItem(obj)
|
|
|
setShowTimePicker(true)
|
|
|
- }} style={{
|
|
|
- backgroundColor: obj.window == selMode ? getThemeColor(selMode) + '1A' : '#B2B2B21A',
|
|
|
- color: obj.window == selMode ? getThemeColor(selMode) : '#000'
|
|
|
- }}>{obj.time}</View>
|
|
|
+ }} style={itemStyle(obj)}>{obj.time}</View>
|
|
|
}
|
|
|
|
|
|
{
|
|
|
@@ -236,11 +306,26 @@ export default function Schedules() {
|
|
|
})
|
|
|
}
|
|
|
</View>
|
|
|
+
|
|
|
+ {
|
|
|
+ selMode != '' && selMode != 'DAY' && selMode != 'NIGHT' && <View className='item_add'
|
|
|
+ style={{ marginTop: 20 }}
|
|
|
+ onClick={() => add()}>
|
|
|
+ <IconAdd color={getAddColor()} width={rpxToPx(34)} />
|
|
|
+ <View className='toolbar_btn' style={{ color: getAddColor() }} >添加</View>
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
{
|
|
|
selMode != '' && <Text onClick={() => {
|
|
|
jumpPage('/_health/pages/schedules?mode=')
|
|
|
}}>查看全部</Text>
|
|
|
}
|
|
|
+
|
|
|
+ <View className="edit_footer_btn" style={{ color: getThemeColor(health.mode), backgroundColor: getThemeColor(health.mode) + '33' }} onClick={tapEdit}>批量编辑</View>
|
|
|
{
|
|
|
showTimePicker && <Modal
|
|
|
testInfo={null}
|
|
|
@@ -253,6 +338,16 @@ export default function Schedules() {
|
|
|
}
|
|
|
</Modal>
|
|
|
}
|
|
|
+
|
|
|
+ {
|
|
|
+ showModal && <Modal testInfo={null}
|
|
|
+ dismiss={() => {
|
|
|
+ setShowModal(false)
|
|
|
+ }}
|
|
|
+ confirm={() => { }}>
|
|
|
+ <AddLabel labels={labels} disMiss={() => setShowModal(false)} />
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
</View>
|
|
|
</View>
|
|
|
}
|