import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, Keyboard, DeviceEventEmitter } from 'react-native'; import { adapatTypeName, colors, filterSqlRows, getCurrentDateNs, getLocalTime, myConfirm, px2dp, size, toast, toastShort, uuid, adaptLocationPoint, validResponseCode, isEmpty, isEmptyStr } from './../../utils'; import BottomSheet from 'reanimated-bottom-sheet' import Animated from 'react-native-reanimated'; import BackgroundTimer from 'react-native-background-timer'; import Sound from 'react-native-sound'; import { BjTypeLocation, TypeBirdResearchLineV1, BjTypeMapMarker, BjTypeCommunityProfileResearch, BjTypeResearchNameDict, BjTypeCommonResearch, BjTypeResearchConnection } from './../../utils/types'; import GPS from './../../utils/GPS'; import { adaptAPIAndName } from '../../utils/adapt'; import mockAction from '../../sevices/mockAction'; import LoadingImageKit from '../kits/KitLoadingImage'; import API from '../../api'; import { navigate } from '../../NavigationService'; interface Props { showLoading: Function hideLoading: Function } interface State { marker: BjTypeMapMarker researchInstance: BjTypeCommunityProfileResearch & TypeBirdResearchLineV1 showLocationText: string } export default class ResearchMsgMapKit extends React.Component { constructor(props: Props) { super(props); }; public marker = null; public fall = null; public sheetRef = null; public delayTimer = null; public delayHideTimer = null; public sheetContainerRef = null; public readonly state: Readonly = { marker: null, researchInstance: null, showLocationText: "", }; componentWillUnmount() { this.delayTimer && clearTimeout(this.delayTimer); this.delayHideTimer && clearTimeout(this.delayHideTimer); this.setState = (state, callback) => { return; } }; public show = (marker: BjTypeMapMarker) => { //打开下拉框 this.setState({ marker: marker }) Keyboard.dismiss(); this.delayHideTimer && clearTimeout(this.delayHideTimer); this.sheetContainerRef.setNativeProps({ style: { display: 'flex', height: px2dp(230), zIndex: 99999999999, elevation: 12 } }); this.sheetRef.snapTo(1); this.sheetRef.snapTo(1); this.queryResearchInstance(marker); }; async queryResearchInstance(marker: BjTypeMapMarker) { const adaptResult = adaptAPIAndName(marker.researchType, 'query', 'research-data'); console.log("adaptResult------>", adaptResult) let res = await mockAction.queryData(adaptResult.tableName, { id: marker.id }) const list: Array = filterSqlRows(res) console.log("调查基础信息---->", JSON.stringify(list)) const currentDetails = list.length ? list[0] : {}; //@ts-ignore if (currentDetails.latitudeStart && currentDetails.longitudeStart) { //@ts-ignore const newLocation = GPS.gcj_decrypt_exact(Number(currentDetails.latitudeStart), Number(currentDetails.longitudeStart)); const showLocationText = adaptLocationPoint(newLocation['lon'].toFixed(6), newLocation['lat'].toFixed(6)) this.setState({ showLocationText }) } //@ts-ignore this.setState({ researchInstance: currentDetails }) }; handleClose() { Keyboard.dismiss(); this.setState({ researchInstance: null }) this.delayHideTimer && clearTimeout(this.delayHideTimer); this.sheetContainerRef.setNativeProps({ style: { display: 'none', height: 0, zIndex: -999 } }); this.sheetRef.snapTo(0); this.sheetRef.snapTo(0); } _onCloseEnd() { this.sheetContainerRef.setNativeProps({ style: { display: 'none', height: 0, zIndex: -1 } }); }; getIconUrl() { const { marker } = this.state; if (!marker) { return { icon: "", nameText: "", tintColor: "#6df90d" } } let url = './../../assets/icons/research-icon-1.png'; let nameText = ""; let tintColor = "#ffc000" switch (marker.researchType) { case 'communityProfileResearch': url = require('./../../assets/icons/research-icon-1.png'); tintColor = "#6df90d" break; case 'actualMeasurementResearch': url = require('./../../assets/icons/research-icon-2.png'); // nameText = '森'; tintColor = "#6df90d" break; case 'sampleLineResearch': url = require('./../../assets/icons/research-icon-3.png'); // nameText = '灌'; tintColor = "#6df90d" break; case 'sampleSquareResearch': url = require('./../../assets/icons/research-icon-4.png'); // nameText = '草'; tintColor = "#6df90d" break; default: break; } return { icon: url, nameText, tintColor } } jumpToNewResearchPage() { try { const { showLoading, hideLoading } = this.props; const { marker, researchInstance } = this.state; //@ts-ignore const item: BjTypeCommonResearch = marker; item.type = marker.researchType; item.researchId = marker.id; console.log("item", item) showLoading && showLoading(); let requestMethod = null; let tablePageRouterName = ''; let queryResearchConnectionParams: BjTypeResearchConnection = { }; switch (item.type) { case 'communityProfileResearch': requestMethod = API.getCommunityProfileResearchDetailstV1; tablePageRouterName = 'NewCommunityProfileResearch'; queryResearchConnectionParams.communityProfileResearchId = item.researchId; break; case 'actualMeasurementResearch': requestMethod = API.getActualMeasurementResearchDetailstV1; tablePageRouterName = 'NewActualMeasurementResearch'; queryResearchConnectionParams.actualMeasurementResearchId = item.researchId; break; case 'sampleSquareResearch': requestMethod = API.getSampleSquareResearchDetailstV1; tablePageRouterName = 'NewSampleSquareResearch'; queryResearchConnectionParams.sampleSquareResearchId = item.researchId; break; case 'sampleLineResearch': requestMethod = API.getSampleLineResearchDetailstV1; tablePageRouterName = 'NewSampleLineResearch'; queryResearchConnectionParams.sampleLineResearchId = item.researchId; break; default: break; } if (!requestMethod) { hideLoading && hideLoading(); return toast("请检查接口映射") } let queryResearchConnectionTask = API.queryResearchConnection(queryResearchConnectionParams); Promise.all([ queryResearchConnectionTask, requestMethod({ id: item.researchId }) ]) .then(resList => { const researchConnectionRes = resList[0]; const researchDetailsRes = resList[1]; hideLoading && hideLoading(); if (validResponseCode(researchDetailsRes)) { let routeParams = { researchInstance: researchDetailsRes.data.list ? researchDetailsRes.data.list[0] : researchDetailsRes.data.info, justView: false } if (researchConnectionRes.data.list.length) { //@ts-ignore routeParams.researchConnection = researchConnectionRes.data.list[0]; } console.log("routeParams------>", routeParams) navigate(tablePageRouterName, routeParams) } else { toastShort("跳转失败,请稍后重试"); } }) .catch(err => { hideLoading && hideLoading(); toastShort("获取详情失败" + err) console.log("err", err) }) } catch (e) { toast("获取详情失败" + e) } }; jumpToDetails() { const { marker, researchInstance } = this.state; let requestMethod = null; let tablePageRouterName = null; console.log("researchInstance", marker); try { const { showLoading, hideLoading } = this.props; //@ts-ignore const item: BjTypeCommonResearch = marker; item.type = marker.researchType; item.researchId = marker.id; if (item.type == 'communityProfileResearch') { return this.jumpToNewResearchPage(); } console.log("item", item) showLoading && showLoading(); let requestMethod = null; let tablePageRouterName = ''; let queryResearchConnectionParams: BjTypeResearchConnection = { }; let researchType = item.type; switch (item.type) { // case 'communityProfileResearch': // requestMethod = API.getCommunityProfileResearchDetailstV1; // tablePageRouterName = 'ResearchCommonTablePage'; // queryResearchConnectionParams.communityProfileResearchId = item.researchId; // break; case 'actualMeasurementResearch': requestMethod = API.getActualMeasurementResearchDetailstV1; tablePageRouterName = 'ResearchCommonTablePage'; queryResearchConnectionParams.actualMeasurementResearchId = item.researchId; break; case 'sampleSquareResearch': requestMethod = API.getSampleSquareResearchDetailstV1; tablePageRouterName = 'ResearchCommonTablePage'; queryResearchConnectionParams.sampleSquareResearchId = item.researchId; break; case 'sampleLineResearch': requestMethod = API.getSampleLineResearchDetailstV1; tablePageRouterName = 'ResearchCommonTablePage'; queryResearchConnectionParams.sampleLineResearchId = item.researchId; break; default: break; } let queryResearchConnectionTask = API.queryResearchConnection(queryResearchConnectionParams); console.log("queryResearchConnectionTask", JSON.stringify(queryResearchConnectionTask)) // return false; if (!requestMethod) { hideLoading && hideLoading(); return toast("请检查接口映射") } Promise.all([ queryResearchConnectionTask, requestMethod({ id: item.researchId }) ]) .then(resList => { console.log("这是首页调查详情", resList) const researchConnectionRes = resList[0]; console.log("researchConnectionRes", JSON.stringify(researchConnectionRes)) const researchDetailsRes = resList[1]; if (validResponseCode(researchDetailsRes) && validResponseCode(researchConnectionRes)) { let routeParams = { researchInstance: researchDetailsRes.data.list ? researchDetailsRes.data.list[0] : researchDetailsRes.data.info, researchType: researchType, justView: false } if (researchConnectionRes.data.list.length) { //@ts-ignore routeParams.researchConnection = researchConnectionRes.data.list[0]; } else { hideLoading && hideLoading(); return toast( item.type == 'communityProfileResearch' ? "当前群落概况信息没有关联调查" : "请先填写群落概况信息" ) } if (item.type == 'communityProfileResearch') { let connectResearchType: BjTypeResearchNameDict = "actualMeasurementResearch"; let connectResearchId = null; let quereConnectResearchDetailsMethod = null; let researchConnection: BjTypeResearchConnection = researchConnectionRes.data.list[0]; if (!isEmpty(researchConnection.actualMeasurementResearchId)) { connectResearchType = 'actualMeasurementResearch'; connectResearchId = researchConnection['actualMeasurementResearchId']; quereConnectResearchDetailsMethod = API.getActualMeasurementResearchDetailstV1; } else if (!isEmptyStr(researchConnection.sampleLineResearchId)) { connectResearchType = 'sampleLineResearch'; connectResearchId = researchConnection['sampleLineResearchId']; quereConnectResearchDetailsMethod = API.getSampleLineResearchDetailstV1; } else if (!isEmpty(researchConnection.sampleSquareResearchId)) { connectResearchType = 'sampleSquareResearch'; connectResearchId = researchConnection['sampleSquareResearchId']; quereConnectResearchDetailsMethod = API.getSampleSquareResearchDetailstV1; } if (connectResearchType && connectResearchId) { console.log("routeParams------>", routeParams) quereConnectResearchDetailsMethod && quereConnectResearchDetailsMethod({ id: connectResearchId }) .then(res => { hideLoading && hideLoading(); routeParams.researchInstance = res.data.list[0]; // routeParams.researchType = item.type; navigate(tablePageRouterName, routeParams) }) .catch(err => { hideLoading && hideLoading(); }) } } else { hideLoading && hideLoading(); console.log("routeParams------>", routeParams) DeviceEventEmitter.emit('add-common-research-float', { researchItem: item }) navigate(tablePageRouterName, routeParams) } } else { toastShort("跳转失败,请稍后重试"); } }) .catch(err => { hideLoading && hideLoading(); toastShort("获取详情失败" + err) console.log("err", err) }) } catch (e) { toast("获取详情失败" + e) } }; renderInner() { const { marker, researchInstance, showLocationText } = this.state; if (marker && marker.id) { const { icon = require('./../../assets/icons/research-icon-1.png') } = this.getIconUrl(); return ( {/* */} { researchInstance ? {researchInstance.serialNumberAndCode} ({adapatTypeName(marker.researchType)}) 经纬度:{showLocationText} 海拔:{researchInstance.altitudeStart}m 调查区域:{researchInstance.researchArea} 创建时间:{getLocalTime('YY:MM:DD HH:MM', researchInstance.createDate)} : 加载数据中.... } ) } return }; render() { const sheetHeight = px2dp(172); return ( this.sheetContainerRef = c} style={styles.container} > { this.sheetRef = c }} borderRadius={px2dp(12)} onCloseEnd={this._onCloseEnd} /> ) } } const styles = StyleSheet.create({ container: { display: 'none', position: 'absolute', bottom: 0, left: 0, width: px2dp(375), height: 0, // backgroundColor: '#fff', borderTopLeftRadius: px2dp(10), borderTopRightRadius: px2dp(10), zIndex: -9999, elevation: 20 }, top: { width: '100%', height: px2dp(32), flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', paddingHorizontal: px2dp(12) }, msgContainer: { width: '100%', height: px2dp(142), // backgroundColor: 'red', flexDirection: 'column', justifyContent: 'flex-start', alignItems: 'center', paddingVertical: px2dp(12) }, topHalf: { flex: 1, height: '100%', justifyContent: 'center', alignItems: 'center' }, bottom: { width: '100%', flex: 1, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', // backgroundColor: '#999', paddingBottom: size.tab_height + px2dp(6), paddingHorizontal: px2dp(10) }, optionIcon: { width: px2dp(38), height: px2dp(38), marginBottom: px2dp(4), tintColor: '#303133' }, optionBtn: { flex: 1, height: '100%', justifyContent: 'center', alignItems: 'center' }, icon: { width: px2dp(30), height: px2dp(30), marginRight: px2dp(10) }, infoRow: { width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginTop: px2dp(12), paddingHorizontal: px2dp(13) }, infoText: { fontSize: 12, color: '#303133', maxWidth: px2dp(170) }, closeBtnContainer: { position: 'absolute', top: px2dp(8), right: 0, width: px2dp(42), height: px2dp(28), justifyContent: 'center', alignItems: 'center' }, closeBtn: { width: '100%', height: '100%', justifyContent: 'center', alignItems: 'center' } })