剪板流程
This commit is contained in:
@@ -8,26 +8,33 @@ import MCheckbox from "@/components/checkbox";
|
||||
import Popup from "@/components/popup";
|
||||
import OfflinePay from "../offlinePay";
|
||||
import ScanPay from "../scanPay";
|
||||
import { GetOrderPayApi, SubmitOrderPayApi } from "@/api/orderPay";
|
||||
import { GetOrderPayApi, SubmitOrderPayApi, GetPrepayOrderPayApi, SubmitPrepayOrderPayApi } from "@/api/orderPay";
|
||||
import { formatPriceDiv } from "@/common/fotmat";
|
||||
import {alert} from "@/common/common"
|
||||
import { PAYMENT_METHOD, PAYMENT_METHOD_PARAM } from "@/common/enum";
|
||||
import { ORDER_STATUS, PAYMENT_METHOD, PAYMENT_METHOD_PARAM } from "@/common/enum";
|
||||
|
||||
type Param = {
|
||||
show?: true|false,
|
||||
onClose?: () => void,
|
||||
onSubmitSuccess?: () => void, //支付成功
|
||||
orderInfo?: OrderInfo
|
||||
orderInfo?: OrderInfo,
|
||||
}
|
||||
|
||||
type OrderInfo = {
|
||||
orderId: number, //应付单id
|
||||
payment_method: 0|PAYMENT_METHOD_PARAM //支付方式
|
||||
should_collect_order_id?: number, //应付单id
|
||||
pre_collect_order_id?: number, //预付单id
|
||||
status?: number, //订单状态
|
||||
payment_method?: 0|PAYMENT_METHOD_PARAM //支付方式
|
||||
}
|
||||
|
||||
type PayStatus = 1|2|3|4|5|null //1:预存款, 2:账期,3:线下汇款, 4:扫码支付, 5:货到付款
|
||||
export default memo(({show = false, onClose, orderInfo, onSubmitSuccess}:Param) => {
|
||||
|
||||
//支付方式枚举
|
||||
const {PaymentMethodPreDeposit, PaymentMethodAccountPeriod, PaymentMethodCashOnDelivery} = PAYMENT_METHOD
|
||||
//订单状态枚举
|
||||
const {SaleorderstatusWaitingPrePayment} = ORDER_STATUS
|
||||
|
||||
//提交参数
|
||||
const [submitData, setSubmitData] = useState<{id:number, payment_method: PayStatus}>({
|
||||
id:0,
|
||||
@@ -38,7 +45,7 @@ export default memo(({show = false, onClose, orderInfo, onSubmitSuccess}:Param)
|
||||
const [offlinePayShow, setofflinePayShow] = useState(false)
|
||||
const onShowOfflinePay = () => {
|
||||
setofflinePayShow(true)
|
||||
onClose?.()
|
||||
// onClose?.()
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
@@ -51,13 +58,22 @@ export default memo(({show = false, onClose, orderInfo, onSubmitSuccess}:Param)
|
||||
//获取支付方式数据
|
||||
const [payInfo, setPayInfo] = useState<any>()
|
||||
const {fetchData: orderFetchData} = GetOrderPayApi()
|
||||
const {fetchData: prepayOrderFetchData} = GetPrepayOrderPayApi()
|
||||
const getOrderPay = async () => {
|
||||
let {data} = await orderFetchData({id: orderInfo?.orderId})
|
||||
setPayInfo(() => data)
|
||||
if(orderInfo&&orderInfo.should_collect_order_id) {
|
||||
//有应收单id时用应收单获取数据
|
||||
let {data} = await orderFetchData({id: orderInfo?.should_collect_order_id})
|
||||
setPayInfo(() => data)
|
||||
} else {
|
||||
//用预付单id获取支付信息
|
||||
let {data} = await prepayOrderFetchData({id: orderInfo?.pre_collect_order_id})
|
||||
setPayInfo(() => data)
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
if(show&&orderInfo?.orderId) {
|
||||
setSubmitData((val) => ({...val, id:orderInfo.orderId}))
|
||||
if(show&&orderInfo&&(orderInfo?.should_collect_order_id||orderInfo?.pre_collect_order_id)) {
|
||||
let id = orderInfo.should_collect_order_id||orderInfo.pre_collect_order_id
|
||||
setSubmitData((val) => ({...val, id:id as number}))
|
||||
getOrderPay()
|
||||
}
|
||||
}, [show, orderInfo])
|
||||
@@ -73,14 +89,20 @@ export default memo(({show = false, onClose, orderInfo, onSubmitSuccess}:Param)
|
||||
}
|
||||
|
||||
//提交支付
|
||||
const {fetchData: submitFetchData} = SubmitOrderPayApi()
|
||||
const {fetchData: submitFetchData} = SubmitOrderPayApi() //应收单提交
|
||||
const {fetchData: submitPrepayOrderFetchData} = SubmitPrepayOrderPayApi() //预付单提交
|
||||
const submitPay = async () => {
|
||||
if(submitData.payment_method === null) {
|
||||
alert.error('请选择支付方式')
|
||||
return false
|
||||
}
|
||||
alert.loading('正在支付')
|
||||
let res = await submitFetchData(submitData)
|
||||
let res:any = null
|
||||
if(orderInfo?.should_collect_order_id) {
|
||||
res = await submitFetchData(submitData)
|
||||
} else {
|
||||
res = await submitPrepayOrderFetchData(submitData)
|
||||
}
|
||||
if(res.success) {
|
||||
alert.success('支付成功')
|
||||
onSubmitSuccess?.()
|
||||
@@ -97,6 +119,17 @@ export default memo(({show = false, onClose, orderInfo, onSubmitSuccess}:Param)
|
||||
)
|
||||
}, [payInfo])
|
||||
|
||||
//是否显示七天账期
|
||||
const show_account_payment = useMemo(() => {
|
||||
//支付方式是账期支付,不显示
|
||||
if(orderInfo?.payment_method == PaymentMethodAccountPeriod.value) return false
|
||||
//支付方式是货到付款,不显示
|
||||
if(orderInfo?.payment_method == PaymentMethodCashOnDelivery.value) return false
|
||||
//订单状态是预付款,不显示
|
||||
if(orderInfo?.status == SaleorderstatusWaitingPrePayment.value) return false
|
||||
return true
|
||||
}, [orderInfo])
|
||||
|
||||
//账期
|
||||
const account_peyment = useMemo(() => {
|
||||
const price = payInfo?.should_collect_money - payInfo?.amount_paid
|
||||
@@ -105,9 +138,6 @@ export default memo(({show = false, onClose, orderInfo, onSubmitSuccess}:Param)
|
||||
)
|
||||
}, [payInfo])
|
||||
|
||||
//支付方式枚举
|
||||
const {PaymentMethodPreDeposit, PaymentMethodAccountPeriod} = PAYMENT_METHOD
|
||||
|
||||
return (
|
||||
<View className={styles.payment_main}>
|
||||
<Popup show={show} showTitle={false} onClose={onClose} >
|
||||
@@ -143,13 +173,12 @@ export default memo(({show = false, onClose, orderInfo, onSubmitSuccess}:Param)
|
||||
</View>
|
||||
<MCheckbox status={submitData.payment_method == PaymentMethodPreDeposit.value} onSelect={() => advanceSelectData(PaymentMethodPreDeposit.value)} onClose={() => advanceSelectData(null)}/>
|
||||
</View>
|
||||
{(orderInfo?.payment_method != PaymentMethodAccountPeriod.value)&&<View className={styles.payment_list_item}>
|
||||
{show_account_payment&&<View className={styles.payment_list_item}>
|
||||
<View className={styles.payment_list_item_left}>
|
||||
<View className={styles.payment_list_item_left_name}>
|
||||
<View className={classnames('iconfont icon-a-tuikuanshouhou', styles.miconfont)}></View>
|
||||
<View className={styles.payment_list_item_left_text}>{payInfo?.account_period}天账期</View>
|
||||
</View>
|
||||
{/* <View className={styles.payment_list_item_left_price}>可用额度 ¥{formatPriceDiv(payInfo?.account_period_credit_available_line)}</View> */}
|
||||
{account_peyment}
|
||||
</View>
|
||||
<MCheckbox status={submitData.payment_method == PaymentMethodAccountPeriod.value} onSelect={() => periodSelectData(PaymentMethodAccountPeriod.value)} onClose={() => periodSelectData(null)}/>
|
||||
|
||||
Reference in New Issue
Block a user