import { View, Text } from "@tarojs/components" import { useEffect, useState, useMemo } from "react" import Taro, { useDidShow } from "@tarojs/taro" import CustomNav from '@/components/CustomNav' import ButtontWX from '@/components/ButtontWX' import formatTimes from "@/utils/codeSegment" import withLayout from '@/layouts' import formatPrice from "@/utils/formatPrice" import AssessModel from "@/components/AssessModel" import useProcessStatus, { getProcessSignBy } from "@/utils/hooks/useProcessStatus" import { orderPrepay, orderDelete, orderInfo, orderRefund } from "@/services/order" // import BottomMoadl from '@/components/BottomMoadl/index' import './style.less' export default withLayout((props) => { // const { stateType } = props const $instance = Taro.getCurrentInstance() const { orderId } = $instance.router.params const [orderInfos, setOrderInfos] = useState() const [isAssessVisible, setIsAssessVisible] = useState(false) const { processStatus } = useProcessStatus(orderInfos) //底部弹窗 // const [showFrame, setShowFrame] = useState(false) // const setRecommend = () => { // setShowFrame(!showFrame) // } const cancelPay = () => { Taro.showModal({ title: '提示', content: '您确定要取消此订单吗?', success: function (res) { if (res.confirm) { orderDelete(orderId).then((e) => { console.log('订单取消/删除', e); Taro.showToast({ title: '订单取消成功', icon: 'success', duration: 2000 }).then(() => { setTimeout(() => { Taro.navigateBack({ delta: 1 }) }, 1000) }) }) } else if (res.cancel) { console.log('用户点击取消') } } }) } useEffect(() => { if (orderId) { orderInfo(orderId).then((res) => { setOrderInfos(res) }) } else { Taro.showToast({ title: '暂无订单详情', icon: 'error', duration: 2000 }).then(() => { setTimeout(() => { Taro.navigateBack({ delta: 1 }) }, 1000) }) } }, [orderId]) const requestPayment = (params) => { Taro.hideLoading() console.log("🚀 ~ file: index.jsx ~ line 92 ~ requestPayment ~ params", params) Taro.requestPayment({ ...params, package: params.packageValue, success: () => { Taro.showToast({ title: "支付成功", icon: "success", duration: 1000, }).then(() => { setTimeout(() => { Taro.reLaunch({ url: `/pages/index/index?tab=2` }) }, 400) }) }, fail: (e) => { Taro.showToast({ title: "支付失败", icon: "none", duration: 2000, }); Taro.reLaunch({ // url: `/pages/MineUserAll/AllOrder/index?tabJump=1` }) }, }) } const pay = () => { orderPrepay(orderId, { payType: 'wx', }).then((e) => { console.log('订单返回', e); Taro.showLoading({ title: '支付中', }) requestPayment(e) }) //支付逻辑 } //退单 const orderRefunds = () => { Taro.showLoading({ title: '退单申请中', }) orderRefund(orderId).then(() => { Taro.showLoading() Taro.showToast({ title: "退单成功", icon: "none", duration: 2000, }).then(() => { setTimeout(() => { Taro.navigateBack({ delta: 1 }) }, 400) }) }).catch(() => { Taro.showLoading() Taro.showToast({ title: "请重试", icon: "error", duration: 2000, }); }) } const startModle = () => { setIsAssessVisible(true) } const onClose = () => { setIsAssessVisible(false) Taro.navigateBack({ delta: 1 }) } const { processLabel, stateStyle, action : Actions } = useMemo(() => { const { label, color } = getProcessSignBy(processStatus) let action = <>; switch (processStatus) { case 1: case 2: action = ; break; case 4: action = ; break; case 5: action = ; break; case 3: case 6: default: break; } return { processLabel: label, stateStyle: color, action } }, [processStatus]) return ( {/* */} 订单编号:{orderInfos?.orderNo} 农机名称:{orderInfos?.machineryName} 作业面积:{orderInfos?.amount} 需求时间:{formatTimes(orderInfos?.appointmentDate, 'yyyy-MM-dd')} 下单时间:{formatTimes(orderInfos?.createDate, 'yyyy-MM-dd')} 订单状态:{processLabel} 费用:{formatPrice(orderInfos?.charges)} 状态:{orderInfos?.payStatus === 1 ? '已付款' : '待付款'} {Actions} ) })