Commit 09899393 authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

fix:处理订单详情无法获取支付方式

parent 483bdb21
import React, { useRef } from 'react'
import { useCallback, useState, useEffect } from 'react'
import { usePageStatus } from '@/hooks/usePageStatus'
import { PublicApi } from '@/services/api'
import { Link } from 'umi'
import { GlobalConfig } from '@/global/config'
import { orderTypeLabel } from '../constant'
import { formatTimeString } from '@/utils'
import StatusColors from '../../../components/StatusColors'
import { message } from 'antd'
interface OrderDetailHookProps {
// 采购、销售
type: 'purchaseOrder' | 'saleOrder'
}
// 订单详情, 支持两种订单模式
export const useOrderDetail = (options: OrderDetailHookProps) => {
// 订单详情内容
const [formData, setFormData] = useState<any>(null)
// 当前的支付信息id 默认第一个
const [currentPayInfoId, setCurrentPayInfoId] = useState<any>(null)
// 支付信息列表
const [payList, setPaylist] = useState<any[]>([])
const { id } = usePageStatus()
const { type } = options
const dataRef = useRef<any>([
{ label: '对应报价单号', name: 'quotationNo', span: 8, render: text => <Link to={'/'}>{text}</Link> },
{ label: '订单摘要', name: 'orderThe', span: 8 },
{ label: type === 'saleOrder' ? '采购会员' : '供应会员', name: type === 'saleOrder' ? 'createMemberName' : '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: type === 'saleOrder' ? 'purchaseOrderInteriorState' : 'interiorState', span: 8, render: text => <StatusColors type={type === 'saleOrder' ? 'saleInside' : 'inside'} status={text}/> },
])
useEffect(() => {
reloadFormData()
// reloadPayList()
}, [])
const reloadFormData = useCallback(() => {
if (id) {
const fn = type === 'purchaseOrder' ? PublicApi.getOrderProcurementOrderDetails : PublicApi.getOrderPurchaseOrderDetails
fn({ id }, { ctlType: "none" }).then(res => {
const { code, data, message: msg } = res
if (code === 1000) {
setFormData(data)
if(data.paymentInformationResponses.length > 0){
setCurrentPayInfoId(data.paymentInformationResponses[0].id)
}
reloadPayList(data.supplyMembersId)
} else {
message.error(msg)
}
})
}
}, [id])
const reloadPayList = (memberId) => {
PublicApi.getPayPayWayList({memberId}).then(res => {
const { code, data } = res
if (code === 1000) {
setPaylist(data)
} else {
message.error(res.message)
}
})
}
// const reloadPayList = useCallback(() => {
// PublicApi.getPayPayWayList().then(res => {
// const { code, data } = res
// if (code === 1000) {
// setPaylist(data)
// }
// })
// }, [id])
// 需共享的状态
const formContext = {
data: formData,
currentPayInfoId,
payList,
ctl: {
setData: setFormData,
setPayId: setCurrentPayInfoId,
},
reloadFormData
}
return {
formContext,
id,
detailList: dataRef.current
}
}
\ No newline at end of file
import React, { useRef } from 'react'
import { useCallback, useState, useEffect } from 'react'
import { usePageStatus } from '@/hooks/usePageStatus'
import { PublicApi } from '@/services/api'
import { Link } from 'umi'
import { GlobalConfig } from '@/global/config'
import { orderTypeLabel } from '../constant'
import { formatTimeString } from '@/utils'
import StatusColors from '../../../components/StatusColors'
import { message } from 'antd'
interface OrderDetailHookProps {
// 采购、销售
type: 'purchaseOrder' | 'saleOrder'
}
// 订单详情, 支持两种订单模式
export const useOrderDetail = (options: OrderDetailHookProps) => {
// 订单详情内容
const [formData, setFormData] = useState<any>(null)
// 当前的支付信息id 默认第一个
const [currentPayInfoId, setCurrentPayInfoId] = useState<any>(null)
// 支付信息列表
const [payList, setPaylist] = useState<any[]>([])
const { id } = usePageStatus()
const { type } = options
const dataRef = useRef<any>([
{ label: '对应报价单号', name: 'quotationNo', span: 8, render: text => <Link to={'/'}>{text}</Link> },
{ label: '订单摘要', name: 'orderThe', span: 8 },
{ label: type === 'saleOrder' ? '采购会员' : '供应会员', name: type === 'saleOrder' ? 'createMemberName' : '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: type === 'saleOrder' ? 'purchaseOrderInteriorState' : 'interiorState', span: 8, render: text => <StatusColors type={type === 'saleOrder' ? 'saleInside' : 'inside'} status={text}/> },
])
useEffect(() => {
reloadFormData()
// reloadPayList()
}, [])
const reloadFormData = useCallback(() => {
if (id) {
const fn = type === 'purchaseOrder' ? PublicApi.getOrderProcurementOrderDetails : PublicApi.getOrderPurchaseOrderDetails
fn({ id }, { ctlType: "none" }).then(res => {
const { code, data, message: msg } = res
if (code === 1000) {
setFormData(data)
if(data.paymentInformationResponses.length > 0){
setCurrentPayInfoId(data.paymentInformationResponses[0].id)
}
reloadPayList(data.supplyMembersId, data.supplyMembersRoleId)
} else {
message.error(msg)
}
})
}
}, [id])
const reloadPayList = (memberId, memberRoleId) => {
PublicApi.getPayPayWayList({memberId, memberRoleId}).then(res => {
const { code, data } = res
if (code === 1000) {
setPaylist(data)
} else {
message.error(res.message)
}
})
}
// const reloadPayList = useCallback(() => {
// PublicApi.getPayPayWayList().then(res => {
// const { code, data } = res
// if (code === 1000) {
// setPaylist(data)
// }
// })
// }, [id])
// 需共享的状态
const formContext = {
data: formData,
currentPayInfoId,
payList,
ctl: {
setData: setFormData,
setPayId: setCurrentPayInfoId,
},
reloadFormData
}
return {
formContext,
id,
detailList: dataRef.current
}
}
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