<template>
	<BasicLayout>
		<view class="xkTf-info">
			<!-- 学生信息卡片 -->
			<XkPayXs :xs="curXs" />

			<!-- 课程信息卡片 -->
			<XkPaySuccessXkkc :dataList="xkTfQdList" />

			<!-- 退费信息卡片 -->
			<view class="xkTf-card">
				<view class="card-body">
					<view class="info-column">
						<text class="label">退费说明:</text>
						<text class="value">{{ xkTf.tfSm }}</text>
					</view>
					<view class="info-column">
						<text class="label">缴费凭证:</text>
						<text class="value">
							<PreviewImage :image-list="jfPzList" empty-text="无缴费凭证" />
						</text>
					</view>
				</view>
			</view>
			<!-- 审批流程 -->
			<LcglSpList :yw-id="xkTf.id" yw-type="XK_TF" />
		</view>
		<template #bottom>
			<YwConfirm :api="xkTfSpApi" :params="spParams" 
				@summit="submit" @reject="handleReject" />
		</template>
	</BasicLayout>
</template>

<script setup lang="ts">
import { onLoad } from "@dcloudio/uni-app";
import { useUserStore } from "@/store/modules/user";
import { imagUrl } from "@/utils";
import XkPayXs from "../components/XkPayXs/index.vue"
import XkPaySuccessXkkc from "../components/XkPaySuccessXkkc/index.vue"
import LcglSpList from "@/components/LcglSpList/index.vue";
import PreviewImage from "@/components/PreviewImage/index.vue";
import YwConfirm from "@/pages/components/YwConfirm/index.vue";
import { getXkTfDetailByIdApi, xkTfSpApi } from "@/api/base/xkTfApi";
import { XkTfPageUtils } from "@/utils/xkTfPageUtils";
const { getJs } = useUserStore();

const curXs = ref<any>({});
const xkTf = ref<any>({});
const xkTfQdList = ref<any>([]);
const jfPzList = ref<any>([]);

const dbFlag = ref(false);
const xkTfId = ref('');

const spParams = computed(() => {
	return {
		xkTfId: xkTfId.value,
		jsId: getJs.id,
	};
});

const goHome = () => {
	uni.reLaunch({
		url: "/pages/base/service/index"
	});
};

// 初始化数据
const initData = (tf: any, xs: any, tfQdList: any[]) => {
	if (xs) {
		xs.xstxUrl = imagUrl(xs.xstx) || "";
	}
  console.log('initData学生', xs);
	curXs.value = xs;
	xkTf.value = tf;
	xkTfQdList.value = tfQdList;
	const jfPz = tf.jfPz || '';
	// 缴费凭证逗号分隔
	jfPzList.value = jfPz.split(',') || [];
};

// 获取详情
const loadData = async (id: string) => {
	const res = await getXkTfDetailByIdApi(id);
	if (!res.result) {
		uni.showToast({ title: '未找到数据', icon: 'none' });
		goHome();
	}
	nextTick(() => {
		initData(res.result.xkTf, res.result.xs, res.result.xkTfQdList);
	});
};

const submit = async () => {
	goHome();
};

// 驳回处理
const handleReject = async () => {
	goHome();
};

onLoad(async (data?: any) => {
	const ret = await XkTfPageUtils.init(data);
	if (!ret || !ret.success) {
		return;
	}
	xkTfId.value = ret.xkTfId;
	dbFlag.value = ret.dbFlag;
	await loadData(xkTfId.value);
});
</script>

<style lang="scss" scoped>
.xkTf-info {
	background-color: #f5f7fa;

	.xkTf-card {
		margin: 15px;
		background-color: #fff;
		border-radius: 8px;
		padding: 15px;
		box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);

		.card-body {

			.info-row {
				display: flex;
				margin-bottom: 10px;

				.label {
					font-size: 14px;
					color: #bbb;
					width: 70px;
					flex-shrink: 0;
					margin-right: 8px;
				}

				.value {
					font-size: 14px;
					color: #333;
					flex: 1;
				}
			}

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

				.label {
					font-size: 14px;
					color: #bbb;
					flex-shrink: 0;
					margin-right: 8px;
					width: 100%;
					margin-bottom: 5px;
				}

				.value {
					font-size: 14px;
					color: #333;
					flex: 1;
					margin-bottom: 10px;
				}
			}
		}
	}
}
</style>