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

import PopupLayout from "@/layouts/PopupLayout.vue";
import ctxRef from "@/utils/ctx_ref.js"
import Context from "./createPopup.js"
import TSelect from "@/components/ui/TSelect.vue";
import TOption from "@/components/ui/TOption.vue";
import TInputText from "@/components/ui/TInputText.vue";
import TTextarea from "@/components/ui/TTextarea.vue";
import SubmitButton from "@/components/form/SubmitButton.vue";
import PostForm from "@/components/form/PostForm.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<PopupLayout>

		<header>提交工单</header>

		<PostForm action="$" @success="ctx.success">
			<DefinitionTable>
				<tbody>
				<tr v-if="ctx.categories.length > 0">
					<td>工单分类</td>
					<td>
						<TSelect name="categoryId">
							<TOption value="0">[请选择分类]</TOption>
							<TOption v-for="category in ctx.categories" :value="category.id">{{category.name}}</TOption>
						</TSelect>
					</td>
				</tr>
				<tr>
					<td class="title">工单标题 *</td>
					<td>
						<TInputText name="subject" maxlength="100" class="w-full" :autofocus="ctx.categories.length == 0"/>
					</td>
				</tr>
				<tr>
					<td>工单内容 *</td>
					<td>
						<TTextarea name="body" rows="6" class="w-full"></TTextarea>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>

			<SubmitButton></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

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