import { Text, View } from '@tarojs/components'
import type { FC } from 'react'
import classnames from 'classnames'
import styles from './index.module.scss'
import LayoutBlock from '@/components/layoutBlock'
import Divider from '@/components/divider'
import NormalButton from '@/components/normalButton'
import { EnumSaleMode } from '@/common/Enumerate'
import { formatDateTime, formatMeterDiv } from '@/common/format'
import { goLink } from '@/common/common'
// import { DeliveryNoticeOrderAudit } from '@/api/index'
// import Taro from '@tarojs/taro'
import SaleModeTag from '@/components/saleModeTag'
// import { alert } from '@/common/common'

interface PropsType {
  itemData: Record<string, any>
  onSuccess?: Function
}

const ItemList: FC<PropsType> = (props) => {
  const { itemData, onSuccess } = props
  // 查看详情
  const handleDetail = (itemData: Record<string, any>) => {
    goLink('/pages/deliveryDetail/index', {
      id: itemData.id,
      order_no: itemData.order_no,
    })
  }

  // const {fetchData} = DeliveryNoticeOrderAudit()

  // // 确认审核
  // const handleAudit = (id: number) => {
  //   if (itemData.delivery_appendix_url.length === 0 ) {
  //     alert.error('请先上传附件')
  //     return
  //   }
  //   Taro.showModal({
  //     content: '确认要审核吗？',
  //     confirmColor: '#337FFF',
  //     success: async (res) => {
  //       if (res.confirm) {
  //         const res = await fetchData({ id })
  //         if (res.success) {
  //           Taro.showToast({ title: '审核成功', icon: 'success' })
  //           onSuccess?.()
  //         }else{
  //           Taro.showToast({ title: '审核失败', icon: 'error' })
  //         }
  //       }
  //     },
  //   })
  // }

  return (
    <LayoutBlock circle customClassName={styles.layoutBlock}>
      <View className={styles.topBar}>
        <View className={styles.topBar__orderNo}>
          <View className={styles.orderNo}>单号：{itemData?.order_no}</View>
          {itemData?.status === 1 && <View className={classnames(styles.topBar__orderStatus, styles['topBar__orderStatus--finish'])}>已审核</View>}
          {itemData?.status === 0 && <View className={classnames(styles.topBar__orderStatus, styles['topBar__orderStatus--toBeAudited'])}>待审核</View>}
        </View>
        <Text className={styles.topBar__orderType}>{itemData?.type_name}</Text>
      </View>
      <Divider direction="horizontal" customStyles={{ margin: '20rpx 0 10rpx 0' }}></Divider>
      <View className={styles.content}>
        <View className={classnames(styles.content__row, styles.bord)}>
          <View className={styles.content__row__left}>货品信息：</View>
          <View className={styles.content__row__right}>
            <SaleModeTag saleMode={itemData.sale_mode} size="small" customClassName={styles.tag}></SaleModeTag>
            {itemData.delivery_product_nums}种面料，{itemData.delivery_product_color_nums}种颜色，共
            {itemData?.sale_mode === EnumSaleMode.Bulk ? `${itemData?.delivery_roll}条` : `${formatMeterDiv(itemData?.delivery_length)}米`}
          </View>
        </View>
        <View className={styles.content__row}>
          <View className={styles.content__row__left}>发货地址：</View>
          <View className={styles.content__row__right}>{itemData?.delivery_address || '空'}</View>
        </View>
        <View className={styles.content__row}>
          <View className={styles.content__row__left}>创建时间：</View>
          <View className={styles.content__row__right}>{formatDateTime(itemData?.create_time) || '空'}</View>
        </View>
      </View>
      <View className={styles.bottomBar}>
        <NormalButton
          customClassName={styles.bottomBar__button}
          plain
          type="info"
          customStyles={{ color: '#636363', borderColor: '#c8c8c8' }}
          round
          onClick={() => handleDetail(itemData)}
        >
          查看详情
        </NormalButton>
        {/* {itemData?.status === 0 && (
          <NormalButton customClassName={styles.bottomBar__button} type='primary' plain round onClick={() => handleAudit(itemData?.id)}>
            确认审核
          </NormalButton>
        )} */}
      </View>
    </LayoutBlock>
  )
}
export default ItemList
