12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 :disabled="true" label="Id Customer" v-model="form.customer_number" />
  41. </div>
  42. <div class="col-12 md:col-6">
  43. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  44. </div>
  45. <div class="col-12 md:col-6">
  46. <AppInputText label="Nomor HP" placeholder="nomor hp" :error="form.errors.phone" v-model="form.phone" />
  47. </div>
  48. <div class="col-12 md:col-6">
  49. <AppInputText label="Alamat" placeholder="alamat" :error="form.errors.address" v-model="form.address" />
  50. </div>
  51. <div class="col-12 md:col-6">
  52. <AppDropdown
  53. label="Jenis Kelamin"
  54. placeholder="Pilih satu"
  55. v-model="form.gender_id"
  56. :options="genders"
  57. :error="form.errors.gender_id"
  58. />
  59. </div>
  60. </div>
  61. </template>
  62. <template #footer>
  63. <div
  64. class="flex flex-column sm:flex-row align-items-center sm:justify-content-center sm:justify-content-between"
  65. >
  66. <AppDialog
  67. message="Yakin akan menghapus data ini?"
  68. v-model:visible="visibleDialog"
  69. @agree="onAgree(customer.id)"
  70. @cancel="onCancel"
  71. />
  72. <Button label="Hapus" icon="pi pi-trash" class="p-button-text p-button-danger" @click="confirmDialog" />
  73. <AppButton @click="submit" label="Simpan" icon="pi pi-check" />
  74. </div>
  75. </template>
  76. </Card>
  77. </div>
  78. </div>
  79. </AppLayout>
  80. </template>