Edit.vue 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 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 AppPagination from '@/components/AppPagination.vue'
  10. import AppLayout from '@/layouts/AppLayout.vue'
  11. import { TransactionTable } from './TableHeader'
  12. const props = defineProps({
  13. customer: Object,
  14. genders: Array,
  15. transactions: Object,
  16. })
  17. const form = useForm({
  18. customer_number: props.customer.customer_number,
  19. name: props.customer.name,
  20. phone: props.customer.phone,
  21. gender_id: props.customer.gender_id,
  22. })
  23. const submit = () => {
  24. form.put(route('customers.update', props.customer.id))
  25. }
  26. const errors = computed(() => usePage().props.value.errors)
  27. watch(errors, () => {
  28. form.clearErrors()
  29. })
  30. const visibleDialog = ref(false)
  31. const confirmDialog = () => {
  32. visibleDialog.value = true
  33. }
  34. const onAgree = (id) => Inertia.delete(route('customers.destroy', id))
  35. const onCancel = () => (visibleDialog.value = false)
  36. </script>
  37. <template>
  38. <Head title="Ubah Customer" />
  39. <AppLayout>
  40. <div class="grid">
  41. <div class="col-12 lg:col-8">
  42. <Card>
  43. <template #content>
  44. <div class="grid">
  45. <div class="col-12 md:col-6">
  46. <AppInputText
  47. :disabled="true"
  48. label="Id Customer"
  49. v-model="form.customer_number"
  50. placeholder="id customer"
  51. />
  52. </div>
  53. <div class="col-12 md:col-6">
  54. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  55. </div>
  56. <div class="col-12 md:col-6">
  57. <AppInputText label="Nomor HP" placeholder="nomor hp" :error="form.errors.phone" v-model="form.phone" />
  58. </div>
  59. <div class="col-12 md:col-6">
  60. <AppDropdown
  61. label="Jenis Kelamin"
  62. placeholder="Pilih satu"
  63. v-model="form.gender_id"
  64. :options="genders"
  65. :error="form.errors.gender_id"
  66. />
  67. </div>
  68. </div>
  69. </template>
  70. <template #footer>
  71. <div
  72. class="flex flex-column sm:flex-row align-items-center sm:justify-content-center sm:justify-content-between"
  73. >
  74. <AppDialog
  75. message="Yakin akan menghapus data ini?"
  76. v-model:visible="visibleDialog"
  77. @agree="onAgree(customer.id)"
  78. @cancel="onCancel"
  79. />
  80. <Button label="Hapus" icon="pi pi-trash" class="p-button-text p-button-danger" @click="confirmDialog" />
  81. <Button label="Simpan" icon="pi pi-check" class="p-button-text" @click="submit" />
  82. </div>
  83. </template>
  84. </Card>
  85. </div>
  86. </div>
  87. <h2>Riwayat Transaksi</h2>
  88. <div class="grid">
  89. <div class="col-12">
  90. <Card>
  91. <template #content>
  92. <DataTable
  93. responsive-layout="scroll"
  94. column-resize-mode="expand"
  95. :value="transactions.data"
  96. :row-hover="true"
  97. :striped-rows="true"
  98. >
  99. <Column
  100. v-for="transactionTable in TransactionTable"
  101. :field="transactionTable.field"
  102. :header="transactionTable.header"
  103. :key="transactionTable.field"
  104. >
  105. <template #body="{ data, field }">
  106. <template v-if="field === 'transactionNumber'">
  107. <p class="font-bold">{{ data[field] }}</p>
  108. <p>{{ data.createdAt }}</p>
  109. </template>
  110. <template v-else-if="field === 'customer'">
  111. <p class="font-bold">{{ data.customer.number }}</p>
  112. <p>{{ data.customer.name }}</p>
  113. <p>{{ data.customer.phone }}</p>
  114. </template>
  115. <template v-else-if="field === 'transactionStatusName'">
  116. <Badge v-if="data['transactionStatusId'] === 1" :value="data[field]"></Badge>
  117. <Badge
  118. v-else-if="data['transactionStatusId'] === 2"
  119. :value="data[field]"
  120. severity="warning"
  121. ></Badge>
  122. <Badge v-else :value="data[field]" severity="success"></Badge>
  123. </template>
  124. <template v-else>
  125. {{ data[field] }}
  126. </template>
  127. </template>
  128. </Column>
  129. <Column>
  130. <template #body="{ data }">
  131. <AppButton
  132. icon="pi pi-angle-double-right"
  133. class="p-button-icon-only p-button-rounded p-button-text"
  134. :href="route('transactions.show', data.id)"
  135. />
  136. </template>
  137. </Column>
  138. </DataTable>
  139. <AppPagination :links="transactions.links" />
  140. </template>
  141. </Card>
  142. </div>
  143. </div>
  144. </AppLayout>
  145. </template>