import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, TextInput, DeviceEventEmitter } from 'react-native'; import DataBaseTableName from '../database/DataBaseTableName'; import { closeDrawer } from '../NavigationService'; import mockAction from '../sevices/mockAction'; import { colors, filterSqlRows, getLocalTime, isEmpty, myConfirm, onePx, px2dp, toastShort } from '../utils'; import { BjTypeCommonResearch, BjTypeResearchNameDict } from '../utils/types'; import redux from './../redux/store'; import JDatePicker from './../components/kits/JDatePicker'; import comStyles from '../assets/styles/com-style'; interface Props { } interface State { researchFilter: { createDateStart: string createDateEnd: string } title: string showTable: boolean, dataCount: { birdResearchLine: number, insectResearchLine: number, beastResearchLine: number, reptileResearchLine: number, plantResearchLine: number, insectResearchPoint: number, fishResearchPoint: number, beastResearchPoint: number, birdResearchPoint: number, birdResearcDisPoint: number, fungusResearchCollect: number, plantResearchCollect: number, waterResearchCollect: number, soilResearchCollect: number, vegetationResearchCollect: number, landResearchCollect: number, forestResearchPlot: number, shrubResearchPlot: number, grassResearchPlot: number, vegetationResearchPoint: number, }, dataChecked: { birdResearchLine: boolean, insectResearchLine: boolean, beastResearchLine: boolean, reptileResearchLine: boolean, plantResearchLine: boolean, insectResearchPoint: boolean, fishResearchPoint: boolean, beastResearchPoint: boolean, birdResearchPoint: boolean, birdResearcDisPoint: boolean, fungusResearchCollect: boolean, plantResearchCollect: boolean, waterResearchCollect: boolean, soilResearchCollect: boolean, vegetationResearchCollect: boolean, landResearchCollect: boolean, forestResearchPlot: boolean, shrubResearchPlot: boolean, grassResearchPlot: boolean, vegetationResearchPoint: boolean, plantPlot: boolean } dataList: Array } export default class DataFilter extends React.Component { constructor(props: Props) { super(props); }; public datePickerRef = null; public currentTimeMode = null; public readonly state: Readonly = { researchFilter: { createDateStart: "", createDateEnd: "" }, title: "", showTable: false, dataCount: { birdResearchLine: 0, insectResearchLine: 0, beastResearchLine: 0, reptileResearchLine: 0, plantResearchLine: 0, insectResearchPoint: 0, fishResearchPoint: 0, beastResearchPoint: 0, birdResearchPoint: 0, birdResearcDisPoint: 0, fungusResearchCollect: 0, plantResearchCollect: 0, waterResearchCollect: 0, soilResearchCollect: 0, vegetationResearchCollect: 0, landResearchCollect: 0, forestResearchPlot: 0, shrubResearchPlot: 0, grassResearchPlot: 0, vegetationResearchPoint: 0, }, dataChecked: { birdResearchLine: true, insectResearchLine: true, beastResearchLine: true, reptileResearchLine: true, plantResearchLine: true, insectResearchPoint: true, fishResearchPoint: true, beastResearchPoint: true, birdResearchPoint: true, birdResearcDisPoint: true, fungusResearchCollect: true, plantResearchCollect: true, waterResearchCollect: true, soilResearchCollect: true, vegetationResearchCollect: true, landResearchCollect: true, forestResearchPlot: true, shrubResearchPlot: true, grassResearchPlot: true, vegetationResearchPoint: true, plantPlot: true }, dataList: [], }; async updateData(data) { console.log("updateData----->", data) const { dataChecked, researchFilter} = data; if(dataChecked && researchFilter){ this.setState({ dataChecked, researchFilter }) } const params = { createUserId: redux.getState().userMsg.userInfo.id, isLocalDelete: '0' } let res = await mockAction.queryData(DataBaseTableName.researchCommonTable, params) const list: Array = filterSqlRows(res) console.log("res", JSON.stringify(list)) this.setState({ dataList: list }) } _onDateChange(e) { let { researchFilter } = this.state; let endTime = researchFilter.createDateEnd; let startTime = researchFilter.createDateStart; console.log(e); if (this.currentTimeMode == 'start') { if (!isEmpty(endTime)) { let startTimeNs = new Date(e).getTime(); if (startTimeNs > new Date(endTime).getTime()) { return toastShort("开始时间不可晚于结束时间,请重新选择!") } }; researchFilter.createDateStart = e; } else { if (!isEmpty(startTime)) { let startTimeNs = new Date(startTime).getTime(); if (startTimeNs > new Date(e).getTime()) { return toastShort("结束时间不可早于开始时间,请重新选择!") } researchFilter.createDateEnd = e; } }; this.setState({ researchFilter }) } showStartTimePicker() { this.setState({ title: "选择开始日期" }) this.currentTimeMode = 'start'; this.datePickerRef?.show(); }; showEndTimePicker() { this.setState({ title: "选择结束日期" }) this.currentTimeMode = 'end'; this.datePickerRef?.show(); }; switchTypeChecked(type: BjTypeResearchNameDict) { let { dataChecked } = this.state; if (type == 'plantPlot') { dataChecked['grassResearchPlot'] = !dataChecked['grassResearchPlot']; dataChecked['shrubResearchPlot'] = !dataChecked['shrubResearchPlot']; dataChecked['forestResearchPlot'] = !dataChecked['forestResearchPlot']; dataChecked[type] = !dataChecked[type]; } else { dataChecked[type] = !dataChecked[type]; } this.setState({ dataChecked }) }; getDataTotalCountBySpeciesType(speciesType: "plant" | "bird" | "beast" | "reptile" | "fish" | "insect" | "fungus" | "env") { let totalCount = 0; const { dataCount, dataList } = this.state; dataList.forEach(ele => { switch (speciesType) { case 'plant': if ( ele.type === 'plantResearchCollect' || ele.type === 'plantResearchLine' || ele.type === 'grassResearchPlot' || ele.type === 'shrubResearchPlot' || ele.type === 'forestResearchPlot' || ele.type == 'vegetationResearchCollect' ) { totalCount++; } break; case 'bird': if (ele.type === 'birdResearcDisPoint' || ele.type == 'birdResearchLine' || ele.type === 'birdResearchPoint') { totalCount++; } break; case 'beast': if (ele.type === 'beastResearchLine' || ele.type === 'beastResearchPoint') { totalCount++; } break; case 'reptile': if (ele.type === 'reptileResearchLine') { totalCount++; } break; case 'fish': if (ele.type === 'fishResearchPoint') { totalCount++; } break; case 'insect': if (ele.type === 'insectResearchLine' || ele.type === 'insectResearchPoint') { totalCount++; } break; case 'fungus': if (ele.type === 'fungusResearchCollect') { totalCount++; } break; case 'env': if (ele.type === 'landResearchCollect' || ele.type === 'soilResearchCollect' || ele.type == 'waterResearchCollect') { totalCount++; } break; default: break; } }) return totalCount; }; getDataCountByCheckedType(speciesType: "plant" | "bird" | "beast" | "reptile" | "fish" | "insect" | "fungus" | "env") { let totalCount = 0; const { dataCount, dataList, dataChecked } = this.state; dataList.forEach(ele => { switch (speciesType) { case 'plant': if (ele.type === 'plantResearchCollect' && dataChecked.plantResearchCollect) { totalCount++; } else if (ele.type === 'plantResearchLine' && dataChecked.plantResearchLine) { totalCount++; } else if (ele.type === 'grassResearchPlot' && dataChecked.grassResearchPlot) { totalCount++; } else if (ele.type === 'shrubResearchPlot' && dataChecked.shrubResearchPlot) { totalCount++; } else if (ele.type === 'forestResearchPlot' && dataChecked.forestResearchPlot) { totalCount++; } else if (ele.type === 'vegetationResearchCollect' && dataChecked.vegetationResearchCollect) { totalCount++; } break; case 'bird': if (ele.type === 'birdResearcDisPoint' && dataChecked.birdResearcDisPoint) { totalCount++; } else if (ele.type == 'birdResearchLine' && dataChecked.birdResearchLine) { totalCount++; } else if (ele.type === 'birdResearchPoint' && dataChecked.birdResearchPoint) { totalCount++; } break; case 'beast': if (ele.type === 'beastResearchLine' && dataChecked.beastResearchLine) { totalCount++; } else if (ele.type === 'beastResearchPoint' && dataChecked.beastResearchPoint) { totalCount++; } break; case 'reptile': if (ele.type === 'reptileResearchLine' && dataChecked.reptileResearchLine) { totalCount++; } break; case 'fish': if (ele.type === 'fishResearchPoint' && dataChecked.fishResearchPoint) { totalCount++; } break; case 'insect': if (ele.type === 'insectResearchLine' && dataChecked.insectResearchLine) { totalCount++; } else if (ele.type === 'insectResearchPoint' && dataChecked.insectResearchPoint) { totalCount++; } break; case 'fungus': if (ele.type === 'fungusResearchCollect' && dataChecked.fungusResearchCollect) { totalCount++; } break; case 'env': if (ele.type === 'landResearchCollect' && dataChecked.landResearchCollect) { totalCount++; } else if (ele.type === 'soilResearchCollect' && dataChecked.soilResearchCollect) { totalCount++; } else if (ele.type == 'waterResearchCollect' && dataChecked.waterResearchCollect) { totalCount++; } break; default: break; } }) return totalCount; }; getResearchTypeCount(researchType: BjTypeCommonResearch) { let { dataList } = this.state; let totalCount = 0; dataList.forEach(ele => { if (ele.type == researchType) { totalCount++; } }) return totalCount; }; resetFilter() { let confirmData = { title: "确认重置所有筛选条件?", confirmText: "重置", confirmFun: this.confirmToResetFilter.bind(this) }; myConfirm(confirmData) }; confirmToResetFilter() { this.setState({ researchFilter: { createDateStart: "", createDateEnd: "" }, dataCount: { birdResearchLine: 0, insectResearchLine: 0, beastResearchLine: 0, reptileResearchLine: 0, plantResearchLine: 0, insectResearchPoint: 0, fishResearchPoint: 0, beastResearchPoint: 0, birdResearchPoint: 0, birdResearcDisPoint: 0, fungusResearchCollect: 0, plantResearchCollect: 0, waterResearchCollect: 0, soilResearchCollect: 0, vegetationResearchCollect: 0, landResearchCollect: 0, forestResearchPlot: 0, shrubResearchPlot: 0, grassResearchPlot: 0, vegetationResearchPoint: 0, }, dataChecked: { birdResearchLine: true, insectResearchLine: true, beastResearchLine: true, reptileResearchLine: true, plantResearchLine: true, insectResearchPoint: true, fishResearchPoint: true, beastResearchPoint: true, birdResearchPoint: true, birdResearcDisPoint: true, fungusResearchCollect: true, plantResearchCollect: true, waterResearchCollect: true, soilResearchCollect: true, vegetationResearchCollect: true, landResearchCollect: true, forestResearchPlot: true, shrubResearchPlot: true, grassResearchPlot: true, vegetationResearchPoint: true, plantPlot: true, }, }) } comfirmToSearch() { const { dataChecked, researchFilter } = this.state; DeviceEventEmitter.emit('data-filter-change', { dataChecked, researchFilter }); closeDrawer(); }; render() { const { researchFilter, showTable, dataChecked, title } = this.state; return ( { showTable ? <> 工具 this.setState({ showTable: false })}> 样点 样线 样地 分区直数 植物({this.getDataTotalCountBySpeciesType('plant') - this.getResearchTypeCount('vegetationResearchCollect')}) - {this.getResearchTypeCount('plantResearchLine')} {this.getResearchTypeCount('forestResearchPlot') + this.getResearchTypeCount('shrubResearchPlot') + this.getResearchTypeCount('grassResearchPlot')} - 植被({this.getResearchTypeCount('vegetationResearchCollect')}) - {this.getResearchTypeCount('vegetationResearchCollect')} - - 鸟类({this.getDataTotalCountBySpeciesType('bird')}) {this.getResearchTypeCount('birdResearchPoint')} {this.getResearchTypeCount('birdResearchLine')} - {this.getResearchTypeCount('birdResearcDisPoint')} 兽类({this.getDataTotalCountBySpeciesType('beast')}) {this.getResearchTypeCount('beastResearchPoint')} {this.getResearchTypeCount('beastResearchLine')} - - 两爬({this.getDataTotalCountBySpeciesType('reptile')}) - {this.getResearchTypeCount('reptileResearchLine')} - - 鱼类({this.getDataTotalCountBySpeciesType('fish')}) - - {this.getResearchTypeCount('fishResearchPoint')} - 昆虫({this.getDataTotalCountBySpeciesType('insect')}) {this.getResearchTypeCount('insectResearchPoint')} {this.getResearchTypeCount('insectResearchLine')} - - 真菌({this.getDataTotalCountBySpeciesType('fungus')}) - {this.getResearchTypeCount('fungusResearchCollect')} - - 地类调查 土样采集 水样采集 {`自然环境\n(${this.getDataTotalCountBySpeciesType('env')})`} {this.getResearchTypeCount('landResearchCollect')} {this.getResearchTypeCount('soilResearchCollect')} {this.getResearchTypeCount('waterResearchCollect')} : this.setState({ showTable: true })} > 查看全部 时间区间 : { researchFilter.createDateStart ? getLocalTime('YY:MM:DD', researchFilter.createDateStart) : 开始时间 } - { researchFilter.createDateEnd ? getLocalTime('YY:MM:DD', researchFilter.createDateEnd) : 结束时间 } 植物 ({this.getDataCountByCheckedType('plant')}/{this.getDataTotalCountBySpeciesType('plant')}) : this.switchTypeChecked('plantResearchLine')} style={[ styles.filterBtn, {marginBottom: px2dp(10)}, dataChecked.plantResearchLine ? { backgroundColor: colors.greenColor } : null ]} > 样线 this.switchTypeChecked('plantPlot')} style={[ styles.filterBtn, {marginBottom: px2dp(10)}, dataChecked.plantPlot ? { backgroundColor: colors.greenColor } : null ]} > 样地 this.switchTypeChecked('vegetationResearchCollect')} style={[ styles.filterBtn, {marginBottom: px2dp(10)}, dataChecked.vegetationResearchCollect ? { backgroundColor: colors.greenColor } : null ]} > 植被 this.switchTypeChecked('plantResearchCollect')} style={[ styles.filterBtn, {marginBottom: px2dp(10)}, dataChecked.plantResearchCollect ? { backgroundColor: colors.greenColor } : null ]} > 采集 鸟类 ({this.getDataCountByCheckedType('bird')}/{this.getDataTotalCountBySpeciesType('bird')}) : this.switchTypeChecked('birdResearchLine')} style={[ styles.filterBtn, dataChecked.birdResearchLine ? { backgroundColor: colors.greenColor } : null ]} > 样线 this.switchTypeChecked('birdResearchPoint')} style={[ styles.filterBtn, dataChecked.birdResearchPoint ? { backgroundColor: colors.greenColor } : null ]} > 样点 this.switchTypeChecked('birdResearcDisPoint')} style={[ styles.filterBtn, dataChecked.birdResearcDisPoint ? { backgroundColor: colors.greenColor } : null ]} > 分区直数 兽类 ({this.getDataCountByCheckedType('beast')}/{this.getDataTotalCountBySpeciesType('beast')}) : this.switchTypeChecked('beastResearchLine')} style={[ styles.filterBtn, dataChecked.beastResearchLine ? { backgroundColor: colors.greenColor } : null ]} > 样线 this.switchTypeChecked('beastResearchPoint')} style={[ styles.filterBtn, dataChecked.beastResearchPoint ? { backgroundColor: colors.greenColor } : null ]} > 样点 两爬 ({this.getDataCountByCheckedType('reptile')}/{this.getDataTotalCountBySpeciesType('reptile')}) : this.switchTypeChecked('reptileResearchLine')} style={[ styles.filterBtn, dataChecked.reptileResearchLine ? { backgroundColor: colors.greenColor } : null ]} > 样线 鱼类 ({this.getDataCountByCheckedType('fish')}/{this.getDataTotalCountBySpeciesType('fish')}) : this.switchTypeChecked('fishResearchPoint')} style={[ styles.filterBtn, dataChecked.fishResearchPoint ? { backgroundColor: colors.greenColor } : null ]} > 样地 昆虫 ({this.getDataCountByCheckedType('insect')}/{this.getDataTotalCountBySpeciesType('insect')}) : this.switchTypeChecked('insectResearchLine')} style={[ styles.filterBtn, dataChecked.insectResearchLine ? { backgroundColor: colors.greenColor } : null ]} > 样线 this.switchTypeChecked('insectResearchPoint')} style={[ styles.filterBtn, dataChecked.insectResearchPoint ? { backgroundColor: colors.greenColor } : null ]} > 样点 真菌 ({this.getDataCountByCheckedType('fungus')}/{this.getDataTotalCountBySpeciesType('fungus')}) : this.switchTypeChecked('fungusResearchCollect')} style={[ styles.filterBtn, dataChecked.fungusResearchCollect ? { backgroundColor: colors.greenColor } : null ]} > 采集 自然环境 ({this.getDataCountByCheckedType('env')}/{this.getDataTotalCountBySpeciesType('env')}) : this.switchTypeChecked('landResearchCollect')} style={[ styles.filterBtn, { marginBottom: px2dp(12) }, dataChecked.landResearchCollect ? { backgroundColor: colors.greenColor } : null ]} > 地类调查 this.switchTypeChecked('soilResearchCollect')} style={[ styles.filterBtn, { marginBottom: px2dp(12) }, dataChecked.soilResearchCollect ? { backgroundColor: colors.greenColor } : null ]} > 土样采集 this.switchTypeChecked('waterResearchCollect')} style={[ styles.filterBtn, { marginBottom: px2dp(12) }, dataChecked.waterResearchCollect ? { backgroundColor: colors.greenColor } : null ]} > 水样采集 } { !showTable ? closeDrawer()} style={styles.bottomOptionBtn} > 取消 重置 确定 : null } this.datePickerRef = c} mode={'date'} date={new Date()} title={title} onDateChange={this._onDateChange.bind(this)} /> ) } } const styles = StyleSheet.create({ header: { width: '100%', height: px2dp(42), // backgroundColor: 'red', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: px2dp(12), marginBottom: px2dp(12) }, searchBox: { width: px2dp(232), height: px2dp(32), backgroundColor: '#f2f2f2', borderWidth: onePx, borderColor: colors.borderLineColor, borderRadius: px2dp(2), flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', paddingHorizontal: px2dp(8) }, bottomOptionBar: { width: '100%', height: px2dp(56), paddingHorizontal: px2dp(13), flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', backgroundColor: '#fff', borderTopWidth: onePx, borderTopColor: colors.borderLineColor }, bottomOptionBtn: { width: px2dp(92), height: px2dp(32), borderRadius: px2dp(4), justifyContent: 'center', alignItems: 'center', backgroundColor: '#fff', borderWidth: onePx, borderColor: colors.borderColor, elevation: 0.2 // elevation: 2, }, bottomOptionBtn1: { width: px2dp(92), height: px2dp(32), borderWidth: 1, borderColor: 'rgba(54, 191, 127, 1)', backgroundColor: 'rgba(54, 191, 127, 1)', borderRadius: px2dp(4), justifyContent: 'center', alignItems: 'center', elevation: 0.2 }, row: { width: '100%', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', // backgroundColor: 'red', paddingHorizontal: px2dp(12), paddingVertical: px2dp(10) }, titleRow: { flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', marginRight: px2dp(8) }, rowTitle: { fontSize: 14, color: '#303133' }, dateFilterContainer: { flex: 1, flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', flexWrap: 'wrap' }, filterCenter: { fontSize: 16, fontWeight: 'bold', color: '#666', marginHorizontal: px2dp(8) }, dateFilter: { width: px2dp(96), height: px2dp(28), backgroundColor: '#fff', elevation: 0.5, borderRadius: px2dp(6), borderWidth: onePx, borderColor: '#d2d2d2', justifyContent: 'center', alignItems: 'center' }, filterBtn: { paddingHorizontal: px2dp(8), height: px2dp(28), backgroundColor: '#fff', elevation: 0.5, borderRadius: px2dp(6), borderWidth: onePx, borderColor: '#d2d2d2', justifyContent: 'center', alignItems: 'center', marginRight: px2dp(10) }, filterBtnText: { fontSize: 14, color: '#7f7f7f' }, switchBtn: { borderBottomWidth: 1, height: px2dp(28), borderBottomColor: colors.greenTextColor, paddingTop: px2dp(2) }, tableContainer: { width: px2dp(300), borderLeftColor: '#d2d2d2', borderLeftWidth: 1, borderTopWidth: 1, borderTopColor: '#d2d2d2' }, tableRow: { width: '100%', height: px2dp(42), flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', borderBottomColor: colors.borderLineColor, borderBottomWidth: 1, }, tableCell: { width: px2dp(52), height: '100%', justifyContent: 'center', alignItems: 'center', borderRightWidth: 1, borderRightColor: colors.borderLineColor }, tableCellText: { fontSize: 14, color: '#303133', textAlign: 'center' } })