import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, TouchableNativeFeedback, DeviceEventEmitter } from 'react-native'; import { back, navigate } from '../../NavigationService'; import { BjInstanceSampleSquareResearch } from '../../database/Instance'; import { colors, myConfirm, onePx, px2dp, size, statusBarHeight } from '../../utils'; import { BjTypeActualMeasurementResearch, BjTypeResearchConnection, BjTypeResearchNameDict, BjTypeSampleLineResearch, BjTypeSampleSquareResearch } from '../../utils/types'; interface Props { activeTab?: number goToPage?: number tabs?: Array<{ name: string key: string }> layerTabs?: Array<{ id: string name: string }> tabIndex: number researchInstance?: BjTypeActualMeasurementResearch & BjTypeSampleLineResearch & BjTypeSampleSquareResearch researchConnection?: BjTypeResearchConnection researchType: BjTypeResearchNameDict type?: 'species' | 'research' isSubSampleSquareResearch?: boolean //是否是下属关联的样方调查 justView: boolean } interface State { activeDefaultColor: string inactiveDefaultColor: string tempResearchInstance: BjTypeActualMeasurementResearch & BjTypeSampleLineResearch & BjTypeSampleSquareResearch } export default class CommonTableTabBar extends React.Component { constructor(props: Props) { super(props); }; public onSubSampleSquareEditFinishListener = null; public readonly state: Readonly = { activeDefaultColor: '#08086b', inactiveDefaultColor: '#666666', tempResearchInstance: this.props.researchInstance }; componentDidMount() { this.onSubSampleSquareEditFinishListener = DeviceEventEmitter.addListener("on-sample-square-research-edit", (a) => { const { tempResearchInstance } = this.state; const newTempResearchInstance = a.tempResearchInstance; if (tempResearchInstance.id == newTempResearchInstance.id) { this.setState({ tempResearchInstance: newTempResearchInstance }) } }) }; componentWillUnmount(): void { this.onSubSampleSquareEditFinishListener && this.onSubSampleSquareEditFinishListener?.remove(); } openSelectResearchTypeToast() { const { tabIndex, researchType } = this.props; const layerTabEventKey = `${researchType}-${tabIndex}`; 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, layerTabs } = this.props; const { tempResearchInstance } = this.state; const layerType = layerTabs[0].id; navigate('ResearchCommonFrequencyPage', { layerType: layerType, researchInstance: tempResearchInstance }) }; _renderTab(name, page, isTabActive, onPressHandler) { const { researchType, type = 'research', isSubSampleSquareResearch = false } = this.props; const textColor = isTabActive ? colors.themeColor : '#7f7f7f' const fontWeight = isTabActive ? 'normal' : 'normal'; const fontSize = isTabActive ? 14 : 14 return ( onPressHandler(page)} > {name} { page == 0 && name == '乔木' && type == 'research' && !isSubSampleSquareResearch ? 幼 : null } { researchType == 'sampleSquareResearch' && type == 'research' && !isSubSampleSquareResearch ? 频 : null } ); } handlePressBack() { back(); }; jumpToResearchDetails() { const { tempResearchInstance } = this.state;; DeviceEventEmitter.emit("show-sample-square-research-dialog", { researchInstance: tempResearchInstance }) // const { researchType, researchConnection } = this.props; // const { tempResearchInstance } = this.state; // 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: tempResearchInstance }) } handleDeleteSubSampleSquare() { myConfirm({ title: "确定删除此关联样方?此操作不可撤销", confirmText: "确定", confirmFun: this.comfirmToDeleteSubSampleSquare.bind(this) }) } comfirmToDeleteSubSampleSquare() { const { researchInstance } = this.props; DeviceEventEmitter.emit('delete-sub-sample-square', { researchInstance }) } render() { const { researchType, isSubSampleSquareResearch = false, layerTabs, type } = this.props; const { tempResearchInstance } = this.state; const currentLayer = layerTabs[0]; return ( {this.props.tabs.map((name, page) => { const isTabActive = this.props.activeTab === page; return this._renderTab(name, page, isTabActive, this.props.goToPage) })} { researchType === 'sampleSquareResearch' && type !== 'species' ? {tempResearchInstance.serialNumberAndCode} { currentLayer.id == 'arbor' ? 幼 : null } 频 : null } ); }; } const styles = StyleSheet.create({ tabsContainer: { position: 'relative', width: '100%', height: px2dp(36), }, tabsContainerHeader: { width: '100%', height: px2dp(36), flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-end', backgroundColor: '#fff', borderBottomWidth: onePx, borderBottomColor: '#d2d2d2', paddingLeft: px2dp(13) }, tab: { width: px2dp(96), height: px2dp(32), justifyContent: 'center', alignItems: 'center', borderWidth: onePx, borderColor: colors.themeColor, borderRadius: px2dp(3), marginRight: px2dp(5), borderBottomLeftRadius: 0, borderBottomRightRadius: 0, borderBottomWidth: 0, flexDirection: 'row', }, smallBtn: { height: px2dp(24), paddingHorizontal: px2dp(5), backgroundColor: '#33C18B36', borderWidth: onePx, borderColor: colors.themeColor, justifyContent: 'center', alignItems: 'center', borderRadius: px2dp(2) }, smallBtnInactive: { height: px2dp(24), paddingHorizontal: px2dp(5), backgroundColor: '#f2f2f2', borderWidth: onePx, borderColor: '#d2d2d2', justifyContent: 'center', alignItems: 'center', borderRadius: px2dp(2) }, smallBtnText: { fontSize: 12, color: colors.themeColor }, pressBtn: { flex: 1, height: '100%', justifyContent: 'center', alignItems: 'center', paddingLeft: px2dp(5) }, tabsContainerHeaderLeft: { flex: 1, height: '100%', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'flex-end', backgroundColor: '#fff', borderBottomWidth: onePx, borderBottomColor: '#d2d2d2', }, tabsContainerHeaderRight: { height: '100%', flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center', backgroundColor: '#fff', borderBottomWidth: onePx, borderBottomColor: '#d2d2d2', paddingRight: px2dp(5) }, deleteIcon: { width: px2dp(16), height: px2dp(16), }, researchInfoBtn: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: '#f2f2f2', paddingHorizontal: px2dp(5), borderRadius: px2dp(3), height: px2dp(26), marginRight: px2dp(8), borderWidth: onePx, borderColor: '#d2d2d2' }, btnText: { fontSize: 12, color: '#666' }, optionBtnText: { fontSize: 12, color: '#666' }, optionBtn: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: '#f2f2f2', paddingHorizontal: px2dp(8), borderRadius: px2dp(3), height: px2dp(26), marginRight: px2dp(8), borderWidth: onePx, borderColor: '#d2d2d2' } });