import React, { useEffect } from 'react' import { useImmer } from 'use-immer' import { AtButton } from 'taro-ui' import { useSelector } from 'react-redux' import { isWeixin, VERSION_STANDARD } from '@/utils' import getPaymentList from '@/utils/payment' import { SpCheckbox, SpCell, SpFloatLayout } from '@/components' import { View, Text, Button } from '@tarojs/components' import './comp-paymentpicker.scss' function CompPaymentPicker(props) { const { type = '', distributor_id, isShowDelivery = false, loading, isPointitemGood = false, isShowBalance = true, disabledPayment = null, title = '支付方式', isOpened = false, onChange = () => {}, onClose = () => {}, onInitDefaultPayType = () => {} } = props const { colorPrimary, pointName } = useSelector((state) => state.sys) const [state, setState] = useImmer({ localType: type, typeList: [] }) const { localType, typeList } = state useEffect(() => { setState((draft) => { draft.localType = type }) getFetch() }, []) const getFetch = async () => { const { list } = await getPaymentList(distributor_id) setState((draft) => { draft.typeList = list }) if (list[0]) { handlePaymentChange(list[0].pay_type_code, channel) handleChange(list[0].pay_type_code) let channel = '' if (typeof list[0].pay_channel != 'undefined') { channel = list[0].pay_channel } onInitDefaultPayType(list[0].pay_type_code, channel) } } const handlePaymentChange = (type) => { if (disabledPayment && disabledPayment[type]) return setState((draft) => { draft.localType = type }) } const handleChange = (type) => { const payItem = typeList.find((item) => item.pay_type_code == type) let channel = '' if (payItem && typeof payItem.pay_channel != 'undefined') { channel = payItem.pay_channel } onChange(type, channel) } const handleCancel = () => { setState((draft) => { draft.localType = type }) onClose() } return ( 确定 } > {title} {isPointitemGood && ( {`${pointName}支付`} {disabledPayment && disabledPayment['point'] ? disabledPayment['point'] : `使用${pointName}支付`} )} {/* {isShowBalance && VERSION_STANDARD && isWeixin && ( // 临时加的 后期需开启注释 */} {/* 余额支付 {disabledPayment && disabledPayment['deposit'] ? disabledPayment['deposit'] : '使用余额支付'} */} {/* )} */} {isShowDelivery && ( 货到付款 {disabledPayment && disabledPayment['delivery'] ? disabledPayment.message : '货到付款'} )} {typeList.map((item, index) => { return ( {item.pay_type_name} 使用{item.pay_type_name} ) })} ) } CompPaymentPicker.options = { addGlobalClass: true } export default CompPaymentPicker