OpenTime.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* eslint-disable prefer-const */
  2. /* eslint-disable no-underscore-dangle */
  3. import React from "react";
  4. import { StyleSheet, LayoutAnimation, Platform, UIManager } from "react-native";
  5. import { range, convert2Digit } from "beeshell/dist/common/utils";
  6. import {
  7. CheckBox,
  8. Layout,
  9. Modal,
  10. Button,
  11. Card,
  12. Text,
  13. MenuItem,
  14. Icon,
  15. SelectItem,
  16. } from "@ui-kitten/components";
  17. import { useEventEmitter, useMount } from "@umijs/hooks";
  18. import { useModel } from "flooks";
  19. import moment from "moment";
  20. import OpenTimeUtil from "../Utils/OpenTimeUtil";
  21. import OpenTimeCom from "./OpenTimeCom";
  22. if (Platform.OS === "android") {
  23. if (UIManager.setLayoutAnimationEnabledExperimental) {
  24. UIManager.setLayoutAnimationEnabledExperimental(true);
  25. }
  26. }
  27. const styles = StyleSheet.create({
  28. checkBoxAll: {
  29. paddingVertical: 10,
  30. },
  31. checkBoxItem: {
  32. paddingVertical: 2,
  33. paddingHorizontal: 10,
  34. },
  35. time: {
  36. // width: 100,
  37. // height: 300,
  38. },
  39. backdrop: {
  40. backgroundColor: "rgba(0, 0, 0, 0.5)",
  41. },
  42. btnList: {
  43. flexDirection: "row",
  44. justifyContent: "space-between",
  45. paddingTop: 15,
  46. },
  47. hideHeight: {
  48. height: 0,
  49. borderWidth: 0,
  50. },
  51. btn: {
  52. flex: 1,
  53. minWidth: 50,
  54. },
  55. });
  56. const ForwardIcon = props => <Icon {...props} name="arrow-ios-forward" />;
  57. const titleText = (props, title, value) => (
  58. <Text {...props} category="s1" numberOfLines={1} ellipsizeMode="tail">
  59. {title}
  60. <Text category="c1" style={{ paddingLeft: 10 }}>
  61. {value}
  62. </Text>
  63. </Text>
  64. );
  65. export default function OpenTime({ submit, week, startTime, endTime }) {
  66. const { weekWords } = useModel("wordsModel");
  67. const node$ = useEventEmitter();
  68. const openTime = React.useMemo(() => {
  69. console.log(week);
  70. if (startTime && endTime && week) {
  71. // eslint-disable-next-line no-underscore-dangle
  72. return new OpenTimeUtil(startTime, endTime, week, weekWords());
  73. }
  74. return new OpenTimeUtil();
  75. }, [startTime, endTime, week, weekWords]);
  76. return (
  77. <>
  78. <SelectItem
  79. appearance="form"
  80. style={{ flex: 1, height: 32 }}
  81. accessoryRight={ForwardIcon}
  82. title={props =>
  83. titleText(props, openTime.getTimeStr(), openTime.getWeekStr())
  84. }
  85. onPress={() => {
  86. node$.emit();
  87. }}
  88. />
  89. <OpenTimeCom
  90. submit={_openTimeUtil => {
  91. submit(
  92. _openTimeUtil.week,
  93. _openTimeUtil.startTime,
  94. _openTimeUtil.endTime
  95. );
  96. }}
  97. openTime={openTime}
  98. node$={node$}
  99. />
  100. </>
  101. );
  102. }