Edit.vue 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 v-if="transactions.totalTransaction" class="grid mt-3 ml-1">
  97. <div class="col-auto">
  98. <h2>
  99. <span class="text-base"> <i class="pi pi-shopping-cart" /> Total Transaksi</span>
  100. <br />
  101. <span class="text-xl font-bold">{{ transactions.totalTransaction }}</span>
  102. </h2>
  103. </div>
  104. </div>
  105. <div class="grid">
  106. <div class="col-12">
  107. <Card>
  108. <template #content>
  109. <DataTable
  110. responsive-layout="scroll"
  111. column-resize-mode="expand"
  112. :value="transactions.details.data"
  113. :row-hover="true"
  114. :striped-rows="true"
  115. >
  116. <Column
  117. v-for="transactionTable in TransactionTable"
  118. :field="transactionTable.field"
  119. :header="transactionTable.header"
  120. :key="transactionTable.field"
  121. >
  122. <template #body="{ data, field }">
  123. <template v-if="field === 'transactionNumber'">
  124. <p class="font-bold">{{ data[field] }}</p>
  125. <p>{{ data.createdAt }}</p>
  126. </template>
  127. <template v-else-if="field === 'customer'">
  128. <p class="font-bold">{{ data.customer.number }}</p>
  129. <p>{{ data.customer.name }}</p>
  130. <p>{{ data.customer.phone }}</p>
  131. </template>
  132. <template v-else-if="field === 'transactionStatusName'">
  133. <Badge v-if="data['transactionStatusId'] === 1" :value="data[field]"></Badge>
  134. <Badge
  135. v-else-if="data['transactionStatusId'] === 2"
  136. :value="data[field]"
  137. severity="warning"
  138. ></Badge>
  139. <Badge v-else :value="data[field]" severity="success"></Badge>
  140. </template>
  141. <template v-else>
  142. {{ data[field] }}
  143. </template>
  144. </template>
  145. </Column>
  146. <Column>
  147. <template #body="{ data }">
  148. <AppButton
  149. icon="pi pi-angle-double-right"
  150. class="p-button-icon-only p-button-rounded p-button-text"
  151. :href="route('transactions.show', data.id)"
  152. />
  153. </template>
  154. </Column>
  155. </DataTable>
  156. <AppPagination :links="transactions.details.links" />
  157. </template>
  158. </Card>
  159. </div>
  160. </div>
  161. </AppLayout>
  162. </template>