<script setup>
	import DraggableButton from "@/pages/components/goHome.vue";
	import TabBar from "@/common/TabBar.vue";
	/**
	 * name：
	 * user：sa0ChunLuyu
	 * date：2024年9月11日 19:24:50
	 */
	import {
		ref
	} from "vue";
	import {
		$api,
		$response,
		$image
	} from "@/api";
	import {
		onShow
	} from "@dcloudio/uni-app";
	import wx from "weixin-js-sdk";
	import {
		useStore
	} from "@/store";
	const $store = useStore();

	// groupId

	let comboInfo = ref({}); // 套餐详情
	let selectIds = ref([]); // 选中自选ID
	let wj = ref(""); //
	let itemsInfo = ref({}); // 自选项目详情
	let comboId = ref(""); // 套餐id
	let personId = ref(""); // 患者id
	let groupId = ref(""); // 团检id
	let tabIndex = ref(-1); // 标签索引
	let total_original_price=ref(0);
	let totalPrice = ref(0); // 总折扣价格
	let groupInfo = ref({}); // 团检信息
	let status = ref(0); // 1个检套餐 2个检自选 3团检套餐 4团检自选
	let buyText = ref("立即购买"); // 购买按钮文字
	let notice = ref({}); // 体检须知
	let losePrice = ref(0); // 剩余金额
	let popupTip = ref(null); // 剩余额度提示弹窗
	let contentInfo=ref([])//详情信息
	let active_keshi=ref([]);
	let popupXuZhi=ref(null);
	let active_miaoshu=ref([]);//已经显示的项目描述
	let buy_info=ref({});
	let userInfo = ref(""); // 病人信息
	let buyInfo = ref({}); // 购买信息
	let yytjInfo = ref({}); // 预约信息
	let truePrice = ref(0); // 总价
	let save_money = ref(0);
	let integral = ref(0);
	let couponList = ref([]);
	let yucunkuan = ref(0); // 计算后的预存款
	let jifen = ref(0); // 计算后的可用积分
	let keyong_jifen = ref(0); // 可用积分
	let netReceiptsPrice = ref(0);
	let erxianInfo = ref(null);
	let selectStatus = ref(null);
	let popup = ref(null);
	let selectIndex = ref(0);
	let PayPopupTip=ref(null);
	let CreatedOrderId=ref(0);

	const GetReadmeDetails = async () => {
		const response = await $api("GetReadme",{sex:comboInfo.value.combo_sex?comboInfo.value.combo_sex:0});
		$response(response, () => {
			notice.value = response.data || false;
			if (tabIndex.value == 0) {
				let num = 5;
				buyText.value = "0" + num;
				tabIndex.value = 1;
				let timer = setInterval(() => {
					num--;
					buyText.value = "0" + num;
					if (num == 0) {
						buyText.value = "立即购买";
						clearInterval(timer);
					}
				}, 1000);
				return;
			}
			uni.hideLoading();
		});
	};

	const $props = defineProps({
		comboId: {
			type: String,
			default: "",
		},
		personId: {
			type: String,
			default: "",
		},
		groupId: {
			type: String,
			default: "",
		},
		itemIds: {
			type: String,
			default: "",
		},
		wj: {
			type: String,
			default: "",
		}
		 
	});
	const WenHaoClick=(i)=>{
		console.log(active_miaoshu.value)
		let index=active_miaoshu.value.indexOf(i)
		if(index>-1){
		        active_miaoshu.value.splice(index, 1);
		    }else{
		        active_miaoshu.value.push(i);
		    }
	}
    const opendDetail=(index)=>{
		if(active_keshi.value.indexOf(index)!== -1){
			active_keshi.value.splice(active_keshi.value.indexOf(index), 1);
		}else{
			active_keshi.value.push(index)
		}
	}
	const mountedAction = async () => {
		selectIds.value = $props.itemIds ? $props.itemIds.split(",") : [];
		wj.value = $props.wj || "";
		comboId.value = $props.comboId || "";
		personId.value = $store.getUser().person_id || "";
		groupId.value = $props.groupId || "";
		// 团检空项目 - 套餐列表 - 套餐详情 - 自选 - 弹剩余额度提醒 - 团检详情
		//   ｜
		//   自选   - 弹推荐套餐/剩余额度提醒 - 团检详情

		// 团检有项目 - 团检详情 - 自选 - 团检详情

		// comboId && person_id
		// 个检 - 套餐列表 - 套餐详情 - 自选 - 个检详情
		//  ｜
		// 自选 - 弹推荐套餐 - 个检详情

		if (groupId.value) {
			if (comboId.value) {
				// 团检套餐
				status.value = 3;
			} else {
				// 团检自选
				status.value = 4;
			}
		} else {
			if (comboId.value) {
				// 个检套餐
				status.value = 1;
			} else {
				// 个检自选
				status.value = 2;
			}
		}
		console.log(status.value, "1个检套餐 2个检自选 3团检套餐 4团检自选");
		uni.showLoading({
			title: "加载中",
		});
		getBuyInfo(); // 获取购买信息
		buyInfo.value = $store.getBuyInfo();
		userInfo.value=$store.getUser()
		let time = setTimeout(() => { 
			
			GetPersonIntegralSaveMoneyCouponInfo();
			clearTimeout(time);
		}, 500);
	};

	const buy = async (step=0) => {
		
		if (step == 1) {
			if (losePrice.value > 0 && groupId.value.length>0) {
			  popupTip.value.open("center"); // 弹剩余额度提醒
			  return;
			}
			await GetReadmeDetails();
			popupXuZhi.value.open();
		}
		if (step ==3) {
			await GetReadmeDetails();
			 popupTip.value.close()
			popupXuZhi.value.open();
			 
		}
		
		if (step == 2) {
			$store.setBuyInfo({
				combo_id: comboId.value,
				combo_sex:comboInfo.value.combo_sex,
				person_id: personId.value,
				group_id: groupId.value,
				item_ids: selectIds.value,
				hospital: $store.save_info?.hospital?$store.save_info?.hospital:1,
				duo_xuan_yi: $store.getDuoXuanYi(),
				wj: wj.value,
				sanfang_code:buy_info.value.sanfang_code?.code_num?buy_info.value.sanfang_code:null
			});
			if (!!$store.yytjInfo.doctor_name) {
				$store.setYytjInfo({
					doctor_name: $store.yytjInfo.doctor_name,
					doctor_date: $store.yytjInfo.doctor_date,
					doctor_id:$store.yytjInfo.doctor_id
				});
			} else {
				$store.setYytjInfo({});
			}
			uni.setStorageSync("yytjInfoS", {});
			popupXuZhi.value.close()
			if (groupId.value || buy_info.value.sanfang_code?.code_num) {
				//团检
				uni.navigateTo({
				 url: '/pages/main/yytjsj/yytjsj_new'
				});
			}else{
				// uni.navigateTo({
				// 	url: "/pages/main/tjyy/tjyy",
				// });
				comfrimyy()
			}
			
		}
	};

	const getBuyInfo = async () => {
		// 获取购买信息
		let obj = {
			item_ids: selectIds.value,
			combo_id: comboId.value,
			hospital: $store.save_info?.hospital?$store.save_info?.hospital:1,
			person_id: personId.value,
			group_id: groupId.value,
			duo_xuan_yi: $store.getDuoXuanYi(),
			wj: wj.value,
			sanfang_code:buy_info.value.sanfang_code?.code_num?buy_info.value.sanfang_code:null
		};
		const response = await $api("BuyInfo", obj);
		$response(response, () => {
			uni.hideLoading();
			contentInfo.value=[]
			if (groupId.value && response.data.group_info.length) {
				// 团检
				groupInfo.value = response.data.group_info[0];
				if (response.data.group_info[0].items?.length) {
					status.value = 3;
				}
				if(groupInfo.value.items?.length){
					contentInfo.value.push(groupInfo.value.items) 
					groupInfo.value.itemscount=0;
					let itemscount=0
					groupInfo.value.items.forEach((v,i)=>{
						if(v.keshi_name!="材料费")
						itemscount=itemscount+v.children.length
					})
					groupInfo.value.itemscount=itemscount
				}
			}
			losePrice.value = response.data.lose_price;
			comboInfo.value = response.data.combo_info;
			if(comboInfo.value.items?.length){
				comboInfo.value.items.forEach((v,i)=>{
					if(v.keshi_name!="材料费"){
							contentInfo.value.push(v)
					}
				})
			
			}
			itemsInfo.value = response.data.items_info;
			if(itemsInfo.value.items?.length){
				contentInfo.value.push(itemsInfo.value.items)
				itemsInfo.value.itemscount=0;
				let itemscount=0
				itemsInfo.value.items.forEach((v,i)=>{
					if(v.keshi_name!="材料费")
					itemscount=itemscount+v.children.length
				})
				itemsInfo.value.itemscount=itemscount
			}
			totalPrice.value = response.data.true_price;
			total_original_price.value=response.data.original_price
			tabIndex.value = 0;
			contentInfo.value=contentInfo.value.flat()
			 
			 
			 
			 $store.setBuyInfo({
			 	combo_id: comboId.value,
			 	combo_sex:comboInfo.value.combo_sex,
			 	person_id: personId.value,
			 	group_id: groupId.value,
			 	item_ids: selectIds.value,
			 	hospital: $store.save_info?.hospital?$store.save_info?.hospital:1,
			 	duo_xuan_yi: $store.getDuoXuanYi(),
			 	wj: wj.value,
			 	sanfang_code:buy_info.value.sanfang_code?.code_num?buy_info.value.sanfang_code:null
			 });
			 let time2 = setTimeout(() => {
			 	getnmrList(); 
			 	clearTimeout(time2);
			 }, 500);
			 
		});
	};
	const getnmrList = async () => {
		// 获取号源项目
		yytjInfo.value = $store.getYytjInfo();
		buyInfo.value=$store.getBuyInfo()
		console.log(yytjInfo.value);
		const response = await $api("BuyInfo", buyInfo.value);
		$response(response, () => {
			if (buyInfo.value.group_id && response.data.group_info.length) {
				// 团检
				groupInfo.value = response.data.group_info[0];
			}
			comboInfo.value = response.data.combo_info;
			itemsInfo.value = response.data.items_info;
			truePrice.value = response.data.true_price;
			erxianInfo.value = response.data.nmr_list2;
			yytjInfo.value.erxianInfo = erxianInfo.value;
			netReceiptsPrice.value = response.data.true_price;
			if (itemsInfo.value.items?.length) { //合并显示材料费
				let cailiao_price = 0
				let cailiao_keshi_key = false;
				itemsInfo.value.items.forEach((v, i) => {
					if (v.keshi_name == "材料费") {
						cailiao_keshi_key = i
						v.children.forEach((v2, i2) => {
							cailiao_price = (Number(cailiao_price) + Number(v2.price))
								.toFixed(2);
						})
					}
	
				})
				if (cailiao_keshi_key) {
					itemsInfo.value.items[cailiao_keshi_key] = {
						keshi_name: "材料费",
						children: [{
							name: "材料",
							desc: "",
							price: cailiao_price
						}]
					}
				}
	
			}
			if (yytjInfo.value.couponPrice) {
				// 优惠券
				// netReceiptsPrice.value = (
				//   netReceiptsPrice.value - yytjInfo.value.couponPrice
				// ).toFixed(2);
			}
	
			if (yytjInfo.value.prepaidPrice) {
				// 预存款
				yucunkuan.value =
					yytjInfo.value.prepaidPrice > netReceiptsPrice.value ?
					netReceiptsPrice.value :
					yytjInfo.value.prepaidPrice;
				netReceiptsPrice.value = (
					netReceiptsPrice.value - yucunkuan.value
				).toFixed(2);
			} else {
				yucunkuan.value = 0;
			}
	
			if (yytjInfo.value.pointsPrice) {
				// 积分
				jifen.value =
					yytjInfo.value.pointsPrice > netReceiptsPrice.value ?
					netReceiptsPrice.value :
					yytjInfo.value.pointsPrice;
				netReceiptsPrice.value = (netReceiptsPrice.value - jifen.value).toFixed(
					2
				);
			} else {
				jifen.value = 0;
			}
	
			if (!yytjInfo.value?.nmr_list?.length) {
				yytjInfo.value.nmr_list = response.data.nmr_list.map((val) => {
					return {
						...val,
						time: "",
						id: "",
					};
				});
				yytjInfo.value.nmr_list.push({
					item_id: -1,
					name: "体检时间",
					time: "",
					id: "",
				});
			}
			uni.hideLoading();
		});
		$store.setYytjInfo(yytjInfo.value);
	};
	const GetPersonIntegralSaveMoneyCouponInfo = async () => {
		// 获取个人积分, 预存款, 优惠券
		const response = await $api("GetPersonIntegralSaveMoneyCouponInfo", {
			person_id: $store.getUser()?.person_id,
			combo_id: buyInfo.value.combo_id
		});
		$response(response, () => {
			couponList.value = response.data.coupon_list;
			save_money.value = response.data.save_money;
			integral.value = response.data.integral;
		});
	};
	const UsableIntegralSaveMoney = async () => {
		// 可用积分
		const response = await $api("UsableIntegralSaveMoney", {
			person_id: $store.getUser()?.person_id,
			ysje: netReceiptsPrice.value,
			ssje: truePrice.value,
			type: 1,
		});
		$response(response, () => {
			keyong_jifen.value = response.data.keyong_jifen;
			if (keyong_jifen.value) {
				selectStatus.value = 1;
				popup.value.open("bottom");
				if (yytjInfo.value.pointsPrice) {
					selectIndex.value = 1;
				} else {
					selectIndex.value = 0;
				}
			} else {
				uni.$lu.toast("暂无积分");
			}
		});
	};
	const comfrimyy = async () => {
	  let plan_id = "";
	  let plan_nmr_id = "";
	  uni.showLoading();
	  console.log(yytjInfo.value?.nmr_list);
	
	
	  if (yytjInfo.value?.nmr_list?.length > 1) {
	    plan_nmr_id = yytjInfo.value?.nmr_list[0]?.id;
	  }
	  if (yytjInfo.value?.nmr_list?.length > 0) {
	    plan_id = yytjInfo.value?.nmr_list[yytjInfo.value?.nmr_list.length - 1]?.id;
	  }
	
	  console.log(groupInfo.value);
	
	  let obj = {
	    person_id: buyInfo.value.person_id,
	    type: buyInfo.value.group_id ? 2 : 1,
	    hospital: buyInfo.value.hospital,
	    group_id: buyInfo.value.group_id,
	    combo_id:
	      buyInfo.value?.combo_id ||
	      (groupInfo.value?.combo_id ? "" : userInfo.value?.combo_id) ||
	      "",
	    item_ids: buyInfo.value.item_ids,
	    plan_id: plan_id,
	    plan_nmr_info:yytjInfo.value?.nmr_list || null,
	    doctor: yytjInfo.value?.doctor_name || "",
	    duo_xuan_yi: $store.getDuoXuanYi(),
	    jifen: Math.ceil(jifen.value),
	    yucunkuan: yucunkuan.value,
		coupon_id:yytjInfo.value?.couponId || null,
	    wj: buyInfo.value.wj,
		erxian_info:erxianInfo.value,
		peiou_info:$store.getPeiOuUser(),//配偶信息
		sanfang_code:buyInfo.value.sanfang_code?.code_num?buyInfo.value.sanfang_code:null
	  };
	  console.log(obj);
	 
	  let apiName="CreateNewOrder"
	  let doneUrl="/pages/buy/done/done?id=" 
	  if($store.getTempPlan()?.plan_id){
		  apiName="OrderCreate"
		  doneUrl="/pages/buy/done/yuyue_done?id="
		  obj.plan_id=$store.getTempPlan()?.plan_id
		  obj.yuyue_fangshi='GeJianPlanFront'
		  obj.order_id=$store.getTempPlan()?.order_id
	  }
	  
	  const response = await $api(apiName, obj);
	  $response(response, () => {
	    if (response.status) {
			 CreatedOrderId.value=response.data.orderid
	      if (response.data.action == "pay") {
	        StartPay(CreatedOrderId.value);
	      } else {
	        uni.reLaunch({
	          url: doneUrl+ CreatedOrderId.value
	        });
	      }
	    }
	    uni.hideLoading();
	  });
	};
	const selectDiscount = (status) => {
		// 选择折扣
		if (status == 2) {
			// 优惠券
			if (couponList.value.length) {
				toRouter("/pages/main/coupon/coupon");
			} else {
				uni.$lu.toast("暂无优惠券");
			}
		}
	
		if (status == 1) {
			// 积分
			if (!jifen.value && !netReceiptsPrice.value) {
				uni.$lu.toast("实际金额已为0元，无需使用积分");
				return;
			}
			UsableIntegralSaveMoney();
		}
	
		if (status == 3) {
			// 预付款
			if (!yucunkuan.value && !netReceiptsPrice.value) {
				uni.$lu.toast("实际金额已为0元，无需使用预付款");
				return;
			}
			if (save_money.value) {
				selectStatus.value = status;
				if (yytjInfo.value.prepaidPrice) {
					selectIndex.value = 1;
				} else {
					selectIndex.value = 0;
				}
				popup.value.open("bottom");
			} else {
				uni.$lu.toast("暂无预付款");
			}
		}
	};
