import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, DeviceEventEmitter } from 'react-native'; import DataBaseTableName from '../../database/DataBaseTableName'; import CustomMarker from './CustomMarker'; import { deepCopy, filterSqlRows } from './../../utils'; import GPS from './../../utils/GPS'; import { BjTypeCommonResearch, BjTypeMapConfig, BjTypeMapMarker, BjTypeResearchNameDict } from './../../utils/types'; import redux from './../../redux/store'; import { adaptAPIAndName } from '../../utils/adapt'; import mockAction from '../../sevices/mockAction'; interface Props { } interface State { researchMarkerList: Array mapConfig: BjTypeMapConfig currentZoomLevel: number } /** * 调查数据集合 */ export default class ResearchDataGroup extends React.Component { constructor(props: Props) { super(props); this.handleGetMarkerData = this.handleGetMarkerData.bind(this) }; public 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, }; public researchFilter = { createDateStart: "", createDateEnd: "" }; public researchLineNameList: Array = []; public mapConfigChangeListener = null; public mapStatusChangeListener = null; public dataList: Array = null; public _state = redux.getState(); public readonly state: Readonly = { researchMarkerList: [], mapConfig: this._state.mapConfig, currentZoomLevel: 9, }; public dataFilterChangeListener = null; componentDidMount(): void { this.mapConfigChangeListener = DeviceEventEmitter.addListener("map-config-change", (a) => { this.setState({ mapConfig: deepCopy(a.mapConfig) }) }) this.mapStatusChangeListener = DeviceEventEmitter.addListener('on-map-status-change', (a) => { console.log("aaaa", a) this.setState({ currentZoomLevel: a.properties.zoomLevel }) }) this.dataFilterChangeListener = DeviceEventEmitter.addListener('data-filter-change', (a) => { this.dataChecked = a.dataChecked; this.researchFilter = a.researchFilter; this.getMarkerData(); }) this.handleGetMarkerData(); } componentWillUnmount(): void { this.mapConfigChangeListener && this.mapConfigChangeListener?.remove(); this.mapStatusChangeListener && this.mapStatusChangeListener?.remove(); }; handleGetMarkerData() { this.getMarkerData(); } async getMarkerData() { this.dataList = []; 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)) let filterList: Array = []; // list.forEach(ele => { // if (this.dataChecked[ele.type]) { // if (this.researchFilter.createDateStart && this.researchFilter.createDateEnd) { // console.log("时间区间", this.researchFilter.createDateStart, this.researchFilter.createDateEnd) // //@ts-ignore // const startDateNs = parseInt(new Date(this.researchFilter.createDateStart).getTime() / 1000); // //@ts-ignore // const endDateNs = parseInt(new Date(this.researchFilter.createDateEnd).getTime() / 1000); // console.log("startDateNs----->", startDateNs); // console.log("endDateNs----->", endDateNs); // if (Number(ele.createDate) >= Number(startDateNs) && Number(ele.createDate) <= Number(endDateNs)) { // filterList.push(ele); // } else { // console.log("不符合----->", ele.createDate) // } // } else { // filterList.push(ele); // } // } // }) filterList = list; console.log("filterList----->", filterList) let queryList = []; let researchDataList = []; let researchMarkerList = []; filterList.forEach(ele => { const adaptResult = adaptAPIAndName(ele.type, 'query', 'research-data'); queryList.push(mockAction.queryData(adaptResult.tableName, { id: ele.id })) }) Promise.all(queryList) .then(resList => { console.log("调查基本信息查询结果集合----->", JSON.stringify(resList)) resList.forEach(researchQueryRes => { const researchQuery = filterSqlRows(researchQueryRes)[0]; console.log("researchQueryRes", researchQuery) researchDataList.push(researchQuery); }) console.log("调查详情结果---->", researchDataList) researchDataList.forEach((researchInstance, researchIndex) => { if (researchInstance.latitudeStart && researchInstance.longitudeStart) { console.log("调查详情结果---->地理信息", researchInstance.latitudeStart , researchInstance.longitudeStart) const newLocation = GPS.gcj_decrypt(researchInstance.latitudeStart, researchInstance.longitudeStart) console.log("newLocation", newLocation) const adaptRowListResult = adaptAPIAndName(filterList[researchIndex].type, 'query', 'row-data'); // let rowList = []; // if (this.researchLineNameList.includes(filterList[researchIndex].type)) { // mockAction.queryData(adaptRowListResult.tableName, { researchId: researchInstance.id }) // .then(rowListRes => { // const rowListQuery = filterSqlRows(rowListRes); // // console.log("rowListQuery------>", rowListQuery) // if (rowListQuery && rowListQuery.length) { // rowList.push( // [ // newLocation['lon'], // newLocation['lat'], // ] // ) // const newRowListQuery = rowListQuery.reverse(); // newRowListQuery.forEach(row => { // if (row.latitude && row.longitude) { // const newRowLocation = GPS.gcj_decrypt(row.latitude, row.longitude) // rowList.push( // [ // newRowLocation['lon'], // newRowLocation['lat'], // ] // ) // } // }) // } // }) // .catch(err => { // }) // } let tempData: BjTypeMapMarker = { id: researchInstance.id, latitude: newLocation['lat'], longitude: newLocation['lon'], rowList: [], researchType: filterList[researchIndex].type, serialNumberAndCode: researchInstance.serialNumberAndCode, } researchMarkerList.push(tempData); } }) this.setState({ researchMarkerList: researchMarkerList }) }) .catch(err => { console.log("获取") }) } render() { const { researchMarkerList, mapConfig, currentZoomLevel } = this.state; let customMarkerElArray = []; if (researchMarkerList && researchMarkerList.length && mapConfig && mapConfig.showResearchData) { researchMarkerList.forEach(marker => { customMarkerElArray.push( ) }) } return customMarkerElArray; } }