Create.vue 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script setup>
  2. import { watch, computed } from 'vue'
  3. import { Head, useForm, usePage } from '@inertiajs/inertia-vue3'
  4. import AppDropdown from '@/components/AppDropdown.vue'
  5. import AppInputText from '@/components/AppInputText.vue'
  6. import AppLayout from '@/layouts/AppLayout.vue'
  7. const props = defineProps({
  8. customer_number: String,
  9. genders: Array,
  10. })
  11. const errors = computed(() => usePage().props.value.errors)
  12. watch(errors, () => {
  13. form.clearErrors()
  14. })
  15. const form = useForm({
  16. customer_number: props.customer_number,
  17. name: '',
  18. phone: '',
  19. gender_id: '',
  20. })
  21. const submit = () => {
  22. form.post(route('customers.store'), { onSuccess: () => form.reset() })
  23. }
  24. </script>
  25. <template>
  26. <Head title="Tambah Customer" />
  27. <AppLayout>
  28. <div class="grid">
  29. <div class="col-12 lg:col-8">
  30. <Card>
  31. <template #content>
  32. <div class="grid">
  33. <div class="col-12 md:col-6">
  34. <AppInputText
  35. :disabled="true"
  36. label="Id Customer"
  37. v-model="form.customer_number"
  38. placeholder="id customer"
  39. />
  40. </div>
  41. <div class="col-12 md:col-6">
  42. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  43. </div>
  44. <div class="col-12 md:col-6">
  45. <AppInputText label="Nomor HP" placeholder="nomor hp" :error="form.errors.phone" v-model="form.phone" />
  46. </div>
  47. <div class="col-12 md:col-6">
  48. <AppDropdown
  49. label="Jenis Kelamin"
  50. placeholder="Pilih satu"
  51. v-model="form.gender_id"
  52. :options="genders"
  53. :error="form.errors.gender_id"
  54. />
  55. </div>
  56. </div>
  57. </template>
  58. <template #footer>
  59. <div class="flex flex-column md:flex-row justify-content-end">
  60. <Button label="Simpan" icon="pi pi-check" class="p-button-outlined" @click="submit" />
  61. </div>
  62. </template>
  63. </Card>
  64. </div>
  65. </div>
  66. </AppLayout>
  67. </template>