Comment.js 9.02 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
} from "react-native";
import dismissKeyboard from 'react-native/Libraries/Utilities/dismissKeyboard';
import {NavigationActions,StackActions} from 'react-navigation'

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 })=>({
    });
    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||"审批意见",
            isBack:true
        });

        _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=false;
                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=()=>{
        if (global.initParam.page){
            global.initParam.page = undefined
        }
        const resetAction = StackActions.reset({
            index: 0,
            actions: [
                NavigationActions.navigate({ routeName: 'TabNav'})
            ]
        })
        this.props.navigation.dispatch(resetAction)

    };
    render() {
        let text='';
        switch (this.status) {
            case "approve":
                text = '同意';
                break;
            case "reject":
                //拒绝
                text = '拒绝';
                break;
            case "transfer":
                text = '转交';
                break;
            //回退
            case "untread":
                text = '回退';

                break;
        }
        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>
                <TouchableOpacity onPress={()=>this.doSave()} style={{width:'70%',height:44,marginTop:10,backgroundColor:global.homeColor,justifyContent:'center',alignItems: "center",borderRadius:4}}>
                    <Text style={{color:'#fff'}}>确认{text}</Text>
                </TouchableOpacity>
            </View>
        );
    }

}

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

});