import { Text, View } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { useEffect, useState } from 'react'
import styles from './index.module.scss'
import IconFont from '@/components/iconfont/iconfont'
import { goLink } from '@/common/common'
import NameLabel from '@/components/nameLabel'

export interface CompanyItem { title: string; purchaser_name: string; phone: string; is_default?: boolean; id?: number }
interface CompanyParam {
  defaultValue?: CompanyItem
  onSelect?: (data: CompanyItem) => void
}
export default (props: CompanyParam) => {
  const { defaultValue, onSelect } = props
  const [data, setData] = useState<CompanyItem>()
  useEffect(() => {
    if (defaultValue) { setData(() => defaultValue) }
  }, [defaultValue])
  const goLink = () => {
    Taro.navigateTo({
      url: '/pages/weightList/index',
      events: {
        getSelectCompanyEvent(data) {
          console.log('data::', data)
          setData(() => data)
          onSelect?.(data as CompanyItem)
        },
      },
    })
  }
  return <View className={styles.payee_head} onClick={goLink}>
    <NameLabel name={data?.title || ''} />
    <View className={styles.payee_head__desc}>
      <View className={styles.payee_head__desc__company}>
        <Text>{data?.title}</Text>
        {/* {data?.is_default && <Text>默认抬头</Text>} */}
      </View>
      <View className={styles.payee_head__desc__name}>
        <Text>{data?.purchaser_name}</Text>
        <Text>{data?.phone}</Text>
      </View>
    </View>
    <View className={styles.more}><IconFont name="icon-xiala" size={50} color="#979797" /></View>
  </View>
}
