DistributionScreen.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* eslint-disable react/destructuring-assignment */
  2. import * as WebBrowser from "expo-web-browser";
  3. import * as React from "react";
  4. import { useModel } from "flooks";
  5. import { Layout, Input, Button, Text } from "@ui-kitten/components";
  6. import { StyleSheet } from "react-native";
  7. import ScrollPage from "../../components/ScrollPage";
  8. const styles = StyleSheet.create({
  9. lay: {
  10. flex: 1,
  11. marginTop: 10,
  12. paddingVertical: 20,
  13. },
  14. item: {
  15. flexDirection: "row",
  16. alignItems: "center",
  17. marginBottom: 7,
  18. alignSelf: "stretch",
  19. },
  20. lab: {
  21. width: 119,
  22. textAlign: "right",
  23. marginRight: 38,
  24. flexShrink: 0,
  25. },
  26. tip: {
  27. width: 86,
  28. paddingHorizontal: 8,
  29. flexShrink: 0,
  30. },
  31. input: {
  32. flexShrink: 1,
  33. minWidth: 0,
  34. },
  35. btn: {
  36. marginTop: 50,
  37. marginBottom: 20,
  38. alignSelf: "center",
  39. },
  40. bottom: {
  41. paddingHorizontal: 70,
  42. },
  43. });
  44. // 配送设置
  45. export default function DistributionScreen({ navigation }) {
  46. const {
  47. distributionTitle,
  48. minutes,
  49. distributionText1,
  50. distributionText2,
  51. distributionText3,
  52. distributionText4,
  53. distributionText5,
  54. distributionText6,
  55. yuan,
  56. confirm,
  57. } = useModel("wordsModel");
  58. const {
  59. startingAmount,
  60. preparationTime,
  61. updateMerchant,
  62. } = useModel("userModel");
  63. const { success } = useModel("loadingModel");
  64. const [amount, setAmount] = React.useState();
  65. const [time, setTime] = React.useState();
  66. React.useEffect(() => {
  67. if (startingAmount) {
  68. setAmount(startingAmount);
  69. }
  70. if (preparationTime) {
  71. setTime(preparationTime);
  72. }
  73. }, [startingAmount, preparationTime]);
  74. const Lable = props => (
  75. <Text category='c1' style={styles.lab}>
  76. {props.children}
  77. </Text>
  78. );
  79. const Tip = props => (
  80. <Text category='c1' status='info' style={styles.tip}>
  81. {props.children}
  82. </Text>
  83. );
  84. const canSubmit = React.useMemo(() => {
  85. if (amount && time) {
  86. return true;
  87. }
  88. return false;
  89. }, [amount, time]);
  90. return (
  91. <ScrollPage statusType='primary' navHeaderBarTitle={distributionTitle}>
  92. <Layout style={styles.lay}>
  93. <Layout style={styles.item}>
  94. <Lable>{distributionText1}</Lable>
  95. <Input
  96. value={amount}
  97. onChangeText={text => {
  98. setAmount(text);
  99. }}
  100. key={2}
  101. keyboardType='numeric'
  102. maxLength={3}
  103. placeholder={distributionText3}
  104. style={styles.input}
  105. />
  106. <Tip>
  107. (0-100
  108. {yuan}
  109. )
  110. </Tip>
  111. </Layout>
  112. <Layout style={styles.item}>
  113. <Lable>{distributionText2}</Lable>
  114. <Input
  115. value={time}
  116. key={1}
  117. onChangeText={text => {
  118. setTime(text);
  119. }}
  120. keyboardType='numeric'
  121. maxLength={2}
  122. placeholder={distributionText4}
  123. style={styles.input}
  124. />
  125. <Tip>
  126. (1-30
  127. {minutes}
  128. )
  129. </Tip>
  130. </Layout>
  131. <Button
  132. disabled={!canSubmit}
  133. onPress={() => {
  134. updateMerchant({
  135. startingAmount: amount,
  136. preparationTime: time,
  137. }).then(() => {
  138. success("修改成功");
  139. navigation.goBack();
  140. });
  141. }}
  142. style={styles.btn}
  143. >
  144. {confirm}
  145. </Button>
  146. <Text category='c1' status='info' style={styles.bottom}>
  147. {distributionText5}
  148. :
  149. </Text>
  150. <Text category='c1' status='info' style={styles.bottom}>
  151. {distributionText6}
  152. :
  153. </Text>
  154. </Layout>
  155. </ScrollPage>
  156. );
  157. }