const comfrimSelect = () => {
		// 确定选择折扣
		if (selectStatus.value == 1) {
			// 积分
			if (selectIndex.value) {
				yytjInfo.value.pointsPrice = keyong_jifen.value;
				// 使用积分要比实际金额大的话 使用的积分要 等于 实际金额
				if (keyong_jifen.value > netReceiptsPrice.value) {
					jifen.value = netReceiptsPrice.value;
				} else {
					jifen.value = keyong_jifen.value;
				}
				netReceiptsPrice.value = (netReceiptsPrice.value - jifen.value).toFixed(
					2
				);
				$store.setYytjInfo(yytjInfo.value);
			} else {
				if (yytjInfo.value.pointsPrice) {
					console.log(jifen.value);
					console.log(netReceiptsPrice.value);
					netReceiptsPrice.value = (
						Number(netReceiptsPrice.value) + Number(jifen.value)
					).toFixed(2);
				}
				yytjInfo.value.pointsPrice = 0;
				jifen.value = 0;
				$store.setYytjInfo(yytjInfo.value);
			}
		} else {
			console.log(selectIndex.value);
			//预存款
			if (selectIndex.value) {
				yytjInfo.value.prepaidPrice = save_money.value;
				// 使用的预存款比实际金额大的话 使用的预存款要 等于 实际金额
				if (save_money.value > netReceiptsPrice.value) {
					yucunkuan.value = netReceiptsPrice.value;
				} else {
					yucunkuan.value = save_money.value;
				}
				netReceiptsPrice.value = (
					netReceiptsPrice.value - yucunkuan.value
				).toFixed(2);
				$store.setYytjInfo(yytjInfo.value);
			} else {
				if (yytjInfo.value.prepaidPrice) {
					// 不使用预存款的话 把扣掉的预存款加上
					netReceiptsPrice.value = (
						Number(netReceiptsPrice.value) + Number(yucunkuan.value)
					).toFixed(2);
				}
				yucunkuan.value = 0;
				yytjInfo.value.prepaidPrice = 0;
				$store.setYytjInfo(yytjInfo.value);
			}
		}
		popup.value.close();
	};
	const addCombo = () => {
		// 增加项目
		let itemIds = $props.itemIds ? $props.itemIds : "";
		let query = "?comboId=" + comboId.value + "&itemIds=" + itemIds;
		if (groupId.value) {
			query += "&groupId=" + groupId.value;
		}
		if($props.wj){
			query +="&wj="+$props.wj
		}
		uni.navigateTo({
			url: "/pages/main/tj/tjzx?" + query,
		});
	};

	const config_ref = ref(null);
	const configRef = (e) => {
		if (!config_ref.value) {
			config_ref.value = e;
			mountedAction();
		}
	};
	const toUrl=(url)=>{
		uni.reLaunch({
			url:url
		})
	}
    const toreadme=()=>{
		GetReadmeDetails();
		 popupTip.value.close()
	}
	const toPlan=async ()=>{
		uni.navigateTo({
		 url: '/pages/main/yytjsj/yytjsj_new'
		});
	}
	const StartPay = async (id) => {
	  //继续支付
	  
	  uni.showLoading();
	  const response = await $api("StartPay", {
	    openid: localStorage.getItem("OPENID"),
	    id: id,
	  });
	  uni.hideLoading();
	  $response(response, () => {
	    if (response.status) {
			PayPopupTip.value.open()
	      let info = response.data.info;
	      let p =
	        "&appid=" +
	        info.appid +
	        "&sub_org_code=" +
	        info.sub_org_code +
	        "&ghzid=" +
	        info.ghzid +
	        "&orderid=" +
	        info.orderid +
	        "&order_desc=" +
	        info.order_desc +
	        "&amount=" +
	        info.amount +
	        "&notify_url=" +
	        info.notify_url +
	        "&timestamp=" +
	        info.timestamp +
	        "&nonce=" +
	        info.nonce +
	        "&signature=" +
	        info.signature;
	      console.log(p);
	      wx.miniProgram.navigateTo({
	        url:
	          "/pages/other/entry/index?path=/pages/physical-examination/payment/index" +
	          p,
	      });
	    }
	  });
	};
 
	onShow(() => {
		buy_info.value=$store.getBuyInfo()
		if (!!config_ref.value) {
			mountedAction();
		}
	});
