CommentReward.js
8.94 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import React, {Component} from 'react';
import {Animated, Image, Modal, StatusBar, StyleSheet, Text, TextInput, TouchableOpacity, View} from 'react-native';
import {height, width, zoomH, zoomW} from '../../utils/getSize';
//图片资源
const defaultIcon = require('../../img/defaultIcon.png');
const vIcon = require('../../img/v.png');
const prise = require('../../img/prise.png');
const writeIcon = require('../../img/writeIcon.png');
const emj = require('../../img/emj.png');
const forwarding = require('../../img/forwarding.png');
const reward = require('../../img/reward.png');
const close = require('../../img/close.png');
/**
* 详情-打赏弹窗
*/
export default class CommentReward extends Component {
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {
showRewardModal:false,//打赏弹框
rewardCheckedNum:1,//打赏选中金额
rewardInputNum:"",//打赏输入的金额
};
}
//设置打赏选中数目
changeRewardNum(num){
this.setState({
rewardCheckedNum:num,
});
}
//打赏
openRewardModal (){
this.setState({
showRewardModal: true
},function () {
StatusBar.setBackgroundColor("rgba(0,0,0,0.50)");
});
}
//打赏支付
rewardPay(){
if(this.state.rewardInputNum.replace(/(^\s*)/g,"").length == 0 && this.state.rewardCheckedNum == -1){
//没有打赏
alert("请选择打赏金额");
return;
}
if (this.state.rewardCheckedNum ==-1 && Number(this.state.rewardInputNum.replace(/(^\s*)/g,"")) < 0.01){
//选择输入金额,但是小于0.01
alert("打赏金额不能小于0.01元");
return ;
}
if (this.state.rewardCheckedNum ==-1 && Number( this.state.rewardInputNum.replace(/(^\s*)/g,"")) > 1000){
//选择输入金额,但是大于1000
alert("打赏金额不能大于1000元");
return ;
}
let money = 0;
if (this.state.rewardCheckedNum !=-1){
//选择固定金额
money = this.state.rewardCheckedNum ;
}else {
money = Number( this.state.rewardInputNum);
}
//选择输入金额
// alert("打赏"+money);
this.closeRewardModal();
this.props.callback(money);
};
/*模态框取消操作*/
closeRewardModal() {
this.setState({
showRewardModal: false,
rewardCheckedNum:1,//打赏选中金额
rewardInputNum:"",//打赏输入的金额
},function(){StatusBar.setBackgroundColor("#B0B1B1");});
};
render() {
return (
<Modal animationType={'none'} visible={this.state.showRewardModal} transparent={true}
onRequestClose={() => this.closeRewardModal()}>
<View activeOpacity={1} style={styles.modalBg}>
<Animated.View style={{
width: '100%',
height:'100%',
paddingLeft:40/zoomW,
paddingRight:40/zoomW,
justifyContent:'center',
alignItems:'center'
}}>
<View style={{width: '100%',height:'60%', backgroundColor: '#fff',padding:20/zoomW}}>
<View style = {styles.commonSpaceBetween}>
<Text style = {{fontSize:12,color:'#000000'}}>请选择打赏金额: </Text>
<TouchableOpacity activeOpacity={0.8} onPress = {() => this.closeRewardModal()}>
<Image style={{width:10/zoomH,height:10/zoomH}} source={close} resizeMode="cover" />
</TouchableOpacity>
</View>
<View style = {[styles.commonSpaceBetween,{marginTop:20/zoomH}]}>
<TouchableOpacity style = {this.state.rewardCheckedNum == 1?styles.checkedBg:[styles.uncheckedBg,{width:'48%'}]}
onPress= {() => {this.changeRewardNum(1)}} activeOpacity={0.8}>
<Text style = {{fontSize:14,color:'#000000'}}>1元</Text>
</TouchableOpacity>
<TouchableOpacity style = {this.state.rewardCheckedNum == 3?styles.checkedBg:[styles.uncheckedBg,{width:'48%'}]}
onPress= {() => {this.changeRewardNum(3)}} activeOpacity={0.8}>
<Text style = {{fontSize:14,color:'#000000'}}>3元</Text>
</TouchableOpacity>
</View>
<View style = {styles.commonSpaceBetween}>
<TouchableOpacity style = {this.state.rewardCheckedNum == 5?styles.checkedBg:[styles.uncheckedBg,{width:'48%'}]}
onPress= {() => {this.changeRewardNum(5)}} activeOpacity={0.8}>
<Text style = {{fontSize:14,color:'#000000'}}>5元</Text>
</TouchableOpacity>
<TouchableOpacity style = {this.state.rewardCheckedNum == 10?styles.checkedBg:[styles.uncheckedBg,{width:'48%'}]}
onPress= {() => {this.changeRewardNum(10)}} activeOpacity={0.8}>
<Text style = {{fontSize:14,color:'#000000'}}>10元</Text>
</TouchableOpacity>
</View>
<Text style = {{fontSize:12,color:'#000000',marginTop:20/zoomH}}>土豪请随意:</Text>
<View style ={[styles.uncheckedBg,{width:'100%',flexDirection:'row',justifyContent:'flex-start'}]}>
<Text style = {{color:'#000000'}}>¥</Text>
<TextInput ref="text" blurOnSubmit = {false} underlineColorAndroid="transparent" value={this.state.rewardInputNum}
style = {{height:'100%',width:'100%',marginLeft:5/zoomW,padding:0}} placeholder='' maxLength={4} keyboardType={'numeric'}
onChangeText={(value) => {this.setState({rewardInputNum:value,rewardCheckedNum:-1})}} />
</View>
<View style = {{flexDirection:'row',justifyContent:'flex-end'}}>
<TouchableOpacity style = {styles.disablePay} onPress = {() => this.closeRewardModal()}>
<Text style = {{fontSize:14,color:'#000000'}}>取消</Text>
</TouchableOpacity>
<TouchableOpacity onPress = {()=>{this.rewardPay()}}
style = {this.state.rewardCheckedNum!=-1 || this.state.rewardInputNum !=''? styles.canPay:styles.disablePay}>
<Text style = {{fontSize:14,color:'#000000'}}>确认支付</Text>
</TouchableOpacity>
</View>
</View>
</Animated.View>
</View>
</Modal>
);
}
}
const styles = StyleSheet.create({
modalBg: {
width: width,
height: height,
backgroundColor: 'rgba(0,0,0,.5)',
display: 'flex',
alignItems: 'center'
},
settingItem: {
width: '100%',
height: (50 / zoomH),
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
},
commonSpaceBetween:{
width:'100%',
flexDirection:'row',
justifyContent:'space-between',
alignItems:'center'
},
checkedBg:{
width:'48%',
height:40/zoomH,
marginTop:10/zoomH,
alignItems:'center',
justifyContent:'center',
borderColor:'#fc0000',
borderWidth:StyleSheet.hairlineWidth
},
uncheckedBg:{
height:40/zoomH,
marginTop:10/zoomH,
alignItems:'center',
justifyContent:'center',
borderColor:'#c3c3c3',
borderWidth:StyleSheet.hairlineWidth
},
disablePay:{
height:40/zoomH,
marginTop:10/zoomH,
alignItems:'center',
justifyContent:'center',
borderColor:'#c3c3c3',
paddingLeft:15/zoomW,
paddingRight:15/zoomW,
marginLeft:20/zoomW,
borderWidth:StyleSheet.hairlineWidth
},
canPay:{
height:40/zoomH,
marginTop:10/zoomH,
alignItems:'center',
justifyContent:'center',
borderColor:'#Fc0000',
paddingLeft:15/zoomW,
paddingRight:15/zoomW,
marginLeft:20/zoomW,
borderWidth:StyleSheet.hairlineWidth
},
});