meal_list.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { View, Text } from '@tarojs/components'
  2. import './meal_list.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. export default function MealList() {
  9. const [showModal, setShowModal] = useState(false)
  10. const [list, setList] = useState<any>([])
  11. const [labels, setLabels] = useState<any>([])
  12. const [showDel, setShowDel] = useState(false)
  13. useEffect(() => {
  14. schedules()
  15. }, [])
  16. function schedules() {
  17. getSchedules({ window: 'EAT' }).then(res => {
  18. console.log('sss',res)
  19. if ((res as any).data && (res as any).data.length > 0) {
  20. setList((res as any).data)
  21. }
  22. }).catch(e => {
  23. })
  24. getLabels({ window: 'EAT' }).then(res => {
  25. setLabels((res as any).labels)
  26. })
  27. }
  28. function add() {
  29. setShowModal(true)
  30. }
  31. function delItem(index) {
  32. delSchedule(list[index].code).then(res => {
  33. schedules()
  34. })
  35. }
  36. return <View>
  37. {
  38. list.map((item, index) => {
  39. // return <AtSwipeAction key={index} isOpened options={[
  40. // {
  41. // text: '删除',
  42. // style: {
  43. // backgroundColor: '#FF4949'
  44. // }
  45. // }
  46. // ]}>
  47. return <View className='item' key={index}>
  48. {
  49. showDel && <Text style={{ color: 'red', marginRight: 5 }} onClick={() => delItem(index)}>删除</Text>
  50. }
  51. <View className='item_left'>
  52. <Text className='item_index'>第{index + 1}餐</Text>
  53. <Text className='item_name'>{item.title}</Text>
  54. </View>
  55. <Text className='item_time'>{item.time}</Text>
  56. <View className='item_line' />
  57. </View>
  58. // </AtSwipeAction>
  59. })
  60. }
  61. <View className='toolbar'>
  62. <View className='toolbar_btn' onClick={add}>添加一餐</View>
  63. <View style={{ flex: 1 }} />
  64. <View className='toolbar_btn' onClick={() => setShowDel(!showDel)}>移除</View>
  65. </View>
  66. {
  67. showModal && <Modal testInfo={null}
  68. dismiss={() => {
  69. setShowModal(false)
  70. }}
  71. confirm={() => { }}>
  72. <AddLabel labels={labels} />
  73. </Modal>
  74. }
  75. </View>
  76. }