<template>
	<view>
		<view class="card_box">
			<!-- <view class="card_head_box">
				<view class="card_head_item" v-for="(item,index) in 8" :key="index"></view>
			</view> -->

			<!-- 先付款 -->
			<view class="tabBox" v-if="listinfo.status == 'unpaid' || !listinfo.id">
				<view class="tab">
					<view v-for="(item, index) in tebtypeList" :key="index" :class="
              is_type == index
                ? 'tab_item' + (is_type + 1) + ' tab_item  active '
                : 'tab_item'
            " @click="tabClick(item, index)">
						<view></view>
						<image class="icon" :src="is_type == index ? item.url_active : item.url" mode="aspectFill" />
						<text class="title" :class="{ active: is_type == index }">{{
              item.title
            }}</text>
					</view>
				</view>
				<view class="table" v-if="is_type == 0">
					<view class="table_left">
						<image class="icon"
							src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/table.png"
							mode="aspectFill" />
						<text class="title">桌台</text>
					</view>
					<view class="value" v-if="listinfo.tableName">
						{{ listinfo.tableName || "" }}
					</view>
				</view>
			</view>

			<view class="card">
				<!-- <orderItemVue
          :useVipPrice="useVipPrice"
          v-if="nowCarts.length"
          :nowCarts="nowCarts"
          :limitDiscount="cartStore.limitTimeDiscount"
        ></orderItemVue> -->
				<orderItemVue :useVipPrice="useVipPrice" v-if="nowCarts" :nowCarts="nowCarts"
					:shopInfo="cartStore.shopInfo" :shopUserInfo="cartStore.shopUserInfo"
					:limitDiscount="cartStore.limitTimeDiscount"></orderItemVue>
				
				<view class="u-flex u-row-center u-m-t-16 u-font-28" v-if="cartStore.allGoods.length>4">
					<view class="u-flex u-col-baseline" @click="showAllGoods=!showAllGoods">
						<text>{{showAllGoods?'收起':'展开'}}</text>
						<view class="guodu u-m-l-10 u-m-t-2" :class="{rotate:!showAllGoods}">
							<up-icon name="arrow-down" size="14"></up-icon>
						</view>
					</view>
				
				</view>	

				<template v-if="listinfo.id&&listinfo.status=='done'">
					<view class="cell-item" v-if="is_type != 0">
						<view class="label">打包费</view>
						<view class="val">
							<view></view>
							<view style="font-size: 28rpx">￥</view>
							<view>{{ cartStore.orderCostSummary.packFee }}</view>
						</view>
					</view>

					<view class="cell-item" v-if="cartStore.orderCostSummary.seatFee">
						<view class="label">餐位费</view>
						<view class="val">
							<view>X{{ cartStore.seatFeeConfig.personCount }}</view>
							<view style="font-size: 28rpx">￥</view>
							<view>{{ cartStore.orderCostSummary.seatFee }}</view>
						</view>
					</view>
				</template>

				<view class="total-wrap u-m-t-30" v-if="listinfo.status == 'unpaid' || !listinfo.id">
					<text>总计</text>
					<text class="u-font-32">￥</text>
					<text class="price">
						{{ cartStore.orderCostSummary.goodsRealAmount }}
					</text>
				</view>

				<view class="total-wrap u-m-t-30" v-else-if="listinfo.status != 'unpaid'">
					<text>实付</text>
					<text class="u-font-32">￥</text>
					<text class="price">
						{{ listinfo.payAmount }}
					</text>
				</view>

				<!-- <view class="total-wrap" v-else>
					<view>实付￥</view>
					<view class="price"> {{listinfo.payAmount||''}} </view>
				</view> -->

				<template v-if="!listinfo.id||listinfo.status=='unpaid'">
					<view class="cell-item" v-if="is_type != 0">
						<view class="label">打包费</view>
						<view class="val">
							<view></view>
							<view style="font-size: 28rpx">￥</view>
							<view>{{ cartStore.orderCostSummary.packFee }}</view>
						</view>
					</view>

					<view class="cell-item" v-if="cartStore.orderCostSummary.seatFee">
						<view class="label">餐位费</view>
						<view class="val">
							<view>X{{ cartStore.seatFeeConfig.personCount }}</view>
							<view style="font-size: 28rpx">￥</view>
							<view>{{ cartStore.orderCostSummary.seatFee }}</view>
						</view>
					</view>
				</template>



				<!-- <view class="cell-item" v-else>
					<view class="label">免餐位费</view>
					<view class="val">
						<view></view>
						<view style="font-size: 28rpx;">￥</view>
						<view>{{listinfo.Seatcharge}}</view>
					</view>
				</view> -->

				<!-- 支付之前 -->
				<block v-if="
            listinfo.status == 'unpaid' ||
            listinfo.status == 'paying' ||
            !listinfo.id
          ">
					<view class="u-m-t-40 u-p-l-20 u-p-r-20">
						<view class="youhui-item" v-if="cartStore.orderCostSummary.fullReduction.actualAmount">
							<view class="u-flex align-center">
								<image src="/static/icon/coup.png" bgColor="#fff" style="width: 50rpx; height: 50rpx">
								</image>
								<text class="color-333 font-14 u-m-l-16 no-wrap">满减活动</text>
							</view>

							<view class="red font-12 u-flex align-center">-￥{{
                  cartStore.orderCostSummary.fullReduction.actualAmount
                }}</view>
						</view>
						<view class="youhui-item" v-if="cartStore.orderCostSummary.vipDiscountAmount">
							<view class="u-flex align-center">
								<image src="/static/icon/newUserDiscount.png" bgColor="#fff"
									style="width: 50rpx; height: 50rpx"></image>
								<text class="color-333 font-14 u-m-l-16 no-wrap">会员折扣</text>
							</view>

							<view class="red font-12 u-flex align-center">
								-￥{{ cartStore.orderCostSummary.vipDiscountAmount }}</view>
						</view>
						<view class="youhui-item" v-if="newUserDiscount">
							<view class="u-flex align-center">
								<image src="/static/icon/newUserDiscount.png" bgColor="#fff"
									style="width: 50rpx; height: 50rpx"></image>
								<text class="color-333 font-14 u-m-l-16 no-wrap">新客立减</text>
							</view>

							<view class="red font-12 u-flex align-center">-￥{{ newUserDiscount }}</view>
						</view>
						<view class="favorable" v-for="(item, indexe) in favorablelist" :key="indexe"
							:class="{ column: item.type == 'product' }" @click="goUrl(item)">
							<view class="favorable_left">
								<view class="u-flex" style="width: 44rpx">
									<u-image bgColor="#fff" :width="item.width || '50rpx'"
										:height="item.height || '50rpx'" v-if="item.icon" :src="item.icon"
										mode=""></u-image>
								</view>
								<text class="name u-m-l-16 no-wrap"> {{ item.name }} </text>
								<template v-if="item.type == 'points' && !pointObj.disabled">
									<text class="u-p-l-6" style="color: #666; max-width: 400rpx; font-size: 10px">
										「可用积分{{ cartStore.shopUserInfo.pointsUser?cartStore.shopUserInfo.pointsUser.pointBalance:0}}，最大可抵扣{{
                      maxPointDiscount
                    }}元」
									</text>
								</template>
							</view>

							<!-- 优惠卷 -->
							<view class="favorable_right" v-if="item.type == 'coupon'">
								<template v-if="cartStore.orderCostSummary.couponDeductionAmount > 0">
									<text class="favorable_right_text red">-￥{{
                      cartStore.orderCostSummary.couponDeductionAmount
                    }}</text>
								</template>
								<template v-else>
									<text class="favorable_right_text red"
										v-if="couponObj.disabled">{{ couponObj.disabledReason }}</text>
									<text class="favorable_right_text red" v-else-if="hasCouponCanUse">有可用优惠券</text>
									<text class="favorable_right_text" v-else>暂无可用优惠券</text>
								</template>
								<template v-if="!couponObj.disabled">
									<up-icon name="arrow-right" color="#575B66" size="16" v-if="
                      listinfo.status == 'unpaid' ||
                      listinfo.status == 'paying' ||
                      !listinfo.id
                    "></up-icon>
								</template>
							</view>

							<!-- 新客立减 -->
							<view class="favorable_right" v-if="item.type == 'newUser'">
								<text class="favorable_right_text red"
									v-if="newUserDiscount > 0">-￥{{ newUserDiscount }}</text>
							</view>

							<!-- 积分 -->
							<view class="favorable_right u-flex u-col-center" v-if="item.type == 'points'">
								<text v-if="pointObj.disabled" class="u-p-l-6 red"
									style="max-width: 440rpx; font-size: 24rpx">{{ pointObj.disabledReason }}</text>
								<template v-else-if="
                    usePoints && cartStore.orderCostSummary.pointDeductionAmount
                  ">
									<up-icon name="checkmark-circle-fill" size="24rpx" color="#FE7E00"></up-icon>
									<text class="red">
										-¥{{ cartStore.orderCostSummary.pointDeductionAmount }}
									</text>
								</template>

								<template v-else>
									<view v-if="maxPointDiscount > 0 && !pointObj.disabled" class="u-flex u-col-center">
										<view class="round"></view>
										<text class="color-333 font-12 no-wrap u-m-l-4">使用抵扣</text>
									</view>
								</template>
							</view>
						</view>
					</view>
				</block>

			</view>
		</view>
		<view class="disocunt " v-if="showDiscount">
			<view class="row" v-if="listinfo.productCouponDiscountAmount">
				<text class="t">商品券</text>
				<text class=" price">-{{listinfo.productCouponDiscountAmount}}</text>
			</view>
			<view class="row" v-if="listinfo.otherCouponDiscountAmount">
				<text class="t">优惠券</text>
				<text class="price">-{{listinfo.otherCouponDiscountAmount}}</text>
			</view>
			<view class="row" v-if="listinfo.pointsDiscountAmount">
				<text class="t">积分抵扣</text>
				<text class="price">-{{listinfo.pointsDiscountAmount}}</text>
			</view>
			<view class="row" v-if="listinfo.discountActAmount">
				<text class="t">满减活动</text>
				<text class="price">-{{listinfo.discountActAmount}}</text>
			</view>
			<view class="row" v-if="listinfo.newCustomerDiscountAmount">
				<text class="t">新客立减</text>
				<text class="price">-{{listinfo.newCustomerDiscountAmount}}</text>
			</view>
			<view class="row" v-if="listinfo.vipDiscountAmount">
				<text class="t">会员折扣</text>
				<text class="price">-{{listinfo.vipDiscountAmount}}</text>
			</view>


		</view>

		<view class="orderInfo" v-if="listinfo.id&&listinfo.status=='done'">
			<view class="row" @click="copyHandle(listinfo.orderNo)">
				<text class="t">订单编号：</text>
				<text class="info"
					style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap">{{ listinfo.orderNo }}(点击复制)</text>
			</view>
			<view class="row">
				<text class="t">下单时间：</text>
				<text class="info">{{
          $u.timeFormat(listinfo.updateTime, "yyyy-mm-dd hh:MM:ss")
        }}</text>
			</view>
			<view class="row" v-if="listinfo.tableName">
				<text class="t">下单台桌：</text>
				<text class="info">{{ listinfo.tableName }}</text>
			</view>
			<view class="row" v-if="orderVIP.shopName">
				<text class="t">下单门店：</text>
				<text class="info">{{ orderVIP.shopName }}</text>
			</view>
			<view class="row" v-if="listinfo.dineMod">
				<text class="t">用餐模式：</text>
				<text class="info" v-if="listinfo.dineMod == 'dine-in'">堂食</text>
				<text class="info" v-if="listinfo.dineMod == 'take-out'">外带</text>
				<text class="info" v-if="listinfo.dineMod == 'take-away'">外卖</text>
			</view>
			<view class="row">
				<text class="t">备注：</text>
				<text class="info u-line-5">{{ listinfo.remark || "" }}</text>
			</view>
			<view class="row" v-if="listinfo.seatNum">
				<text class="t">就餐人数：</text>
				<text class="info">{{ listinfo.seatNum || "" }}</text>
			</view>
			<view class="row" v-if="listinfo.refundType">
				<text class="t">退款方式：</text>
				<text class="info">{{
          listinfo.refundType == "cash" ? "手动退款" : "原路退回"
        }}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		useCartsStore
	} from "@/stores/carts.js";
	import * as discountActivityApi from "@/common/api/market/discountActivity";
	const cartStore = useCartsStore();
	import {
		consumeDiscount
	} from "@/common/api/market/index.js";
	import orderItemVue from "./order-item.vue";
	import {
		ref,
		reactive,
		defineProps,
		computed,
		defineEmits,
		watch,
		watchEffect,
		defineExpose,
		toRaw,
		onMounted,
		provide,
		nextTick,
	} from "vue";
	import {
		returnHasCouponCanUse
	} from "@/utils/coupon.js";
	import {
		BigNumber
	} from "bignumber.js";
	
	
	const showAllGoods=ref(false)
	let hasCouponCanUse = ref(false);

	const usePoints = ref(false);

	function chnageIsUsePoints() {
		usePoints.value = !usePoints.value;
	}

	import IntegralInput from "./IntegralInput.vue";
	import {
		APImemberPointsmyPoints,
		APImemberPointscalcUsablePoints,
		APImemberPointscalcDeductionAmount,
	} from "@/common/api/shop/index.js";
	import goodsIcon from "@/static/icon/goods.png";
	import coupIcon from "@/static/icon/coup.png";
	// import pointsIcon from "@/static/icon/points.png";
	import pointsIcon from "@/static/icon/jifen.png";
	// 定义自定义事件
	const emits = defineEmits(["customevent", "istype", "learcoupons"]);

	// teb  切换送餐和打包
	const tebtypeList = reactive([{
			title: "送餐到桌",
			show: false,
			type: "table",
			val: "dine-in",
			url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/tab1.png",
			url_active: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/tab1_active.png",
		},
		{
			title: "打包外带",
			show: false,
			type: "takeself",
			val: "take-out",
			url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/tab2.png",
			url_active: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/tab2_active.png",
		},
	]);

	const favorablelist = ref([
		//   {
		//     name: "新客立减",
		//     type: "newUser",
		//     width: "40rpx",
		//     height: "34rpx",
		//     value: "",
		//     icon: coupIcon,
		//     url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/coupon.png",
		//   },
		{
			name: "优惠券",
			type: "coupon",
			value: "",
			icon: coupIcon,
			url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/coupon.png",
		},
		{
			icon: pointsIcon,
			name: "积分抵扣",
			type: "points",
			value: "",
			url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/points.png",
		},
	]);

	const props = defineProps({
		useVipPrice: {
			type: Boolean,
			default: false,
		},
		freeCheck: {
			type: Boolean,
		},
		shifu: {
			type: [String, Number],
			defalut: 0,
		},
		listinfo: {
			type: Object,
			default: {
				combinedArray: {},
				Productroll: 0,
				coupondiscountAmount: 0,
				couponInfoList: "",
				pointsDiscountAmount: 0,
				packFeess: 0,
				totalPrices: 0,
				Seatcharge: 0,
				payAmount: 0,
				remark: "",
			},
		},
		orderVIP: {
			type: Object,
		},
		ordershopUserInfo: {
			type: Object,
			default: {
				isTableFee: 0,
			},
		},
		isBwc: {
			type: Boolean,
			default: false,
		},
		nowCarts: {
			type: Array,
			default: () => {
				return [];
			},
		},
	});

	/**
	 * 判断一个对象里的某些属性是否存在且值不等于0，满足其中一个就返回true，否则false
	 * @param {Object} obj - 要检测的目标对象（若为非对象类型直接返回false）
	 * @param {Array<string>} keys - 要检测的属性名数组（若为非数组/空数组直接返回false）
	 * @returns {boolean} 满足条件返回true，否则返回false
	 */
	function isObjHasPropertyAndNotNull(obj, keys) {
		console.log(obj)
		// 1. 边界校验：obj必须是有效对象，keys必须是非空数组
		if (
			!obj || // 排除null/undefined
			typeof obj !== 'object' || // 排除字符串/数字/布尔等非对象类型
			!Array.isArray(keys) || // 确保keys是数组
			keys.length === 0 // 空数组直接返回false
		) {
			return false;
		}

		// 2. 遍历所有要检测的属性
		for (const key of keys) {
			console.log(obj[key])
			// 检查属性是否是对象自身的（排除原型链上的属性） + 属性值不等于0
			if (obj.hasOwnProperty(key) && obj[key] !== 0) {
				return true; // 只要有一个满足，立即返回true
			}
		}

		// 3. 所有属性都不满足条件
		return false;
	}

	const showDiscount = computed(() => {
		if(!props.listinfo.id||props.listinfo.status!='done'){
			return false
		}
		const keys = ['productCouponDiscountAmount', 'otherCouponDiscountAmount',
			'pointsDiscountAmount', 'discountActAmount', 'newCustomerDiscountAmount', 'vipDiscountAmount'
		]
		if (isObjHasPropertyAndNotNull(props.listinfo, keys)) {
			return true
		}
		return false
	})

	const is_type = ref(0);

	//满减活动
	const discountActivityRes = ref(null);

	//当前使用的满减活动的门槛满减
	const discountActivity = ref(null);
	//备份当前使用的满减活动的门槛满减
	let back_discountActivity = null;

	const couponObj = computed(() => {
		const obj = {
			disabled: false,
			disabledReason: "",
		};
		const freeDineConfig = props.orderVIP.freeDineConfig;
		if (props.isBwc && freeDineConfig.enable) {
			//使用了霸王餐
			if (!freeDineConfig.withCoupon) {
				obj.disabled = true;
				obj.disabledReason = "霸王餐与优惠券不可同时使用";
			}
		}
		//使用了满减活动
		const res = discountActivityRes.value;

		if (discountActivity.value && res) {
			if (!res.couponShare) {
				obj.disabled = true;
				obj.disabledReason = "当前满减活动不可与其他优惠共享";
			}
		}
		if (obj.disabled) {
			cartStore.backendCoupons = [];
		}
		return obj;
	});


	//积分可抵扣最大金额
	const maxMoney = computed(() => {
		return (
			cartStore.orderCostSummary.orderOriginFinalPayAmount +
			cartStore.orderCostSummary.pointDeductionAmount
		);
	});
	const pointObj = computed(() => {
		const obj = {
			disabled: false,
			disabledReason: "",
		};
		const freeDineConfig = props.orderVIP.freeDineConfig;
		if (props.isBwc && freeDineConfig.enable) {
			//使用了霸王餐
			if (!freeDineConfig.withPoints) {
				obj.disabled = true;
				obj.disabledReason = "霸王餐与积分不可同时使用";
			}
		}
		//使用了满减活动
		const res = discountActivityRes.value;
		if (discountActivity.value && res) {
			if (!res.pointsShare) {
				obj.disabled = true;
				obj.disabledReason = "当前满减活动不可与积分同享";
			}
		}
		//积分抵扣不足
		if (maxMoney.value * 1 < cartStore.pointDeductionRule.minPaymentAmount || !cartStore.pointDeductionRule
			.enableRewards) {
			obj.disabled = true;
			obj.disabledReason = "积分抵扣不足或不可用";
		}
		if (obj.disabled) {
			cartStore.setUserPoints(0);
		}

		return obj;
	});

	// 监听送餐/打包切换
	const tabClick = (item, index) => {
		is_type.value = index;
		emits("istype", is_type.value);
		cartStore.setDinnerType(item.val);
		// this.getchoseEatModel('tabClick', index, item);
	};
	cartStore.setDinnerType(tebtypeList[is_type.value].val);

	// 清空
	const bwcclear = () => {
		IntegralInputclose();
	};

	// 跳转
	const goUrl = (item) => {
		const canDikouGoodsArr = props.nowCarts;
		// const goodsOrderPrice = props.listinfo.totalPrices
		// const user=uni.cache.get('shopUserInfo')
		uni.setStorageSync(
			"goodsOrderPrice",
			cartStore.orderCostSummary.goodsRealAmount
		);

		switch (item.type) {
			case "coupon":
				if (couponObj.value.disabled) {
					return uni.showToast({
						title: couponObj.value.disabledReason,
						icon: "none",
					});
				}
				uni.pro.navigateTo("/pages/order/coupon", {});
				break;

			case "points":
				if (pointObj.value.disabled) {
					return uni.showToast({
						title: pointObj.value.disabledReason,
						icon: "none",
					});
				}
				if (maxPointDiscount.value <= 0) {
					return;
				}
				chnageIsUsePoints();
				break;
		}
	};

	// 积分
	const calcUsablePointsData = reactive({
		minIntegral: 1, //最小
		maxIntegral: "", //最多积分
		instructionText: "",
		unusableReason: "",
		showModal: false,
		integral: "",
	});


	const maxPointDiscount = ref(0);


	async function getMaxPointsDiscount() {
		if (!props.orderVIP.id) {
			return;
		}

		let userPoints = cartStore.shopUserInfo.pointsUser ? cartStore.shopUserInfo.pointsUser.pointBalance : 0;

		//1积分等于多少钱
		const onePointsMoney = cartStore.pointDeductionRule.pointsPerYuan ? ((1 || 0) / cartStore.pointDeductionRule
			.pointsPerYuan) : 0


		const calcMaxDiscount = Math.floor(maxMoney.value * (cartStore.pointDeductionRule.maxDeductionRatio / 100))
		const userMaxDiscount = BigNumber(userPoints).times(onePointsMoney).decimalPlaces(2, BigNumber.ROUND_DOWN)
			.toNumber()

		maxPointDiscount.value = Math.min(calcMaxDiscount, userMaxDiscount)
		console.log('积分最大可抵扣金额', maxPointDiscount.value)
		cartStore.pointDeductionRule.maxDeductionAmount = maxPointDiscount.value || 0
		if (usePoints.value && cartStore.pointDeductionRule.enableRewards) {
			let num = (maxPointDiscount.value || 0) * cartStore.pointDeductionRule.pointsPerYuan
			if (num > userPoints) {
				num = userPoints
			}
			console.log('积分使用数量', num)
			cartStore.setUserPoints(num);
		}
		if (!cartStore.pointDeductionRule.enableRewards) {
			cartStore.setUserPoints(0);
		}
	}
	watch(
		() => maxMoney.value,
		(newval) => {

			getMaxPointsDiscount();
		}
	);
	watch(
		() => usePoints.value,
		(newval) => {
			if (newval) {
				getMaxPointsDiscount();
			} else {
				cartStore.setUserPoints(0);
			}
		}
	);



	// 积分取消清空
	const IntegralInputclose = async () => {
		calcUsablePointsData.integral = null;
		calcUsablePointsData.showModal = false;
		// cartStore.setUserPoints(0);
	};

	// * 复制订单号
	const copyHandle = (e) => {
		uni.setClipboardData({
			data: e,
			success() {
				uni.showToast({
					title: "复制成功",
					icon: "none",
				});
			},
		});
	};

	// 将方法暴露给父组件
	defineExpose({
		bwcclear,
		IntegralInputclose,
	});

	watch(
		() => props.listinfo.seatNum,
		(newval) => {
			cartStore.setSeatFeeConfig("personCount", newval || 0);
		}
	);

	const newUserDiscount = ref(0);
	const back_favorablelist = toRaw(favorablelist.value);
	async function getConsumeDiscount() {
		let  consumeDiscountRes =null
		if(cartStore.consumeDiscount&&cartStore.newUserDiscount){
			consumeDiscountRes=cartStore.consumeDiscount
		}else{
			 consumeDiscountRes = await consumeDiscount({
				shopId: uni.cache.get("shopId"),
			});
		}
	
		if (!consumeDiscountRes) {
			favorablelist.value = back_favorablelist.filter(
				(v) => v.name != "新客立减"
			);
			return;
		}

		if (consumeDiscountRes) {
			newUserDiscount.value = consumeDiscountRes.amount;
			cartStore.newUserDiscount = consumeDiscountRes.amount || 0;
			cartStore.consumeDiscount = consumeDiscountRes;
		}
	}

	// 初始化订单计算可能为计算完毕，所以判断监听价格变化后再获取优惠券
	let loadFinish = false;
	watch(
		() => cartStore.orderCostSummary.goodsRealAmount,
		async (newval) => {
			if (newval && !loadFinish) {
				const goodsOrderPrice = cartStore.orderCostSummary.goodsRealAmount;
				const dinnerType = cartStore.dinnerType;
				const shopInfo = cartStore.shopInfo;
				const shopId = cartStore.shopInfo.shopId;
				const user = uni.cache.get("shopUserInfo");
				const shopUserId = user.id;
				const allGoods = cartStore.allGoods;

				hasCouponCanUse.value = await returnHasCouponCanUse({
					goodsOrderPrice,
					dinnerType,
					shopId,
					shopInfo,
					shopUserId,
					allGoods,
					user,
				});
			}
		}
	);

	const originalPrice = computed(() => {
		const originalPrice =
			cartStore.orderCostSummary.goodsRealAmount +
			-cartStore.orderCostSummary.newUserDiscount +
			cartStore.orderCostSummary.packFee +
			cartStore.orderCostSummary.seatFee;
		return originalPrice <= 0 ? 0 : originalPrice;
	});

	watch(
		() => originalPrice.value,
		() => {
			if (discountActivityRes.value) {
				calcDiscountActivity();
			}
		}
	);

	watch(
		() => props.isBwc,
		(newval) => {
			const freeDineConfig = props.orderVIP.freeDineConfig;
			if (newval) {
				discountActivity.value = null;
				cartStore.fullReductionActivities = [];
				usePoints.value = false;
				cartStore.setUserPoints(0);
			} else {
				cartStore.fullReductionActivities = fullReductionActivities;
				if (back_discountActivity) {
					calcDiscountActivity();
				}
			}
		}
	);

	function calcDiscountActivity() {
		const res = discountActivityRes.value;
		const user = uni.cache.get("shopUserInfo");

		const usedFullReductionActivityFullAmount =
			cartStore.orderCostSummary.fullReduction
			.usedFullReductionActivityFullAmount;


		if (res && res.thresholds && res.thresholds.length > 0) {
			const canUseThresholds = res.thresholds
				.filter((v) => {
					return usedFullReductionActivityFullAmount >= v.fullAmount;
				})
				.sort((a, b) => {
					return b.discountAmount - a.discountAmount;
				});

			if (canUseThresholds.length) {
				discountActivity.value = canUseThresholds[0];
				back_discountActivity = canUseThresholds[0];
			}
		}
		if (!discountActivity.value) {
			return;
		}
		console.log("当前满减门槛", discountActivity.value);
	}


	let fullReductionActivities = []
	async function getDiscountActivity() {
		const res = await discountActivityApi.config({
			shopId: uni.cache.get("shopId"),
		});
		if (!res) {
			return;
		}
		discountActivityRes.value = res;
		cartStore.fullReductionActivities = [res];
		fullReductionActivities = [res];

		calcDiscountActivity();
	}
	onMounted(async () => {
		await getConsumeDiscount();
		getDiscountActivity();
	});
	
	const nowCarts=computed(()=>{
		if(cartStore.allGoods.length<=0){
			return []
		}
		if(showAllGoods.value){
			return cartStore.allGoods
		}
		return cartStore.allGoods.slice(0,4)
	})
