import { DeliverNoticeOrder, DeliveryNoticeOrderAudit, DeliveryNoticeOrderUpload } from '@/api' import { formatDateTime, formatMeterDiv, formatWeightDiv } from '@/common/format' import Cell from '@/components/cell' import Divider from '@/components/divider' import LayoutBlock from '@/components/layoutBlock' import NormalButton from '@/components/normalButton' import SaleModeTag from '@/components/saleModeTag' import UploadImage from '@/components/uploadImage' import { View, Text } from '@tarojs/components' import Taro from '@tarojs/taro' import { useRouter } from '@tarojs/taro' import { alert } from '@/common/common' import { FC, useCallback, useEffect, useMemo, useState } from 'react' import styles from './index.module.scss' const DeliveryDetail: FC = () => { const router = useRouter() const { fetchData } = DeliverNoticeOrder() const [detailInfo, setDetailInfo] = useState>({}) const getData = async () => { const { id, order_no } = router.params const res = await fetchData({ id, order_no, }) console.log('res==>', res.data) setDetailInfo(res.data) } useEffect(() => { getData() }, []) const { fetchData: uploadData } = DeliveryNoticeOrderUpload() const { fetchData: FetchAudit } = DeliveryNoticeOrderAudit() const DetailItem = useMemo(() => { const element = !!detailInfo?.weight_list?.length && detailInfo?.weight_list.map((weightItem) => { return ( {weightItem.product_code} {weightItem.product_name} 共 {weightItem?.sale_mode === 0 ? `${weightItem.roll} 条` : `${formatMeterDiv(weightItem?.length || 0)} 米`} {weightItem.product_color_code} {weightItem.product_color_name} x{weightItem?.sale_mode === 0 ? `${weightItem.roll} 条` : `${formatMeterDiv(weightItem?.length || 0)} 米`} {formatWeightDiv(weightItem.weight)}/kg ) }) return <>{element} }, [detailInfo]) const [readyToUploadList, setReadyToUploadList] = useState([]) const handleUploadChange = (imageList: string[]) => { console.log('imageList===>', imageList) setReadyToUploadList((prev) => [...prev, ...imageList]) } // 上传附件 const handleUploadPic = useCallback(async () => { const res = await uploadData({ id: Number(router.params.id), delivery_appendix: readyToUploadList, }) if (res.success) { alert.success('上传成功') } else { alert.error('上传核失败') } }, [readyToUploadList]) // 审核 const handleAudit = useCallback(() => { if (readyToUploadList.length === 0 ) { alert.error('请先上传附件') return } Taro.showModal({ confirmColor: '#337FFF', title: '确定审核?', success: async function (res) { if (res.confirm) { const res = await FetchAudit({ id: Number(router.params.id) }) if (res.success) { alert.success('审核成功') getData() } else { alert.error('审核失败') } } else if (res.cancel) { console.log('用户点击取消') } }, }) }, [readyToUploadList]) const BottomBar = useMemo(() => { return ( 上传附件 确认审核 ) }, [handleUploadPic, handleAudit]) return ( 发货单号:{detailInfo?.order_no} {detailInfo?.status === 0 ? 待审核 : 已完成} {DetailItem} 汇总: 共{detailInfo?.weight_list?.length || 0}种面料,4种颜色,共 {detailInfo?.sale_mode === 0 ? `${detailInfo?.total_roll}条` : `${formatMeterDiv(detailInfo?.total_length)}米`} ,重量{detailInfo?.total_weight}kg 订单信息 附件 {detailInfo?.status === 0 && BottomBar} ) } export default DeliveryDetail