Commit bb653d88 authored by GuanHua's avatar GuanHua
parents 9c53cb48 c6d9900d
import React, { useState, useEffect, useContext, useRef } from 'react'
import OrderDetailHeader from '../../components/OrderDetailHeader'
import { Button, Row, Col } from 'antd'
import { Link, history } from 'umi'
import { OrderModalType, SaleOrderInsideWorkState } from '@/constants'
import { orderTypeLabel, SALE_ORDER_STATUS } from './constant'
import { formatTimeString } from '@/utils'
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus'
import { PublicApi } from '@/services/api'
import AuditProcess from '@/components/AuditProcess'
import { findLastIndexFlowState } from '../utils'
import OrderDetailWrapper from '../../components/OrderDetailWrapper'
import { GlobalConfig } from '@/global/config'
import OrderProductTable from './components/orderProductTable'
import { OrderDetailContext } from './context'
import MellowCard from '@/components/MellowCard'
import OrderMergeInfo from './components/orderMergeInfo'
import OrderTransformRecord from './components/orderTransformRecord'
import OrderPayTabs from './components/orderPayTabs'
import StatusColors from '@/pages/transaction/components/StatusColors'
import OrderPayResultModal from './components/orderPayResultModal'
import OrderDeleveRecord from './components/orderDeleveRecord'
import OrderElectronModal from './components/orderElectronModal'
import ModalForm from '@/components/ModalForm'
import { createFormActions } from '@formily/antd'
import OrderHandDeleveModal from './components/orderHandDeleve'
export interface CommonOrderDetailProps {}
const approvedActions = createFormActions()
const CommonOrderDetail:React.FC<CommonOrderDetailProps> = (props) => {
const approvedRef = useRef<any>({})
const [btnLoading, setBtnLoading] = useState<boolean>(false)
const [formData, setFormData] = useState<any>(null)
let { id, pageStatus, page_type = SALE_ORDER_STATUS.READY_APPROVED_ORDER, orderDeliveryDetailsId } = usePageStatus()
page_type = Number(page_type)
const payResultVisible = useRef<any>({})
const electronRef = useRef<any>({})
const handDelevedRef = useRef<any>({})
const [payResultType, setPayResultType] = useState<'default' | 'preview'>('default')
useEffect(() => {
reloadFormData()
}, [])
const reloadFormData = () => {
if (id) {
PublicApi.getOrderPurchaseOrderDetails({id}).then(({data, code}) => {
if (code === 1000) {
setFormData(data)
}
})
}
}
const handleConfirmApproved = () => {
approvedActions.submit()
}
const formContext = {
data: formData,
payResultType,
setPayResultType,
payResultVisible,
reloadFormData,
ctl: {
setData: setFormData
}
}
const handleSubmit = async () => {
let result: any = {}
const caseData = typeof page_type === 'string' ? parseInt(page_type) : page_type
switch(caseData) {
case SALE_ORDER_STATUS.READY_APPROVED_ORDER: {
//@todo 暂时写死
// const params = {
// id: parseInt(id),
// usingElectronicContracts: 0,
// state: 1
// }
// result = await PublicApi.postOrderSubmittedReviewOrder(params)
break;
}
case SALE_ORDER_STATUS.ONE_LEVEL_APPROVED_ORDER: {
const params = {
id: parseInt(id),
state: 1
}
result = await PublicApi.postOrderSubmittedReviewOrderOne(params)
break;
}
case SALE_ORDER_STATUS.TWO_LEVEL_APPROVED_ORDER: {
const params = {
id: parseInt(id),
state: 1
}
result = await PublicApi.postOrderSubmittedReviewOrderTwo(params)
break;
}
case SALE_ORDER_STATUS.CONFIRM_ORDER: {
const params = {
id: parseInt(id),
state: 1
}
result = await PublicApi.postOrderConfirmedOrder(params)
break;
}
case SALE_ORDER_STATUS.CONFIRM_PAY_RESULT_ORDER: {
const params = {
id: parseInt(id),
state: 1
}
result = await PublicApi.postOrderConfirmedPaymentResultsOrder(params)
break;
}
case SALE_ORDER_STATUS.CONFIRM_DELIVE_GOODS_ORDER: {
// const params = {
// orderId: parseInt(id),
// // 订单发货明细id(发货单ID)
// id: parseInt(orderDeliveryDetailsId)
// }
// result = await PublicApi.postOrderConfirmShipmentOrder(params)
const deleveBox = document.querySelector('#deleveBox') as any
window.scrollTo(0, deleveBox.offsetTop)
break;
}
// 确认全部回单
case SALE_ORDER_STATUS.CONFIRM_RETURN_ORDER: {
const params = {
id: parseInt(id)
}
result = await PublicApi.postOrderReceiptOrderConfirmedAll(params)
break;
}
// 待归档
case SALE_ORDER_STATUS.RETURN_DOCUMENT_ORDER: {
const params = {
id: parseInt(id)
}
result = await PublicApi.postOrderOfOrdersToBeFiled(params)
break;
}
}
if (result.code === 1000) {
history.goBack()
}
setBtnLoading(false)
}
const startPush = () => {
if (page_type === SALE_ORDER_STATUS.CONFIRM_PAY_RESULT_ORDER) {
setPayResultType('default')
payResultVisible.current.setVisible(true)
return
}
if (page_type === SALE_ORDER_STATUS.READY_APPROVED_ORDER) {
electronRef.current.setVisible(true)
return
}
// 手工发货,需弹窗确认
if (formData.purchaseOrderInteriorState === SaleOrderInsideWorkState.HAND_DELEVED_ORDER) {
handDelevedRef.current.setVisible(true)
return ;
}
// 一级审核, 二级审核, 确认订单 都需要通过弹窗确认后再提交
if (page_type === SALE_ORDER_STATUS.ONE_LEVEL_APPROVED_ORDER || page_type === SALE_ORDER_STATUS.TWO_LEVEL_APPROVED_ORDER || page_type === SALE_ORDER_STATUS.CONFIRM_ORDER) {
approvedRef.current.setVisible(true)
return ;
}
handleSubmit()
}
const renderExtra = () => {
if (!formData || page_type === SALE_ORDER_STATUS.PREVIEW_ORDER) {
return null
}
let text = ''
switch(formData.purchaseOrderInteriorState) {
case SaleOrderInsideWorkState.CONFIRM_ORDER: {
text = '确认提交'
break;
}
case SaleOrderInsideWorkState.READY_CONFIRM_PAY_RESULT: {
text = '确认支付结果'
break;
}
case SaleOrderInsideWorkState.CONFIRM_RECEIPT: {
text = '确认全部已回单'
break;
}
case SaleOrderInsideWorkState.CONFIRM_DELIVERY_ORDER: {
text = '去确认发货'
break;
}
case SaleOrderInsideWorkState.FILLING_ORDER: {
text = '确认归档'
break
}
case SaleOrderInsideWorkState.HAND_DELEVED_ORDER: {
text = '确认手工发货'
break
}
default: {
text = '提交审核'
break;
}
}
return <Button type='primary' onClick={startPush} loading={btnLoading}>{text}</Button>
}
const detailList = [
{ label: '对应报价单号', name: 'quotationNo', span: 8, render: text => <Link to={'/'}>{text}</Link> },
{ label: '订单摘要', name: 'orderThe', span: 8 },
{ label: '供应会员', name: 'supplyMembersName', span: 8 },
{ label: '下单模式', name: 'orderModel', span: 8, render: text => GlobalConfig.web.orderMode.find(v => v.value === text)?.label || '' },
{ label: '订单类型', name: 'type', span: 8, render: text => orderTypeLabel[text] },
{ label: '下单时间', name: 'createTime', span: 8, render: text => formatTimeString(text) },
{ label: '外部状态', name: 'externalState', span: 8, render: text => <StatusColors type='out' status={text}/> },
{ label: '内部状态', name: 'purchaseOrderInteriorState', span: 8, render: text => <StatusColors type='saleInside' status={text}/> },
]
const headerTiTle = formData ? {
picName: '单',
titleLabel: '订单号: ',
titleValue: formData.orderNo
} : null
return formData ? (
<div>
<OrderDetailContext.Provider value={formContext}>
<OrderDetailHeader headerTitle={headerTiTle} detailList={detailList} detailData={formData} extraRight={renderExtra()}/>
<OrderDetailWrapper>
<div className='gray-wrap'>
{/* 工作流进度 */}
{ pageStatus !== PageStatus.ADD && formData && <AuditProcess
customTitleKey='operationalProcess'
customKey='state'
outerVerifyCurrent={findLastIndexFlowState(formData.externalWorkflowFlowRecordLogResponses) || 0}
innerVerifyCurrent={findLastIndexFlowState(formData.interiorWorkflowFlowRecordLogResponses) || 0}
outerVerifySteps={formData.externalWorkflowFlowRecordLogResponses || []}
innerVerifySteps={formData.interiorWorkflowFlowRecordLogResponses || []}
></AuditProcess> }
{/* 商品列表 */}
<OrderProductTable/>
{/* 支付信息 todo */}
<OrderPayTabs/>
{/* 杂项 */}
<OrderMergeInfo/>
{/* 订单发货记录 */}
<OrderDeleveRecord/>
{/* 订单流转记录 */}
<OrderTransformRecord/>
</div>
</OrderDetailWrapper>
<OrderElectronModal
currentRef={electronRef}
/>
<OrderHandDeleveModal
currentRef={handDelevedRef}
/>
<OrderPayResultModal currentRef={payResultVisible} type={payResultType}/>
{/* 提交时触发的弹窗集合 */}
<ModalForm
modalTitle='提示'
currentRef={approvedRef}
confirm={handleConfirmApproved}
actions={approvedActions}
schema={{
type: 'object',
properties: {
NO_SUBMIT: {
type: 'object',
"x-component": 'mega-layout',
"x-component-props": {
labelAlign: 'top',
},
properties: {
state: {
type: 'radio',
enum: [
{ label: '审核通过', value: 1 },
{ label: '审核不通过', value: 0 },
],
default: 1,
"x-linkages": [
{
type: 'value:visible',
target: 'cause',
condition: "{{$value === 0}}"
}
]
},
cause: {
type: 'textarea',
"x-component-props": {
rows: 4,
placeholder: '在此输入你的原因, 最多60个汉字'
},
title: '审核不通过原因',
"x-rules": [
{
required: true,
message: '请输入审核不通过原因'
},
{
limitByte: true,
maxByte: 30
}
]
}
}
}
}
}}
onSubmit={handleSubmit}
/>
</OrderDetailContext.Provider>
</div>
) : null
}
CommonOrderDetail.defaultProps = {}
export default CommonOrderDetail
\ 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