</script>

<style lang="scss" scoped>
	::v-deep .orderInfo .u-textarea {
		background: #fafafa;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}

	.round {
		width: 24rpx;
		height: 24rpx;
		border-radius: 50%;
		background-color: #fff;
		border: 1px solid #d9d9d9;
	}

	::v-deep .u-textarea__field {
		background: #fafafa;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}

	.t {
		font-weight: bold;
		font-size: 28rpx;
		color: #333333;
		flex-shrink: 0;
	}

	.card_box {
		background-color: #fff;
		// box-shadow: 0rpx 8rpx 12rpx 2rpx rgba(87,86,86,0.35);
		position: relative;
		width: 100%;
		height: 100%;
		// box-shadow: 0rpx 4rpx 12rpx 2rpx rgba(87,86,86,0.35);
		border-radius: 18rpx;
		padding-bottom: 32rpx;

		.tabBox {
			width: 100%;
			margin-top: 52rpx;
			position: relative;
			z-index: 1;

			.tab {
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-radius: 22rpx 22rpx 0 0;
				// background-color: $uni-bg-color;

				.tab_item {
					width: 50%;
					height: 90rpx;
					line-height: 90rpx;
					display: flex;
					align-items: center;
					padding-left: 30rpx;
					box-sizing: border-box;
					background-color: #fefbf8;
					border-radius: 0 22rpx 0 0;
					position: relative;

					.title {
						font-weight: 500;
						font-size: 28rpx;
						color: #999999;
						position: relative;
						z-index: 1;
					}

					.title.active {
						color: #e8ad7b;
					}

					.icon {
						width: 48rpx;
						height: 48rpx;
						margin-right: 16rpx;
						position: relative;
						z-index: 1;
					}
				}

				.tab_item.active {
					background-color: #fff;
				}

				// .tab_item.active:after {
				//  content: "";
				//          position: absolute;
				//          top: 0;
				//          left: -4px;
				//          width: 40px;
				//          height: 26px;
				//          background: orange;
				// }
				.tab_item.active:before {
					content: "";
					position: absolute;
					top: -20rpx;
					left: 0;
					right: 0;
					bottom: 0;
					border-radius: 2px;
					background: #fff;
					transform: skewX(0deg);
				}

				.tab_item1.active:before {
					border-radius: 22rpx 40rpx 0 0;
				}

				.tab_item2.active:before {
					border-radius: 40rpx 22rpx 0 0;
				}
			}

			.table {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 30rpx;
				box-sizing: border-box;
				height: 90rpx;
				background-color: $uni-bg-color;
				border-bottom: 1rpx solid #e5e5e5;

				.table_left {
					display: flex;
					align-items: center;

					.icon {
						width: 32.86rpx;
						height: 39.07rpx;
						margin-right: 24rpx;
					}

					.title {
						display: flex;
						align-items: center;
						color: #e8ad7b;
					}
				}

				.value {
					font-weight: 500;
					font-size: 32rpx;
					color: #333333;
				}
			}

			.pack {
				display: flex;
				flex-direction: column;
				padding: 30rpx;
				box-sizing: border-box;
				background-color: $uni-bg-color;
				border-radius: 0 0 22rpx 22rpx;

				.top {
					display: flex;
					flex-direction: column;
					margin-top: 8rpx;

					.title {
						font-size: 28rpx;
						color: #333;
						font-weight: bold;
						margin-bottom: 16rpx;
					}

					.address {
						font-size: 24rpx;
						font-weight: 400;
						color: #999;
					}
				}

				.list {
					display: flex;
					flex-direction: column;

					.item {
						height: 70rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						font-size: 28rpx;

						.lable {
							color: #666;
							font-weight: 500;
						}

						.getPhone {
							display: flex;
							align-items: center;

							.u-input {
								width: 340rpx;
								border: none;

								input {
									font-size: 24rpx;
									color: #333;
								}

								.input-placeholder {
									font-size: 24rpx;
								}
							}
						}

						.text,
						.getBtn {
							color: #e8ad7b;
						}

						.getBtn {
							border-radius: 12rpx;
							border: 2rpx solid #e8ad7b;
							padding: 8rpx 20rpx;
							box-sizing: border-box;
						}
					}
				}
			}
		}

		.card_head_box {
			width: 100%;
			display: flex;
			justify-content: space-between;
			position: absolute;
			top: -22.5rpx;
			padding: 0 44rpx;

			.card_head_item {
				width: 45rpx;
				height: 45rpx;
				background-color: #f9f9f9;
				border-radius: 50%;
				// box-shadow: inset 0rpx -13rpx 18rpx -16rpx rgba(87, 86, 86, 0.35);
			}
		}

		.card {
			// background-color: #fff;
			border-radius: 20upx;
			margin-bottom: 28upx;
			position: relative;

			.card_item {
				display: flex;
				flex-direction: column;
				position: relative;
				padding: 0 34rpx;

				.head {
					display: flex;
					justify-content: space-between;
					// padding: 32rpx 0;

					.head_left {
						display: flex;
						align-items: center;

						.placeNum {
							font-weight: bold;
							font-size: 32rpx;
							color: #333333;
							margin-right: 32rpx;
							flex-shrink: 0;
						}

						.placeTime {
							font-weight: 400;
							font-size: 32rpx;
							color: #666666;
							flex-shrink: 0;
						}
					}
				}

				.shop-info {
					padding-top: 28rpx;

					.item:nth-child(1) {
						margin-top: 0;
					}

					.item {
						margin-bottom: 32rpx;
						display: flex;

						.cover {
							position: relative;
						}

						.info {
							flex: 1;
							display: flex;
							flex-direction: column;
							padding-left: 16upx;

							.productName {
								font-weight: bold;
								font-size: 28rpx;
								color: #333333;
								margin-top: 20rpx;
							}

							.productSkuName {
								font-weight: 400;
								font-size: 24rpx;
								color: #999999;
								display: -webkit-box;
								-webkit-box-orient: vertical;
								-webkit-line-clamp: 3;
								overflow: hidden;
								text-overflow: ellipsis;
							}

							.n {
								font-size: 24upx;
								color: #999;
							}
						}

						.price {
							display: flex;
							flex-direction: column;
							align-items: flex-end;
							padding-left: 68rpx;

							.priceAmount {
								font-weight: 500;
								font-size: 28rpx;
								color: #333333;
								margin-top: 26rpx;
							}

							.num {
								font-weight: 400;
								font-size: 24rpx;
								color: #999999;
								margin-top: 22rpx;
							}
						}
					}
				}

				.status {
					align-self: flex-end;
					width: 92rpx;
					height: 40rpx;
					line-height: 40rpx;
					text-align: center;
					background: #999999;
					border-radius: 10rpx 10rpx 10rpx 10rpx;
					font-weight: 400;
					font-size: 22rpx;
					color: #ffffff;
					margin-top: 32rpx;
				}

				.totalAmount {
					width: 100%;
					display: flex;
					justify-content: flex-end;
					align-items: flex-end;
					padding: 32rpx 0;
					border-bottom: 2rpx dashed #e5e5e5;

					.label {
						font-weight: bold;
						font-size: 28rpx;
						color: #333333;
					}

					.price {
						font-weight: bold;
						font-size: 36rpx;
						color: #333333;
					}
				}

				.semicircle_icon {
					width: 100%;
					position: absolute;
					top: -22.5rpx;
					left: 0;
					display: flex;
					justify-content: space-between;

					.semicircle_left_icon {
						width: 45rpx;
						height: 45rpx;
						margin-left: -22.5rpx;
						background-color: #f9f9f9;
						border-radius: 50%;
						// box-shadow: inset -20rpx 0rpx 22rpx -20rpx rgba(87, 86, 86, 0.35);
					}

					.semicircle_right_icon {
						width: 45rpx;
						height: 45rpx;
						margin-right: -22.5rpx;
						background-color: #f9f9f9;
						border-radius: 50%;
						// box-shadow: inset 13rpx 0rpx 16rpx -9rpx rgba(87, 86, 86, 0.35);
					}
				}
			}

			.cell-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 32rpx 34rpx 0 34rpx;

				.label {
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;
					padding-bottom: 32rpx;
				}

				.val {
					display: flex;
					align-items: flex-end;
					padding-bottom: 32rpx;
					border-bottom: 2rpx dashed #e5e5e5;

					view:nth-child(1) {
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
						margin-right: 42rpx;
					}

					view:nth-child(2) {
						display: flex;
						align-items: flex-end;
						font-weight: bold;
						font-size: 36rpx;
						color: #333333;
					}
				}

				.val.column {
					display: flex;
					flex-direction: column;

					.productCoupon {
						display: flex;
						align-items: flex-end;
						margin: 0 0 10rpx 0;

						.name {
							font-weight: 400;
							font-size: 26rpx;
							color: #999;
							margin: 0;
						}

						.num {
							font-weight: 400;
							font-size: 26rpx;
							color: #999;
							margin: 0 30rpx;
							line-height: 20rpx;
						}

						.amount {
							font-weight: bold;
							font-size: 26rpx;
							color: #333;
						}
					}
				}
			}

			.favorable {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 60rpx;
				box-sizing: border-box;
				// border-bottom: 2rpx solid #E5E5E5;

				.favorable_left {
					display: flex;
					align-items: center;

					.icon {
						width: 40rpx;
						height: 40rpx;
						margin-right: 16rpx;
					}

					.name {
						font-size: 28rpx;
						font-weight: 400rpx;
						color: #333;
					}
				}

				.favorable_right {
					display: flex;
					align-items: center;

					.favorable_right_text {
						font-size: 24rpx;
						color: #999;
						font-weight: 400rpx;

						&.red {
							color: #ff3232;
						}
					}
				}

				.favorable_right {
					.column {
						display: flex;
						flex-direction: column;
						align-items: flex-end;

						.favorable_right_text {
							margin-bottom: 10rpx;

							&.red {
								color: #ff3232;
							}

							text:nth-child(1) {
								font-size: 26rpx;
								color: #999;
							}

							text:nth-child(2) {
								font-size: 26rpx;
								color: #999;
								margin: 0 30rpx;
							}

							text:nth-child(3) {
								font-size: 26rpx;
								color: #333;
							}
						}
					}
				}

				.favorable_right.column {
					align-items: flex-start;
				}
			}

			.favorable.column {
				align-items: flex-start;
			}

			.cell-item.column {
				align-items: flex-start;
			}

			.total-wrap {
				display: flex;
				margin: 0 30rpx;
				justify-content: flex-end;
				align-items: flex-end;
				padding: 32rpx 0 0 34rpx;
				font-weight: bold;
				font-size: 28rpx;
				color: #333333;
				border-top: 2rpx dashed #e5e5e5;

				.price {
					font-weight: bold;
					font-size: 36rpx;
				}
			}

			.order_footer {
				display: flex;
				flex-direction: column;
				padding: 34rpx;
				position: relative;
			}
		}
	}

	.orderInfo {
		background: #ffffff;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
		margin-top: 32rpx;
		padding: 32rpx 34rpx;

		// box-shadow: 0rpx 4rpx 12rpx 2rpx rgba(87,86,86,0.35);
		.row {
			display: flex;
			justify-content: space-between;
			margin-bottom: 32rpx;

			.t {
				font-weight: bold;
				font-size: 28rpx;
				color: #333333;
				flex-shrink: 0;
			}

			.info {
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
			}
		}

		.row:last-child {
			margin-bottom: none;
		}
	}

	.fixedview {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;

		.flex-between {
			width: 100%;
			padding: 36rpx 54rpx 102rpx 54rpx;
			background: #ffffff;

			.fixedview_one {
				display: flex;
				align-items: flex-end;

				.fixedview_oneone {
					font-weight: 400;
					font-size: 28rpx;
					color: #666666;
				}

				.fixedview_onetow {
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;

					text {
						font-size: 24rpx;
					}
				}
			}

			.fixedview_tow {
				width: 140rpx;
				height: 56rpx;
				line-height: 56rpx;
				text-align: center;
				background: #e3ad7f;
				border-radius: 12rpx 12rpx 12rpx 12rpx;
				font-weight: 400;
				font-size: 28rpx;
				color: #ffffff;
			}
		}
	}

	.red {
		color: #ff3232;
	}

	.youhui-item {
		height: 60rpx;
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-content: center;
	}

	.align-center {
		align-items: center;
	}

	.limitDiscount {
		background-color: #cc5617;
		padding: 2rpx 10rpx;
		white-space: nowrap;
		text-align: center;
		position: absolute;
		top: 0;
		left: 0;
		font-weight: 400;
		font-size: 24rpx;
		color: #ffffff;
		border-radius: 20rpx 0rpx 20rpx 0rpx;
		z-index: 9;
		color: #fff;
	}

	.disocunt {
		background: #FFFFFF;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
		overflow: hidden;
		margin-top: 32rpx;

		.price {
			color: #FF1C1C;
			font-size: 28rpx;
			line-height: 42rpx;
		}

		.row {
			padding: 16rpx 24rpx;
			display: flex;
			justify-content: space-between;

			.t {
				font-weight: bold;
				font-size: 28rpx;
				color: #333333;
				flex-shrink: 0;
			}

			.info {
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
			}
		}
	}
	.guodu{
		transition:all .3s linear; 
		padding-top: 2rpx;
	}
	.rotate{
		transform: rotate(-90deg);
	}
</style>