import Taro from "@tarojs/taro"; import { Button, Textarea, View } from "@tarojs/components"; import formatPrice from "@/utils/formatPrice"; import SpinBox from "@/components/Spin/SpinBox"; import { useState, useEffect } from "react"; import OrderCard from '@/components/CompoentsOrder/OrderCard' import withLayout from "@/layouts"; import { getOrderSub, refund } from "@/services/payOrder"; import CustomNav from "@/components/CustomNav"; import BlackSpot from "@/assets/icons/GuideCheck/BlackSpot.png"; import "./style.less"; const options = [ { title: "计划有变,没时间消费", key: 1, }, { title: "误认为是外卖", key: 2, }, { title: "没看清楚使用规则,要用时才发现限制很多", key: 3, }, { title: "预约不上", key: 4, }, { title: "店里更优惠", key: 5, }, { title: "网友/朋友评价不好", key: 6, }, ]; export default withLayout((props) => { const { router, person } = props; const { id } = props.router.params; const [loading, setLoading] = useState(false) // 说明 const [explain, setExplain] = useState(); const [list, setList] = useState([]); // 总价 totalPrice const [totalPrice, setTotalPrice] = useState({}); const [checkeds, setCheckeds] = useState([1]); const getData = (orderId) => { setLoading(true) getOrderSub({ pageNum: 1, pageSize: 50, orderId: orderId, }).then((res) => { setList(res.records); setLoading(false) }).catch(e => { setLoading(false) }) }; useEffect(() => { getData(id); }, []); const viewOK = (e) => { if (checkeds.indexOf(e.key) > -1) { setCheckeds(checkeds.filter((x) => x != e.key)); } else { let arr = checkeds; arr.push(e.key); setCheckeds([...arr]); } }; const onRefund = () => { Taro.showLoading({ title: '退款中', }) refund(id, { refundDecription: checkeds?.map(x => options.filter(y => y.key == x)[0]?.title).join(';'), refundReason: explain, }).then((res) => { Taro.hideLoading(); Taro.navigateBack({ delta: 1 }) Taro.showToast({ title: "退款成功", icon: "none", duration: 3000, }); }); }; useEffect(() => { let total = { cashback: 0, //已获返现 charges: 0, //实付金额 refundPrice: 0, //退款金额 }; list.map((x) => { total.cashback += x.cashback; total.charges += x.charges; total.refundPrice += x.charges - x.cashback; }); setTotalPrice(total); }, [list]); return ( 商品信息 {/* 商品信息结束 */} {(list || []).map((item) => { return ( ); })} {/* 卡片结束 */} 退款原因 {/* 退款结束 */} {options.map((x) => { return ( -1 ? "bg2" : `Refund-star-view2` }`} key={x.key} onClick={() => viewOK(x)} > {x.title} ); })} 退款说明