<script setup>
// Copyright 2024 FlexCDN root@flexcdn.cn. All rights reserved. Official site: https://flexcdn.cn .

import ctxRef from "@/utils/ctx_ref.js"
import Context from "./buy.js"
import SubmitButton from "@/components/form/SubmitButton.vue";
import PayMethodSelector from "@/components/pay/PayMethodSelector.vue";
import TRadio from "@/components/ui/TRadio.vue";
import PostForm from "@/components/form/PostForm.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<h5 class="!mb-4">购买域名解析套餐</h5>

	<PostForm action="$" @success="ctx.success">
		<input type="hidden" name="planId" :value="ctx.plan.id"/>
		<DefinitionTable>
			<tbody>
			<tr>
				<td class="title">套餐类型</td>
				<td><strong>{{ctx.plan.name}}</strong></td>
			</tr>
			<tr>
				<td>付费周期</td>
				<td>
					<TRadio name="period" :value="'yearly'" v-model="ctx.period">按年</TRadio> &nbsp; &nbsp;
					<TRadio name="period" :value="'monthly'" v-model="ctx.period">按月</TRadio>
				</td>
			</tr>
			<tr>
				<td>价格</td>
				<td>
					<span v-if="ctx.period == 'yearly'">￥{{ctx.plan.yearlyPrice}}元/年</span>
					<span v-if="ctx.period == 'monthly'">￥{{ctx.plan.monthlyPrice}}元/月</span>
				</td>
			</tr>
			<tr>
				<td>有效期</td>
				<td>
					<span v-if="ctx.period == 'yearly'">{{ctx.plan.yearFrom}} 到 {{ctx.plan.yearTo}}</span>
					<span v-if="ctx.period == 'monthly'">{{ctx.plan.monthFrom}} 到 {{ctx.plan.monthTo}}</span>
				</td>
			</tr>
			<tr>
				<td>支付方式</td>
				<td>
					<PayMethodSelector @change="ctx.changePayMethod"></PayMethodSelector>
				</td>
			</tr>
			</tbody>
		</DefinitionTable>
		<SubmitButton v-if="ctx.methodCode == '@balance'">确定使用余额购买</SubmitButton>
		<SubmitButton v-if="ctx.methodCode != '@balance'">下一步</SubmitButton>
	</PostForm>
</template>

<style lang="postcss" scoped>
</style>