schedule_item.tsx 6.6 KB

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