Edit.vue 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 class="grid">
  72. <div class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-start">
  73. <AppDialog
  74. message="Yakin akan menghapus data ini?"
  75. v-model:visible="visibleDialog"
  76. @agree="onAgree(customer.id)"
  77. @cancel="onCancel"
  78. />
  79. <Button
  80. v-if="!customer.relation"
  81. label="Hapus"
  82. icon="pi pi-trash"
  83. class="p-button-outlined p-button-danger"
  84. @click="confirmDialog"
  85. />
  86. </div>
  87. <div class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-end">
  88. <Button label="Simpan" icon="pi pi-check" class="p-button-outlined" @click="submit" />
  89. </div>
  90. </div>
  91. </template>
  92. </Card>
  93. </div>
  94. </div>
  95. <h2>Riwayat Transaksi</h2>
  96. <div class="grid">
  97. <div class="col-12">
  98. <Card>
  99. <template #content>
  100. <DataTable
  101. responsive-layout="scroll"
  102. column-resize-mode="expand"
  103. :value="transactions.data"
  104. :row-hover="true"
  105. :striped-rows="true"
  106. >
  107. <Column
  108. v-for="transactionTable in TransactionTable"
  109. :field="transactionTable.field"
  110. :header="transactionTable.header"
  111. :key="transactionTable.field"
  112. >
  113. <template #body="{ data, field }">
  114. <template v-if="field === 'transactionNumber'">
  115. <p class="font-bold">{{ data[field] }}</p>
  116. <p>{{ data.createdAt }}</p>
  117. </template>
  118. <template v-else-if="field === 'customer'">
  119. <p class="font-bold">{{ data.customer.number }}</p>
  120. <p>{{ data.customer.name }}</p>
  121. <p>{{ data.customer.phone }}</p>
  122. </template>
  123. <template v-else-if="field === 'transactionStatusName'">
  124. <Badge v-if="data['transactionStatusId'] === 1" :value="data[field]"></Badge>
  125. <Badge
  126. v-else-if="data['transactionStatusId'] === 2"
  127. :value="data[field]"
  128. severity="warning"
  129. ></Badge>
  130. <Badge v-else :value="data[field]" severity="success"></Badge>
  131. </template>
  132. <template v-else>
  133. {{ data[field] }}
  134. </template>
  135. </template>
  136. </Column>
  137. <Column>
  138. <template #body="{ data }">
  139. <AppButton
  140. icon="pi pi-angle-double-right"
  141. class="p-button-icon-only p-button-rounded p-button-text"
  142. :href="route('transactions.show', data.id)"
  143. />
  144. </template>
  145. </Column>
  146. </DataTable>
  147. <AppPagination :links="transactions.links" />
  148. </template>
  149. </Card>
  150. </div>
  151. </div>
  152. </AppLayout>
  153. </template>