import Taro from "@tarojs/taro"; import { Button, Icon, Text, Textarea, View } from "@tarojs/components"; import { useState, useEffect } from "react"; import withLayout from "@/layouts"; import CustomNav from "@/components/CustomNav"; import { getShopDetail, getShopPackage, getExtendContent } from '@/services/home'; import { getVerifyTargetList, putVerifyTarget } from "@/services/payOrder"; import formatTime from '@/utils/formatTime' import Popup from "@/components/Popup"; import SpinBox from "@/components/Spin/SpinBox"; import formatPrice from "@/utils/formatPrice"; import LocationBig from "@/assets/icons/UserCenter/LocationBig.png"; import Perfection from "@/assets/icons/UserCenter/Perfection.png"; import Check_OK from "@/assets/icons/UserCenter/Check_OK.png"; import Check_NO from "@/assets/icons/UserCenter/Check_NO.png"; import BlackSpot from "@/assets/icons/GuideCheck/BlackSpot.png"; import food from "@/assets/icons/ProCard/food.png"; import ProCard_hot from "@/assets/icons/ProCard/ProCard_hot.png"; import TBCard from './Card' import "./style.less"; export default withLayout((props) => { const { router, person, location } = props; const { id, subOrderId } = props.router.params; const [submiting, setSubmiting] = useState(false) const [showDialog, setShowDialog] = useState(false); //核销 const [Consumption, setConsumption] = useState(false); const [checked, setChecked] = useState([]); const [shopContent, setShopContent] = useState([]) const [loading, setLoading] = useState(false) const [list, setList] = useState([]); const getShop = () => { getShopDetail(id, { location: location }).then(e => { setShopContent(e) }) } const getList = (params) => { setLoading(true) getVerifyTargetList({ shopId: id, isMine: true, isVerified: 0, pageNum: 1, pageSize: 50, }).then((res) => { if (res) { setList(res.records) if (res.records && res.records.length > 0) { if (res.records.length === 1) { setChecked([res.records[0].verifyNo]) } else { setChecked([res?.records.filter(x => x.subOrderId == subOrderId)[0]?.verifyNo].filter(Boolean)) } } else { Taro.navigateBack({ delta: 1 }) } } setLoading(false) }).catch(() => setLoading(false)); }; useEffect(() => { if (id) { getList(); getShop(); } }, [id]); const handleCheck = (verifyNo) => { const inx = checked.indexOf(verifyNo) if (inx === -1) { setChecked([...checked, verifyNo]) } else { const p1 = checked.slice(0, inx) const p2 = checked.slice(inx + 1) setChecked(p1.concat(p2)) } } const handleVerifyClick = () => { if (!checked || !checked.length) { Taro.showToast({ title: '请选择待核销套餐', icon: 'none', }) return; } setShowDialog(true); }; const ButtonCancel = () => { setShowDialog(false); }; const ButtonOK = (e) => { if (!submiting) { Taro.showLoading({ title: '核销中' }) setSubmiting(true); Promise.all(checked.map(verifyNo => putVerifyTarget(verifyNo))) .then(res => { Taro.hideLoading() setSubmiting(false); setShowDialog(false); setConsumption(true); }) .catch(e => { Taro.hideLoading() setShowDialog(false); setSubmiting(false); getList(); // 刷新数据 Taro.showToast({ title: '核销失败', icon: 'none', duration: 2000 }) }) } }; const PerfectionOK = () => { setConsumption(false); if (list?.length > 1) { getList() } else { Taro.navigateBack({ delta: 1 }) } }; const btnText = ['确认核销', checked && checked.length > 0 ? `(${checked.length})` : undefined].filter(Boolean).join(' ') return ( 真的要翻我的牌子吗? 核销后套餐券不退不换, 请核对无误后再点击确认。 请和店员说一下:“我核销好了” 当前所在店铺:{shopContent?.shopName || []} 请选择你要核销的套餐 {(list || []).map((item) => { return ( ) })} ); });