Commit 2294e27c authored by 前端-许佳敏's avatar 前端-许佳敏

确认手工发货

parent 1501fed2
import React, { useContext, useRef, useEffect } from 'react'
import { Modal, Button } from 'antd'
import NiceForm from '@/components/NiceForm'
import { createFormActions, ISchema } from '@formily/antd'
import ModalForm from '@/components/ModalForm'
import { history } from 'umi'
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect'
import { PublicApi } from '@/services/api'
import { useHttpRequest } from '@/hooks/useHttpRequest'
import { OrderDetailContext } from '../_public/order/context'
import moment from 'moment'
export interface OrderHandDeleveModalProps {
currentRef: any
}
const schemaActions = createFormActions()
const schema: ISchema = {
type: 'object',
properties: {
NO_SUBMIT: {
type: 'object',
"x-component": "mega-layout",
"x-component-props": {
labelAlign: 'left',
labelCol: 6
},
properties: {
addresId: {
type: 'string',
enum: [],
title: '发货地址',
"x-rules": [
{
message: '请选择发货地址',
required: true
}
]
},
deliverTime: {
type: 'string',
"x-component": 'date',
title: '发货日期',
"x-rules": [
{
message: '请选择发货日期',
required: true
}
],
"x-mega-props": {
full: true
}
},
deliverNo: {
type: 'string',
title: '发货单号',
"x-rules": [
{
required: true,
message: '请输入发货单号'
},
{
limitByte: true,
maxByte: 20
},
]
},
logisticsCompanyId: {
type: 'string',
enum: [],
title: '物流公司',
"x-rules": [
{
message: '请选择物流公司',
required: true
}
]
},
name: {
type: 'string',
display: false
},
logisticsCompany: {
type: 'string',
display: false
}
}
}
}
}
const OrderHandDeleveModal:React.FC<OrderHandDeleveModalProps> = (props) => {
const { data } = useContext(OrderDetailContext)
const dataRef = useRef<any>({})
const handleSubmit = async (value) => {
const params = {
...value,
orderId: data.id,
deliverTime: moment(value.deliverTime).valueOf()
}
const { code } = await PublicApi.postOrderManualDelivery(params)
if (code === 1000) {
history.goBack()
}
}
const handleConfirm = () => {
schemaActions.submit()
}
return (
<ModalForm
modalTitle='手工发货'
previewPlaceholder=' '
currentRef={props.currentRef}
schema={schema}
actions={schemaActions}
onSubmit={handleSubmit}
confirm={handleConfirm}
initialValues={{
deliverTime: moment().format('YYYY-MM-DD')
}}
effects={($, actions) => {
useAsyncSelect('addresId', async () => (await PublicApi.getLogisticsSelectListShipperAddress()).data, ['fullAddress', 'id'])
useAsyncSelect('logisticsCompanyId', async () => (await PublicApi.getLogisticsSelectListCompany()).data, ['name', 'id'])
// 获取联动的select后续事件, 为了设置对应的name值
$('requestAsyncSelect').subscribe(({ name, payload }) => {
if (name === 'addresId') {
dataRef.current.addresId = payload
}
if (name === 'logisticsCompanyId') {
dataRef.current.logisticsCompanyId = payload
}
})
$('onFieldInputChange', 'addresId').subscribe(({value}) => {
actions.setFieldValue('name', dataRef.current.addresId.find(v => v.value === value)?.label || '')
})
$('onFieldInputChange', 'logisticsCompanyId').subscribe(({value}) => {
actions.setFieldValue('logisticsCompany', dataRef.current.logisticsCompanyId.find(v => v.value === value)?.label || '')
})
}}
/>
)
}
OrderHandDeleveModal.defaultProps = {}
export default OrderHandDeleveModal
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment