Edit.vue 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <script setup>
  2. import { ref, watch, computed } from 'vue'
  3. import { Inertia } from '@inertiajs/inertia'
  4. import { Head, useForm, usePage } from '@inertiajs/inertia-vue3'
  5. import AppInputText from '@/components/AppInputText.vue'
  6. import AppInputNumber from '@/components/AppInputNumber.vue'
  7. import AppDialog from '@/components/AppDialog.vue'
  8. import AppLayout from '@/layouts/AppLayout.vue'
  9. const props = defineProps({
  10. laundry: Object,
  11. })
  12. const form = useForm({
  13. name: props.laundry.name,
  14. price: props.laundry.price,
  15. unit: props.laundry.unit,
  16. })
  17. const submit = () => {
  18. form.put(route('laundries.update', props.laundry.id))
  19. }
  20. const errors = computed(() => usePage().props.value.errors)
  21. watch(errors, () => {
  22. form.clearErrors()
  23. })
  24. const visibleDialog = ref(false)
  25. const confirmDialog = () => {
  26. visibleDialog.value = true
  27. }
  28. const onAgree = (id) => Inertia.delete(route('laundries.destroy', id))
  29. const onCancel = () => (visibleDialog.value = false)
  30. </script>
  31. <template>
  32. <Head title="Ubah Tipe Laundry" />
  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 label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  41. </div>
  42. <div class="col-12 md:col-6">
  43. <AppInputNumber label="Harga" placeholder="harga" :error="form.errors.price" v-model="form.price" />
  44. </div>
  45. <div class="col-12 md:col-6">
  46. <AppInputText label="Satuan" placeholder="satuan" :error="form.errors.unit" v-model="form.unit" />
  47. </div>
  48. </div>
  49. </template>
  50. <template #footer>
  51. <div class="grid">
  52. <div class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-start">
  53. <AppDialog
  54. message="Yakin akan menghapus data ini?"
  55. v-model:visible="visibleDialog"
  56. @agree="onAgree(laundry.id)"
  57. @cancel="onCancel"
  58. />
  59. <Button
  60. v-if="!laundry.relation"
  61. label="Hapus"
  62. icon="pi pi-trash"
  63. class="p-button-outlined p-button-danger"
  64. @click="confirmDialog"
  65. />
  66. </div>
  67. <div class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-end">
  68. <Button label="Simpan" icon="pi pi-check" class="p-button-outlined" @click="submit" />
  69. </div>
  70. </div>
  71. </template>
  72. </Card>
  73. </div>
  74. </div>
  75. </AppLayout>
  76. </template>