Authored by 孙凯

add add coupon review by hongmo

... ... @@ -24,15 +24,22 @@ export default class AddCoupon extends Component {
constructor(props) {
super(props);
this.textInputChange = this.textInputChange.bind(this);
this.state = {
disable: true,
text: '',
};
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
textInputChange(event) {
let dis = true;
if (event.nativeEvent.text) {
dis = false;
}
this.setState({
disable: dis,
text: event.nativeEvent.text,
});
}
render() {
... ... @@ -43,31 +50,33 @@ export default class AddCoupon extends Component {
let needShowToast = data?data.showMessage:false;
let message = data?data.message:false;
console.log(data);
return (
<View style={styles.container}>
<TextInput
autoCapitalize="none"
clearButtonMode="always"
placeholder={'输入优惠劵码'}
onChange={this.props.updateValue}
style={styles.textInput}
maxLength={50}
underlineColorAndroid="transparent"
onFocus={() => {
//this.props.onFocus && this.props.onFocus(refId);
}}
/>
<TouchableOpacity activeOpacity={1}
onPress={() => {
// this.props.onPressUseNow && this.props.onPressUseNow(resource)
}}
>
<View style={{marginTop: 10,marginLeft: 10,width: 70,height: 35 * DEVICE_WIDTH_RATIO,backgroundColor: 'red',borderRadius: 5,alignItems: 'center',justifyContent: 'center'}}>
<Text style={styles.text}>确定</Text>
</View>
</TouchableOpacity>
<View style={styles.contentContainer}>
<TextInput
multiline={true}
autoCapitalize={'none'}
clearButtonMode={'always'}
placeholder={'输入优惠劵码'}
onChange={this.textInputChange}
style={styles.textInput}
maxLength={50}
underlineColorAndroid="transparent"
/>
<TouchableOpacity activeOpacity={1}
onPress={() => {
if (!this.state.disable) {
let dismissKeyboard = require('dismissKeyboard');
dismissKeyboard();
this.props.onPressOK && this.props.onPressOK(this.state.text)
}
}}
>
<View style={{marginTop: 10,marginLeft: 10,width: 70,height: 35 * DEVICE_WIDTH_RATIO,backgroundColor: this.state.disable?'gray':'red',borderRadius: 5,alignItems: 'center',justifyContent: 'center'}}>
<Text style={styles.text}>确定</Text>
</View>
</TouchableOpacity>
</View>
{needShowToast ? <Prompt
text={message}
duration={1000}
... ... @@ -86,6 +95,9 @@ const DEVICE_WIDTH_RATIO = width / 320;
let styles = StyleSheet.create({
container: {
flex: 1,
},
contentContainer: {
flexDirection: 'row',
},
textInput: {
... ...
... ... @@ -45,23 +45,22 @@ class AddCouponContainer extends Component {
constructor(props) {
super(props);
this.resetReceiveCouponResult=this.resetReceiveCouponResult.bind(this);
this.updateValue = this.updateValue.bind(this);
this.onPressOK = this.onPressOK.bind(this);
}
componentDidMount() {
// this.props.actions.addCoupon('aaaaaaaaa');
}
componentWillUnmount() {
}
resetReceiveCouponResult() {
this.props.actions.resetReceiveCouponResult();
onPressOK(coupon_code){
this.props.actions.addCoupon(coupon_code);
}
updateValue(event) {
console.log(event);
resetReceiveCouponResult() {
this.props.actions.resetReceiveCouponResult();
}
render() {
... ... @@ -71,7 +70,7 @@ class AddCouponContainer extends Component {
<AddCoupon
resource={addCoupon}
resetReceiveCouponResult={this.resetReceiveCouponResult}
updateValue={this.updateValue}
onPressOK={this.onPressOK}
/>
</View>
);
... ...