123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { Inertia } from '@inertiajs/inertia'
  4. import { Head, useForm } from '@inertiajs/inertia-vue3'
  5. import AppButton from '@/components/AppButton.vue'
  6. import AppDropdown from '@/components/AppDropdown.vue'
  7. import AppInputText from '@/components/AppInputText.vue'
  8. import AppDialog from '@/components/AppDialog.vue'
  9. import AppLayout from '@/layouts/AppLayout.vue'
  10. const props = defineProps({
  11. customer: Object,
  12. genders: Array,
  13. })
  14. const form = useForm({
  15. customer_number: props.customer.customer_number,
  16. name: props.customer.name,
  17. phone: props.customer.phone,
  18. address: props.customer.address,
  19. gender_id: props.customer.gender_id,
  20. })
  21. const submit = () => {
  22. form.put(route('customers.update', props.customer.id))
  23. }
  24. const visibleDialog = ref(false)
  25. const confirmDialog = () => {
  26. visibleDialog.value = true
  27. }
  28. const onAgree = (id) => Inertia.delete(route('customers.destroy', id))
  29. const onCancel = () => (visibleDialog.value = false)
  30. </script>
  31. <template>
  32. <Head title="Ubah Customer" />
  33. <AppLayout>
  34. <div class="grid">
  35. <div class="col-12 lg:col-8">
  36. <Card>
  37. <template #content>
  38. <div class="grid">
  39. <div class="col-12 md:col-6">
  40. <AppInputText
  41. :disabled="true"
  42. label="Id Customer"
  43. v-model="form.customer_number"
  44. placeholder="id customer"
  45. />
  46. </div>
  47. <div class="col-12 md:col-6">
  48. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  49. </div>
  50. <div class="col-12 md:col-6">
  51. <AppInputText label="Nomor HP" placeholder="nomor hp" :error="form.errors.phone" v-model="form.phone" />
  52. </div>
  53. <div class="col-12 md:col-6">
  54. <AppInputText label="Alamat" placeholder="alamat" :error="form.errors.address" v-model="form.address" />
  55. </div>
  56. <div class="col-12 md:col-6">
  57. <AppDropdown
  58. label="Jenis Kelamin"
  59. placeholder="Pilih satu"
  60. v-model="form.gender_id"
  61. :options="genders"
  62. :error="form.errors.gender_id"
  63. />
  64. </div>
  65. </div>
  66. </template>
  67. <template #footer>
  68. <div
  69. class="flex flex-column sm:flex-row align-items-center sm:justify-content-center sm:justify-content-between"
  70. >
  71. <AppDialog
  72. message="Yakin akan menghapus data ini?"
  73. v-model:visible="visibleDialog"
  74. @agree="onAgree(customer.id)"
  75. @cancel="onCancel"
  76. />
  77. <Button label="Hapus" icon="pi pi-trash" class="p-button-text p-button-danger" @click="confirmDialog" />
  78. <AppButton @click="submit" label="Simpan" icon="pi pi-check" class="p-button-text" />
  79. </div>
  80. </template>
  81. </Card>
  82. </div>
  83. </div>
  84. </AppLayout>
  85. </template>