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

  console.log('app product_edit ready')

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

  console.log(id);

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

  let dt= js.data.result.product_byid.data[id];

  console.log(dt)

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

  document.querySelector('#a7_name').value = dt.name || '';

  document.querySelector('#a7_brand').value = dt.brand || '';

  document.querySelector('#a7_code').value = dt.item_code || '';

  document.querySelector('#a7_price').value = dt.price_per_unit || '';

});



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

  $(document).off("click", "#product_edit_button").on("click", "#product_edit_button", function(e) {

    e.preventDefault();

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

    const name = $('#a7_name').val();

    const brand = $('#a7_brand').val();

    const code = $('#a7_code').val();

    const price = $('#a7_price').val();



    let req = {

      id,name,code,brand,price

    }

    if (id && name && brand && price) {

      product_edit(req);

    } else {

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

    }

  });

})