{% put scripts %}
<script>
    $(function () {
        var $form = $('#mall-payment-form')
        var $overlay = $('.mall-overlay');
        var $body = $('body')

        $body.on('click', '.mall-payment-customer-method', function (e) {
            $overlay.prependTo($body).show()
        })

        $body.on('submit', '#mall-payment-form', function (e) {
            if (e.originalEvent.defaultPrevented) {
                return false;
            }
            e.preventDefault();
            $overlay.prependTo($('body')).show()

            var submit = this.querySelector('[type="submit"]')
            submit.classList.add('oc-loading')
            submit.disabled = true
            $form.request('{{ __SELF__ }}::onSubmit', {
                error: function(res) {
                    submit.classList.remove('oc-loading')
                    submit.disabled = false
                    $overlay.hide()
                    this.error(res)
                }
            })
        })
    })
</script>
{% endput %}