import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, DeviceEventEmitter, FlatList } from 'react-native'; import FastImage from 'react-native-fast-image'; import { TextInput } from 'react-native-gesture-handler'; import Animated, { useAnimatedStyle, useSharedValue, withSpring, withTiming } from 'react-native-reanimated'; import comStyles from '../../assets/styles/com-style'; import { BjInstanceActualMeasurementResearchTableRow, BjInstanceCommunityProfileResearch } from '../../database/Instance'; import { colors, deepCopy, filterSqlRows, handleDismissKeyboard, isEmpty, onePx, px2dp, toastShort } from '../../utils'; import { BjTypeActualMeasurementResearchTableRow, BjTypeCommunityProfileResearch, BjTypeProtectionLandNameRow, BjTypeSpeceisNameRow } from '../../utils/types'; import FootLine from '../../components/kits/KitFootLine'; import debounce from '../../utils/debounce'; import mockAction from '../../sevices/mockAction'; import DataBaseTableName from '../../database/DataBaseTableName'; import redux from './../../redux/store'; import KitDashBorderLine from '../kits/KitDashBorderLine'; interface Props { onPickerResult?: Function } interface State { row: BjTypeActualMeasurementResearchTableRow } interface TypeResearch { name: string type: string } const ProtectionLandNameDialog = (props: Props) => { const containerRef = React.useRef(null); const delayTimer = React.useRef(null); const delayTimer1 = React.useRef(null); const overlayOpacity = useSharedValue(0.1); const layoutScaleValue = useSharedValue(1); const [tempResearchInstance, setTempResearchInstance] = React.useState(deepCopy(BjInstanceCommunityProfileResearch)); const [resultList, setResultList] = React.useState>([]); const showToastListener = React.useRef(null); const hideToastListener = React.useRef(null); const tempKey = React.useRef(null); const inputRef = React.useRef(null); React.useEffect(() => { overlayOpacity.value = withTiming(0.2); layoutScaleValue.value = withSpring(0); showToastListener.current = DeviceEventEmitter.addListener('show-protectionland-name-dialog', (a) => { tempKey.current = a.key; setTempResearchInstance(deepCopy(a.researchInstance)); delayTimer.current = setTimeout(() => { handleShowToast() }, 0); }); hideToastListener.current = DeviceEventEmitter.addListener('hide-protectionland-name-dialog', (a) => { handleHideToast() }); return () => { delayTimer.current && clearTimeout(delayTimer.current); delayTimer1.current && clearTimeout(delayTimer1.current); showToastListener.current && showToastListener.current?.remove(); hideToastListener.current && hideToastListener.current?.remove(); } }, []); const handleShowToast = () => { requestAnimationFrame(() => { containerRef.current.setNativeProps({ style: { width: '100%', height: '100%' } }) delayTimer1.current = setTimeout(() => { overlayOpacity.value = 0.52; layoutScaleValue.value = 1; }, 0); }) }; const handleHideToast = () => { delayTimer.current = setTimeout(() => { containerRef.current.setNativeProps({ style: { width: 0, height: 0 } }) }, 240); overlayOpacity.value = 0.1; layoutScaleValue.value = 0; handleDismissKeyboard(); } const handleComfirmToast = () => { const { onPickerResult } = props; let row: BjTypeProtectionLandNameRow = { protectionLandName: tempResearchInstance.protectionLandName } onPickerResult && onPickerResult(row); handleHideToast(); } const overlayAnimatedStyle = useAnimatedStyle(() => { return { opacity: withTiming(overlayOpacity.value, { duration: 240 }) } }); const toastBodyAnimatedStyle = useAnimatedStyle(() => { return { transform: [ { scale: withSpring(layoutScaleValue.value, { stiffness: 96 }), } ], opacity: withTiming(layoutScaleValue.value, { duration: 120 }), } }) const _onTextChange = (text) => { let _tempResearchInstance = tempResearchInstance; _tempResearchInstance.protectionLandName = text; setTempResearchInstance(deepCopy(_tempResearchInstance)); if (text) { debounce(() => { let findType = 'findAll'; var re = new RegExp("^[a-zA-Z]+$"); let likeFilter: BjTypeProtectionLandNameRow = { protectionLandName: text }; let filter = {}; mockAction.queryByMultipleLike1(DataBaseTableName.protectionLandInfoTable, likeFilter, findType, filter) .then(res => { console.log(filterSqlRows(res)) if (isEmpty(tempResearchInstance.protectionLandName)) { setResultList([]); } else { let _resultList = filterSqlRows(res); setResultList(_resultList) } }) .catch(err => { console.log("查询失败", err) }) }, 50); } }; const formatSearchText = (originStr: string) => { try { let { protectionLandName } = tempResearchInstance var re = new RegExp("^[a-zA-Z]+$"); let likeFilter: BjTypeSpeceisNameRow = {}; if (isEmpty(protectionLandName)) { return originStr; } let reg = new RegExp(protectionLandName); let str = originStr.split(reg); let txt = []; if (str.length === 0 || str.length === 1) { return originStr } if (str.length > 0) { txt.push({str[0]}); } txt.push({protectionLandName}); if (str.length > 1) { txt.push({str[1]}); } if (str.length >= 3) { for (let i = 2; i < str.length; i++) { txt.push({protectionLandName}); txt.push({str[i]}); } } return txt; } catch (e) { console.log("格式化失败", e) return originStr; } } const pickerResult = (item) => { const { onPickerResult } = props; onPickerResult && onPickerResult(item); handleHideToast(); } const render_item = ({ item, index }) => { return ( pickerResult(item)} style={{ fontSize: 15, color: '#30133', fontWeight: '400', marginBottom: px2dp(3) }} > {formatSearchText(item.protectionLandName)} pickerResult(item)} > 市(州): {item.protectionLandCity} 县(区): {item.protectionLandCounty} pickerResult(item)} > 类型: {item.protectionLandType} 级别: {item.protectionLandLevel} ) } const render_footer = () => { if (resultList.length) { return } }; const render_empty = () => { const { protectionLandName } = tempResearchInstance; if (protectionLandName) { return ( 没有匹配的搜索结果 ) } } return ( {/* 保护地信息快速录入 */} 保护地名称: { resultList && resultList.length ? 点击保护地搜索结果可直接使用 : null } index + ""} ListFooterComponent={render_footer()} ListEmptyComponent={render_empty()} keyboardShouldPersistTaps={'handled'} /> 取消 确定 ) }; const styles = StyleSheet.create({ overlay: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, width: '100%', height: '100%', backgroundColor: '#000', zIndex: -1 }, container: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, zIndex: 999, width: 0, height: 0, overflow: 'hidden' }, content: { position: 'relative', width: '100%', height: '100%', flex: 1, justifyContent: 'center', alignItems: 'center', // backgroundColor: 'red' }, toastBody: { width: px2dp(300), height: px2dp(480), backgroundColor: '#fff', borderRadius: px2dp(8), elevation: 12, justifyContent: 'space-between', alignItems: 'center', paddingVertical: px2dp(12) }, dialogHeader: { width: px2dp(268), height: px2dp(32), borderBottomWidth: 1, borderBottomColor: '#909399', flexDirection: 'row', justifyContent: 'center', alignItems: 'center', paddingHorizontal: px2dp(2) }, dialogHeaderRight: { flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center' }, footer: { width: px2dp(272), flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginTop: px2dp(12) }, footerLeftBtn: { width: px2dp(133), height: px2dp(36), borderRadius: px2dp(18), justifyContent: 'center', alignItems: 'center', backgroundColor: '#00D38F58', borderTopRightRadius: px2dp(3), borderBottomRightRadius: px2dp(3), }, footerRightBtn: { width: px2dp(133), height: px2dp(36), borderRadius: px2dp(18), justifyContent: 'center', alignItems: 'center', backgroundColor: colors.themeColor, borderTopLeftRadius: px2dp(3), borderBottomLeftRadius: px2dp(3) }, selectItem: { flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', borderBottomWidth: 1, borderBottomColor: '#303133', paddingTop: px2dp(16) }, selectItemName: { fontSize: 16, color: '#303133', marginLeft: px2dp(3) }, group: { width: px2dp(268), backgroundColor: '#f2f5f8', paddingHorizontal: px2dp(8), borderRadius: px2dp(3), marginTop: px2dp(12), paddingVertical: px2dp(6), }, groupRow: { width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: px2dp(8) }, groupTitle: { fontSize: 15, color: '#303133', marginBottom: px2dp(5) }, groupHeader: { }, item: { width: px2dp(268), paddingTop: px2dp(10) }, itemTitle: { fontSize: 14, color: '#303133' }, itemInput: { width: '100%', height: px2dp(24), lineHeight: px2dp(24), justifyContent: 'center', alignItems: 'center' }, searchBox: { width: px2dp(268), height: px2dp(36), flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', }, searchBoxTitle: { fontSize: 15, color: '#303133', marginRight: px2dp(5) }, searchBoxInput: { borderBottomWidth: 1, borderBottomColor: '#d2d2d2', width: px2dp(138), height: px2dp(32), fontSize: 15, color: '#303133' }, emptyContainer: { width: px2dp(240), height: px2dp(360), justifyContent: 'center', alignItems: 'center', }, emptyIcon: { width: px2dp(112), height: px2dp(112), }, infoRow: { width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', paddingTop: px2dp(5) }, infoRowItemText: { flex: 1, textAlign: 'left', fontSize: 14, color: '#303133' }, redText: { color: colors.redColor }, headerText: { width: px2dp(268), fontSize: 14, color: '#909399', // marginBottom: px2dp(10), textAlign: 'left', marginTop: px2dp(8) } }) export default ProtectionLandNameDialog;