OrderCard.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 = list => {
  85. return (
  86. <Layout style={styles.menuItem}>
  87. {[...list].map((item, index) => {
  88. const { goods } = item;
  89. return MenuTitle(goods.name, item.goodsRealPrice, item.num, index + 1);
  90. })}
  91. </Layout>
  92. );
  93. };
  94. function getGoodsInfo(orderGoodsSpecs) {
  95. const info = {
  96. list: orderGoodsSpecs,
  97. name: "",
  98. num: 0,
  99. };
  100. if (orderGoodsSpecs.length > 0) {
  101. info.num = orderGoodsSpecs.reduce((pre, cur) => {
  102. return pre + cur.num;
  103. }, 0);
  104. info.name = orderGoodsSpecs[0].goods.name;
  105. }
  106. return info;
  107. }
  108. export default function OrderCard(props) {
  109. const {
  110. orderInfo2,
  111. orderInfo3,
  112. orderInfo4,
  113. orderInfo5,
  114. orderInfo6,
  115. getWordsStr,
  116. orderButton1,
  117. orderButton2,
  118. overTips,
  119. } = useModel("wordsModel");
  120. const { showDialog } = useModel("dialogModel");
  121. const { receivedOrder } = useModel("orderInfoModel");
  122. const { info, updateInfo, style } = props;
  123. const {
  124. id,
  125. payMethod,
  126. orderTime,
  127. userAddress,
  128. merchantStatus,
  129. user,
  130. riderStatus,
  131. remark,
  132. orderGoodsSpecs,
  133. realAmount,
  134. riderName,
  135. timeOfArrival,
  136. userReceivedTime,
  137. } = info || {};
  138. const Footer = props => {
  139. if (riderStatus && riderStatus !== "NOT_RECEIVED") {
  140. return (
  141. <Layout {...props} style={[props.style]}>
  142. <Layout style={styles.orderItem1}>
  143. <Text category="c2">
  144. 骑手:
  145. {riderName}
  146. </Text>
  147. <Button
  148. appearance="outline"
  149. onPress={() => {
  150. Linking.openURL(`tel:+${user.phone}`);
  151. }}
  152. >
  153. 联系骑手
  154. </Button>
  155. </Layout>
  156. <Layout style={styles.orderItem1}>
  157. <Text category="c2">
  158. 预计送达时间:
  159. {timeOfArrival}
  160. </Text>
  161. </Layout>
  162. {riderStatus === "CARRY_OUT" && (
  163. <Layout style={styles.orderItem1}>
  164. <Text category="c2">
  165. 实际送达时间:
  166. {userReceivedTime}
  167. </Text>
  168. </Layout>
  169. )}
  170. </Layout>
  171. );
  172. }
  173. if (merchantStatus === "NOT_RECEIVED") {
  174. return (
  175. <Layout {...props} style={[props.style, styles.footerContainer]}>
  176. <Button
  177. style={styles.footerControl}
  178. appearance="outline"
  179. onPress={() => {
  180. showDialog({
  181. bodyText: overTips,
  182. status: "danger",
  183. cancelable: true,
  184. confirmCallback: () => {
  185. receivedOrder(id, false).then(res => {
  186. updateInfo(res);
  187. });
  188. },
  189. });
  190. }}
  191. >
  192. {orderButton1}
  193. </Button>
  194. <Button
  195. style={styles.footerControl}
  196. onPress={() => {
  197. receivedOrder(id, true).then(res => {
  198. updateInfo(res);
  199. });
  200. }}
  201. appearance="outline"
  202. >
  203. {orderButton2}
  204. </Button>
  205. </Layout>
  206. );
  207. }
  208. return null;
  209. };
  210. const orderGoodsSpecsShowInfo = getGoodsInfo(orderGoodsSpecs || []);
  211. return (
  212. <Card appearance="orderCard" disabled style={[style]} footer={Footer}>
  213. {riderStatus ? (
  214. <Text>
  215. 骑手
  216. {getWordsStr(riderStatus)}
  217. </Text>
  218. ) : (
  219. <Text>
  220. 商家
  221. {getWordsStr(merchantStatus)}
  222. </Text>
  223. )}
  224. <Layout style={styles.orderItem1}>
  225. <Text category="c2">{id}</Text>
  226. <Text category="c2">
  227. {orderInfo2}:{orderTime}
  228. </Text>
  229. </Layout>
  230. <Layout style={styles.orderItem1}>
  231. <Text category="h6">{user.nickname}</Text>
  232. <Text category="h6">{getWordsStr(payMethod)}</Text>
  233. </Layout>
  234. <Layout style={styles.orderItem1}>
  235. <Text category="c2">{user.phone}</Text>
  236. <Button
  237. appearance="outline"
  238. onPress={() => {
  239. Linking.openURL(`tel:+${user.phone}`);
  240. }}
  241. >
  242. {orderInfo3}
  243. </Button>
  244. </Layout>
  245. <Layout style={styles.orderItem2}>
  246. <Text category="c2" style={styles.leftText}>
  247. {orderInfo4}
  248. </Text>
  249. <Text category="h1">{userAddress}</Text>
  250. </Layout>
  251. <Layout style={styles.orderItem2}>
  252. <Text category="c2" style={styles.leftText}>
  253. {orderInfo5}
  254. </Text>
  255. <Layout style={styles.lay}>
  256. <MenuGroup
  257. appearance="orderProduct"
  258. title={() => MenuTitle(orderGoodsSpecsShowInfo.name, realAmount)}
  259. style={styles.menuGroup}
  260. >
  261. <MenuItem
  262. disabled
  263. style={styles.menuItem}
  264. title={lsitMenu(orderGoodsSpecsShowInfo.list)}
  265. />
  266. </MenuGroup>
  267. </Layout>
  268. </Layout>
  269. <Layout style={styles.orderItem2}>
  270. <Text category="c2" style={styles.leftText}>
  271. {orderInfo6}:
  272. </Text>
  273. <Text category="h1">{remark || "无"}</Text>
  274. </Layout>
  275. </Card>
  276. );
  277. }