edit_schedule.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { View, Text } from '@tarojs/components'
  2. import './edit_schedule.scss'
  3. import { useEffect, useState } from 'react'
  4. import Modal from '@/components/layout/Modal.weapp'
  5. import AddLabel from '../components/add_label'
  6. import { delSchedule, getLabels, getSchedules } from '@/services/health'
  7. import { AtSwipeAction } from "taro-ui"
  8. import { useSelector } from 'react-redux'
  9. import { getThemeColor } from '@/features/health/hooks/health_hooks'
  10. import showActionSheet from '@/components/basic/ActionSheet'
  11. export default function EditSchedule() {
  12. const [showModal, setShowModal] = useState(false)
  13. const [list, setList] = useState<any>([])
  14. const [labels, setLabels] = useState<any>([])
  15. const [showDel, setShowDel] = useState(false)
  16. const health = useSelector((state: any) => state.health);
  17. let navigation, showActionSheetWithOptions;
  18. useEffect(() => {
  19. schedules()
  20. }, [])
  21. function schedules() {
  22. getSchedules({ window: health.mode, is_all_day: false }).then(res => {
  23. console.log('sss', res)
  24. if ((res as any).data && (res as any).data.length > 0) {
  25. setList((res as any).data)
  26. }
  27. }).catch(e => {
  28. })
  29. getLabels({ window: health.mode }).then(res => {
  30. setLabels((res as any).labels)
  31. })
  32. }
  33. function add() {
  34. setShowModal(true)
  35. }
  36. function delItem(index) {
  37. delSchedule(list[index].id).then(res => {
  38. schedules()
  39. global.refreshWindow()
  40. global.refreshHistory()
  41. })
  42. }
  43. function tapEdit() {
  44. let array:any = []
  45. switch(health.mode){
  46. case 'DAY':
  47. case 'NIGHT':
  48. array = ['设置提醒']
  49. break
  50. case 'FAST':
  51. case 'SLEEP':
  52. array = ['调整时间','设置提醒']
  53. break;
  54. case 'EAT':
  55. case 'ACTIVE':
  56. array = ['调整时间','设置提醒','编辑标记','删除']
  57. break;
  58. }
  59. showActionSheet({
  60. showActionSheetWithOptions: showActionSheetWithOptions,
  61. title: 'Oprate Title',
  62. itemList: array,
  63. success: (res) => {
  64. // tapActionSheet(res)
  65. }
  66. })
  67. }
  68. return <View>
  69. {
  70. list.map((item, index) => {
  71. // return <AtSwipeAction key={index} isOpened options={[
  72. // {
  73. // text: '删除',
  74. // style: {
  75. // backgroundColor: '#FF4949'
  76. // }
  77. // }
  78. // ]}>
  79. return <View className='item' key={index}>
  80. {
  81. showDel && <Text style={{ color: 'red', marginRight: 5 }} onClick={() => delItem(index)}>删除</Text>
  82. }
  83. <View className='item_left'>
  84. {
  85. health.mode == 'EAT' && <Text className='item_index'>第{index + 1}餐</Text>
  86. }
  87. <Text className='item_name'>{item.title}</Text>
  88. </View>
  89. <Text className='item_time'>{item.time}</Text>
  90. <View className='item_line' />
  91. </View>
  92. // </AtSwipeAction>
  93. })
  94. }
  95. {
  96. (health.mode == 'EAT' || health.mode == 'ACTIVE') && <View className='toolbar'>
  97. <View className='toolbar_btn' style={{ color: getThemeColor(health.mode) }} onClick={add}>添加</View>
  98. <View style={{ flex: 1 }} />
  99. <View className='toolbar_btn' style={{ color: getThemeColor(health.mode) }} onClick={() => setShowDel(!showDel)}>移除</View>
  100. </View>
  101. }
  102. <Text onClick={tapEdit}>批量编辑</Text>
  103. {
  104. showModal && <Modal testInfo={null}
  105. dismiss={() => {
  106. setShowModal(false)
  107. }}
  108. confirm={() => { }}>
  109. <AddLabel labels={labels} />
  110. </Modal>
  111. }
  112. </View>
  113. }