Review.js
8.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import React, { Component } from 'react';
import {Image, View, Text, StyleSheet,ScrollView,TouchableOpacity,Dimensions } from 'react-native';
import CouponeItem from '../CouponItem'
import StampItem from '../StampItem'
import Star from '../Star'
import ReviewItem from '../ReviewItem'
import {get} from 'axios'
import { SERVER } from '../../common/servername';
import AsyncStorage from '@react-native-community/async-storage';
import Loading from './Loading'
export default class AddTab extends Component {
static navigationOptions = {
headerShown: false
}
state = {
current:1,
id:0,
review:[],
user:{},
rating_1:0,
rating_2:0,
rating_3:0,
rating_4:0,
rating_5:0,
store:{},
loading:true
}
constructor(props) {
super(props)
}
componentDidMount() {
AsyncStorage.getItem('user',(err,res) => {
this.setState({
user:JSON.parse(res)
})
})
if(this.props.navigation.state.params) {
this.setState({
id:this.props.navigation.state.params.id
},() => {
get(`http://${SERVER}/reviews/${this.state.id}`).then(res=> {
this.setState({
review:res.data.data,
rating_1:res.data.data.filter((e,i) => e.reviewGrade==1).length,
rating_2:res.data.data.filter((e,i) => e.reviewGrade==2).length,
rating_3:res.data.data.filter((e,i) => e.reviewGrade==3).length,
rating_4:res.data.data.filter((e,i) => e.reviewGrade==4).length,
rating_5:res.data.data.filter((e,i) => e.reviewGrade==5).length,
})
})
get(`http://${SERVER}/stores/${this.state.id}`).then(res => {
this.setState({
store:res.data.data[0],
})
setTimeout(() => {
this.setState({
loading:false
})
}, 500);
})
})
}
}
render() {
const rating = this.state.store.rating
const reviewCount = this.state.store.reviewCount
return (
<View style={{backgroundColor:"white",height:"100%"}}>
<View style={{width:"100%",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,backgroundColor:"#615F5F"}}>
<TouchableOpacity onPress={() => this.props.navigation.goBack(null)}>
<Image source={require('../../assets/back.png')}/>
</TouchableOpacity>
<Text style={{color:"white",fontSize:16,marginLeft:16}}>
평점 및 리뷰
</Text>
</View>
{this.state.loading?<Loading/>:
<ScrollView style={{paddingLeft:16,paddingRight:16,paddingTop:16,backgroundColor:"white"}}>
<View style={{flexDirection:"row",marginBottom:16}}>
<Image style={{width:"30%",height:Dimensions.get("screen").width*0.15}} resizeMode="contain" source={require('../../assets/img.png')}/>
<Text style={{fontSize:15,color:"black",alignSelf:"center"}}>
{this.state.store.name}
</Text>
</View>
<View style={{flexDirection:"row"}}>
<View style={{width:"30%"}}>
<Text style={{textAlign:"center",fontSize:40,fontWeight:"bold",color:"black"}}>
{rating}{rating==1|| rating==2 || rating==3 || rating==4 || rating==5?".0":""}
</Text>
<Star style={{flexDirection:"row",justifyContent:"center",marginTop:5,marginBottom:4.3}} navigation={this.props.navigation} item={this.state.store.rating} />
<View>
<Text style={{textAlign:"center",fontSize:11,color:"#615F5F"}}>
{this.state.review.length}
</Text>
</View>
</View>
<View style={{width:"50%",marginLeft:70}}>
<View style={{flexDirection:"row",marginBottom:8}}>
<Text style={{marginRight:8, fontSize:9,color:"black"}}>
5
</Text>
<View style={{backgroundColor:"#F1F1F1",borderRadius:15,width:"80%",height:15 }}>
<View style={[{backgroundColor:"#FFD63A",width:this.state.rating_5/this.state.review.length*100+"%",height:"100%",borderRadius:15},this.state.review.length==0?{width:0}:undefined]}>
</View>
</View>
</View>
<View style={{flexDirection:"row",marginBottom:8}}>
<Text style={{marginRight:8, fontSize:9,color:"black"}}>
4
</Text>
<View style={{backgroundColor:"#F1F1F1",borderRadius:15,width:"80%",height:15 }}>
<View style={[{backgroundColor:"#FFD63A",width:this.state.rating_4/this.state.review.length*100+"%",height:"100%",borderRadius:15},this.state.review.length==0?{width:0}:undefined]}>
</View>
</View>
</View>
<View style={{flexDirection:"row",marginBottom:8}}>
<Text style={{marginRight:8, fontSize:9,color:"black"}}>
3
</Text>
<View style={{backgroundColor:"#F1F1F1",borderRadius:15,width:"80%",height:15 }}>
<View style={[{backgroundColor:"#FFD63A",width:this.state.rating_3/this.state.review.length*100+"%",height:"100%",borderRadius:15},this.state.review.length==0?{width:0}:undefined]}>
</View>
</View>
</View>
<View style={{flexDirection:"row",marginBottom:8}}>
<Text style={{marginRight:8, fontSize:9,color:"black"}}>
2
</Text>
<View style={{backgroundColor:"#F1F1F1",borderRadius:15,width:"80%",height:15 }}>
<View style={[{backgroundColor:"#FFD63A",width:this.state.rating_2/this.state.review.length*100+"%",height:"100%",borderRadius:15},this.state.review.length==0?{width:0}:undefined]}>
</View>
</View>
</View>
<View style={{flexDirection:"row",marginBottom:8}}>
<Text style={{marginRight:8, fontSize:9,color:"black"}}>
1
</Text>
<View style={{backgroundColor:"#F1F1F1",borderRadius:15,width:"80%",height:15 }}>
<View style={[{backgroundColor:"#FFD63A",width:this.state.rating_1/this.state.review.length*100+"%",height:"100%",borderRadius:15},this.state.review.length==0?{width:0}:undefined]}>
</View>
</View>
</View>
</View>
</View>
<View style={{marginTop:24}}>
{this.state.review.map((e,i) => <ReviewItem item={e} user={this.state.user} store={this.state.store}/>)}
</View>
</ScrollView>}
<View style={{zIndex:10,marginTop:20,bottom:0,width:"100%"}}>
<TouchableOpacity onPress={() => this.props.navigation.navigate("WriteReview",{id:this.state.id})} style={{backgroundColor:"#f4cd37",padding:20}}>
<Text style={{textAlign:"center",fontSize:15,fontWeight:"bold",color:"black"}}>
리뷰쓰기
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});