{"version":3,"file":"valuation.d3dd1798.js","sources":["../../../app/javascript/components/mixins/valuation.js"],"sourcesContent":["export default {\n    props: {\n        prendas: Array,\n        aforos: Object,\n        slug: {type: String, default: 'empeno'}\n    },\n    data() {\n        return {\n            step: 1,\n            step_counter: 1,\n            type: [],\n            category: null,\n            garment: {},\n            isMobile: window.innerWidth < 801,\n            haveLoan: false,\n            titles: [\n                '¿Qué tipo de prenda vas a empeñar?',\n                '',\n                '',\n                'Detalles de la prenda',\n            ],\n            titles_tag: [\n                'tipo_de_prenda',\n                'selecciona_tu_prenda',\n                'detalles_de_la_prenda',\n                'valor_de_la_prenda'\n            ],\n            weight_units: {\n                'gramos': 'g',\n                'onzas': 'oz'\n            }\n        }\n    },\n    provide() {\n        return {\n            weight_units: this.weight_units\n        }\n    },\n    mounted() {\n        window.onresize = () => {\n            this.isMobile = window.innerWidth < 801\n        }\n    },\n    methods: {\n        setStep(step) {\n            scroll(0, 0)\n            if (step <= 0) {\n                location.href = `/seccion/${this.slug}`\n                this.step = 1\n                return\n            }\n            this.step = step\n        },\n        setGarments(payload) {\n            let garments = this.prendas.filter(prenda => prenda.tipo.value === payload.tipo.value && prenda.categoria.value === payload.categoria.value)[0]\n            this.type = garments\n            this.titles[this.step] = this.type.titulo_paso_2.value\n            this.category = garments.categoria.value\n            this.garment = {}\n            this.garment.categoria = garments.categoria.value\n\n            this.setGarmentsDataLayer()\n            this.setStep(this.step + 1)\n        },\n        setGarment(itemIndex) {\n            let prenda = this.type.prendas.value[itemIndex]\n            this.garment.prenda = prenda.titulo === 'Otro' ? 'Joya' : this.type.prendas.value[itemIndex].titulo\n            this.garment.unidades = prenda?.unidades\n            if (prenda?.valor) {\n                this.garment.valor = prenda.valor\n                this.garment.cali_peso = prenda.peso\n            }\n            this.titles[this.step] = this.sectionThreeTitle()\n\n            this.setGarmentsDataLayer()\n            this.setStep(this.step + 1)\n        },\n        setGarmentDetails(details) {\n            this.garment.kilataje = this.getKilataje(details.kilataje)\n            this.garment.peso = parseFloat(details.gramos)\n            this.garment.aforo = this.getAforo()\n            this.garment.categoria = this.category\n\n            dataLayer.push({\n                event: \"select_cotizador\",\n                flow: this.getFlow(),\n                step: this.step_counter,\n                step_name: this.titles_tag[this.step - 1],\n                cotizador_kilataje: this.category === 'oro' ? this.garment.kilataje : '',\n                cotizador_peso: this.garment.peso,\n                cotizador_ley:this.category === 'plata' ? this.garment.kilataje : '',\n                ...this.getBudgets()\n            })\n            this.step_counter++\n\n            this.setStep(this.step + 1)\n        },\n        getAforo() {\n            let key = this.slug !== 'empeno' ? this.slug : this.category\n            return this.aforos[key]\n        },\n        getKilataje(kilataje) {\n            let karatType = {\n                'oro': 'K',\n                'plata': 'L',\n            }\n            return `${kilataje}${karatType[this.category]}`\n        },\n        sendGarment(loan) {\n            this.garment.prestamo = loan.loan\n            this.garment.loanInformation = loan.title\n            this.garment.tipo = this.type.titulo.value\n            this.$emit('getValuatedGarment', this.garment)\n            this.haveLoan = true\n\n            dataLayer.push({\n                event: \"select_cotizador\",\n                flow: this.getFlow(),\n                step: this.step_counter,\n                step_name: this.titles_tag[this.step - 1],\n                tipo_de_prenda: `${this.garment.prenda}`,\n                cotizador_kilataje: this.category === 'oro' ? this.garment.kilataje : '',\n                cotizador_peso: this.garment.peso,\n                cotizador_ley:this.category === 'plata' ? this.garment.kilataje : '',\n                cotizador_te_podemos_prestar: this.garment.prestamo,\n                ...this.getBudgets()\n            })\n            this.step_counter++\n        },\n        async createLog(cta, reset = true) {\n            if (this.garment?.prestamo && isNaN(this.garment.prestamo)) return\n            this.garment.cta = cta\n            this.garment.flujo = this.slug\n            let log = null\n            await this.$axios.post('/valuador/save_valuated_garments', {valuatedGarments: [this.garment]})\n                .then((response) => {\n                    log = response.data[0]\n                    let last_quotation = {\n                        src: window.location.href,\n                        quotation_id: log._id,\n                        date: new Date().toISOString()\n                    }\n                    this.saveQuotationCookie(last_quotation)\n                })\n                .catch((error) => {\n                    console.error(error)\n                })\n            if (reset) this.setStep(1)\n            return log['_id']['$oid']\n        },\n        garmentInformation() {\n            let peso = this.garment?.cali_peso ? this.garment.cali_peso : this.garment.peso\n            let type = 'g'\n            if (this.garment?.unidades) type = this.weight_units[this.garment.unidades] ? this.weight_units[this.garment.unidades] : 'g'\n            let regex = /(\\d+(?:\\.\\d+)?)(\\D+)/\n            let kilataje = regex.exec(this.garment.kilataje)\n            return `<b>${this.garment.prenda === 'Otro' ? 'Joya' : this.garment.prenda} de ${this.garment.categoria}</b> de <b>${kilataje[1]}${kilataje[2]}</b> de <b>${peso} ${type}</b>`\n        },\n        sectionThreeTitle() {\n            if (!this.type?.tipo) return ''\n            let title = this.type?.tipo?.value === 'joya' ? `Detalles de ${this.garment.prenda === 'Aretes' ? 'tus' : 'tu'} ${this.garment.prenda} de ${this.category}` :\n                `Detalles de tu ${this.type['tipo']['value']} de ${this.category}`\n\n            return title\n        },\n        saveQuotationCookie(quotation) {\n            quotation = btoa(JSON.stringify(quotation))\n            document.cookie = `last_quotation=${quotation}; path=/`\n        },\n        getFlow(){\n            let flow = document.location.pathname;\n            return flow.split('/')[2]\n        },\n        getBudgets() {\n            let data = {}\n            if (this.garments && this.budget) {\n                let total = this.garments.reduce((acc, item) => acc + item.prestamo, 0)\n                data.cotizador_meta = this.budget\n                data.cotizador_faltante = this.budget - total\n            }\n\n            return data\n        },\n        setGarmentsDataLayer() {\n            let type = this.garment.prenda ? this.garment.prenda : `${this.type.tipo.value} de ${this.type.categoria.value}`\n            dataLayer.push({\n                event: \"select_cotizador\",\n                flow: this.getFlow(),\n                step: this.step_counter,\n                step_name: this.titles_tag[this.step - 1],\n                tipo_de_prenda: type,\n                ...this.getBudgets()\n            })\n            this.step_counter++\n        }\n    },\n    watch: {\n        step(newValue) {\n            this.haveLoan = false\n        },\n    }\n}"],"names":["Valuation","step","payload","garments","prenda","itemIndex","details","key","kilataje","loan","cta","reset","_a","log","response","last_quotation","error","_b","peso","type","_c","quotation","data","total","acc","item","newValue"],"mappings":"AAAA,MAAeA,EA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