import "./ShopCoupons.scss"; import { useState, useEffect } from "react"; import { post } from "../../js/helpers/data-helper"; const ShopCoupons = ({ onBack, shop, memberID }) => { const [coupons, setCoupons] = useState([]); const [receiving, setReceiving] = useState(false); const getList = async () => { try { const { code, data, msg } = await post( "/api/ar/v1/applet/ShopDetailCouponList", { paging: 0, memberID, shopCode: shop.code, } ); if (code !== 200) window.weui.toast(msg, { className: "toast", }); else setCoupons(data); } catch (error) { console.warn(error); } }; useEffect(() => { getList(); }, []); const receive = async (coupon) => { setReceiving(true); try { const { code, data, msg } = await post( "/api/ar/v1/applet/ShopCouponReceive", { couponCode: coupon.code, memberID, } ); window.weui.toast(msg, { className: "toast", }); if (code === 200) { getList(); } } catch (error) { console.warn(error); } finally { setReceiving(false); } }; return (
{ onBack && onBack(); }} >
{shop.name}
{coupons.map((coupon, i) => (
{coupon.title}
= coupon.detailReceiveCount ? "disabled" : "") } onClick={() => { if ( coupon.detailReceived >= coupon.detailReceiveCount || receiving ) return; receive(coupon); }} > {coupon.detailReceived >= coupon.detailReceiveCount ? "已领取" : "领券"}
使用期限
{coupon.beginTime}至{coupon.endTime}
{ coupon.isOpen = !coupon.isOpen; setCoupons([...coupons]); }} > 查看详情
{!!coupon.isOpen && (
使用规则
{coupon.couponRules}
)}
))}
); }; export default ShopCoupons;