import Taro, { Component } from '@tarojs/taro';
import './index.scss'
import { getClientList } from '@services/client'
import { getItemList } from '@services/item'
import emptyImg from '@assets/empty.png'
import dayjs from 'dayjs'
import { savePoint, updatePoint } from '@services/common'
export default class Index extends Component {

  config = {
    navigationBarTitleText: '我的客户'
  }

  state = {
    list: [],
    status: ['报备', '到访', '认购', '签约'],//报备客户状态
    recomstatus: ['推荐', '到访', '认购', '签约'],//推荐客户状态
    verifyStatus: ['待审核', '审核同意', '未通过'],
    floorList: '',
    floor: '',
    recordId: null
  }
  componentWillMount() {
    savePoint({
      event: 'list',
      eventType: 'agent',
      propertyName: '我的客户',
      data: '{}'
    }).then(res => {
      this.setState({
        recordId: res.recordId
      })
      console.log('我的客户')
    })
  }


  componentWillUnmount() {
    const { recordId } = this.state
    recordId && updatePoint(recordId)
  }
  componentDidMount() {
    this.loadList()
  }
  //获取楼盘列表
  loadGetFloor() {
    const params = {
      pageNumber: 1,
      pageSize: 50,
      keywords: ''
    }
    getItemList(params).then(res => {
      this.setState({
        floorList: res
      })
    })
  }
  loadList() {
    var that = this;
    const params = {
      pageNumber: 1,
      pageSize: 50,
      keywords: ''
    }
    this.loadGetFloor()
    getClientList(params).then(res => {
      that.setState({
        list: res.records
      }, () => {
      })
    })
  }

  formatDate(value) {
    return dayjs(value).format('YYYY-MM-DD')
  }
  navigateTo(id) {
    Taro.navigateTo({ url: `/pages/agent/progress/index?customerId=${id}` })
  }
  getName(dict, id) {
    dict = dict.records || []
    // let floorName = (dict.filter(({ buildingId: target }) => id === target)[0] || {}).name
    return (dict.filter(({ buildingId: target }) => id === target)[0] || {}).buildingName

  }
  render() {
    const { list, status, floorList } = this.state
    return (
      <View className='myClient'>
        {/* <View className='search__box'>
          <Search placeholder='搜索客户姓名/手机号'></Search>
        </View> */}

        {/*<View className='client__status'>
             <Text>{status[item.status - 1]}</Text>
          </View>*/}
        {!list.length &&
          <View className="empty">
            <Image className="empty__img" mode="widthFix" src={emptyImg}></Image>
            <View className="empty__text">暂无我的客户数据~</View>
          </View>
        }
        {list.length &&
          <View className='client__content'>
            <ScrollView
              scrollY
              scroll-with-animation
              enable-back-to-top
              className="list"
              style={{
                height: "100vh"
              }}>
              {
                list.map((item, index) => {
                  return (
                    <View className='client__list' key={index} onClick={this.navigateTo.bind(this, item.customerId)}>
                      <Image className='bg' src={item.verifyStatus == 2 ? require('@assets/person/card1.png') : require('@assets/person/card2.png')}></Image>
                      <View className='client'>
                        <View className='client__status2'>
                          {
                            //报备1 ，推荐2
                            item.reportRecommendStatus == 1 ? (<Text>{status[item.status - 1]}</Text>) : (<Text>{item.verifyStatus == 1 ? recomstatus[item.status - 1] : verifyStatus[item.verifyStatus]}</Text>)
                          }
                          {/* <Text>{item.verifyStatus==1?status[item.status-1]:verifyStatus[item.verifyStatus]}</Text> */}
                        </View>
                        <View className='client__top'>
                          <View className='client__infor'>
                            <Text className='client__name'>{item.name}  &emsp;</Text>
                            <Image className='sex' src={item.sex == 1 ? require('@assets/person/guest/man.png') : require('@assets/person/guest/women.png')} mode='widthFix'></Image>
                          </View>


                        </View>

                        <View className='phone'>手机:&emsp;{item.phone}</View>
                        <View className='phone'>意向楼盘:&emsp;{item.intention ? item.intention : '暂无'}</View>

                      </View>
                      <View className='time'>{dayjs(item.createDate).format('YYYY-MM-DD HH:mm:ss')}</View>
                    </View>
                  )
                })
              }
            </ScrollView>
          </View>
        }

      </View>
    );
  }
}