TabDetailView.js 3.51 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TextInput,
    Image,
    ScrollView,
    StyleSheet,
    TouchableOpacity,
} from 'react-native';
import {Row, Rows, Table} from 'react-native-table-component';
import {xnBorderWidth} from "../utils/utils";

const HPading = (16);
const VPading = (6);

/**
 * 表格/明细 组件
 */
export default class TabDetailView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            tableHead: ['Head', 'Head2', 'Head3', 'Head4'],
            tableData: [
                ['1', '2', '3', '4'],
                ['a', 'b', 'c', 'd'],
                ['1', '2', '3', '456\n789'],
                ['a', 'b', 'c', 'd']
            ],
            dataList:[],// 列表数据
        };
        this.attrData = this.props.attrData;
        this.extendData = JSON.parse(this.attrData.data);
        this.tabType = this.attrData.data.type;// 固定:list=列表|table=表格
    }

    render() {
        const options = this.state;

        let {name, code, type, description, isRequired, isPreview} = this.attrData;
        // 按钮文本 //  // 显示合计
        let {buttonText, showCount} = this.extendData;

        return(
            <View style={{width: '100%', backgroundColor: 'white', paddingHorizontal: 5, paddingVertical: 10}}>
                <View style={{flexDirection: 'row',height:titleViewHeight,backgroundColor:'#fff'}}>
                    {isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}
                    {!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)', marginBottom: 5}}>{name||''}</Text>
                </View>
                {this.tabType === 'list' && this.renderListItem()}
                {this.tabType === 'table' && this.renderTableItem()}
                {/** TODO 显示合计 */}
                {showCount && <View style={{width: '100%', height: 44, alignItems: 'center', borderBottomWidth: xnBorderWidth(),
                    borderBottomColor: '#ddd', flexDirection: 'row'}}
                >
                    <Text style={{marginLeft: 10, fontSize: 16, color: 'black'}}>合计</Text>
                </View>}
                <TouchableOpacity
                    style={{width: '100%', height: 44, alignItems: 'center', justifyContent: 'center'}}
                    activeOpacity={0.8}
                    onPress={()=>{
                        let itemData = {};
                        let tempList = this.state.dataList||[];
                        tempList.push(itemData);
                        this.setState({
                            dataList: tempList
                        })
                    }}
                >
                    <Text style={{fontSize: 16, color: global.homeColor}}>{'+' + buttonText}</Text>
                </TouchableOpacity>
            </View>
        );
    }

    /**
     * 列表
     */
    renderListItem() {
    }

    /**
     * 表格
     */
    renderTableItem() {
        return (
            <View style={{width: '100%', backgroundColor: 'white'}}>
                <Table borderStyle={{borderWidth: 1, borderColor: '#f0f'}}>
                    <Row data={options.tableHead} style={styles.head} textStyle={styles.text}/>
                    <Rows data={options.tableData} textStyle={styles.text}/>
                </Table>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    head: { height: 40, backgroundColor: '#f1f8ff' },
    text: { margin: 6 }
})