<template>
	<view class="content" style="padding: 20rpx;overflow: hidden;padding-bottom: 160rpx;">
		<rich-text :nodes="richText"></rich-text>
	</view>
	<view class="btn-wrap">
		<button type="default" class="button" @click="addInterestsList()">
			下一步
		</button>
	</view>
</template>

<script setup lang="ts">
	import { onLoad} from "@dcloudio/uni-app";
	import { reactive, ref } from "vue";
	import { equityProductsInfo } from "@/utils/network/api.js";
	import { stringToJson } from "@/utils/network/encryption";
	import { request } from "@/utils/network/request";
	import { msg, navTo } from "@/utils/utils";
	import { jump } from "@/datas/9901Jump.js";
	import {
		getOpenidApi
	} from "@/utils/network/api";
	import {
		getItem,
		setItem
	} from "@/utils/storage";
import { deviceType } from "@/utils/network/difference";
	const state = reactive({
		openid: "",
		equityId: "",
		id: "",
		clientFee: "",
		list: [],  //权益数据
		choiceValue: [],  //选择的权益数据的下标
		choiceValueComplete: [],   //选择的权益数据的具体数据
		isValueCard: "",
		type: 0,
		userType: 0,
		promoteId: "",  //产品id
		totalAmount: 0,  //产品+权益产品金额
		changeCardType: "",//储值卡转记账卡选权益产品
		applyId: "",
		orderId: "",
		sysType: "",
		signAgencyId:"",
	})

	let richText = ref('')
	onLoad((option : any) => {
		console.log("option===", option)
		// #ifdef MP-ALIPAY
		state.sysType = 'ALI';
		// #endif
		// #ifdef MP-WEIXIN
		state.sysType = 'WECHAT';
		// #endif
		console.log("promoteId", option)
		state.clientFee = option.clientFee;
		state.equityId = option.equityId;
		state.userType = option.userType;
		state.type = option.type;
		state.isValueCard = option.isValueCard;
		state.promoteId = option.promoteId;
		state.totalAmount = option.fee;
		// 储值卡转记账卡传过来的参数
		state.changeCardType = option.changeCardType;
		state.applyId = option.applyId;
		state.orderId = option.orderId;
		getInfo();
		getOpenID();
		state.signAgencyId = option.signAgencyId;
	})
	const addInterestsList = () => {
		console.log("state.signAgencyId",state.signAgencyId,deviceType)
		if(state.signAgencyId==deviceType){
			let obj={
				type:state.type,
				userType:state.userType,
				promoteId:state.promoteId
			}
			const params = encodeURIComponent(JSON.stringify(obj))
			jump("15",params)
		}else{
			if (state.changeCardType == "1") {
				navTo(
					`/subpackage/after-sale/to-bookkeeping-card/mailing_information?orderId=${state.orderId}&&applyId=${state.applyId}&&productId=${state.promoteId}&&totalAmount=${state.totalAmount}&&equityId=${state.equityId}`
				)
			} else {
				// 正常流程
				uni.redirectTo({
					url: `/subpackage/orders/essential-information?promoteId=${getItem("promoteId")}&userType=${state.userType}&type=${state.type}&isValueCard=${state.isValueCard}&totalAmount=${state.totalAmount}&equityId=${state.equityId}`,
				});
			}
		}
		
	}

	const getInfo = () => {
		const options = {
			type: 2,
			data: {
				"singleEquityId": state.equityId,
			},
			method: 'POST',
			showLoading: true,
		}
		request(equityProductsInfo, options).then((res) => {
			const data = stringToJson(res.bizContent);
			console.log("333333", data.productIntro)
			richText.value = data.productIntro
		})
	}
	//获取微信小程序openid
	const getOpenID = () => {
		// #ifdef MP-WEIXIN
		uni.login({
			provider: "weixin",
			success: function (e) {
				console.log(e);
				getOpenid(e.code);
			},
		});
		//#endif
	};
	const getOpenid = (code) => {
		const options = {
			type: 2,
			data: {
				"jsCode": code
			},
			method: "POST",
			showLoading: true,
		};
		// #ifdef MP-WEIXIN
		request(getOpenidApi, options).then((res) => {
			const result = stringToJson(res.bizContent);
			console.log("获取微信小程序openid", result);
			const openidData = stringToJson(result.data);
			state.openid = openidData.openid;
			setItem("QYorder", state);
		});
		// #endif
	}
</script>

<style scoped lang="scss">
	.btn-wrap {
		text-align: center;
		position: fixed;
		bottom: 40rpx;
		width: 90%;
		left: 5%;
	}

	.imageDefault {
		height: 40rpx;
		width: 40rpx;
		transform: rotate(270deg);
		margin-right: 12rpx;
		color: white;
	}

	.imageChange {
		height: 40rpx;
		width: 40rpx;
		transform: rotate(90deg);
		margin-right: 12rpx;
		color: white;
	}

	.item {
		width: 90%;
		margin: 20rpx auto;
		background-color: rgb(41, 199, 207);
		border-radius: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
		color: white;
		font-size: 32rpx;

	}

	.button {
		height: 80rpx;
		background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
		border-radius: 40rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #ffffff;
		line-height: 80rpx;
	}

	.item>.title {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.children {
		margin-left: 50rpx;
		margin-top: 16rpx;
	}

	.children>view {
		height: 50rpx;
		line-height: 50rpx;
	}

	.show {
		display: inline-block;
	}

	.hide {
		display: none;
	}

	.ul-item {
		// padding: 5px 20rpx;
		padding-top: 20rpx;
		display: flex;
		align-items: center;

		.item-value {
			padding: 20rpx;
			position: absolute;
			display: flex;
			align-items: center;
			width: 80%;

			.content {
				width: 51%;

				.title {
					font-size: 32rpx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: #ffffff;

				}

				.tip {
					font-size: 24rpx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: #ffffff;
				}
			}
		}

		.icon-tip {
			width: 100rpx;
			height: 100rpx;
		}

		.content {
			margin-left: 40rpx;
		}
	}

	.money {
		color: white;
	}
</style>