schedules_list.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { View, Text, Image } from '@tarojs/components'
  2. import './schedules_list.scss'
  3. import './edit.scss'
  4. import { useEffect, useState } from 'react'
  5. import Modal from '@/components/layout/Modal.weapp'
  6. import AddLabel from '../components/add_label'
  7. import { delSchedule, getLabels, getSchedules } from '@/services/health'
  8. import { AtSwipeAction } from "taro-ui"
  9. import { useSelector } from 'react-redux'
  10. import { getThemeColor } from '@/features/health/hooks/health_hooks'
  11. import showActionSheet from '@/components/basic/ActionSheet'
  12. import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
  13. import { IconAdd } from '@/components/basic/Icons'
  14. import { rpxToPx } from '@/utils/tools'
  15. export default function SchedulesList() {
  16. const [showModal, setShowModal] = useState(false)
  17. const [list, setList] = useState<any>([])
  18. const [labels, setLabels] = useState<any>([])
  19. const [showDel, setShowDel] = useState(false)
  20. const health = useSelector((state: any) => state.health);
  21. let navigation, showActionSheetWithOptions;
  22. useEffect(() => {
  23. schedules()
  24. }, [])
  25. global.refreshSchedules = () => {
  26. schedules()
  27. }
  28. function schedules() {
  29. let windows = ''
  30. switch (health.mode) {
  31. case 'FAST':
  32. windows = 'FAST,EAT';
  33. break
  34. case 'EAT':
  35. windows = 'EAT,FAST';
  36. break
  37. case 'SLEEP':
  38. windows = 'SLEEP,ACTIVE';
  39. break
  40. case 'ACTIVE':
  41. windows = 'ACTIVE,SLEEP';
  42. break
  43. }
  44. getSchedules({ window: windows }).then(res => {
  45. if ((res as any).data && (res as any).data.length > 0) {
  46. // setList((res as any).data)
  47. let grouped: any = {};
  48. (res as any).data.forEach(item => {
  49. const window = item.window;
  50. if (!grouped[window]) {
  51. grouped[window] = { window: window, list: [] };
  52. }
  53. grouped[window].list.push(item);
  54. });
  55. var array = Object.values(grouped)
  56. array.map((dt: any) => {
  57. if (dt.window == 'EAT' || dt.window == 'ACTIVE') {
  58. dt.list.push({
  59. add: true
  60. })
  61. }
  62. })
  63. setList(array)
  64. }
  65. }).catch(e => {
  66. })
  67. getLabels({ window: health.mode }).then(res => {
  68. setLabels((res as any).labels)
  69. })
  70. }
  71. function add() {
  72. setShowModal(true)
  73. }
  74. function delItem(index) {
  75. delSchedule(list[index].id).then(res => {
  76. schedules()
  77. global.refreshWindow()
  78. global.refreshHistory()
  79. })
  80. }
  81. function tapEdit() {
  82. jumpPage('./schedules_edit')
  83. return;
  84. let array: any = []
  85. switch (health.mode) {
  86. case 'DAY':
  87. case 'NIGHT':
  88. array = ['设置提醒']
  89. break
  90. case 'FAST':
  91. case 'SLEEP':
  92. array = ['调整时间', '设置提醒']
  93. break;
  94. case 'EAT':
  95. case 'ACTIVE':
  96. array = ['调整时间', '设置提醒', '编辑标记', '删除']
  97. break;
  98. }
  99. showActionSheet({
  100. showActionSheetWithOptions: showActionSheetWithOptions,
  101. title: 'Oprate Title',
  102. itemList: array,
  103. success: (res) => {
  104. tapActionSheet(res)
  105. }
  106. })
  107. }
  108. function tapActionSheet(index) {
  109. const mode = health.mode;
  110. switch (index) {
  111. case 0:
  112. switch (mode) {
  113. case 'DAY':
  114. case 'NIGHT':
  115. jumpPage('/_health/pages/schedules_reminder')
  116. break;
  117. default:
  118. jumpPage('/_health/pages/schedules_time')
  119. break;
  120. }
  121. break;
  122. case 1:
  123. jumpPage('/_health/pages/schedules_reminder')
  124. break;
  125. case 2:
  126. jumpPage('/_health/pages/schedules_mark')
  127. break;
  128. case 3:
  129. jumpPage('/_health/pages/schedules_del')
  130. break;
  131. }
  132. }
  133. function getTitle() {
  134. switch (health.mode) {
  135. case 'FAST':
  136. return '断食和进食';
  137. case 'EAT':
  138. return '进食和断食';
  139. case 'SLEEP':
  140. return '睡眠和活动';
  141. case 'ACTIVE':
  142. return '活动和睡眠';
  143. }
  144. return ''
  145. }
  146. return <View>
  147. <View className='schedule_header_title'>{getTitle()}</View>
  148. {
  149. list.map((item, index) => {
  150. return <View key={index} style={{ display: 'flex', flexDirection: 'column', marginBottom: rpxToPx(36) }}>
  151. {
  152. item.list.map((obj, i) => {
  153. if (obj.add) {
  154. return <View key={i * 100} className='item_add'
  155. hoverClass='cell_hover'
  156. hoverStayTime={50}
  157. onClick={add}>
  158. <IconAdd color={getThemeColor(item.window)} width={rpxToPx(34)} />
  159. <View className='toolbar_btn' style={{ color: getThemeColor(item.window) }} >添加</View>
  160. <View style={{ flex: 1 }} />
  161. {/* <View className='toolbar_btn' style={{ color: getThemeColor(health.mode) }} onClick={() => setShowDel(!showDel)}>移除</View> */}
  162. </View>
  163. }
  164. return <View className='schedule_item' key={i * 100} hoverClass='cell_hover' hoverStayTime={50} onClick={() => {
  165. }}>
  166. <View className='item_left'>
  167. <Text className='item_index'>{i + 1}</Text>
  168. <Text className='item_name'>{obj.title}</Text>
  169. </View>
  170. <View style={{ flex: 1 }} />
  171. {
  172. !obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
  173. }
  174. <Text className='item_time'>{obj.time}</Text>
  175. {
  176. i < item.list.length - 1 && <View className='item_line' />
  177. }
  178. </View>
  179. })
  180. }
  181. </View>
  182. })
  183. }
  184. <View className="edit_footer_btn" style={{ color: getThemeColor(health.mode), backgroundColor: getThemeColor(health.mode) + '33' }} onClick={tapEdit}>批量编辑</View>
  185. {
  186. showModal && <Modal testInfo={null}
  187. dismiss={() => {
  188. setShowModal(false)
  189. }}
  190. confirm={() => { }}>
  191. <AddLabel labels={labels} />
  192. </Modal>
  193. }
  194. </View>
  195. }