|
| 1 | +<template> |
| 2 | + <UForm |
| 3 | + :validate="createValidator(createPartnerAgreementSchema)" |
| 4 | + :state="state" |
| 5 | + class="flex flex-col gap-3" |
| 6 | + @submit="onSubmit" |
| 7 | + > |
| 8 | + <UPopover> |
| 9 | + <UFormField |
| 10 | + label="Дата заключения" |
| 11 | + name="concludedAt" |
| 12 | + required |
| 13 | + > |
| 14 | + <UInput |
| 15 | + :value="selectedConcludedAt ? df.format(selectedConcludedAt.toDate(getLocalTimeZone())) : ''" |
| 16 | + placeholder="Выберите дату" |
| 17 | + size="xl" |
| 18 | + class="w-full items-center justify-center cursor-pointer" |
| 19 | + :ui="{ trailing: 'pe-1.5' }" |
| 20 | + /> |
| 21 | + </UFormField> |
| 22 | + |
| 23 | + <template #content> |
| 24 | + <UCalendar v-model="selectedConcludedAt" class="p-2" /> |
| 25 | + </template> |
| 26 | + </UPopover> |
| 27 | + |
| 28 | + <UPopover> |
| 29 | + <UFormField |
| 30 | + label="Дата окончания" |
| 31 | + name="willEndAt" |
| 32 | + required |
| 33 | + > |
| 34 | + <UInput |
| 35 | + :value="selectedWillEndAt ? df.format(selectedWillEndAt.toDate(getLocalTimeZone())) : ''" |
| 36 | + placeholder="Выберите дату" |
| 37 | + size="xl" |
| 38 | + class="w-full items-center justify-center cursor-pointer" |
| 39 | + :ui="{ trailing: 'pe-1.5' }" |
| 40 | + /> |
| 41 | + </UFormField> |
| 42 | + |
| 43 | + <template #content> |
| 44 | + <UCalendar v-model="selectedWillEndAt" class="p-2" /> |
| 45 | + </template> |
| 46 | + </UPopover> |
| 47 | + |
| 48 | + <UFormField label="Номер договора (внутренний)" name="internalId"> |
| 49 | + <UInput |
| 50 | + v-model="state.internalId" |
| 51 | + size="xl" |
| 52 | + class="w-full items-center justify-center" |
| 53 | + /> |
| 54 | + </UFormField> |
| 55 | + |
| 56 | + <UFormField label="Роялти, %" name="royalty"> |
| 57 | + <UInputNumber |
| 58 | + v-model="state.royalty" |
| 59 | + orientation="vertical" |
| 60 | + :step="0.1" |
| 61 | + size="xl" |
| 62 | + class="w-full items-center justify-center" |
| 63 | + /> |
| 64 | + </UFormField> |
| 65 | + |
| 66 | + <UFormField label="Мин. роялти, руб" name="minRoyaltyPerMonth"> |
| 67 | + <UInputNumber |
| 68 | + v-model="state.minRoyaltyPerMonth" |
| 69 | + orientation="vertical" |
| 70 | + size="xl" |
| 71 | + class="w-full items-center justify-center" |
| 72 | + /> |
| 73 | + </UFormField> |
| 74 | + |
| 75 | + <UFormField label="Паушальный взнос, руб" name="lumpSumPayment"> |
| 76 | + <UInputNumber |
| 77 | + v-model="state.lumpSumPayment" |
| 78 | + orientation="vertical" |
| 79 | + size="xl" |
| 80 | + class="w-full items-center justify-center" |
| 81 | + /> |
| 82 | + </UFormField> |
| 83 | + |
| 84 | + <UFormField :label="$t('common.comment')" name="comment"> |
| 85 | + <UInput |
| 86 | + v-model="state.comment" |
| 87 | + size="xl" |
| 88 | + placeholder="Для внутреннего использования" |
| 89 | + class="w-full items-center justify-center" |
| 90 | + /> |
| 91 | + </UFormField> |
| 92 | + |
| 93 | + <UButton |
| 94 | + type="submit" |
| 95 | + variant="solid" |
| 96 | + color="secondary" |
| 97 | + size="xl" |
| 98 | + block |
| 99 | + class="mt-3" |
| 100 | + :label="$t('common.create')" |
| 101 | + /> |
| 102 | + </UForm> |
| 103 | +</template> |
| 104 | + |
| 105 | +<script setup lang="ts"> |
| 106 | +import type { CreatePartnerAgreement } from '#shared/services/partner' |
| 107 | +import type { CalendarDate } from '@internationalized/date' |
| 108 | +import type { FormSubmitEvent } from '@nuxt/ui' |
| 109 | +import { createPartnerAgreementSchema } from '#shared/services/partner' |
| 110 | +import { DateFormatter, getLocalTimeZone } from '@internationalized/date' |
| 111 | +
|
| 112 | +const { partnerId, legalEntityId } = defineProps<{ partnerId: string, legalEntityId: string }>() |
| 113 | +const emit = defineEmits(['success', 'submitted']) |
| 114 | +
|
| 115 | +const { t } = useI18n() |
| 116 | +const actionToast = useActionToast() |
| 117 | +
|
| 118 | +const partnerStore = usePartnerStore() |
| 119 | +
|
| 120 | +const state = ref<Partial<CreatePartnerAgreement>>({ |
| 121 | + concludedAt: undefined, |
| 122 | + willEndAt: undefined, |
| 123 | + internalId: undefined, |
| 124 | + royalty: undefined, |
| 125 | + minRoyaltyPerMonth: undefined, |
| 126 | + lumpSumPayment: undefined, |
| 127 | + comment: undefined, |
| 128 | + legalEntityId, |
| 129 | +}) |
| 130 | +
|
| 131 | +const df = new DateFormatter('ru-RU', { |
| 132 | + dateStyle: 'long', |
| 133 | +}) |
| 134 | +
|
| 135 | +const selectedConcludedAt = shallowRef<CalendarDate | undefined>() |
| 136 | +const selectedWillEndAt = shallowRef<CalendarDate | undefined>() |
| 137 | +
|
| 138 | +watch(selectedConcludedAt, () => { |
| 139 | + state.value.concludedAt = new Date( |
| 140 | + `${selectedConcludedAt.value?.toString()} 12:00:00`, |
| 141 | + ).toISOString() |
| 142 | +}) |
| 143 | +watch(selectedWillEndAt, () => { |
| 144 | + state.value.willEndAt = new Date( |
| 145 | + `${selectedWillEndAt.value?.toString()} 12:00:00`, |
| 146 | + ).toISOString() |
| 147 | +}) |
| 148 | +
|
| 149 | +async function onSubmit(event: FormSubmitEvent<CreatePartnerAgreement>) { |
| 150 | + const toastId = actionToast.start() |
| 151 | + emit('submitted') |
| 152 | +
|
| 153 | + try { |
| 154 | + await $fetch(`/api/partner/id/${partnerId}/agreement`, { |
| 155 | + method: 'POST', |
| 156 | + body: event.data, |
| 157 | + }) |
| 158 | +
|
| 159 | + await partnerStore.update() |
| 160 | +
|
| 161 | + actionToast.success(toastId, t('toast.partner-agreement-created')) |
| 162 | + emit('success') |
| 163 | + } catch (error) { |
| 164 | + console.error(error) |
| 165 | + actionToast.error(toastId) |
| 166 | + } |
| 167 | +} |
| 168 | +</script> |
0 commit comments