OrderCard.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* eslint-disable react/jsx-props-no-spreading */
  2. /* eslint-disable no-shadow */
  3. import React from "react";
  4. import { StyleSheet } from "react-native";
  5. import {
  6. Card,
  7. Text,
  8. Button,
  9. Layout,
  10. MenuGroup,
  11. MenuItem,
  12. } from "@ui-kitten/components";
  13. import { Linking } from "expo";
  14. import { useModel } from "flooks";
  15. const styles = StyleSheet.create({
  16. orderItem1: {
  17. justifyContent: "space-between",
  18. flexDirection: "row",
  19. marginBottom: 10,
  20. },
  21. orderItem2: {
  22. alignItems: "flex-start",
  23. flexDirection: "row",
  24. marginBottom: 15,
  25. },
  26. leftText: {
  27. flexShrink: 0,
  28. marginRight: 8,
  29. minWidth: 60,
  30. },
  31. menuGroup: {
  32. padding: 0,
  33. margin: 0,
  34. },
  35. lay: {
  36. flex: 1,
  37. },
  38. menuTitle: {
  39. flexDirection: "row",
  40. flex: 1,
  41. },
  42. footerContainer: {
  43. flexDirection: "row",
  44. justifyContent: "flex-end",
  45. },
  46. footerControl: {
  47. width: 112,
  48. marginLeft: 5,
  49. },
  50. sub: {
  51. flex: 1,
  52. flexShrink: 0,
  53. },
  54. menuItem: {
  55. flex: 1,
  56. // paddingHorizontal: 0,
  57. // paddingVertical: 0,
  58. // paddingLeft: 0,
  59. // marginTop: 5,
  60. // marginHorizontal: 5,
  61. },
  62. right: {
  63. textAlign: "right",
  64. },
  65. center: {
  66. textAlign: "center",
  67. },
  68. });
  69. const MenuTitle = (title, sub, num, index) => (
  70. <Layout style={styles.menuTitle} key={index || 0}>
  71. <Text category='h1' style={styles.sub}>
  72. {title}
  73. </Text>
  74. {num && (
  75. <Text category='h1' style={[styles.sub, styles.center]}>
  76. {num}
  77. </Text>
  78. )}
  79. <Text category='h1' style={[styles.sub, styles.right]}>
  80. {sub}
  81. </Text>
  82. </Layout>
  83. );
  84. const lsitMenu = () => {
  85. return (
  86. <Layout style={styles.menuItem}>
  87. {[1, 2].map((item, index) => {
  88. return MenuTitle(`圣诞节副科${ item}`, "¥9999.99", 2, index + 1);
  89. })}
  90. </Layout>
  91. );
  92. };
  93. export default function OrderCard(props) {
  94. const {
  95. orderInfo2,
  96. orderInfo3,
  97. orderInfo4,
  98. orderInfo5,
  99. orderInfo6,
  100. getWordsStr,
  101. orderButton1,
  102. orderButton2,
  103. overTips,
  104. } = useModel("wordsModel");
  105. const { showDialog } = useModel("dialogModel");
  106. const { receivedOrder } = useModel("orderInfoModel");
  107. const { info, updateInfo,style } = props;
  108. const {
  109. id,
  110. payMethod,
  111. orderTime,
  112. userAddress,
  113. merchantStatus,
  114. user,
  115. riderStatus,
  116. } = info || {};
  117. const Footer = (props) => {
  118. if (riderStatus) {
  119. return (
  120. <Layout
  121. {...props}
  122. style={[props.style]}
  123. >
  124. <Layout style={styles.orderItem1}>
  125. <Text category='c2'>骑手:胖齐齐</Text>
  126. <Button
  127. appearance='outline'
  128. onPress={() => {
  129. Linking.openURL(`tel:+${ user.phone}`);
  130. }}
  131. >
  132. 联系骑手
  133. </Button>
  134. </Layout>
  135. <Layout style={styles.orderItem1}>
  136. <Text category='c2'>
  137. 预计送达时间:2019-12-31 13:17
  138. </Text>
  139. </Layout>
  140. {riderStatus === "CARRY_OUT" && (
  141. <Layout style={styles.orderItem1}>
  142. <Text category='c2'>
  143. 实际送达时间:2019-12-31 13:17
  144. </Text>
  145. </Layout>
  146. )}
  147. </Layout>
  148. );
  149. } if (merchantStatus === "NOT_RECEIVED") {
  150. return (
  151. <Layout
  152. {...props}
  153. style={[props.style, styles.footerContainer]}
  154. >
  155. <Button
  156. style={styles.footerControl}
  157. appearance='outline'
  158. onPress={() => {
  159. showDialog({
  160. bodyText: overTips,
  161. status: "danger",
  162. cancelable: true,
  163. confirmCallback: () => {
  164. receivedOrder(id, false).then((res) => {
  165. updateInfo(res);
  166. });
  167. },
  168. });
  169. }}
  170. >
  171. {orderButton1}
  172. </Button>
  173. <Button
  174. style={styles.footerControl}
  175. onPress={() => {
  176. receivedOrder(id, true).then((res) => {
  177. updateInfo(res);
  178. });
  179. }}
  180. appearance='outline'
  181. >
  182. {orderButton2}
  183. </Button>
  184. </Layout>
  185. );
  186. }
  187. return null;
  188. };
  189. return (
  190. <Card
  191. appearance='orderCard'
  192. disabled
  193. style={[style]}
  194. footer={Footer}
  195. >
  196. {riderStatus ? (
  197. <Text>
  198. 骑手
  199. {getWordsStr(riderStatus)}
  200. </Text>
  201. ) : (
  202. <Text>
  203. 商家
  204. {getWordsStr(merchantStatus)}
  205. </Text>
  206. )}
  207. <Layout style={styles.orderItem1}>
  208. <Text category='c2'>{id}</Text>
  209. <Text category='c2'>
  210. {orderInfo2}
  211. :
  212. {orderTime}
  213. </Text>
  214. </Layout>
  215. <Layout style={styles.orderItem1}>
  216. <Text category='h6'>{user.nickname}</Text>
  217. <Text category='h6'>{getWordsStr(payMethod)}</Text>
  218. </Layout>
  219. <Layout style={styles.orderItem1}>
  220. <Text category='c2'>{user.phone}</Text>
  221. <Button
  222. appearance='outline'
  223. onPress={() => {
  224. Linking.openURL(`tel:+${ user.phone}`);
  225. }}
  226. >
  227. {orderInfo3}
  228. </Button>
  229. </Layout>
  230. <Layout style={styles.orderItem2}>
  231. <Text category='c2' style={styles.leftText}>
  232. {orderInfo4}
  233. </Text>
  234. <Text category='h1'>{userAddress}</Text>
  235. </Layout>
  236. <Layout style={styles.orderItem2}>
  237. <Text category='c2' style={styles.leftText}>
  238. {orderInfo5}
  239. </Text>
  240. <Layout style={styles.lay}>
  241. <MenuGroup
  242. appearance='orderProduct'
  243. title={() => MenuTitle("圣诞节副科", "¥9999.99")}
  244. style={styles.menuGroup}
  245. >
  246. <MenuItem
  247. disabled
  248. style={styles.menuItem}
  249. title={lsitMenu}
  250. />
  251. </MenuGroup>
  252. </Layout>
  253. </Layout>
  254. <Layout style={styles.orderItem2}>
  255. <Text category='c2' style={styles.leftText}>
  256. {orderInfo6}
  257. :
  258. </Text>
  259. <Text category='h1'>多放辣椒</Text>
  260. </Layout>
  261. </Card>
  262. );
  263. }