import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, TouchableNativeFeedback, DeviceEventEmitter } from 'react-native'; import { back, navigate } from '../../NavigationService'; import { colors, myConfirm, onePx, px2dp, size, statusBarHeight, toastShort } from '../../utils'; import { BjTypeActualMeasurementResearch, BjTypeResearchConnection, BjTypeResearchNameDict, BjTypeSampleLineResearch, BjTypeSampleSquareResearch } from '../../utils/types'; interface Props { activeTab?: number goToPage?: number tabs?: Array<{ name: string key: string }> researchInstance?: BjTypeActualMeasurementResearch & BjTypeSampleLineResearch & BjTypeSampleSquareResearch researchType?: BjTypeResearchNameDict researchConnection?: BjTypeResearchConnection comfirmToFinishResearch?: Function justView: boolean } interface State { activeDefaultColor: string inactiveDefaultColor: string } export default class CommonTableTabBar extends React.Component { constructor(props: Props) { super(props); }; public readonly state: Readonly = { activeDefaultColor: '#08086b', inactiveDefaultColor: '#666666' }; _renderTab(name, page, isTabActive, onPressHandler) { const textColor = isTabActive ? '#fff' : colors.greenTextColor const fontWeight = isTabActive ? 'normal' : 'normal'; const fontSize = isTabActive ? 14 : 14 return ( onPressHandler(page)} > {name} ); } handlePressBack() { back(); }; adaptResearchType() { const { researchType, researchInstance } = this.props; let typeName = ""; switch (researchType) { case 'actualMeasurementResearch': typeName = "实(全)测法"; break; case 'sampleSquareResearch': let layerName = ""; switch (researchInstance.targetSpeciesLiveType) { case 'arbor': layerName = "乔木"; break; case 'shrub': layerName = "灌木"; break; case 'plant': layerName = "草本"; break; case 'moss': layerName = "苔藓"; break; default: break; } typeName = layerName + "样方(圆)记录表"; break; case 'sampleLineResearch': typeName = "样线(带)法"; break; default: break; } return typeName; } openSelectResearchTypeToast() { const { researchType } = this.props; const layerTabEventKey = `${researchType}-${0}`; const researchTypeList = [ { name: "幼树调查", type: 'small-tree', icon: null, active: false }, { name: "幼苗调查", type: 'small-seedling', icon: null, active: false } ] DeviceEventEmitter.emit('show-selete-research-type-toast', { key: layerTabEventKey, researchTypeList }) }; jumpToFrequencyPage() { const { researchType, researchInstance, researchConnection } = this.props; const layerType = researchInstance.targetSpeciesLiveType; navigate('ResearchCommonFrequencyPage', { layerType: layerType, researchInstance }) }; handleFinishResearch() { const { justView, researchType } = this.props; if(justView){ return toastShort("回收站数据不支持此操作") } myConfirm({ title: researchType =='sampleLineResearch' ? "确认结束当前调查?结束后,不再支持新增数据" : "确认结束当前调查?结束后,仍支持新增数据", confirmText: "确定", confirmFun: this.comfirmToFinishResearch.bind(this) }) } comfirmToFinishResearch() { const { comfirmToFinishResearch } = this.props; comfirmToFinishResearch && comfirmToFinishResearch(); } jumpToResearchDetails() { const { researchInstance, researchType, researchConnection, justView } = this.props; let tablePageRouterName = null; switch (researchType) { case 'communityProfileResearch': tablePageRouterName = 'NewCommunityProfileResearch'; break; case 'actualMeasurementResearch': tablePageRouterName = 'NewActualMeasurementResearch'; break; case 'sampleSquareResearch': tablePageRouterName = 'NewSampleSquareResearch'; break; case 'sampleLineResearch': tablePageRouterName = 'NewSampleLineResearch'; break; default: break; } navigate(tablePageRouterName, { researchConnection, researchInstance, justView }) } render() { const { researchInstance, researchType } = this.props; return ( {this.props.tabs.map((name, page) => { const isTabActive = this.props.activeTab === page; return this._renderTab(name, page, isTabActive, this.props.goToPage) })} { researchInstance && researchInstance.finishDate ? 已完成 : 完成调查 } { researchType == 'sampleSquareResearch' ? {this.adaptResearchType()} {researchInstance.serialNumberAndCode} { this.props.activeTab == 0 ? <> { researchInstance.targetSpeciesLiveType == 'arbor' ? 幼 : null } 频 : null } : {this.adaptResearchType()} {researchInstance.serialNumberAndCode} } ); }; } const styles = StyleSheet.create({ tabsContainer: { position: 'relative', width: '100%', height: size.head_height + statusBarHeight + px2dp(36), paddingTop: statusBarHeight, backgroundColor: '#fff', }, tabsContainerHeader: { width: '100%', height: size.head_height, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', backgroundColor: '#fff', borderBottomWidth: onePx, borderBottomColor: '#d2d2d2' }, container: { width: px2dp(172), height: px2dp(34), flexDirection: 'row', justifyContent: 'center', alignItems: 'center', borderRadius: px2dp(5), overflow: 'hidden', backgroundColor: colors.themeColor, borderWidth: 1, borderColor: colors.greenTextColor }, swichBarItem1: { width: px2dp(86), height: px2dp(36), justifyContent: 'center', alignItems: 'center', }, swichBarItem2: { width: px2dp(86), height: px2dp(36), backgroundColor: '#fff', justifyContent: 'center', alignItems: 'center', }, sideBtn: { width: px2dp(76), height: size.head_height, paddingLeft: px2dp(13), flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center' }, header: { width: '100%', height: px2dp(36), flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', backgroundColor: '#f2f5f8', paddingLeft: px2dp(12) }, headerLeft: { flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', width: px2dp(180) }, tag: { height: px2dp(26), backgroundColor: '#e2e6e8', justifyContent: 'center', alignItems: 'center', paddingHorizontal: px2dp(5), borderRadius: px2dp(3), marginRight: px2dp(5), borderWidth: onePx, borderColor: '#e0e0e0' }, tagText: { fontSize: 12, color: '#303133' }, sideSmallBtn: { height: '100%', paddingHorizontal: px2dp(15), justifyContent: 'center', alignItems: 'center', // backgroundColor: 'red' }, headerRight: { flex: 1, height: '100%', flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center' }, smallBtn: { height: px2dp(20), backgroundColor: colors.themeColor, justifyContent: 'center', alignItems: 'center', paddingHorizontal: px2dp(3), marginHorizontal: px2dp(6), borderRadius: px2dp(3) }, smallBtnText: { fontSize: 12, color: '#fff', }, researchInfoBtn: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: '#33C18B12', paddingHorizontal: px2dp(5), borderRadius: px2dp(3), height: px2dp(26), marginRight: px2dp(8), borderWidth: onePx, borderColor: colors.greenTextColor }, btnText: { fontSize: 12, color: '#303133' }, optionBtnText: { fontSize: 12, color: '#303133' }, optionBtn: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: '#33C18B12', paddingHorizontal: px2dp(8), borderRadius: px2dp(3), height: px2dp(26), marginRight: px2dp(8), borderWidth: onePx, borderColor: colors.greenTextColor }, deleteIcon: { width: px2dp(16), height: px2dp(16), }, });