Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Text, View, StyleSheet, TouchableOpacity, Image, TextInput, SafeAreaView, } from 'react-native';
  3. import { Item, Input, Icon, Left, Button, DatePicker, Picker } from 'native-base';
  4. import axios from 'axios';
  5.  
  6. class Transaksi extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. id: '',
  11. date: '',
  12. name: '',
  13. amount: ''
  14. }
  15. }
  16.  
  17. componentDidMount() {
  18. console.log(this.state);
  19. axios({
  20. method: 'get',
  21. url: 'http://192.168.1.25/selling/public/api/transactions',
  22. dataType: 'json',
  23. headers: {
  24. 'Accept': 'application/json',
  25. 'Content-Type': 'application/json'
  26. },
  27. })
  28. .then(response => {
  29. var transaction = [];
  30. for (var i = 0; i < response.data.results.transactions.length; i++) {
  31. transaction.push([
  32. response.data.results.transactions[i].id,
  33. response.data.results.transactions[i].date,
  34. response.data.results.transactions[i].name,
  35. response.data.results.transactions[i].amount,
  36. response.data
  37. ]);
  38. }
  39. });
  40. console.log(this.state.data);
  41.  
  42. axios({
  43. method: 'get',
  44. url: 'http://192.168.1.25/selling/public/api/members',
  45. dataType: 'json',
  46. headers: {
  47. 'Accept' : 'application/json',
  48. 'Content-Type' : 'application/json'
  49. },
  50. })
  51. .then(response => {
  52. var member = [];
  53. for (var i = 0; i < response.data.results.members.length; i++) {
  54. member.push([
  55. response.data.results.members[i].id,
  56. response.data.results.members[i].name,
  57. response.data.results.members[i].email,
  58. response.data.results.members[i].telp,
  59. response.data
  60. ]);
  61. }
  62.  
  63. });
  64. console.log(this.state.data);
  65. }
  66.  
  67. handleSubmit = () => {
  68. console.log(this.state)
  69. axios({
  70. method: 'post',
  71. url: 'http://192.168.1.25/selling/public/api/transactions',
  72. dataType: 'json',
  73. headers: {
  74. 'Accept': 'application/json',
  75. 'Content-type': 'application/json'
  76. },
  77. data: {
  78. date: this.state.date,
  79. name: this.state.transactions,
  80. amount: this.state.amount
  81. },
  82. })
  83. .then(function (response) {
  84. console.log(response.data);
  85. })
  86. .catch(function (error) {
  87. console.log(error);
  88. });
  89. this.setState({ date: '', name: '', amount: '' });
  90. }
  91.  
  92. // onValueChange() {
  93. // this.setState({
  94. // transactions: value
  95. // });
  96. // }
  97. formatValue(amount) {
  98. (parseFloat(amount) / 100, "$ ");
  99. }
  100.  
  101. render() {
  102. const state = this.state;
  103. return (
  104. <View style={{ flex: 2, backgroundColor: '#fff' }}>
  105. <View style={{ marginHorizontal: 17, paddingTop: 15 }}>
  106. <Text style={[
  107. styles.text, { textAlign: 'left' }, { color: '#000' },
  108. ]}>
  109. Tanggal
  110. </Text>
  111. <DatePicker
  112. locale={"en"}
  113. timeZoneOffsetInMinutes={undefined}
  114. modalTransparent={false}
  115. iosIcon={<Icon name="arrow-down" />}
  116. animationType={"slide"}
  117. androidMode={"calendar"}
  118. placeHolderText="Pilih Tanggal"
  119. underlineColorAndroid="#1171EC"
  120. onDateChange={date => this.setState({ date: date })} value={this.state.date}
  121. disabled={false}
  122. />
  123. {/* <TextInput placeholder="Pilih Tanggal" onDateChange={date => this.setState({ date })} value={this.state.date} underlineColorAndroid="#1171EC" /> */}
  124. </View>
  125. <View style={{ marginHorizontal: 17, paddingTop: 15 }}>
  126. <Text style={[
  127. styles.text, { textAlign: 'left' }, { color: '#000' },
  128. ]}>
  129. Nama
  130. </Text>
  131. <Picker
  132. selectedValue={this.state.transactions}
  133. onValueChange={(itemValue, itemIndex) =>
  134. this.setState({ transactions: itemValue })} >
  135. {this.state.table && this.state.table.map((item, key) =>
  136. <Picker.Item label={item.name} value={item.name} key={key} />
  137. )}
  138. </Picker>
  139. </View>
  140.  
  141. <View style={{ marginHorizontal: 17, paddingTop: 15 }}>
  142. <Text style={[
  143. styles.text, { textAlign: 'left' }, { color: '#000' },
  144. ]}>
  145. Jumlah
  146. </Text>
  147. <TextInput placeholder="Rp. " onDateChange={amount => this.setState({ amount })} value={this.formatValue(this.state.amount)} underlineColorAndroid="#1171EC" />
  148. </View>
  149. </View>
  150.  
  151. )
  152. }
  153. }
  154. export default Transaksi;
  155. const styles = StyleSheet.create({
  156. container: {
  157. flex: 1,
  158. alignItems: 'center',
  159. justifyContent: 'center',
  160. },
  161. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement