import React from 'react' import Taro from '@tarojs/taro' import { View, Text, ScrollView } from '@tarojs/components' import { AtIndexes } from 'taro-ui' import { Checkbox } from 'tea-component-mobile' import { abbr } from './abbr' import './index.less' interface IndexesProps { checkIndexesList: any selectALLSHOW: Boolean list: any isAbbr: Boolean } export default class Indexes extends React.Component { constructor(props: any) { super(props) this.state = { scrollTop: 0, toView: '', CheckboxList: [], } } goToIndex(key) { let i = 0 let child = 0 for (let is = 0; is <= this.props.list.length; is++) { if (this.props.list[is].key === key) { break } i++ child += this.props.list[is].items.length } Taro.showToast({ title: key, icon: 'none', duration: 1000, }) var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth // var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight let len = i * ((w / 375) * 28) + child * ((w / 375) * 36) this.setState({ scrollTop: len, }) const partIndex = document.getElementById('footerIndexs'); if (partIndex) { partIndex.scrollTop = this.state.scrollTop } } componentWillMount() { this.setState({ CheckboxList: this.props.checkIndexesList, }) } handleCheckbox(items) { this.setState({ CheckboxList: items }) this.props.handleCheckIndexesList(items) } render() { const { scrollTop, CheckboxList } = this.state let indexsarr = new Array() if (this.props.selectALLSHOW) { this.props.list.map((item) => { indexsarr = [...indexsarr, ...item.items] }) indexsarr = indexsarr.map((citem) => { return citem.name }) } return ( {this.props.selectALLSHOW ? ( { if (CheckboxList.length === indexsarr.length) { this.setState({ CheckboxList: [], }) } else { this.setState({ CheckboxList: indexsarr, }) } this.props.handleCheckIndexesList(this.state.CheckboxList) }} > {CheckboxList.length === indexsarr.length ? 'Clear All' : 'Select All'} ) : ( '' )} console.log(e)}> {this.props.list.map((title) => { return ( {title.key} {title.items.map((item) => { return ( {this.props.isAbbr ? abbr[item.name] || item.name : item.name} ) })} ) })} {/* 右侧索引英文 */} {this.props.list.map((item) => { return ( {item.key} ) })} ) } }