import * as React from 'react'; import { taker, getApiUrl, getToUserId } from '../../../helper'; import './index.scss'; import Icon from '@beisen/bsapp-mobile-ui/es/icon'; 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: [] } } componentDidMount(){ 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[] = []; if(data){ data.map((d:any,k:number)=>{ let have = resData.filter((i:any)=>i.name == d.name).length if(!!have){ wallData.push(d); } }) }else{ resData.forEach((item: any) => { wallData.push(item) }); } update(wallData); this.setState({ isFetching: false, // wallData }) } checkboxListChange = (data: any) => { const wallData = this.props.data || [], { update } = this.props, newWallData: any = []; wallData.forEach((item:any) => { 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.props.data, { 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} = this.state; const wallData = this.props.data || []; const wallLen = wallData.length; return
{ !isFetching &&
    { wallData.map((item: any, index: number) => { return (
  • { this.checkboxListChange(item) }} style={{'width': '130px','display': 'inline-block'}}> {item.name}
    { wallLen > 1 && }
  • ) }) }
}
} }