Advertisement
Guest User

Untitled

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