index.js 3.4 KB
import React, { Component } from 'react'
import { connect } from 'dva'
import Tabs from "../../components/Tabs";
import { dataFilter } from '../../utils/dataFilter';
import styles from './myUser.css'
import shareHide from "../../utils/shareHide";
import {Toast} from "antd-mobile"



class MyUser extends Component {
  constructor(props){
    super(props)
    this.state={
      tab:['未提交','已提交'],
      user: true,
      hasClient: [false, false],
      letter:'',
      currentStatus:0,
      nameList: [],
      storeNameList: [],
      storeNameList1:[],
      nameList1:[],
      show:false,
    }
  }
  addUser = ()=>{
    // this.props.history.push('/addUser');
    let id = localStorage.getItem('id')
    window.location.href = window.location.href.split('#')[0] + '#/addUser?id=' + id
    localStorage.setItem('clientNeededInfo', 'null');
    localStorage.setItem('clientNeededInfoIsShare', 1);
}
  amentClient=()=>{
    this.props.history.push('/amendClient')
  }


  componentDidMount(){
    document.title = '我的客户';

    shareHide();
    this.getUser();
    this.getUser1();



  }
  componentWillUnmount(){
    document.title = '';
  }
  getUser=()=>{
    let that = this;
    this.props.dispatch({
      type: 'myUser/getAllUser',
      payload: {
        "id":localStorage.getItem("id"),
        "currentState":0,
      },
      callback(data) {
        let { hasClient } = that.state;
        hasClient[0] = data.length > 0;
        that.setState({
          nameList: data,
          // nameList: [],
          storeNameList: data,
          hasClient,
          show:true,
        })
        // that.props.amentClient();
      }
    })
}

  getUser1=()=>{
    let that = this;
    this.props.dispatch({
      type: 'myUser/getAllUser',
      payload: {
        "id":localStorage.getItem("id"),
      },
      callback(data){
        let { hasClient } = that.state;
        hasClient[1] = data.length > 0;
        that.setState({
          nameList1: data,
          // nameList1: [],
          hasClient,
          storeNameList1: data,
          show:true,
        })

      }
    })
  }

  delete = (id)=>{
    console.log(444);
    let that  = this;
    this.props.dispatch({
      type:'myUser/deleteCustomer',
      payload:{
        "id":id,
      },
      callback(){
        that.getUser()
        that.getUser1()
      }

    })
  }
  goAddUser = (item, status) => {
    const storeItem = { ...item, isSubmit: status };
    localStorage.setItem('clientNeededInfo', JSON.stringify(storeItem))
    this.props.history.push('/addUser');
  }

  dataFilterToProp(keywords, idx) {
    if (idx === 0) {
      this.setState({
        nameList: dataFilter(this.state.storeNameList, ['name'], keywords)
      })
    } else {
      this.setState({
        nameList1: dataFilter(this.state.storeNameList1, ['name'], keywords)
      })
    }

  }

  render() {
    return (
      <div className={styles.box}>
        {
          this.state.show &&<Tabs title={this.state.tab} user={this.state.user} letter={this.state.letter}  addUser={this.addUser}   editor={this.editor} delete={this.delete} amentClient = {this.amentClient} nameList = {this.state.nameList} nameList1 = {this.state.nameList1} goAddUser = {this.goAddUser} content={'修改'} dataFilterToProp= {this.dataFilterToProp.bind(this)} hasClient={this.state.hasClient} />
        }
      </div>
    )
  }
}

MyUser.propsTypes = {}

export default connect(({myUser})=>({myUser}))(MyUser)