Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template>
- <HeaderApp />
- <div class="tw-text-primary tw-font-bold tw-text-center tw-text-2xl tw-mt-5">Simulasi Kredit Kendaraan</div>
- <div class="tw-container tw-mx-auto tw-max-w-[800px] tw-px-4">
- <VechicleForm v-model="form" v-if="step == 1" />
- <SimulatorDetail v-if="step == 2" v-model="form" />
- <div class="tw-flex tw-items-center tw-justify-between tw-space-x-2">
- <q-btn
- :label="t('button.back')"
- color="grey"
- outline
- rounded
- type="button"
- class="tw-w-full md:tw-w-auto"
- @click="onBack()"
- />
- <q-btn
- label="Lanjutkan"
- color="secondary"
- rounded
- class="tw-w-full md:tw-w-auto"
- @click="onSubmit()"
- :disable="buttonDisable"
- />
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import HeaderApp from 'components/lib/HeaderApp.vue'
- import { Loading, Notify } from 'quasar'
- import { GetErrorMessage } from 'src/common/utils/error.utils'
- import VechicleForm from 'src/pages/simulator/VechicleForm.vue'
- import { computed, reactive, ref } from 'vue'
- import { useI18n } from 'vue-i18n'
- import { SimulatorRequest } from '../../../common/entities/simulator.entity'
- import { useSimulatorEndpoint } from '../../../common/endpoints/simulator.endpoint'
- import { useRouter } from 'vue-router'
- import SimulatorDetail from 'src/pages/simulator/SimulatorDetail.vue'
- import { useSimulatorStore } from '../../../stores/simulator.store'
- import { useAppStore } from 'src/stores/app.store'
- import { useAuthenticationStore } from '../../../stores/authentication.store'
- import { APPLICANT_SUBMISSION, LOGIN } from 'src/router/router-name'
- import { useApplicantEndpoint } from 'src/common/endpoints/applicant.endpoint'
- import { SectionCollection } from 'src/common/interfaces/response.interface'
- import { useParameterStore } from 'src/stores/parameter.store'
- const { t } = useI18n()
- const form = reactive<SimulatorRequest>({} as SimulatorRequest)
- const simulatorEndpoint = useSimulatorEndpoint()
- const step = ref<number>(1)
- const router = useRouter()
- const buttonDisable = computed(() => {
- if (step.value == 1) {
- if (!form.jenis_jaminan || !form.merek || !form.model || !form.tahun) {
- return true
- } else {
- return false
- }
- } else {
- if (!form.tenor || form.tenor == 'ALL') {
- return true
- } else {
- return false
- }
- }
- })
- const simulatorStore = useSimulatorStore()
- const appStore = useAppStore()
- const authStore = useAuthenticationStore()
- const parameterStore = useParameterStore()
- const applicantEndpoint = useApplicantEndpoint()
- const getPlafond = computed(() => simulatorStore.getPlafond)
- const flag = computed(() => parameterStore.getFlagging)
- const onSubmit = async () => {
- try {
- Loading.show()
- if (step.value <= 1) {
- form.tenor = 'ALL'
- step.value += 1
- } else {
- if (authStore.$state.isLoggedIn == true) {
- const inquiryData = (await applicantEndpoint.getOne()).data
- const dataSimulator = { ...inquiryData }
- dataSimulator.brand = form.merek
- dataSimulator.vehicle_type = form.jenis_jaminan
- dataSimulator.year = form.tahun
- dataSimulator.type = form.model
- dataSimulator.flagging = flag.value ?? ''
- dataSimulator.tenor = form.tenor?.match(/\d+/)?.[0] ?? ''
- dataSimulator.credit_amount = getPlafond.value ?? ''
- appStore.setApplicantData(dataSimulator)
- if (inquiryData.flagging) {
- parameterStore.setFlagging(inquiryData.flagging)
- }
- const collection: SectionCollection = { sectionId: inquiryData?.sectionId }
- router.push({
- name: APPLICANT_SUBMISSION,
- params: {
- collection: JSON.stringify(collection),
- },
- })
- } else {
- router.push({ name: LOGIN })
- }
- }
- } catch (error) {
- Notify.create({
- type: 'negative',
- message: GetErrorMessage(error as Error),
- })
- } finally {
- Loading.hide()
- }
- }
- function onBack() {
- try {
- if (step.value > 1) {
- step.value -= 1
- } else {
- router.go(-1)
- }
- } catch (error) {
- Notify.create({
- type: 'negative',
- message: GetErrorMessage(error as Error),
- })
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement