import { useState } from 'react' import styled from 'styled-components' import { Input, Popup, SafeArea, Radio, Button, ErrorBlock } from 'antd-mobile' import { RightOutline } from 'antd-mobile-icons' import OrderCard from './order-card' import { OrderListType } from '@/types/order' import { showError } from '@/utils' import { flowApi } from '@/services/flow' import { useAppDispatch } from '@/store/storeHooks' import emptyImage from '@/images/orders/empty.png' interface SelectOrderType { value: string inForm?: boolean shopId: string buyerOpenUid: string buyerNick: string shopUniqueKey?: string companyKey: string onSelect?: (newValue: string) => void onBlur?: (newValue: string) => void onChange: (id: string, detail?: OrderListType) => boolean | void } const InputBox = styled.div` position: relative; height: 47px; background: #fff; border: 0.5px solid #dcdcdc; padding: 10px 88px 10px 12px; border-radius: 6px; font-size: 14px; box-sizing: border-box; color: #111111; &.in-form { height: 45px; border: 0; padding: 0; } ` // const InputBoxNoBorder = styled(InputBox)` // border: 0; // ` const InputRight = styled.div` display: flex; align-items: center; position: absolute; top: 50%; transform: translateY(-50%); right: 8px; font-size: 14px; z-index: 2; color: #ff5000; ` const PopupContentBox = styled.div` padding: 14px 6px 0; .adm-error-block { margin-top: 100px; } ` const PopupTitle = styled.div` height: 24px; font-size: 16px; color: #333333; font-weight: 500; text-align: center; line-height: 24px; margin-bottom: 12px; ` const FixedButtonBox = styled.div` position: fixed; right: 0; bottom: 0; left: 0; padding: 16px 10px; background: #fff; ` const SelectOrder = (props: SelectOrderType) => { const [popupOrderId, setPopupOrderId] = useState(props.value || '') const [orderList, setOrderList] = useState([]) const [orderPopup, setOrderPopup] = useState(false) const dispatch = useAppDispatch() const { shopId, buyerNick, companyKey, onChange, onSelect } = props const handleChange = (value: string) => { onChange?.(value) } const handleBlur = () => { props.onBlur?.(props.value || '') } const handlePopup = () => { dispatch( flowApi.endpoints.orderList.initiate({ shopId, buyerNick, companyKey }) ) .then(res => { const { error, isError, isSuccess, data } = res if (isError) { showError(error) } if (isSuccess && data) { setOrderList(data) } }) .catch(err => { showError(err as Error) }) .finally(() => { setOrderPopup(true) }) } const confirmPopup = () => { const orderInfo = orderList.find(order => order.orderNo === popupOrderId) const flag = onChange(orderInfo ? popupOrderId : '', orderInfo) setOrderPopup(!!flag) handleChange(popupOrderId) onSelect?.(popupOrderId) } return ( <>
选择订单
{ setOrderPopup(false) }} onClose={() => { setOrderPopup(false) }} bodyStyle={{ height: '87vh', backgroundColor: '#F2F2F2', borderRadius: '20px 20px 0 0' }} > 选择订单
{!orderList.length ? ( ) : ( { setPopupOrderId(val as string) }} > {orderList.map(item => { return ( {item.itemList.map((it, index) => ( ))} ) })} )}
) } export default SelectOrder