index.js 4.1 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,
      loadingFlag:true
    }
  }
  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')
  }

  componentWillMount(){
    Toast.loading('loading...',0);
    this.getUser();
  }
  componentDidMount(){
    document.title = '我的客户';

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

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

      }
    })
  }

  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() {
    if(this.state.loadingFlag){
      return <div></div>
    }
    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}
                                  storeNameList = {this.state.storeNameList}
                                  storeNameList1 = {this.state.storeNameList1}
                                  goAddUser = {this.goAddUser}
                                  content={'修改'}
                                  dataFilterToProp= {this.dataFilterToProp.bind(this)}
                                  hasClient={this.state.hasClient} />
        }
      </div>
    )
  }
}

MyUser.propsTypes = {}

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