$(document).on('page:beforein', '.page[data-name="bank_edit"]', async function (e) {

  console.log('app bank_edit ready')

  var i = e.detail.route.params.id;

  console.log(i);

  let js = JSON.parse(localStorage.getItem('t01_bank'));

  let dt= js.data[i];

  console.log(dt)

  document.querySelector('#b2_id').value = dt.id || '';

  document.querySelector('#b2_cif').value = dt.cif || '';

  document.querySelector('#b2_account_name').value = dt.account_name || '';

  document.querySelector('#b2_bank_name').value = dt.bank_name || '';

  document.querySelector('#b2_swift_code').value = dt.swift_code|| '';

  document.querySelector('#b2_account_number').value = dt.account_number || '';

  document.querySelector('#b2_currency').value = dt.currency|| '';

});



$$(document)['on']('page:init', '.page[data-name="bank_edit"]', function(e) {  

  $$('.bank_edit_button')['on']('click', function() {

  e.preventDefault();

    const id = $('#b2_id').val();

    const cif = $('#b2_name').val();

    const account_name= $('#b2_account_name').val();

    const bank_name= $('#b2_bank_name').val();

    const swift_code= $('#b2_swift_code').val();

    const account_number= $('#b2_account_number').val();

    const currency= $('#b2_currency').val();



    let req = {

      id,cif,account_name,bank_name,swift_code,account_number,currency

    }

    if (id && account_number && bank_name) {

      bank_edit(req);

      //console.log(req)

    } else {

      app.dialog.alert("All fields are required", "Bank Edit Errors");

    }    

  })

});



$$(document)['on']('page:init', '.page[data-name="bank_edit"]', function(e) {  

  $$('#bank_delete_button')['on']('click', function() {

  e.preventDefault();

    const id = $('#b2_id').val();



    let req = {

      id

    }

    if (id) {

      bank_delete(req);

      //console.log(req)

    } else {

      app.dialog.alert("All fields are required", "Bank Edit Errors");

    }    

  })

});