</script>
<template>
	<view style="background-color: #fff;">
	<TabBar style="z-index: 2;"></TabBar>
	<uni-popup ref="PayPopupTip" :mask-click="false">
	  <view
	    class="mb-70rpx bg-#fff text-center box-border pt-80rpx pb-50rpx px-65rpx w-90vw rounded-15rpx"  
	  >
	    <view
	      class="w-full text-center text-##090909 text-26rpx line-height-[50rpx]"
	      >是否继续支付？</view
	    >
	    <view class="mt-50rpx between">
	      <button
	        type="primary"
	        @click="toUrl('/pages/main/order/order')"
	        class="w-196rpx h-68rpx center text-#fff text-24rpx !bg-#239EA3 rounded-8rpx"
	      >
	        取消
	      </button>
	      <button
	        @click=" StartPay(CreatedOrderId)"
	        class="w-196rpx h-68rpx center text-#239EA3 text-24rpx !bg-#D9F3F2 rounded-8rpx"
	      >
	        继续
	      </button>
	    </view>
	  </view>
	</uni-popup> 
	<uni-popup ref="popup">
		<view class="center relative px-10rpx pb-30rpx text-36rpx bg-#fff rounded-t-15rpx box-border col">
			<view class="text-28rpx p-[40rpx_50rpx_25rpx_50rpx] between w-full bs b-b-1 b-#DEDEDE box-border">
				<text class="line-height-[1] text-#171717 mr-10rpx">{{
	      selectStatus == 1 ? "积分" : "预存款"
	    }}</text>
				<view class="mr-auto text-#888787">
					（剩余<text class="text-#FB670E">{{
	        selectStatus == 1 ? keyong_jifen : save_money
	      }}</text>)
				</view>
				<uni-icons @click="popup.close()" type="closeempty" color="#A6A6A6" size="26" class=""></uni-icons>
			</view>
			<view class="text-#171717 text-28rpx px-40rpx box-border w-full">
				<view class="between pl-20rpx pr-10rpx box-border bs b-b-1 b-#E1ECEE h-90rpx" @click="selectIndex = 0">
					<text>暂不使用{{ selectStatus == 1 ? "积分" : "预存款" }}</text>
					<uni-icons :type="!selectIndex ? 'checkbox-filled' : 'circle'"
						:color="!selectIndex ? '#239EA3' : '#A6A6A6'" size="20" class=""></uni-icons>
				</view>
				<view class="between pl-20rpx pr-10rpx box-border bs b-b-1 b-#E1ECEE h-90rpx" @click="selectIndex = 1">
					<text v-if="selectStatus == 1">抵扣￥{{
	          jifen
	            ? jifen
	            : keyong_jifen > netReceiptsPrice
	            ? netReceiptsPrice
	            : keyong_jifen
	        }}使用{{
	          Math.ceil(
	            jifen
	              ? jifen
	              : keyong_jifen > netReceiptsPrice
	              ? netReceiptsPrice
	              : keyong_jifen
	          )
	        }}积分</text>
					<text v-else>使用剩余预存款中的￥{{
	          yucunkuan
	            ? yucunkuan
	            : save_money > netReceiptsPrice
	            ? netReceiptsPrice
	            : save_money
	        }}</text>
					<uni-icons :type="selectIndex ? 'checkbox-filled' : 'circle'"
						:color="selectIndex ? '#239EA3' : '#A6A6A6'" size="20" class=""></uni-icons>
				</view>
			</view>
			<view @click="comfrimSelect"
				class="text-#fff text-34rpx rounded-full bg-#239EA3 mt-80rpx ma w-520rpx h-100rpx center">
				确定
			</view>
		</view>
	</uni-popup>
	<uni-popup ref="popupTip">
	  <view
	    class="mb-70rpx bg-#fff text-center box-border pt-80rpx pb-50rpx px-65rpx w-90vw rounded-15rpx"  
	  >
	    <view
	      class="w-full text-center text-##090909 text-26rpx line-height-[50rpx]"
	      >您还剩余
	      {{ losePrice }}
	      元体检额度尚未使用，确认提交后剩余体检额度将无法使用!</view
	    >
	    <view class="mt-50rpx between">
	      <button
	        type="primary"
	        @click="buy(3)"
	        class="w-196rpx h-68rpx center text-#fff text-24rpx !bg-#239EA3 rounded-8rpx"
	      >
	        我想好了
	      </button>
	      <button
	        @click="popupTip.close()"
	        class="w-196rpx h-68rpx center text-#239EA3 text-24rpx !bg-#D9F3F2 rounded-8rpx"
	      >
	        我再想想
	      </button>
	    </view>
	  </view>
	</uni-popup> 
	<view class="tishi2">温馨提示：<span style="color: #e95513;">若要增加项目可以到现场预检咨询</span></view>
	<view>
		<view v-if="!!$store.config">
			<view :ref="configRef"></view>
		</view>
	</view>
	<!-- 人员信息 -->
	<view  v-if="status == 1 || status==2">
		<view  style="border: 1px solid #ccc; margin: 20rpx;"
			class="p-20rpx pb-20rpx pt-20rpx rounded-15rpx bg-#fff "  v-if="userInfo">  
			<!-- <view class="text-#0E0E0E text-30rpx b-0 b-solid b-b-1 b-#E1ECEE pb-20rpx mb-35rpx">预约人信息</view> -->
		
			<view>
				<view style="display: flex;justify-content: space-between;padding-right: 10rpx;">
					<view style="display: flex; justify-content: center; align-items: center;">
						<view class="text-32rpx text-#000 " style="font-weight: bolder;">{{
					  userInfo.name
					}}</view>
						<view class="text-24rpx text-#8B8B8B  " style="margin-left: 40rpx;;">
							<text>{{ userInfo.sex == 1 ? "男性" : "女性" }}</text>
							<!-- <text class="ml-20rpx">{{
					    userInfo.married == 1
					      ? "已婚"
					      : userInfo.married == 2
					      ? "未婚"
					      : "未知"
					  }}</text> -->
							<text class="ml-40rpx mr-auto">{{ userInfo.phone }}</text>
							<!-- <button
					    v-if="!buyInfo.group_id"
					    @click="toRouter('/pages/user/choose/choose')"
					    class="text-24rpx text-#fff bg-#31AEB6 rounded-full px-26rpx h55rpx !m-0 center !ml-auto"
					  >
					    更改预约人
					  </button> -->
		
						</view>
					</view>
					<!-- <image @click="toRouter('/pages/user/choose/choose')" style="width: 50rpx;height: 50rpx;" src="@/static/assets/qiehuan@2x.png"></image> -->
		
				</view>
			</view>
		</view>
		<view v-if="integral || couponList.length || save_money" style="border: 1px solid #ccc;margin: 0rpx 20rpx 20rpx 20rpx; padding: 20rpx;border-radius: 20rpx;">
			<view v-if="integral"  
				class="  pr-17rpx rounded-15rpx bg-#fff between text-24rpx line-height-[1]"  style="padding: 10rpx 30rpx;" 
				@click="selectDiscount(1)">
				<view>
					<text class="text-#050505">积分</text>
					<text class="text-#828383">（{{ integral }}）</text>
				</view>
				<view class="ml-auto mr-20rpx">
					<text class="text-#FB4F1A" v-if="jifen">-¥{{ Math.ceil(jifen) }}</text>
					<text class="text-#070707" v-else>去选择</text>
				</view>
				<uni-icons type="right" size="12"></uni-icons>
			</view>
			
			<view v-if="couponList.length" 
				class="  pr-17rpx rounded-15rpx bg-#fff between text-24rpx line-height-[1] " style="padding: 10rpx 30rpx;" 
				@click="selectDiscount(2)">
				<view>
					<text class="text-#050505">优惠券</text>
					<text class="text-#828383">（共{{ couponList.length }}个）</text>
				</view>
				<view class="ml-auto mr-20rpx">
					<text class="text-#FB4F1A" v-if="yytjInfo.couponName">{{ yytjInfo.couponName }}</text>
					<text class="text-#070707" v-else>去选择</text>
				</view>
				<uni-icons type="right" size="12"></uni-icons>
			</view>
			
			<view v-if="save_money"  
				class="  pr-17rpx rounded-15rpx bg-#fff between text-24rpx line-height-[1]  " style="padding: 10rpx 30rpx;" 
				@click="selectDiscount(3)">
				<view>
					<text class="text-#050505">预存款</text>
					<text class="text-#828383">（剩余{{ save_money }}）</text>
				</view>
				<view class="ml-auto mr-20rpx">
					<text class="text-#FB4F1A" v-if="yucunkuan">-¥{{ yucunkuan }}</text>
					<text class="text-#070707" v-else>去选择</text>
				</view>
				<uni-icons type="right" size="12"></uni-icons>
			</view>
		</view>
		
	</view> 
	<!-- 人员信息 -->
	
	
   
	<view class="px-30rpx box-border comboInfo">
		<view v-if="status != 1 && status!=2" class="pt-35rpx rounded-15rpx px-10rpx bg-#fff pb-30rpx box-border b-0 b-t-1 b-solid b-#E1ECEE"  style="display: none;">
			
			<view  class="px-15rpx pt-10rpx">
				<!-- 2个检自选 和 3团检套餐 4团检自选 都要显示头像和名字 -->
				<view class="flex items-center">
					<image src="@/static/assets/userm.png" class="w-70rpx h-70rpx mr-35rpx" />
					<view class="flex items-center grow">
						<text class="text-#707070 text-24rpx">您好，</text>
						<text class="text-#0E0E0E text-32rpx">{{
              groupId ? groupInfo.name : $store.getUser().name
            }}</text>
					</view>
				</view>
				<view v-if="status != 2" class="text-24rpx mt-40rpx groupInfo">
					<!-- 3团检套餐 4团检自选 都要显示单位部门等信息 -->
					<view class="pb-30rpx">
						<text class="text-#8B8B8B">单位名称：</text>
						<text>{{ groupInfo.group_name }}</text>
					</view>
					<view class="pb-30rpx">
						<text class="text-#8B8B8B">部门名称：</text>
						<text>{{ groupInfo.bumen_name }}</text>
					</view>
					<view class="pb-30rpx" v-if="groupInfo.combo_name || comboInfo?.combo_name">
						<text class="text-#8B8B8B">套餐名称：</text>
						<text>{{ groupInfo.combo_name || comboInfo?.combo_name }}</text>
					</view>
				<!-- 	<view>
						<text class="text-#8B8B8B">体检额度：</text>
						<text>{{ groupInfo.tongshou_xiane }}</text>
					</view> -->
				</view>
			</view>
		</view>
		<view class="pb-150rpx">
			<!-- <view class="flex items-center justify-around px-30rpx   pt-30rpx">
				<view>
					<text class="text-30rpx text-#2E2E2E">套餐项目</text>
					<span v-if="status==1 && JSON.stringify(comboInfo) !== '{}'" class="combo_tag_wrapper" >{{ comboInfo?.tags[0]?.text }}</span> 
					<span v-if="status==2"  class="combo_tag_wrapper">{{ itemsInfo?.itemscount }}</span> 
				</view>
				
			</view> -->
			<view  class="mt--10rpx bg-#fff py-10rpx px-14rpx box-border flex-col flex">
				<!-- 套餐内容 -->
				<view v-if="contentInfo.length>0" class="mb-120rpx">
					<!-- 套餐项目 -->
					 
					<view class="flex h-58rpx bg-#239ea3 mb-26rpx text-#fff text-26rpx rounded-10rpx">
						<view v-if="[1,2].indexOf(status) !== -1" style="text-align: center;width: 100%;height: 58rpx;line-height: 58rpx;">
							<!-- 1个检套餐 显示套餐信息 -->
						 
							 	<text  v-if="status==2"> 项目自选 </text>
								<text  v-if="status==1">{{ comboInfo.combo_name }}</text> 
							 
						</view>
						<view  v-if="status ==3" style="text-align: center;width: 100%;height: 58rpx;line-height: 58rpx;">
							{{ groupInfo.group_name }} 
						</view>
					</view>
					<view v-for="(val, index) in contentInfo" :key="index">
						<view v-if="val.keshi_name != '材料费'">
							<view class="flex h-58rpx bg-#E6F5F6 text-#333 text-27rpx rounded-10rpx mt-10rpx"  @click="opendDetail(index)">
								<view class="min-w-250rpx max-w-250rpx keshi_name_k font-bold">{{ val.keshi_name }}</view>
								<view class="grow center">{{ val.children.length }}个项目</view>
								<view class="grow center xiangqingbutton"  > 
									<uni-icons type="down" size="10"></uni-icons>
								</view>
							</view>
							<view v-if="active_keshi.indexOf(index)!== -1">
								<view class="xian mt-10rpx "></view>
								<view class="  bg-#FBFBFB text-#000 text-26rpx rounded-10rpx p-20rpx little_item_k " v-for="(v, i) in val.children"
									:key="i">
									<view style="display: flex; align-items: center;">
										<view class="break-all   box-border ">
											{{i+1}}.{{ v.name }}
										</view>
										<!-- <view @click="WenHaoClick(index+''+i)" class="wenhao">?</view> -->
									</view>
									
									<view v-if="active_miaoshu.indexOf(index+''+i) == -1" class="grow text-24rpx text-#E95513 mt-10rpx   box-border">{{ v.desc || "-" }}</view>
								</view>
							</view>
							
						</view>
					</view>
				</view>

 
			</view>
			<uni-popup ref="popupXuZhi">
				<view class="tishi_main">
					<!-- 体检须知 -->
					 <view style="display: flex;justify-content: end;height: 1rpx;">
						 <uni-icons @click="popupXuZhi.close()" type="closeempty" size="20"></uni-icons>
					 </view>
						<view class="text-#2E2E2E text-30rpx font-900 text-center">
							体检须知
						</view>
						<!-- <view class="text-28rpx text-#2E2E2E">
							<image class="w-5rpx h-26rpx" src="@/static/assets/slices/tjcol2x.png"></image>
							体检须知
						</view> -->
				
						<view class="flex flex-justify-around text-#111111 text-28rpx pt-24rpx pb-40rpx">
							<view class="flex flex-col flex-items-center">
								<image class="w-80rpx h-80rpx" src="@/static/assets/slices/xgtc.png"></image>
								选购套餐
							</view>
							<view class="pt-25rpx">
								<image class="w-30rpx h-30rpx" src="@/static/assets/slices/lt.png"></image>
							</view>
							<view class="flex flex-col flex-items-center">
								<image class="w-80rpx h-80rpx" src="@/static/assets/slices/yytj.png"></image>
								预约体检
							</view>
							<view class="pt-25rpx">
								<image class="w-30rpx h-30rpx" src="@/static/assets/slices/lt.png"></image>
							</view>
							<view class="flex flex-col flex-items-center">
								<image class="w-80rpx h-80rpx" src="@/static/assets/slices/qwty.png"></image>
								前往体检
							</view>
							<view class="pt-25rpx">
								<image class="w-30rpx h-30rpx" src="@/static/assets/slices/lt.png"></image>
							</view>
							<view class="flex flex-col flex-items-center">
								<image class="w-80rpx h-80rpx" src="@/static/assets/slices/lqbg.png"></image>
								领取报告
							</view>
						</view>
						<view class="pb-20rpx text-28rpx text-#2E2E2E">
							<image class="w-5rpx h-26rpx" src="@/static/assets/slices/tjcol2x.png"></image>
							体检注意事项
						</view>
						<view v-html="notice.content" class="text-24rpx" style="line-height: 46rpx; max-height: 760rpx;overflow: scroll;"></view>
					 
					<view class="tishi_button" @click="buy(2)"  >我已知晓</view>
				</view>
			</uni-popup>
			
		</view>
		<view class="fixed bottom-110 h-150rpx left-0 w-full bg-gradient-to-r from-#02b4bd to-#ABD7D7 p-30rpx box-border between">
			<view class="grow">
				<view class="flex items-end" v-if="comboId != 0"> 
					<text class="original_price_wrapper">¥ {{ total_original_price }} </text>
				</view> 
				<view class="flex items-end"> 
					<text class="text-42rpx text-#ED6907 mr-20rpx font-bold">
						<!-- ¥{{  totalPrice  }} -->
							¥{{  netReceiptsPrice  }}
						
						</text>
				</view>
			</view>
			<view class="flex"> 
				<!-- <button v-if="!buy_info?.sanfang_code?.code_num" @click="addCombo()" class="button bgcolor_huang">
					增加项目
				</button> -->
				<button v-if="status == 1 || status==2" @click="buy(1)" class="button">
					<span v-if="comboInfo.combo_name?.indexOf('婚检') != -1">下一步</span><span v-else>购买</span>  
				</button>
				<button v-else @click="buy(2)" class="button"> <!-- 团检 -->
					下一步
				</button>
			 
			 
			 
			</view>
		</view>
	</view>
	</view>
