rollTab.jsx 2.6 KB
Newer Older
徐立's avatar
徐立 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
/**
 * 徐立
 * 滚动图标选择
 */
import React, { Component } from 'react';
import BasicsCard from './Basics';
import { formulaList } from '../excelInitFuc/functionList';

export default class rollTab extends Component {
    constructor(props){
        super(props)
        this.state = {
            tabList : [],
            name : '', // 转存名字
        }
    }
    componentDidMount(){
        this.setState({
            tabList:formulaList
        },()=>{
            this.setCloseAll()
        })
        this.props.setPagesTotal(formulaList.length)
    }
    // 修改选中样式
    setCheckedList = (name) => {
        const { tabList } = this.state
        if(name == this.state.name){
            let ary = tabList.map(item => {
                item.isPitch = false
                item.isShowList = false
                    return item
            })
            this.setState({
                tabList:ary,
                name: ''
            })
            return
        }
        let ary = tabList.map(item => {
            if(item.name == name){
                item.isPitch = true
                item.isShowList = true
                return item
            }
            item.isPitch = false
            item.isShowList = false
                return item
        })
        this.setState({
            tabList:ary,
            name
        })
    }
    // 选中函数后关闭全部
    setCloseAll = () => {
        const { tabList } = this.state
        let ary = tabList.map(item => {
            item.isPitch = false
            item.isShowList = false
                return item
        })
        this.setState({
            tabList:ary,
            name: ''
        })
        return
    }
    render() {
        const {
            setPitchOn, // 打开所有函数选择框
            setFunction, // 设置函数相关
            pages, // 页码
        } = this.props
        const {
            tabList
        } = this.state
        let pageMax = Math.ceil(tabList.lebgth/14)
        return (
                tabList.map((item,i) => {
                    if(i>=(pages==1?1:(pages-1)*13)-1&&i<(pages==pageMax?pageMax*13:pages==1?pages*14:pages*13)){
                        return<BasicsCard
                        key={i}
                        setCloseAll = { this.setCloseAll }
                        setCheckedList = { this.setCheckedList }
                        item = {item}
                        setFunction={setFunction}
                        setPitchOn={setPitchOn}/>
                    }
                    return null
                })
        )
    }
}