<template>
    <div class="cashier-wrapper">
        <form ref="formDom" :action="pageData.formData.actionUrl" method="post" id="submitForm">
            <input type="hidden" name="callbackUrl" :value="pageData.formData.callbackUrl">
            <input type="hidden" name="currency" :value="pageData.formData.currency">
            <input type="hidden" name="merType" :value="pageData.formData.merType">
            <input type="hidden" name="merchantNo" :value="pageData.formData.merchantNo">
            <input type="hidden" name="merchantOrderNo" :value="pageData.formData.merchantOrderNo">
            <input type="hidden" name="noticeUrl" :value="pageData.formData.noticeUrl">
            <input type="hidden" name="orderAmount" :value="pageData.formData.orderAmount">
            <input type="hidden" name="productDetail" :value="pageData.formData.productDetail">
            <input type="hidden" name="sign" :value="pageData.formData.sign">
            <input type="hidden" name="timeStamp" :value="pageData.formData.timeStamp">
            <input type="hidden" name="version" :value="pageData.formData.version">
        </form>
    </div>
</template>

<script setup>
import { onMounted, ref, reactive, nextTick } from "vue";
import {usdRechargeRequestByAchpay} from "@/http/account"
import {setChromeStorage, getChromeStorage} from "@/uilts/chromeExtension"

let formDom = ref(null);

let pageData = reactive({
    formData: {
        actionUrl: '',
        callbackUrl: '',
        currency: '',
        merType: '',
        merchantNo: '',
        merchantOrderNo: '',
        noticeUrl: '',
        orderAmount: '',
        productDetail: '',
        sign: '',
        timeStamp: '',
        version: '',
    }
})

const getLocalPayInfo = async () => {
    let payInfo = await getChromeStorage('achPayInfo');

    if(payInfo && payInfo.amountValue) {
        let achPayInfo = {
            amountValue: '',
            tab: payInfo.tab
        };
        setChromeStorage({ achPayInfo : JSON.stringify(achPayInfo)});

        usdRechargeRequestByAchpay({
            params: {
                amountValue: payInfo.amountValue
            }
        }).then(res => {
            if(res.code == 0) {
                pageData.formData = res.data;
                nextTick(() => {
                    formDom.value && formDom.value.submit();
                })
            }
        })
    }
}


onMounted(() => {
    getLocalPayInfo();
}) 

</script>

<style scoped lang="scss">
.cashier-wrapper {
}
</style>