</template>
<style scoped lang="scss">
	.comboInfo {
		position: relative;
		z-index: 1;
		background-color: #fff;
        min-height: calc(100vh - 200rpx);
	 

		.active {
			color: #239ea3;
			font-weight: bold;
			position: relative;

			&::after {
				content: "";
				width: 26rpx;
				height: 3rpx;
				background-color: #239ea3;
				position: absolute;
				left: 50%;
				bottom: -10rpx;
				transform: translateX(-50%);
			}
		}
	}
</style>
<style scoped>
	.combo_name_row{
		text-align: center;
		 width: 100%;
		color: #333;
		font-weight: 900;
		font-size: 28rpx;
		  
	}
	.keshi_name_k{
		line-height: 58rpx;
		padding-left: 30rpx;
	}
	.xian{
		height: 6rpx;
		border-radius: 6rpx;
		background-color: #B0E0E2;
	}
	.combo_tag_wrapper {
		padding-left: 13rpx;
		padding-right: 13rpx;
		height: 28rpx;
		line-height: 28rpx;
		border-radius: 5rpx;
		font-weight: 900;
		font-size: 18rpx;
		color: #47abd8;
		margin: 10rpx 8rpx 10rpx 10rpx;
		border: 3rpx solid #009FA8;
	}
	.little_item_k{
		border-bottom: 1px solid #ccc;
	}
	.wenhao{
		height: 18rpx;
		width: 18rpx;
		background-color: #009FA8;
		line-height: 18rpx;
		border-radius: 18rpx;
		color: #fff;
		text-align: center;
		font-size: 14rpx;
		margin-left: 10rpx;
	}
	.xiangqingbutton{
		color:#009FA8;
		font-size: 17rpx;
	}
	.button {
		color: #00828e;
		background-color: #fff;
		height: 58rpx;
		line-height: 58rpx;
		text-align: center;
		min-width: 174rpx;
		border-radius: 58rpx;
		margin-right: 20rpx;
		font-size: 29rpx;
	}
	.bgcolor_huang{
		background-color: #FF6D00;
		color: #fff;
	}
	.original_price_wrapper {
		font-weight: bolder;
		font-size: 18rpx;
		color: #333;
		line-height: 1;
		text-decoration-line: line-through; 
	}
	.tishi_main{
		background-color: #fff;
		padding: 40rpx 30rpx 20rpx 30rpx;
		width:600rpx;
		border-radius: 40rpx;
	}
	.tishi_button{
		width: 365rpx;
		background-color: #009da5;
		color:#fff;
		text-align: center;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		border-radius: 40rpx;
		margin: 20rpx auto 10rpx auto;
	}
	.groupInfo{
		border: 1px solid #ccc;
		padding: 20rpx 20rpx 0rpx 20rpx;
		border-radius: 20rpx;
	}
	.tishi2{
		font-size: 28rpx;
		 padding-left: 40rpx;
		 padding-top: 16rpx;
		background-color: #fff;
		margin-bottom: 20rpx;
	}
</style>