ApprovedLayout.js 8.3 KB
/**
 *
 * Copyright 2016-present reading
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

import React ,{Component} from 'react';
import {StyleSheet, Text, View, Image, TouchableOpacity, NativeModules} from 'react-native';
import {xnToast,xnBorderWidth,toPersonalPageWithUserId} from "../../utils/utils";

import moment from "moment";

let dayTime=moment(new Date()).utc().zone(-8).format('YYYY-MM-DD');

class ApprovedLayout extends Component {
      constructor(props) {
          super(props);
          this.state = {
              submitUserName:"张三",
              processName:"张三提交的请假单",
              flowStatus:"IN_PROCESS"
          };
      }
      render() {
          const approvedList=this.props.approvedList;
          return (
              <View style={styles.approvedLayout}>
                  { approvedList.map((v, i) => this._renderRow(v, i))}
              </View>
          )
      }

    //
    _renderRow = (v, i) =>{
        const length= this.props.approvedList.length-1;
        let shotName="";
        if(v.auditUserName && v.auditUserName.length>2){
            shotName =v.auditUserName.substring(v.auditUserName.length-2)
        }else if(v.auditUserName && v.auditUserName.length>0) {
            shotName =v.auditUserName;
        }

        if(v.endTime){
            let submitTimeDay=moment(new Date(Number(v.endTime))).utc().zone(-8).format('YYYY-MM-DD');
            if(submitTimeDay!=dayTime){
                v.showMonth=moment(new Date(Number(v.endTime))).utc().zone(-8).format('MM/DD')
                v.showTime=moment(new Date(Number(v.endTime))).utc().zone(-8).format('HH:mm')
            }else{
                v.showMonth="今天";
                v.showTime=moment(new Date(Number(v.endTime))).utc().zone(-8).format('HH:mm');
            }

        }else{
            v.showTime=""
        }
        return (
            <View style={styles.approvedRow}  key={i}>
                <View style={styles.approvedTime}>
                    <Text style={styles.approvedTimeText}>{v.showTime}</Text>
                    <Text style={styles.approvedTimeText}>{v.showMonth}</Text>
                </View>
                <View style={styles.approvedLineLayout} >
                    <View style={[styles.approvedLine]}></View>
                    {v.status=="RUNNING"&&<View style={[styles.approvedLineIconActive]}></View>}
                    {v.status!="RUNNING"&&<View style={[styles.approvedLineIcon]}></View>}
                </View>
                <View style={styles.approvedBox}>

                    <TouchableOpacity style={[styles.approvedImg,{backgroundColor:global.homeColor}]} onPress={()=>{
                        if(v.status == 'START'){
                            toPersonalPageWithUserId(this.props.startUserId);
                        }else{
                            toPersonalPageWithUserId(v.auditUserId);
                        }
                    }}>
                        {!v.avatar&&<Text style={styles.approvedImgText}>{shotName}</Text>}
                        {v.avatar&& <Image style={styles.approvedImgAvatar}  source={{uri:v.avatar}} resizeMode="contain"></Image>}
                    </TouchableOpacity>
                    <View style={styles.approvedContent}>
                        <View style={styles.approvedName}>
                            <Text  style={styles.approvedNameText}>{v.auditUserName}</Text>
                            <Text style={[styles.approvedResultText,{marginLeft:10,paddingLeft:10,borderLeftWidth:1,borderLeftColor:"#ddd"}]} >{v.position}</Text>
                        </View>
                        <View style={styles.approvedResult}>
                            {v.status=="EXECUTED"&&v.status=="NONE"&&<Text style={[styles.infoPass,styles.infoWidth]} >自动通过</Text>}
                            {v.status=="EXECUTED"&&v.auditResult=="NONE"&&<Text style={[styles.infoPass,styles.infoWidth]} >自动通过</Text>}
                            {v.status=="EXECUTED"&&v.auditResult=="UNTREAD"&&<Text style={[styles.infoError,styles.infoWidth]} >回退</Text>}
                            {v.status=="EXECUTED"&&v.auditResult=="APPROVE"&&<Text style={[styles.infoPass,styles.infoWidth]} >同意</Text>}
                            {v.status=="EXECUTED"&&v.auditResult=="REJECT"&&<Text style={[styles.infoError,styles.infoWidth]} >拒绝</Text>}
                            {v.status=="EXECUTED"&&v.auditResult=="WITHDRAW"&&<Text style={[styles.infoError,styles.infoWidth]} >撤回</Text>}
                            {v.status=="EXECUTED"&&v.auditResult=="TRANSFER"&&<Text style={[styles.infoInProcess,styles.infoWidth]} >转交</Text>}
                            {v.status=="EXECUTED"&&v.auditResult=="TAKE"&&<Text style={[styles.approvedResultText,styles.infoWidth]} >受理</Text>}
                            {v.status=="RUNNING"&&<Text style={[styles.infoInProcess,styles.infoWidth]} >审批中</Text>}
                            {v.status=="WAITING"&&<Text style={[styles.infoInProcess,styles.infoWidth]} >待审批</Text>}
                            {v.status=="START"&&<Text style={[styles.approvedResultText,styles.infoWidth]} >提交</Text>}
                            <Text style={[styles.approvedResultText]} >{v.auditContent}</Text>
                        </View>

                    </View>

                </View>
            </View>
        )
    };

}


const styles = StyleSheet.create({
    approvedLayout: {
        paddingLeft: 15,
        paddingRight: 10,
        backgroundColor: "#eee",
    },

    approvedRow: {
        flexDirection:"row"
    },
    approvedTime:{
        paddingTop:15,
        width:40,
    },
    approvedTimeText:{
        fontSize:10,
        color:"#999"
    },

    approvedLineLayout:{
        width:20,
        marginRight:15,
        alignItems:"center",
        paddingTop:15,
    },
    approvedLine: {
        position:"absolute",
        left:"50%",
        top:0,
        bottom:0,
        width:xnBorderWidth(),
        backgroundColor: "#d8d8d8",
        zIndex:1
    },

    approvedLineIconActive: {
        position: "relative",
        zIndex:10,
        width:14,
        height:14,
        backgroundColor: "#52c26e",

        borderRadius:7
    },
    approvedLineIcon: {
        position: "relative",
        zIndex:10,
        width:10,
        height:10,
        backgroundColor: "#d8d8d8",
        borderRadius:5
    },
    approvedBox:{
        flex:1,
        borderWidth:xnBorderWidth(),
        borderColor:"#eee",
        borderStyle:"solid",
        paddingTop: 15,
        paddingBottom: 15,
        paddingLeft: 10,
        paddingRight: 10,
        borderRadius:4,
        backgroundColor: "#fff",
        marginTop:10,
        marginBottom:10,
        flexDirection:"row"
    },
    approvedImg:{
        width:40,
        height:40,
        marginRight:10,
        justifyContent:"center",
        alignItems:"center",
        backgroundColor: "#39f",
        borderRadius:4,
    },
    approvedImgText:{
        color:"#fff",
        fontSize:10
    },
    approvedImgAvatar:{
        width:40,
        height:40,
        borderRadius:4,
    },
    approvedContent:{
        flex:1,
        flexDirection:"column"

    },
    approvedName:{
        height:20,
        flexDirection:"row",
        alignItems:"center",
    },
    approvedNameText:{
        fontSize:14,
        color:"#333"
    },
    approvedResult:{
        marginRight:5,
        marginTop:5,
        flex: 1,
        flexDirection:"row",
    },
    approvedResultText:{
        fontSize:10,
        marginRight:5,
        color:"#999",
    },

    infoInProcess:{
        fontSize:10,
        marginRight:5,
        color:"#dcc38a",
    },
    infoPass:{
        fontSize:10,
        marginRight:5,
        color:"#52c26e",
    },
    infoError:{
        fontSize:10,
        marginRight:5,
        color:"#ea281a",
    },
    infoWidth:{

    }

});

export default ApprovedLayout;