schedule_item.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import showAlert from "@/components/basic/Alert";
  2. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  3. import { rpxToPx } from "@/utils/tools";
  4. import { View, Text } from "@tarojs/components";
  5. import { AtSwipeAction } from "taro-ui";
  6. import StatusIndicator, { StatusType } from "../base/status_indicator";
  7. import { MainColorType } from "@/context/themes/color";
  8. import { IconError, IconNotificationOff } from "@/components/basic/Icons";
  9. import { useState } from "react";
  10. import NewModal from "../base/new_modal";
  11. import Card from "./card";
  12. import NewTimePicker from "../base/new_timepicker";
  13. import './schedule_item.scss'
  14. export default function ScheduleItem(props: {
  15. key: any,
  16. obj: any,
  17. highlight?: boolean,
  18. disable?: boolean,
  19. gray?: boolean,
  20. days?: string,
  21. showLine: boolean,
  22. errors: any,
  23. selMode: any,
  24. hideReminderIcon?: boolean,
  25. onDelete?: Function,
  26. onChange?: Function
  27. }) {
  28. const [showTimePicker, setShowTimePicker] = useState(false)
  29. const [time, setTime] = useState(props.obj.time)
  30. function itemStyle(obj) {
  31. if (obj.is_conflict) {
  32. return {
  33. // backgroundColor: '#FF00001A',
  34. // color: '#FF0000'
  35. backgroundColor: '#B2B2B21A',
  36. color: '#000',
  37. borderWidth: 2,
  38. borderColor: '#FF0000',
  39. borderStyle: 'solid'
  40. }
  41. }
  42. if (props.errors.length > 0) {
  43. return {
  44. backgroundColor: '#B2B2B21A',
  45. color: '#000'
  46. }
  47. }
  48. return {
  49. backgroundColor: obj.window == props.selMode ? getThemeColor(props.selMode) + '1A' : '#B2B2B21A',
  50. color: obj.window == props.selMode ? getThemeColor(props.selMode) : '#000'
  51. }
  52. }
  53. return <View key={props.key}>
  54. <AtSwipeAction
  55. isOpened={false}
  56. autoClose
  57. disabled={(props.obj.window != 'EAT' && props.obj.window != 'ACTIVE' && !props.disable) || props.obj.window == 'FAST' || props.obj.window == 'SLEEP'}
  58. options={[
  59. {
  60. text: '删除',
  61. style: {
  62. backgroundColor: '#FF4949'
  63. }
  64. }
  65. ]}
  66. onClick={() => {
  67. if (props.obj.window == 'ACTIVE' || props.obj.window == 'EAT') {
  68. // if (item.list.length == 1) {
  69. // Taro.showToast({
  70. // title: '至少保留一项',
  71. // icon: 'none'
  72. // })
  73. // return;
  74. // }
  75. }
  76. showAlert({
  77. title: '删除',
  78. content: '确认删除此计划',
  79. showCancel: true,
  80. cancel: () => {
  81. console.log('cancel')
  82. },
  83. confirm: () => {
  84. if (props.onDelete) {
  85. props.onDelete()
  86. }
  87. // delItem(index, i)
  88. }
  89. })
  90. }}
  91. ><View className='schedule_item' style={{
  92. width: rpxToPx(700),
  93. boxSizing: 'border-box',
  94. backgroundColor: props.highlight ? getThemeColor(props.obj.window) + '0D' : '#fff'
  95. }}>
  96. <View className='item_left2'>
  97. <StatusIndicator
  98. type={props.obj.is_conflict ? StatusType.img : StatusType.normal}
  99. text={props.obj.title}
  100. fontSize={rpxToPx(34)}
  101. fontColor="#000"
  102. color={props.obj.is_conflict ? MainColorType.error : props.errors.length == 0 ? getThemeColor(props.obj.window) : 'transparent'} >
  103. {
  104. props.obj.is_conflict && <IconError color="#fff" width={rpxToPx(26)} />
  105. }
  106. </StatusIndicator>
  107. <View style={{ flex: 1 }} />
  108. {
  109. props.days && <View className="h30" style={{ color: MainColorType.g02 }}>+{props.days} day</View>
  110. }
  111. {
  112. !props.hideReminderIcon && props.obj.specific_time && !props.obj.reminder && <IconNotificationOff color={MainColorType.g03} width={rpxToPx(28)} />
  113. }
  114. <View style={{ width: rpxToPx(12) }} />
  115. {
  116. !props.disable && props.obj.specific_time && <View className='edit_item_time' onClick={() => {
  117. // setSelIndex(i)
  118. // setSelItem(obj)
  119. setTime(props.obj.time)
  120. setShowTimePicker(true)
  121. // if (props.onClick)
  122. // props.onClick()
  123. }} style={itemStyle(props.obj)}>{props.obj.time}</View>
  124. }
  125. {
  126. props.disable && <View className="edit_item_time" style={{ backgroundColor: 'transparent', color: props.gray ? MainColorType.g02 : '#000' }}>{props.obj.time}</View>
  127. }
  128. </View>
  129. {
  130. props.showLine && <View className='border_footer_line' style={{ left: rpxToPx(66) }} />
  131. }
  132. </View>
  133. </AtSwipeAction>
  134. {
  135. showTimePicker && <NewModal title={props.obj.title}
  136. dismiss={() => { setShowTimePicker(false) }}
  137. confirm={() => {
  138. setShowTimePicker(false)
  139. if (props.onChange)
  140. props.onChange(time)
  141. // props.onChange({
  142. // time: time,
  143. // duration: minutes,
  144. // isYesterday: isYesterday
  145. // })
  146. }}
  147. themeColor={getThemeColor(props.obj.window)}>
  148. <Card>
  149. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  150. <View className="picker_title" style={{ color: getThemeColor(props.obj.window), width: rpxToPx(618) }}>{time}
  151. <View className="border_footer_line" />
  152. </View>
  153. <NewTimePicker time={time}
  154. color={getThemeColor(props.obj.window)}
  155. onChange={(e) => {
  156. setTime(e)
  157. }}
  158. />
  159. </View>
  160. </Card>
  161. </NewModal>
  162. }
  163. </View>
  164. }