|
|
@@ -0,0 +1,157 @@
|
|
|
+import { View, Text } from "@tarojs/components";
|
|
|
+import './schedules_conflict.scss'
|
|
|
+import { useState } from "react";
|
|
|
+import Taro, { useRouter } from "@tarojs/taro";
|
|
|
+import { rpxToPx } from "@/utils/tools";
|
|
|
+import Modal from "@/components/layout/Modal.weapp";
|
|
|
+import { getThemeColor } from "@/features/health/hooks/health_hooks";
|
|
|
+import TimePicker from "@/features/common/TimePicker";
|
|
|
+import { createSchedule } from "@/services/health";
|
|
|
+import { useSelector } from "react-redux";
|
|
|
+import showAlert from "@/components/basic/Alert";
|
|
|
+
|
|
|
+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 SchedulesConflict() {
|
|
|
+ let router
|
|
|
+ let navigation;
|
|
|
+ if (useNavigation) {
|
|
|
+ navigation = useNavigation()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ router = useRoute()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ router = useRouter()
|
|
|
+ }
|
|
|
+
|
|
|
+ const health = useSelector((state: any) => state.health);
|
|
|
+ const [schedules, setSchedules] = useState(JSON.parse(router.params.schedules))
|
|
|
+ const [errors, setErrors] = useState(JSON.parse(router.params.errors))
|
|
|
+ const count = JSON.parse(router.params.schedules).filter(obj => obj.is_all_day == true).length
|
|
|
+ const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
+ const [selItem, setSelItem] = useState<any>(null)
|
|
|
+ const [selIndex, setSelIndex] = useState(-1)
|
|
|
+ const [showErrorTip, setShowErrorTip] = useState(true)
|
|
|
+ debugger
|
|
|
+
|
|
|
+ function modalContent() {
|
|
|
+ const strTime = selItem.time
|
|
|
+
|
|
|
+ var title = selItem.title
|
|
|
+ var color = getThemeColor(selItem.window)
|
|
|
+
|
|
|
+ return <TimePicker time={strTime}
|
|
|
+ color={color}
|
|
|
+ title={title}
|
|
|
+ confirm={(e) => {
|
|
|
+ selItem.time = e
|
|
|
+ setSelItem(selItem)
|
|
|
+ setShowTimePicker(false)
|
|
|
+ var array = JSON.parse(JSON.stringify(schedules))
|
|
|
+ array[selIndex].time = e
|
|
|
+ setSchedules(array)
|
|
|
+ checkData(array)
|
|
|
+ // confirmPickerTime(e)
|
|
|
+ }}
|
|
|
+ cancel={() => {
|
|
|
+ setShowTimePicker(false)
|
|
|
+ }} />
|
|
|
+ }
|
|
|
+
|
|
|
+ function checkData(array) {
|
|
|
+ createSchedule({
|
|
|
+ schedules: array,
|
|
|
+ // only_check: true
|
|
|
+ }).then(res => {
|
|
|
+ setSchedules((res as any).schedules)
|
|
|
+ setErrors((res as any).error_messages?(res as any).error_messages:[])
|
|
|
+ if ((res as any).result) {
|
|
|
+ setShowErrorTip(false)
|
|
|
+ global.refreshWindow()
|
|
|
+ global.refreshSchedules()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setShowErrorTip(true)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function done() {
|
|
|
+ createSchedule({
|
|
|
+ schedules: schedules
|
|
|
+ }).then(res => {
|
|
|
+ if ((res as any).result) {
|
|
|
+ global.refreshWindow()
|
|
|
+ global.refreshSchedules()
|
|
|
+ Taro.navigateBack({
|
|
|
+ delta: router.params.isAdd == 1 ? 1 : 2
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setSchedules((res as any).schedules)
|
|
|
+ showAlert({
|
|
|
+ title: '弹窗标题',
|
|
|
+ content: '冲突描述',
|
|
|
+ showCancel: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return <View style={{ display: 'flex', flex: 1, flexDirection: 'column' }}>
|
|
|
+ <Text className="title">Scheduling Conflict</Text>
|
|
|
+ <Text className="sub_title">Adjust your schedule to resolve</Text>
|
|
|
+ {
|
|
|
+ errors.map((item, index) => {
|
|
|
+ return <View key={index} className='error_tip'>{item}</View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ {
|
|
|
+ errors.length == 0 && <View className='success_tip'>时间冲突已解决,并保存</View>
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ schedules.map((item, index) => {
|
|
|
+ if (item.is_all_day) return <View key={index} />
|
|
|
+ return <View className="conflict_item" key={index}>
|
|
|
+ <Text className="conflict_index">{index + 1 - count}</Text>
|
|
|
+ <Text className="conflict_title">{item.title}</Text>
|
|
|
+ {
|
|
|
+ item.is_conflict && <Text className="conflict_tip">时间冲突,请调整</Text>
|
|
|
+ }
|
|
|
+ <View className={item.is_conflict ? 'conflict_time' : 'normal_time'} onClick={() => {
|
|
|
+ setSelIndex(index)
|
|
|
+ setSelItem(item)
|
|
|
+ setShowTimePicker(true)
|
|
|
+ }}>{item.time}</View>
|
|
|
+ {
|
|
|
+ index < schedules.length - 1 && <View className="border_footer_line" style={{ marginLeft: rpxToPx(40) }} />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ {/* <View className="edit_footer_btn2" style={{ color: getThemeColor(health.mode), backgroundColor: getThemeColor(health.mode) + '33' }} onClick={done}>Resolved</View> */}
|
|
|
+ {
|
|
|
+ showTimePicker && <Modal
|
|
|
+ testInfo={null}
|
|
|
+ dismiss={() => {
|
|
|
+ setShowTimePicker(false)
|
|
|
+ }}
|
|
|
+ confirm={() => { }}>
|
|
|
+ {
|
|
|
+ modalContent()
|
|
|
+ }
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+}
|