No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

696 líneas
22 KiB

  1. import React, { Component } from "react";
  2. import { StyleSheet, Text, View, Image, TouchableOpacity,ImageBackground } from "react-native";
  3. import {
  4. Container,
  5. Header,
  6. Content,
  7. Left,
  8. Body,
  9. Right,
  10. Title,
  11. Button,
  12. Icon,
  13. Row,
  14. Col,
  15. List,
  16. ListItem,
  17. Footer,
  18. Radio,
  19. Card,
  20. } from "native-base";
  21. import * as colors from "../assets/css/Colors";
  22. import ProgressCircle from "react-native-progress-circle";
  23. import { Divider } from "react-native-elements";
  24. import Moment from "moment";
  25. import axios from "axios";
  26. import {
  27. tablet,
  28. cancelation_reasons,
  29. api_url,
  30. cancel_order,
  31. font_description,
  32. font_title,
  33. order_details,
  34. api_url1,
  35. } from "../config/Constants";
  36. import { Button as Btn } from "react-native-elements";
  37. import { Loader } from "../components/GeneralComponents";
  38. import Dialog, {
  39. DialogTitle,
  40. SlideAnimation,
  41. DialogContent,
  42. DialogFooter,
  43. DialogButton,
  44. } from "react-native-popup-dialog";
  45. import { fb } from "../config/firebaseConfig";
  46. export default class OrderDetails extends Component<Props> {
  47. constructor(props) {
  48. super(props);
  49. // this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
  50. // this.open_dialog = this.open_dialog.bind(this);
  51. this.state = {
  52. data: this.props.route.params.data,
  53. products: this.props.route.params.data.product,
  54. TotalPrice: "",
  55. // isDialogVisible:false,
  56. // isLoding:false,
  57. // reasons:[],
  58. // selected_reason:1
  59. };
  60. // this.get_reasons();
  61. // this.booking_sync();
  62. }
  63. // booking_sync = () =>{
  64. // fb.ref('/customers/'+global.id+'/orders/'+this.state.data.id).on('value', snapshot => {
  65. // if(snapshot.val().status != this.state.data.status){
  66. // this.get_order_details();
  67. // }
  68. // });
  69. // }
  70. payNow = async () => {
  71. // await axios
  72. // .patch(
  73. // `${api_url1}/order/update_orderStatus`,
  74. // { id: this.state.data._id, status: "paid", payment: "true" },
  75. // { headers: { Authorization: `Bearer ${global.fcm_token}` } }
  76. // )
  77. // .then((res) => {
  78. // console.log(res);
  79. // alert("Payment Success");
  80. // })
  81. // .then(this.props.navigation.navigate("MyOrders"))
  82. // .then(this.props.navigation.navigate("Payment"))
  83. // .catch((error) => alert(error));
  84. this.props.navigation.navigate("Payment", { data: this.state.data });
  85. };
  86. cancelNow = async () => {
  87. await axios
  88. .patch(
  89. `${api_url1}/order/update_orderStatus`,
  90. { id: this.state.data._id, status: "cancelled" },
  91. { headers: { Authorization: `Bearer ${global.fcm_token}` } }
  92. )
  93. .then((res) => {
  94. console.log(res);
  95. alert("Order Cancelled");
  96. })
  97. .then(this.props.navigation.navigate("MyOrders"));
  98. // .catch((error) => alert(error));
  99. };
  100. // get_order_details = async () => {
  101. // this.setState({ isLoding : true });
  102. // await axios({
  103. // method: 'post',
  104. // url: api_url + order_details,
  105. // data: { id : this.state.data.id }
  106. // })
  107. // .then(async response => {
  108. // this.setState({ isLoding : false, data:response.data.result });
  109. // })
  110. // .catch(error => {
  111. // this.setState({ isLoding : false });
  112. // });
  113. // }
  114. // get_reasons = async() =>{
  115. // this.setState({ isLoding:true });
  116. // await axios({
  117. // method: "get",
  118. // url: api_url + cancelation_reasons
  119. // })
  120. // .then(async (response) => {
  121. // this.setState({ isLoding:false });
  122. // this.setState({ reasons : response.data.result });
  123. // })
  124. // .catch((error) => {
  125. // this.setState({ isLoding:false });
  126. // alert("Something went wrong");
  127. // });
  128. // }
  129. // cancel_order = async() =>{
  130. // this.setState({ isLoding:true, isDialogVisible:false });
  131. // await axios({
  132. // method: "post",
  133. // url: api_url + cancel_order,
  134. // data:{ order_id : this.state.data.id }
  135. // })
  136. // .then(async (response) => {
  137. // this.setState({ isLoding:false });
  138. // let data = this.state.data;
  139. // data.status = response.data.result.id;
  140. // data.label_name = response.data.result.label_name;
  141. // this.setState({ data : data });
  142. // })
  143. // .catch((error) => {
  144. // this.setState({ isLoding:false });
  145. // alert("Something went wrong");
  146. // });
  147. // }
  148. // open_dialog = () =>{
  149. // this.setState({ isDialogVisible: true })
  150. // }
  151. // change_reason = (reason) =>{
  152. // this.setState({ selected_reason : reason });
  153. // }
  154. handleBackButtonClick = () => {
  155. this.props.navigation.goBack(null);
  156. };
  157. render() {
  158. return (
  159. <Container>
  160. <View>
  161. <View style={styles.od_style1}>
  162. <TouchableOpacity
  163. style={styles.od_style2}
  164. onPress={this.handleBackButtonClick}
  165. activeOpacity={1}
  166. >
  167. <Icon
  168. onPress={this.handleBackButtonClick}
  169. style={styles.od_style3}
  170. name="arrow-back"
  171. />
  172. </TouchableOpacity>
  173. <View style={styles.od_style4} />
  174. <Text style={styles.od_style5}>
  175. {this.state.data.vendor.userName}
  176. </Text>
  177. </View>
  178. </View>
  179. <Content>
  180. <Row>
  181. <Body>
  182. <View style={{ flexDirection: "row" }}>
  183. {/* <Text style={styles.od_style6}>
  184. Status - {this.state.data.status}
  185. </Text> */}
  186. {/* {if(this.state.data.status== 'processing')
  187. { */}
  188. {/* <View
  189. style={{
  190. // backgroundColor: "red",
  191. padding: 10,
  192. borderRadius: 12,
  193. }}
  194. >
  195. <Text
  196. style={{ color: "white" }}
  197. >
  198. {this.state.data.status}
  199. </Text>
  200. </View>
  201. {/* } */}
  202. </View>
  203. <Text style={styles.od_style6}>
  204. Order Id - {this.state.data._id}
  205. </Text>
  206. <Text style={styles.od_style7}>
  207. {Moment(this.state.data.created_at).format("DD MMM-YYYY hh:mm")}
  208. </Text>
  209. </Body>
  210. </Row>
  211. <Row style={styles.od_style8}>
  212. <Body>
  213. <ImageBackground
  214. source={{uri:this.state.data.prescription}}
  215. resizeMode="cover"
  216. style={{flex:1,height:244,width:'100%'}}
  217. >
  218. </ImageBackground>
  219. {/* <ProgressCircle
  220. percent={this.state.data.vendor.status * 16.666}
  221. radius={60}
  222. borderWidth={3}
  223. color={colors.theme_fg}
  224. shadowColor="#e6e6e6"
  225. bgColor="#FFFFFF"
  226. > */}
  227. {/* <View style={styles.od_style9}>
  228. <Image style={styles.od_style10} source={tablet} />
  229. </View>
  230. </ProgressCircle> */}
  231. {/* <Text style={styles.od_style11}>{this.state.data.label_name}</Text> */}
  232. </Body>
  233. </Row>
  234. <Divider style={styles.od_style12} />
  235. <Row style={styles.od_style13}>
  236. <Left>
  237. <Text style={styles.od_style14}>Delivery Address -</Text>
  238. <Text style={styles.od_style15} />
  239. </Left>
  240. <Right>
  241. <Text style={styles.od_style18}>
  242. {" "}
  243. {this.state.data.vendor.address}
  244. </Text>
  245. </Right>
  246. </Row>
  247. <Row style={styles.od_style16}>
  248. <Left>
  249. <Text style={styles.od_style17}>Payment Mode -</Text>
  250. </Left>
  251. <Right>
  252. <Text style={styles.od_style18}>
  253. {this.state.data.paymentMode}
  254. </Text>
  255. </Right>
  256. </Row>
  257. <View style={styles.od_style19} />
  258. <Divider style={styles.od_style20} />
  259. <Row style={styles.od_style21}>
  260. <Left>
  261. <Text style={styles.od_style22}>Your items:</Text>
  262. </Left>
  263. </Row>
  264. <List>
  265. {this.state.products.map((row, index) => (
  266. <ListItem>
  267. <Row>
  268. <Col style={styles.od_style23}>
  269. <Text style={styles.od_style24}>{row.product.title}</Text>
  270. </Col>
  271. <Col>
  272. <Text style={styles.od_style25}>
  273. {row.product.description}
  274. </Text>
  275. </Col>
  276. <Col style={styles.od_style26}>
  277. <Text style={styles.od_style27}>
  278. {global.currency}
  279. {row.product.price}
  280. </Text>
  281. {/* {this.setState({TotalPrice:(row.product.price)})} */}
  282. </Col>
  283. </Row>
  284. </ListItem>
  285. ))}
  286. </List>
  287. <Row style={styles.od_style28}>
  288. <Col>
  289. <Text style={styles.od_style29}>Subtotal -</Text>
  290. </Col>
  291. <Col style={styles.od_style30}>
  292. {/* <Text style={styles.od_style31} >{global.currency}{this.state.data.sub_total}</Text> */}
  293. </Col>
  294. <Right>
  295. <Text style={styles.od_style41}>-</Text>
  296. </Right>
  297. </Row>
  298. <Row style={styles.od_style32}>
  299. <Col>
  300. <Text style={styles.od_style33}>Discount -</Text>
  301. </Col>
  302. <Col style={styles.od_style34}>
  303. {/* <Text style={styles.od_style35} >{global.currency}{this.state.data.discount}</Text> */}
  304. </Col>
  305. <Right>
  306. <Text style={styles.od_style41}>-</Text>
  307. </Right>
  308. </Row>
  309. <Row style={styles.od_style36}>
  310. <Col>
  311. <Text style={styles.od_style37}>Delivery Charge -</Text>
  312. </Col>
  313. <Col style={styles.od_style38}>
  314. {/* <Text style={styles.od_style39} >{global.currency}{this.state.data.delivery_charge}</Text> */}
  315. </Col>
  316. <Right>
  317. <Text style={styles.od_style41}>-</Text>
  318. </Right>
  319. </Row>
  320. <Row style={styles.od_style40}>
  321. <Col>
  322. <Text style={styles.od_style41}>Tax -</Text>
  323. </Col>
  324. <Col style={styles.od_style42}>
  325. {/* <Text style={styles.od_style43} >{global.currency}{this.state.data.tax}</Text> */}
  326. </Col>
  327. <Right>
  328. <Text style={styles.od_style41}>-</Text>
  329. </Right>
  330. </Row>
  331. <Row style={styles.od_style40}>
  332. <Col>
  333. <Text style={styles.od_style41}>Total Amount -</Text>
  334. </Col>
  335. <Right>
  336. <Text style={styles.od_style41}>{this.state.data.amount}</Text>
  337. </Right>
  338. </Row>
  339. <View style={styles.od_style44} />
  340. <Divider style={styles.od_style45} />
  341. <Row style={styles.od_style46}>
  342. <Col />
  343. <Col style={styles.od_style48}>
  344. {/* <Text style={styles.od_style49} >{global.currency}{this.state.data.total}</Text> */}
  345. </Col>
  346. </Row>
  347. <View style={styles.od_style50} />
  348. {/* <Loader visible={this.state.isLoding} /> */}
  349. </Content>
  350. {/* {this.state.data.status <= 2 && */}
  351. {this.state.data.status == "processing" ||
  352. this.state.data.status == "new" ? (
  353. <View>
  354. <Footer style={styles.od_style511}>
  355. <View
  356. style={{
  357. flexDirection: "row",
  358. justifyContent: "space-between",
  359. }}
  360. >
  361. <Text style={styles.od_style47}>Total </Text>
  362. <Text style={styles.od_style47}>{this.state.data.amount}</Text>
  363. </View>
  364. </Footer>
  365. {this.state.data.status == "processing" &&
  366. this.state.data.payment == false ? (
  367. <Footer style={styles.od_style51}>
  368. <View style={styles.od_style52}>
  369. <Btn
  370. title="Pay now"
  371. onPress={this.payNow}
  372. buttonStyle={styles.od_style53}
  373. />
  374. </View>
  375. </Footer>
  376. ) : (
  377. <Footer style={styles.od_style51}>
  378. <View style={styles.od_style52}>
  379. <Btn
  380. title="Cancel"
  381. onPress={this.cancelNow}
  382. buttonStyle={styles.od_style53}
  383. />
  384. </View>
  385. </Footer>
  386. )}
  387. </View>
  388. ) : (
  389. <View>
  390. {this.state.data.status == "paid" && (
  391. <View
  392. style={{
  393. paddingHorizontal: 23,
  394. height: 42,
  395. alignContent: "center",
  396. alignItems: "center",
  397. justifyContent: "center",
  398. flexDirection:'row',
  399. marginVertical:12
  400. }}
  401. >
  402. <Text style={{ fontSize: 20 }}>Status -</Text>
  403. <View
  404. style={{backgroundColor:'white',padding:6,borderRadius:4,width:62,alignContent: "center",
  405. alignItems: "center",
  406. justifyContent: "center",}}
  407. >
  408. <Text style={{ fontSize: 20,color:'#4CAF50',fontWeight:'bold' }}>Paid</Text>
  409. </View>
  410. </View>
  411. )}
  412. {this.state.data.status == "cancelled" && (
  413. <View
  414. style={{
  415. paddingHorizontal: 23,
  416. height: 42,
  417. alignContent: "center",
  418. alignItems: "center",
  419. justifyContent: "center",
  420. flexDirection:'row',
  421. marginVertical:12
  422. }}
  423. >
  424. <Text style={{ fontSize: 20 }}>Status - </Text>
  425. <View
  426. style={{backgroundColor:'white',padding:6,borderRadius:4,paddingHorizontal:6,alignContent: "center",
  427. alignItems: "center",
  428. justifyContent: "center",}}
  429. >
  430. <Text style={{ fontSize: 20,color:'#f44336' }}>Cancelled</Text>
  431. </View>
  432. </View>
  433. )}
  434. {this.state.data.status == "delivered" && (
  435. <View
  436. style={{
  437. paddingHorizontal: 23,
  438. height: 42,
  439. alignContent: "center",
  440. alignItems: "center",
  441. justifyContent: "center",
  442. flexDirection:'row',
  443. marginVertical:12
  444. }}
  445. >
  446. <Text style={{ fontSize: 20 }}>Status - </Text>
  447. <View
  448. style={{backgroundColor:'white',padding:6,borderRadius:6,alignContent: "center",paddingHorizontal:6,
  449. alignItems: "center",
  450. justifyContent: "center",}}
  451. >
  452. <Text style={{ fontSize: 20,color:'#008CBA' }}>Delivered</Text>
  453. </View>
  454. </View>
  455. )}
  456. </View>
  457. )}
  458. {/* } */}
  459. <Dialog
  460. // visible={this.state.isDialogVisible}
  461. width="90%"
  462. animationDuration={100}
  463. dialogTitle={<DialogTitle title="Please select reason" />}
  464. dialogAnimation={
  465. new SlideAnimation({
  466. slideFrom: "bottom",
  467. })
  468. }
  469. footer={
  470. <DialogFooter>
  471. <DialogButton
  472. text="CLOSE"
  473. textStyle={styles.od_style54}
  474. onPress={() => {
  475. this.setState({ isDialogVisible: false });
  476. }}
  477. />
  478. <DialogButton
  479. text="OK"
  480. textStyle={styles.od_style55}
  481. // onPress={this.cancel_order.bind(this)}
  482. />
  483. </DialogFooter>
  484. }
  485. onTouchOutside={() => {
  486. // this.setState({ isDialogVisible: false });
  487. }}
  488. >
  489. <DialogContent>
  490. {/* <List>
  491. {this.state.reasons.map((row, index) => (
  492. <ListItem onPress={this.change_reason.bind(this,row.id)}>
  493. <Col>
  494. <Text style={styles.od_style56}>{row.reason}</Text>
  495. </Col>
  496. <Col style={styles.od_style57}>
  497. <Radio selectedColor={colors.theme_fg} selected={this.state.selected_reason == row.id ? true : false } />
  498. </Col>
  499. </ListItem>
  500. ))}
  501. </List> */}
  502. </DialogContent>
  503. </Dialog>
  504. {/* <Loader visible={this.state.isLoding} /> */}
  505. </Container>
  506. );
  507. }
  508. }
  509. const styles = StyleSheet.create({
  510. od_style1: { alignItems: "flex-start", margin: 10 },
  511. od_style2: { width: 100, justifyContent: "center" },
  512. od_style3: { color: colors.theme_fg_two, fontSize: 30 },
  513. od_style4: { margin: 5 },
  514. od_style5: {
  515. fontSize: 25,
  516. color: colors.theme_fg_two,
  517. fontFamily: font_title,
  518. },
  519. od_style6: {
  520. marginTop: 10,
  521. fontSize: 15,
  522. color: colors.theme_fg_two,
  523. fontFamily: font_title,
  524. },
  525. od_style7: { marginTop: 5, fontSize: 12, fontFamily: font_description },
  526. od_style8: { margin: 20 },
  527. od_style9: { height: 60, width: 60 },
  528. od_style10: { flex: 1 },
  529. od_style11: {
  530. marginTop: 10,
  531. fontSize: 13,
  532. color: colors.theme_fg,
  533. fontFamily: font_title,
  534. },
  535. od_style12: {
  536. backgroundColor: colors.theme_fg_two,
  537. width: "90%",
  538. alignSelf: "center",
  539. },
  540. od_style13: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  541. od_style14: {
  542. marginTop: 10,
  543. fontSize: 13,
  544. color: colors.theme_fg_two,
  545. fontFamily: font_title,
  546. },
  547. od_style15: { marginTop: 5, fontSize: 13, fontFamily: font_description },
  548. od_style16: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  549. od_style17: {
  550. marginTop: 10,
  551. fontSize: 13,
  552. color: colors.theme_fg_two,
  553. fontFamily: font_title,
  554. },
  555. od_style18: { marginTop: 5, fontSize: 13, fontFamily: font_description },
  556. od_style19: { marginTop: 10 },
  557. od_style20: {
  558. backgroundColor: colors.theme_fg_two,
  559. width: "90%",
  560. alignSelf: "center",
  561. },
  562. od_style21: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  563. od_style22: {
  564. marginTop: 10,
  565. fontSize: 13,
  566. color: colors.theme_fg_two,
  567. fontFamily: font_title,
  568. },
  569. od_style23: { width: 40 },
  570. od_style24: {
  571. fontSize: 15,
  572. color: colors.theme_fg,
  573. fontFamily: font_title,
  574. width: 121,
  575. },
  576. od_style25: { fontFamily: font_description },
  577. od_style26: { width: 70 },
  578. od_style27: { fontFamily: font_description },
  579. od_style28: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  580. od_style29: { fontFamily: font_title },
  581. od_style30: { width: 70 },
  582. od_style31: { fontFamily: font_title },
  583. od_style32: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  584. od_style33: { fontFamily: font_title },
  585. od_style34: { width: 70 },
  586. od_style35: { fontFamily: font_title },
  587. od_style36: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  588. od_style37: { fontFamily: font_title },
  589. od_style38: { width: 70 },
  590. od_style39: { fontFamily: font_title },
  591. od_style40: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  592. od_style41: { fontFamily: font_title },
  593. od_style42: { width: 70 },
  594. od_style43: { fontFamily: font_title },
  595. od_style44: { marginBottom: 20 },
  596. od_style45: {
  597. backgroundColor: colors.theme_fg_two,
  598. width: "90%",
  599. alignSelf: "center",
  600. },
  601. od_style46: { marginLeft: 20, marginRight: 20, marginTop: 10 },
  602. od_style47: {
  603. fontFamily: font_title,
  604. color: colors.theme_fg_two,
  605. fontSize: 18,
  606. },
  607. od_style48: { width: 80 },
  608. od_style49: {
  609. fontFamily: font_title,
  610. color: colors.theme_fg_two,
  611. fontSize: 18,
  612. },
  613. od_style50: { margin: 10 },
  614. od_style51: { backgroundColor: colors.theme_bg_three },
  615. od_style511: {
  616. backgroundColor: colors.theme_bg_three,
  617. marginVertical: -12,
  618. paddingVertical: 12,
  619. },
  620. od_style52: { width: "90%", justifyContent: "center" },
  621. od_style53: { backgroundColor: colors.theme_bg, fontFamily: font_title },
  622. od_style54: { fontSize: 16, color: colors.theme_fg_two },
  623. od_style55: { fontSize: 16, color: colors.theme_fg_two },
  624. od_style56: { fontFamily: font_description },
  625. od_style57: { width: "15%", alignItems: "flex-end" },
  626. header: {
  627. justifyContent: "flex-start",
  628. height: "10%",
  629. backgroundColor: colors.theme_bg,
  630. borderBottomLeftRadius: 45,
  631. borderBottomRightRadius: 45,
  632. shadowOffset: { width: 0, height: 15 },
  633. shadowColor: colors.theme_bg,
  634. shadowOpacity: 0.1,
  635. shadowRadius: 8,
  636. elevation: 10,
  637. },
  638. header_card: {
  639. alignItems: "center",
  640. borderRadius: 15,
  641. justifyContent: "center",
  642. },
  643. header_card_item: {
  644. borderTopLeftRadius: 15,
  645. borderTopRightRadius: 15,
  646. borderBottomLeftRadius: 15,
  647. borderBottomRightRadius: 15,
  648. shadowOffset: { width: 0, height: 15 },
  649. shadowColor: colors.theme_bg,
  650. shadowOpacity: 0.1,
  651. shadowRadius: 8,
  652. elevation: 10,
  653. },
  654. icon: {
  655. color: colors.theme_fg_two,
  656. },
  657. header_body: {
  658. flex: 3,
  659. justifyContent: "center",
  660. },
  661. title: {
  662. alignSelf: "center",
  663. color: colors.theme_fg_two,
  664. alignSelf: "center",
  665. fontSize: 16,
  666. fontFamily: font_title,
  667. },
  668. delivery_date_label: {
  669. marginTop: 10,
  670. fontSize: 13,
  671. color: colors.theme_fg_two,
  672. fontFamily: font_title,
  673. },
  674. delivery_date: {
  675. marginTop: 5,
  676. fontSize: 13,
  677. },
  678. });