2026-09-13 21:02:25 +03:30
|
|
|
<template>
|
2026-09-14 15:22:54 +03:30
|
|
|
<!--
|
|
|
|
|
Ported from legacy henza_admin/src/views/city/createCity.vue.
|
|
|
|
|
Converted from a standalone page to a modal (BaseFormModal): the /city/create
|
|
|
|
|
route still exists and still renders this component directly for a route-based
|
|
|
|
|
fallback (a-form as a plain page), but cityList.vue now opens it as a modal via
|
|
|
|
|
the `open`/`id` props instead of navigating.
|
|
|
|
|
-->
|
|
|
|
|
<BaseFormModal
|
|
|
|
|
v-if="asModal"
|
|
|
|
|
:open="Boolean(open)"
|
|
|
|
|
:id="id"
|
|
|
|
|
add-title="افزودن شهر"
|
|
|
|
|
edit-title="افزودن شهر"
|
|
|
|
|
:loading="loading"
|
|
|
|
|
:submitting="loading"
|
|
|
|
|
width="sm"
|
|
|
|
|
@update:open="$emit('update:open', $event)"
|
|
|
|
|
@submit="handleSubmit"
|
|
|
|
|
>
|
|
|
|
|
<div class="grid-2">
|
|
|
|
|
<a-form-item label="نام شهر" :validate-status="err.title ? 'error' : ''" :help="err.title">
|
|
|
|
|
<a-input v-model:value="form.title" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
<a-form-item label="استان">
|
|
|
|
|
<a-input v-model:value="form.province" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</div>
|
|
|
|
|
</BaseFormModal>
|
|
|
|
|
|
|
|
|
|
<!-- route-based fallback for direct links to /city/create -->
|
|
|
|
|
<a-spin v-else :spinning="loading">
|
2026-09-13 21:02:25 +03:30
|
|
|
<a-form layout="vertical" @submit.prevent="handleSubmit">
|
|
|
|
|
<a-card title="افزودن شهر">
|
|
|
|
|
<div class="grid-2">
|
|
|
|
|
<a-form-item label="نام شهر" :validate-status="err.title ? 'error' : ''" :help="err.title">
|
|
|
|
|
<a-input v-model:value="form.title" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
<a-form-item label="استان">
|
|
|
|
|
<a-input v-model:value="form.province" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</div>
|
|
|
|
|
<a-button type="primary" @click="handleSubmit">ثبت اطلاعات</a-button>
|
|
|
|
|
</a-card>
|
|
|
|
|
</a-form>
|
|
|
|
|
</a-spin>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { reactive, ref } from 'vue';
|
2026-09-14 15:22:54 +03:30
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2026-09-13 21:02:25 +03:30
|
|
|
import { message } from 'ant-design-vue';
|
2026-09-14 15:22:54 +03:30
|
|
|
import BaseFormModal from '../../components/common/BaseFormModal.vue';
|
2026-09-13 21:02:25 +03:30
|
|
|
import api from '../../api/client';
|
|
|
|
|
|
2026-09-14 15:22:54 +03:30
|
|
|
const props = defineProps<{
|
|
|
|
|
/** Present -> rendered as a modal by the parent list page. */
|
|
|
|
|
open?: boolean;
|
|
|
|
|
id?: string;
|
|
|
|
|
}>();
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
(e: 'update:open', value: boolean): void;
|
|
|
|
|
(e: 'success'): void;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
// `asModal` is fixed at mount: the parent decides which way this component is
|
|
|
|
|
// used (modal vs the plain /city/create route) by passing `open` or not.
|
|
|
|
|
const asModal = props.open !== undefined;
|
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
2026-09-13 21:02:25 +03:30
|
|
|
const router = useRouter();
|
2026-09-14 15:22:54 +03:30
|
|
|
|
2026-09-13 21:02:25 +03:30
|
|
|
const loading = ref(false);
|
|
|
|
|
const form = reactive<Record<string, any>>({ title: '', province: '' });
|
|
|
|
|
const err = reactive<Record<string, string>>({});
|
|
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
|
Object.keys(err).forEach((k) => delete err[k]);
|
|
|
|
|
if (!form.title) {
|
|
|
|
|
err.title = 'لطفا مقدار را وارد کنید';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
loading.value = true;
|
|
|
|
|
await api.post('cities', form);
|
|
|
|
|
message.info('اطلاعات با موفقیت به ثبت رسید.');
|
2026-09-14 15:22:54 +03:30
|
|
|
if (asModal) {
|
|
|
|
|
emit('success');
|
|
|
|
|
emit('update:open', false);
|
|
|
|
|
} else {
|
|
|
|
|
router.push('/city/list');
|
|
|
|
|
}
|
2026-09-13 21:02:25 +03:30
|
|
|
} catch (e: any) {
|
|
|
|
|
message.error(e?.response?.data?.message ?? 'خطا در ثبت اطلاعات.');
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-09-14 15:09:11 +03:30
|
|
|
<!-- .grid-2 now comes from the global utilities.less (dedup) -->
|