import { View, Text, Image } from "@tarojs/components"; import './guide.scss' import '@/_health/pages/schedules.scss' import NewHeader, { NewHeaderType } from "../components/new_header"; import { useEffect, useState } from "react"; import { createSchedule, delSchedule, getLabelsEvent, getSchedules } from "@/services/health"; import { setFooter, setSchedules } from "@/store/health"; import { useDispatch, useSelector } from "react-redux"; import Card from "../components/card"; import { rpxToPx } from "@/utils/tools"; import { getScenario, getThemeColor } from "@/features/health/hooks/health_hooks"; import Modal from "@/components/layout/Modal.weapp"; import TimePicker from "@/features/common/TimePicker"; import NewButton, { NewButtonType } from "../base/new_button"; import { MainColorType } from "@/context/themes/color"; import { jumpPage } from "@/features/trackTimeDuration/hooks/Common"; import { IconAdd } from "@/components/basic/Icons"; import AddLabel from "../components/add_label"; import ScheduleItem from "../components/schedule_item"; import { useTranslation } from "react-i18next"; import showAlert from "@/components/basic/Alert"; import CellFooter, { CellFooterType } from "../base/cell_footer"; import CellFooterText from "../base/cell_footer_text"; import StatusIndicator, { StatusType } from "../base/status_indicator"; import Taro from "@tarojs/taro"; let useRoute; let useNavigation; let scenario = ''; if (process.env.TARO_ENV == 'rn') { useRoute = require("@react-navigation/native").useRoute useNavigation = require("@react-navigation/native").useNavigation } export default function GuideEat() { const systemInfo: any = Taro.getWindowInfo(); const navigationBarHeight = systemInfo.statusBarHeight + 44; const user = useSelector((state: any) => state.user); const health = useSelector((state: any) => state.health); const [list, setList] = useState(health.schedules) const [errors, setErrors] = useState([]) const [highlight, setHighlight] = useState(true) const [showModal, setShowModal] = useState(false) const [labels, setLabels] = useState([]) const [posting, setPosting] = useState(false) const { t } = useTranslation() let navigation, showActionSheetWithOptions; let router if (useNavigation) { navigation = useNavigation() } const dispatch = useDispatch() const selMode = 'EAT' useEffect(() => { getLabelsEvent({ window: 'EAT' }).then(res => { setLabels((res as any).labels) }) setTimeout(() => { setHighlight(false) }, 2000) }, []) useEffect(() => { var temps: any = [] list.map(item => { if (item.id) { var isFind = false health.schedules.map(obj => { if (obj.id == item.id) { isFind = true } }) if (!isFind) { temps.push(item) } } }) var array = JSON.parse(JSON.stringify(list)) var filterArray = array.filter(item => !temps.some(itemA => itemA.id == item.id)) setList(filterArray) }, [health.schedules]) function check(array, tapDone = false) { if (tapDone) { if (posting) return setPosting(true) } createSchedule({ schedules: array, only_check: true, return_all: true, op_page: 'SCHEDULE_WALKTHROUGH_3', sort_by: 'EVENT' }).then(res => { if ((res as any).result) { dispatch(setSchedules((res as any).schedules)) dispatch(setFooter((res as any).footer)) setList((res as any).schedules) setErrors([]) if (tapDone) { jumpPage('./guide_active') } } else { setList((res as any).schedules) dispatch(setFooter((res as any).footer)) setErrors((res as any).error_messages ? (res as any).error_messages : []) } setPosting(false) }).catch(e => { setPosting(false) }) } function add() { const scenario = getScenario(health.windows, 'EAT') var items = list.filter(item => item.window == 'EAT') if (scenario.access.max && scenario.access.max <= items.length) { showAlert({ title: '会员', content: '会员desc', showCancel: true, confirm: () => { jumpPage('/pages/store/product_list', 'ProductList', navigation) } }) return; } setShowModal(true) } function isDisable(obj) { if ((obj.window == 'FAST' || obj.window == 'SLEEP') && !obj.is_conflict) { return true } return false } function footerTitle() { if (health.footer) { return health.footer.eat.title } return '' } function footerDesc() { if (health.footer) { return health.footer.eat.description } return '' } function items() { var items = list.filter(item => item.window == 'EAT') return { errors.map((item1, index) => { return {item1} }) } { items.map((obj, i) => { return { const scenario = getScenario(health.windows, 'EAT') if (scenario.access.min >= items.length) { showAlert({ title: '删除', content: '最少保留' + items.length + '个', showCancel: true, confirm: () => { } }) return } if (errors.length > 0) { Taro.showToast({ title: '请先解决冲突', icon: 'none' }) return } delSchedule(obj.id).then(res => { var temps = JSON.parse(JSON.stringify(health.schedules)) var temps2 = temps.filter(item => item.id != obj.id) dispatch(setSchedules(temps2)) dispatch(setFooter((res as any).footer)) var array = JSON.parse(JSON.stringify(list)) for (var j = 0; j < array.length; j++) { if (array[j].id == obj.id) { array.splice(j, 1) } } setList(array) check(array) global.refreshWindow() }) }} onChange={(time) => { var array = JSON.parse(JSON.stringify(list)) array.map(item => { if ((item.id && item.id == obj.id) || (!item.id && item.title == obj.title)) { item.time = time item.op_ms = new Date().getTime() } }) dispatch(setSchedules(array)) check(array) }} /> }) } add()}> } function fastSleepItems() { var items = list.filter(item => item.window == 'FAST') return { items.map((obj, i) => { return { var array = JSON.parse(JSON.stringify(list)) for (var j = 0; j < array.length; j++) { if (array[j].id == obj.id) { array.splice(j, 1) } } setList(array) check(array) global.refreshWindow() }} onChange={(time) => { var array = JSON.parse(JSON.stringify(list)) array.map(item => { if ((item.id && item.id == obj.id) || (!item.id && item.title == obj.title)) { item.time = time item.op_ms = new Date().getTime() } }) setList(array) check(array) }} /> }) } } return { Taro.navigateBack() }} /> { items() } { fastSleepItems() } 0} color={MainColorType.eat} width={rpxToPx(646)} height={rpxToPx(96)} onClick={() => { check(list, true) }} /> { showModal && setShowModal(false)} onlyCheck={true} schedules={list} confirm={(res) => { setShowModal(false) if ((res as any).result) { dispatch(setSchedules((res as any).schedules)) dispatch(setFooter((res as any).footer)) setList((res as any).schedules) setErrors([]) } else { setList((res as any).schedules) dispatch(setFooter((res as any).footer)) setErrors((res as any).error_messages ? (res as any).error_messages : []) } }} color={MainColorType.eat} /> } {/* { showModal && { setShowModal(false) }} confirm={() => { }}> setShowModal(false)} onlyCheck={true} schedules={list} confirm={(res) => { if ((res as any).result) { dispatch(setSchedules((res as any).schedules)) dispatch(setFooter((res as any).footer)) setList((res as any).schedules) setErrors([]) } else { setList((res as any).schedules) dispatch(setFooter((res as any).footer)) setErrors((res as any).error_messages ? (res as any).error_messages : []) } }} color={MainColorType.eat} /> } */} }