Advertisement
saljuputih

Untitled

Sep 5th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. TextInput,
  6. Left,
  7. right,
  8. ScrollView,
  9. AsyncStorage,
  10. TouchableOpacity,
  11. View,
  12. ToastAndroid,
  13. } from 'react-native';
  14. import axios from 'axios';
  15. import DeviceInfo from 'react-native-device-info';
  16. import { StackActions, NavigationActions } from 'react-navigation';
  17. import jsSHA512 from 'js-sha512';
  18. import moment from 'moment';
  19. import { BASE_URL, COLOR } from 'app/src/config/variable.js';
  20.  
  21. // Relative Path
  22. // import BeritaItem from '../components/BeritaItem.js';
  23. // Absolute Path
  24. import OprItem from 'app/src/components/OprItem.js';
  25.  
  26. export default class Transaksi extends Component {
  27. constructor(props) {
  28. super(props);
  29.  
  30. this.state = {
  31. ApiType: 'GetVoc',
  32. DeviceId: DeviceInfo.getUniqueID(),
  33. UserName: '',
  34. Password: '',
  35. DateTime: moment().format("YYYYMMDDHHmmss"),
  36. Signature: jsSHA512.hmac(DeviceInfo.getUniqueID(), moment().format("YYYYMMDDHHmmss") + 'GetVoc'),
  37. Opr: this.props.navigation.state.params.opr,
  38. pricelist: [],
  39. Msisdn: '',
  40. }
  41. }
  42.  
  43. detailBerita() {
  44. alert('detail berita');
  45. }
  46.  
  47. getMovies() {
  48. const movies = axios.get('https://facebook.github.io/react-native/movies.json');
  49. console.error('test')
  50. }
  51.  
  52. async componentDidMount() {
  53.  
  54. const hmac = jsSHA512.hmac(this.state.DeviceId, this.state.DateTime + this.state.ApiType);
  55. this.setState({Signature: hmac});
  56.  
  57. const getList = await axios.post(BASE_URL, this.state);
  58.  
  59. if (getList.data.ResponseCode == '000') {
  60. this.setState({pricelist: getList.data.Data})
  61. }else {
  62. alert(getList.data.Messages);
  63. }
  64.  
  65. console.warn(JSON.stringify(getList.data));
  66. }
  67.  
  68. async beliPulsa(vtype) {
  69. if (this.state.Msisdn === ""){
  70. ToastAndroid.show("No. HP wajib di isi", ToastAndroid.SHORT);
  71. return false;
  72. }
  73.  
  74. this.setState({
  75. ApiType: 'TOPUP',
  76. Product: vtype,
  77. })
  78.  
  79. // const token = await AsyncStorage.getItem("token");
  80. const hmac = jsSHA512.hmac(this.state.DeviceId, this.state.DateTime + this.state.ApiType);
  81. this.setState({Signature: hmac});
  82.  
  83. const postBeliPulsa = await axios.post(BASE_URL,this.state);
  84. if (postBeliPulsa.data.ResponseCode == '000'){
  85.  
  86. }else{
  87. ToastAndroid.show(postBeliPulsa.data.Messages, ToastAndroid.SHORT);
  88. }
  89.  
  90. console.warn(JSON.stringify(postBeliPulsa.data));
  91. }
  92.  
  93. render() {
  94. const that = this;
  95. const {navigate} = this.props.navigation;
  96. return (
  97. <View style={{flex: 1, backgroundColor: 'blue'}}>
  98. <View style={{flexDirection: 'row', flex: 0.10, alignSelf: 'center'}}>
  99. <Text style={{fontSize: 20, fontWeight: 'bold', paddingLeft: 10, paddingTop:5}}></Text>
  100. <Text style={{fontSize: 20, fontWeight: 'bold', paddingTop:5}}>{this.state.Opr}</Text>
  101. </View>
  102. <View style={{flexDirection: 'row', flex: 0.10}}>
  103. <TextInput
  104. style={{width: '100%', fontSize:20, height: 50, backgroundColor: '#F5FCFF'}}
  105. placeholder="Masukkan Nomor Yang Diisi"
  106. keyboardType='numeric'
  107. value={this.state.Msisdn}
  108. onChangeText={(text) => this.setState({Msisdn: text})}
  109. />
  110. </View>
  111. <View style={{flex: 0.80, backgroundColor: 'white'}}>
  112. <ScrollView>
  113. {this.state.pricelist.map(function(value, index) {
  114. return (
  115. <TouchableOpacity
  116. key={index}
  117. style={styles.priceItem}
  118. onPress={() => navigate('DetilPage', {vtype: value.vtype, opr: this.state.Opr, msisdn: this.state.Msisdn, ket: value.ket})}
  119. >
  120.  
  121. <Text style={{fontSize: 15, fontWeight: 'bold', paddingLeft: 10, paddingTop:5, color:'blue'}}>{value.ket}</Text>
  122. <Text style={{fontSize: 15, fontWeight: 'bold', paddingLeft: 10, paddingTop:5, color:'green', textAlign: 'right'}}>Rp. {value.harga1}</Text>
  123. </TouchableOpacity>
  124. )
  125. })}
  126. </ScrollView>
  127. </View>
  128. </View>
  129. );
  130. }
  131. }
  132.  
  133. Transaksi.navigationOptions = {
  134. //header: null
  135. title: "PILIH NOMINAL"
  136. }
  137.  
  138. const styles = StyleSheet.create({
  139. container: {
  140. flex: 1,
  141. backgroundColor: '#F5FCFF',
  142. },
  143. kolom_menu: {
  144. flexDirection: 'row',
  145. flexWrap: 'wrap'
  146. },
  147. priceItem:{
  148. borderBottomWidth : 2,
  149. borderBottomColor : '#ccc',
  150. padding : 10,
  151. }
  152. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement