Advertisement
kidto1412

form parent

May 15th, 2025
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <HeaderApp />
  3.   <div class="tw-text-primary tw-font-bold tw-text-center tw-text-2xl tw-mt-5">Simulasi Kredit Kendaraan</div>
  4.   <div class="tw-container tw-mx-auto tw-max-w-[800px] tw-px-4">
  5.     <VechicleForm v-model="form" v-if="step == 1" />
  6.     <SimulatorDetail v-if="step == 2" v-model="form" />
  7.  
  8.     <div class="tw-flex tw-items-center tw-justify-between tw-space-x-2">
  9.       <q-btn
  10.         :label="t('button.back')"
  11.         color="grey"
  12.         outline
  13.         rounded
  14.         type="button"
  15.         class="tw-w-full md:tw-w-auto"
  16.         @click="onBack()"
  17.       />
  18.       <q-btn
  19.         label="Lanjutkan"
  20.         color="secondary"
  21.         rounded
  22.         class="tw-w-full md:tw-w-auto"
  23.         @click="onSubmit()"
  24.         :disable="buttonDisable"
  25.       />
  26.     </div>
  27.   </div>
  28. </template>
  29. <script lang="ts" setup>
  30. import HeaderApp from 'components/lib/HeaderApp.vue'
  31. import { Loading, Notify } from 'quasar'
  32. import { GetErrorMessage } from 'src/common/utils/error.utils'
  33. import VechicleForm from 'src/pages/simulator/VechicleForm.vue'
  34. import { computed, reactive, ref } from 'vue'
  35. import { useI18n } from 'vue-i18n'
  36. import { SimulatorRequest } from '../../../common/entities/simulator.entity'
  37. import { useSimulatorEndpoint } from '../../../common/endpoints/simulator.endpoint'
  38. import { useRouter } from 'vue-router'
  39. import SimulatorDetail from 'src/pages/simulator/SimulatorDetail.vue'
  40. import { useSimulatorStore } from '../../../stores/simulator.store'
  41. import { useAppStore } from 'src/stores/app.store'
  42. import { useAuthenticationStore } from '../../../stores/authentication.store'
  43. import { APPLICANT_SUBMISSION, LOGIN } from 'src/router/router-name'
  44. import { useApplicantEndpoint } from 'src/common/endpoints/applicant.endpoint'
  45. import { SectionCollection } from 'src/common/interfaces/response.interface'
  46. import { useParameterStore } from 'src/stores/parameter.store'
  47.  
  48. const { t } = useI18n()
  49.  
  50. const form = reactive<SimulatorRequest>({} as SimulatorRequest)
  51.  
  52. const simulatorEndpoint = useSimulatorEndpoint()
  53.  
  54. const step = ref<number>(1)
  55.  
  56. const router = useRouter()
  57.  
  58. const buttonDisable = computed(() => {
  59.   if (step.value == 1) {
  60.     if (!form.jenis_jaminan || !form.merek || !form.model || !form.tahun) {
  61.       return true
  62.     } else {
  63.       return false
  64.     }
  65.   } else {
  66.     if (!form.tenor || form.tenor == 'ALL') {
  67.       return true
  68.     } else {
  69.       return false
  70.     }
  71.   }
  72. })
  73.  
  74. const simulatorStore = useSimulatorStore()
  75. const appStore = useAppStore()
  76. const authStore = useAuthenticationStore()
  77. const parameterStore = useParameterStore()
  78.  
  79. const applicantEndpoint = useApplicantEndpoint()
  80.  
  81. const getPlafond = computed(() => simulatorStore.getPlafond)
  82. const flag = computed(() => parameterStore.getFlagging)
  83.  
  84. const onSubmit = async () => {
  85.   try {
  86.     Loading.show()
  87.     if (step.value <= 1) {
  88.       form.tenor = 'ALL'
  89.       step.value += 1
  90.     } else {
  91.       if (authStore.$state.isLoggedIn == true) {
  92.         const inquiryData = (await applicantEndpoint.getOne()).data
  93.         const dataSimulator = { ...inquiryData }
  94.         dataSimulator.brand = form.merek
  95.         dataSimulator.vehicle_type = form.jenis_jaminan
  96.         dataSimulator.year = form.tahun
  97.         dataSimulator.type = form.model
  98.         dataSimulator.flagging = flag.value ?? ''
  99.         dataSimulator.tenor = form.tenor?.match(/\d+/)?.[0] ?? ''
  100.         dataSimulator.credit_amount = getPlafond.value ?? ''
  101.  
  102.         appStore.setApplicantData(dataSimulator)
  103.         if (inquiryData.flagging) {
  104.           parameterStore.setFlagging(inquiryData.flagging)
  105.         }
  106.         const collection: SectionCollection = { sectionId: inquiryData?.sectionId }
  107.         router.push({
  108.           name: APPLICANT_SUBMISSION,
  109.           params: {
  110.             collection: JSON.stringify(collection),
  111.           },
  112.         })
  113.       } else {
  114.         router.push({ name: LOGIN })
  115.       }
  116.     }
  117.   } catch (error) {
  118.     Notify.create({
  119.       type: 'negative',
  120.       message: GetErrorMessage(error as Error),
  121.     })
  122.   } finally {
  123.     Loading.hide()
  124.   }
  125. }
  126.  
  127. function onBack() {
  128.   try {
  129.     if (step.value > 1) {
  130.       step.value -= 1
  131.     } else {
  132.       router.go(-1)
  133.     }
  134.   } catch (error) {
  135.     Notify.create({
  136.       type: 'negative',
  137.       message: GetErrorMessage(error as Error),
  138.     })
  139.   }
  140. }
  141. </script>
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement