Comment.js 9.71 KB
/**
 * Created by DEV005 on 2017/11/13.
 */

/**
 * Created by tdzl2003 on 12/18/16.
 */
import React, {Component} from "react";
import {
    Image,
    ListView,
    NativeModules,
    StyleSheet,
    Text,
    TextInput,
    TouchableOpacity,
    View,
    Platform,
    RefreshControl,
    ActivityIndicator,
    ScrollView,
    Dimensions,
    Modal,
NavigationActions
} from "react-native";
import dismissKeyboard from 'react-native/Libraries/Utilities/dismissKeyboard';
import { observable, useStrict, action } from 'mobx';
import { observer } from 'mobx-react';
import {xnToast} from "../utils/utils";
import AppService from "../service/AppService";


import ApprovedLayout from './public/ApprovedLayout';
import moment from "moment";



export default class Detail extends Component {
    static navigationOptions = ({ navigation, screenProps })=>({
        title:navigation.state.params.title,
        headerLeft:(<View style={{flexDirection: 'row',flex:1}}>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:10}} onPress={navigation.state.params?navigation.state.params._goBack:null}>
                <Image style={{  width:16,height:16}}  source={require('../img/back.png')}  resizeMode="contain"/>
            </TouchableOpacity>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:15}} onPress={navigation.state.params?navigation.state.params._close:null}>
                <Image style={{  width:16,height:16}}  source={require('../img/close.png')}  resizeMode="contain"/>
            </TouchableOpacity>
        </View>),
        headerRight:(<View style={{flexDirection: 'row',flex:1}}>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:10}} onPress={navigation.state.params?navigation.state.params.doSave:null}>
                <Text style={{fontSize:16,color:"#fff"}} >确定</Text>
            </TouchableOpacity>
        </View>)
    });
    constructor(props){
        super(props);
        this.state = {
            content:"",
            placeholder:""
        };
    }
    status=this.props.navigation.state.params.status||"";
    params=this.props.navigation.state.params;
    isRequired=false;
    ajaxLoading=false;
    componentDidMount(){
        let  _this=this;
        //设置头部
        this.props.navigation.setParams({
            title:_this.params.title||"审批意见",
            _goBack:()=>{
                if(_this.params.goBackKey){
                    this.props.navigation.goBack(_this.params.goBackKey);
                }else {
                    this.props.navigation.goBack();
                }
                
            },
            _close:()=>{
                NativeModules.system.navTo("BACK")
            },
            doSave:()=>{
                this.doSave();
            }
        });

        _this.init();
    }

    init=()=>{
        let  _this=this;
        switch (_this.status){
            //通过
            case "approve":
                _this.setState({
                    placeholder:"请输入同意理由(非必填)"
                })
                _this.isRequired=false;
                break;
            // 拒绝
            case "reject":
                _this.setState({
                    placeholder:"请输入拒绝理由(必填)"
                })
                _this.isRequired=true;
                break;
            case "transfer":
                _this.setState({
                    placeholder:"请输入转交理由(非必填)"
                })
                _this.isRequired=false;
                break;
           
            //回退
            case "untread":
                _this.setState({
                    placeholder:"请输入回退理由(必填)"
                })
                _this.isRequired=true;
                break;
            //评论
            case "comment":
                _this.setState({
                    placeholder:"说点什么呗..."
                })
                _this.isRequired=true;
                break;
        }


    }

    doSave=()=>{
        let  _this=this;

        let vm={
            id:_this.params.id, //stepId
            flowId:_this.params.flowId,
            rowVersion:_this.params.rowVersion,
            tenantId:global.tenantId,
            submitDescription:_this.state.content||""
        };

        if(_this.ajaxLoading){
            return;
        }
        switch (_this.status){
            //通过
            case "approve":
                //同意
                _this.ajaxLoading=true;
                AppService.approveFlowStep(vm).then(data=> {
                    _this.ajaxLoading=false;
                    if (data.errors == null || data.errors.length > 0) {
                        xnToast(data.errors[0].message);
                        return
                    }
                    xnToast("已同意!");
                    dismissKeyboard();
                    _this.toPage()

                });

                break;
            // 拒绝
            case "reject":
                //拒绝
                if(_this.isRequired &&!vm.submitDescription){
                    xnToast("拒绝理由不能为空!")
                    return ;
                }
                _this.ajaxLoading=true;
                AppService.rejectFlowStep(vm).then(data=> {
                    _this.ajaxLoading=false;
                    if (data.errors == null || data.errors.length > 0) {
                        xnToast(data.errors[0].message);
                        return
                    }
                    xnToast("已拒绝!");
                    dismissKeyboard();
                    _this.toPage()

                });

                break;
            case "transfer":
                if(!_this.params.submitUser){
                    xnToast("提交人不能为空!");
                    return
                }
                vm.assignUserName=_this.params.submitUser.name
                vm.assignUserId=_this.params.submitUser.id,
                vm.assignReason=_this.state.content||"",

                    console.log(vm);
                _this.ajaxLoading=true;
                AppService.transferFlowStep(vm).then(data=> {
                    _this.ajaxLoading=false;
                    if (data.errors == null || data.errors.length > 0) {
                        xnToast(data.errors[0].message);
                        return
                    }
                    xnToast("已转交!");
                    dismissKeyboard();
                    _this.toPage();
                });

                break;

             
            //回退
            case "untread":
                vm.assignReason=_this.state.content||"";

                if(_this.isRequired &&!vm.assignReason){
                    xnToast("回退理由不能为空!")
                    return ;
                }

                //回退
                _this.ajaxLoading=true;
                AppService.untreadFlowStep(vm).then(data=> {
                    _this.ajaxLoading=false;
                    if (data.errors == null || data.errors.length > 0) {
                        xnToast(data.errors[0].message);
                        return
                    }
                    xnToast("已回退!");
                    dismissKeyboard();
                    _this.toPage()

                });

                break;

            //评论
            case "comment":
                let comment={
                    content:_this.state.content||"",
                    businessType:"WORKFLOW",
                    anonymous:false,
                    userId:global.userId,
                    businessId:_this.params.flowId,
                }

                if(_this.isRequired &&!comment.content){
                    xnToast("评论内容不能为空!")
                    return ;
                }

                //回退
                _this.ajaxLoading=true;
                AppService.createComment(comment).then(data=> {
                    _this.ajaxLoading=false;
                    if (data.errors == null || data.errors.length > 0) {
                        xnToast(data.errors[0].message);
                        return
                    }
                    xnToast("已评论!");
                    _this.params.callback();
                    dismissKeyboard();
                    _this.props.navigation.goBack();

                });

                break;
        }

    }

    toPage=()=>{
        this.props.navigation.navigate("Index")

        const resetAction = NavigationActions.reset({
            index: 0,
            actions: [
                NavigationActions.navigate({ routeName: 'Index'})
            ]
        })
        this.props.navigation.dispatch(resetAction)

    }
    render() {
        return (
            <View style={styles.body}>
                <View style={styles.input}>
                    <TextInput
                        placeholder={this.state.placeholder}
                        style={styles.inputArea}
                        multiline={true}
                        underlineColorAndroid="transparent"
                        onChangeText={(text)=>this.state.content = text}
                    />
                </View>
            </View>
        );
    }

}

const styles = StyleSheet.create({
    body:{
        flex:1,
        flexDirection:"column",
        backgroundColor:"#ecf0f3",
    },
    input: {
        paddingLeft:0,
        paddingTop: 15,
        paddingRight:0,
        marginBottom:15
    },
    inputArea: {
        fontSize: 14,
        height: 200,
        lineHeight:24,
        textAlignVertical: "top",
        backgroundColor:"#fff",
        padding:15
    },

});