Create.vue 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <script setup>
  2. import { useForm, Head } from '@inertiajs/inertia-vue3'
  3. import { useFormErrorReset } from '@/components/useFormErrorReset'
  4. import AppInputText from '@/components/AppInputText.vue'
  5. import AppInputNumber from '@/components/AppInputNumber.vue'
  6. import AppDropdown from '@/components/AppDropdown.vue'
  7. import AppAutocompleteBasic from '@/components/AppAutocompleteBasic.vue'
  8. import DashboardLayout from '@/layouts/DashboardLayout.vue'
  9. defineProps({
  10. customers: Object,
  11. })
  12. const form = useForm({
  13. number: null,
  14. status: null,
  15. price: null,
  16. qty: null,
  17. customer_id: null,
  18. })
  19. useFormErrorReset(form)
  20. const optionStatus = [
  21. {
  22. label: 'Pending',
  23. value: 'pending',
  24. },
  25. {
  26. label: 'Success',
  27. value: 'success',
  28. },
  29. ]
  30. const customerOnComplete = (event) => {
  31. Inertia.reload({
  32. data: { search: event.query },
  33. only: ['customers'],
  34. })
  35. }
  36. const customerOnSelected = (event) => {
  37. form.customer = event.value
  38. }
  39. const onSubmit = () => {
  40. form.post(route('sales.store'), { onSuccess: () => form.reset() })
  41. }
  42. </script>
  43. <template>
  44. <Head title="Tambah Penjualan" />
  45. <DashboardLayout>
  46. <div class="grid">
  47. <div class="col-12 lg:col-8">
  48. <Card>
  49. <template #title> Tambah Penjualan </template>
  50. <template #content>
  51. <div class="grid">
  52. <div class="col-12 md:col-6">
  53. <AppInputText
  54. label="Nomor Penjualan"
  55. placeholder="nomor penjualan"
  56. type="number"
  57. :error="form.errors.number"
  58. v-model="form.number"
  59. />
  60. </div>
  61. <div class="col-12 md:col-6">
  62. <!-- <AppDropdown
  63. label="Status"
  64. placeholder="status"
  65. :option="optionStatus"
  66. :error="form.errors.status"
  67. v-model="form.status"
  68. /> -->
  69. </div>
  70. <div class="col-12 md:col-6">
  71. <AppInputNumber
  72. label="Harga"
  73. placeholder="harga"
  74. :error="form.errors.price"
  75. v-model="form.price"
  76. />
  77. </div>
  78. <div class="col-12 md:col-6">
  79. <AppInputText
  80. label="Kuantitas"
  81. placeholder="kuantitas"
  82. :error="form.errors.qty"
  83. v-model="form.qty"
  84. />
  85. </div>
  86. <div class="col-12 md:col-6">
  87. <AppAutocompleteBasic
  88. label="Pelanggan"
  89. placeholder="pelanggan"
  90. :error="form.errors.customer_id"
  91. v-model="form.customer_id"
  92. @suggestions="customers"
  93. @complete="customerOnComplete"
  94. @item-select="customerOnSelected"
  95. >
  96. <template #item="slotProps">
  97. <template v-if="slotProps.item">
  98. <div class="flex flex-column">
  99. <span>{{ slotProps.item.name }}</span>
  100. <span>{{ slotProps.item.type }}</span>
  101. <span class="font-bold">{{
  102. slotProps.item.platNumber
  103. }}</span>
  104. </div>
  105. </template>
  106. </template>
  107. <template #empty>
  108. <span
  109. class="cursor-pointer"
  110. style="color: var(--primary-color)"
  111. @click="gotoMember"
  112. >
  113. Tambah Produk
  114. </span>
  115. </template>
  116. </AppAutocompleteBasic>
  117. </div>
  118. </div>
  119. </template>
  120. <template #footer>
  121. <div class="flex flex-column md:flex-row justify-content-end">
  122. <Button
  123. label="Simpan"
  124. icon="pi pi-check"
  125. class="p-button-outlined"
  126. :disabled="form.processing"
  127. @click="onSubmit"
  128. />
  129. </div>
  130. </template>
  131. </Card>
  132. </div>
  133. </div>
  134. </DashboardLayout>
  135. </template>