import * as React from 'react'; import { taker, getApiUrl, getToUserId } from '&/helper'; import './index.scss'; interface Props { data: any, update: Function } interface State { isFetching: boolean; wallData: any[] } export default class Toggle extends React.Component{ constructor(props: Props) { super(props); this.state = { isFetching: true, wallData: [] } this.getData() } getData = async () => { const { data, update } = this.props const url = getApiUrl(`proxy/GetUPaaSCoreGateway/TalentHonor/GetAppItems?code=TalentOperation&toUserId=${getToUserId()}`); const res = await taker(url); if (res.Code !== 200) return; const resData = res.OperationObject.map((item: any) => { return { name: item.Title, inCheck: true } }) const wallData: any[] = []; resData.forEach((item: any) => { const oldData = data ? data.find((i: any) => { return i.name == item.name }) : null; wallData.push(oldData ? oldData : item) }); update(wallData); this.setState({ isFetching: false, wallData }) } checkboxListChange = (data: any) => { const { wallData } = this.state, { update } = this.props, newWallData: any = []; wallData.forEach(item => { newWallData.push({ name: item.name, inCheck: item.name == data.name ? !data.inCheck : item.inCheck }) }) update(newWallData) this.setState({ wallData: newWallData }) } changeOrder = (index: number) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation() const { wallData } = this.state, { update } = this.props, wallLen = wallData.length; let newWallData: any[] = []; const prev = index - 1 <= 0 ? [] : wallData.slice(0, index - 1); let next = []; newWallData = newWallData.concat(prev); if (index) { newWallData.push(wallData[index]) newWallData.push(wallData[index - 1]) next = index + 1 == wallLen ? [] : wallData.slice(index + 1); } else { newWallData.push(wallData[index + 1]) newWallData.push(wallData[index]) next = index + 2 == wallLen ? [] : wallData.slice(index + 2); } newWallData = newWallData.concat(next); update(newWallData) this.setState({ wallData: newWallData }) } handleInputChange = (e: React.ChangeEvent) => { } render() { const { isFetching, wallData } = this.state; const wallLen = wallData.length; return
{ !isFetching &&
    { wallData.map((item: any, index: number) => { return (
  • { this.checkboxListChange(item) }}> {item.name} { wallLen > 1 && }
  • ) }) }
}
} }