<script>
//===================================================================*/
/* イベント
//===================================================================*/
//　F9 Excel
$(document).on("click", ".popaf0311mFunc9:not('.noevent')", function (e) {
  $('#af0311mExcel').trigger('printExcel');
});
//　F12 メニュー/戻る
$(document).on("click", ".popaf0311mFunc12:not('.noevent')", function (e) {
  $('#af0311mClose').trigger('popClose');
});

//表示
$(document).on("click", ".popup-af0311m", function (e) {

    popup.openPopup("af0311m", "");
    af0311m.initial();
    $("#af0311m").focus();
});

$("#af0311mExcel").on("printExcel", function (e) {
  var me = this;
  // 読込
  var top = $(this).closest(".af0311m");
  common.clearFormError(".af0311m")
  
  var errflg = false;

{*  元は必須で任意に変更した形跡有
//  if(stringUtil.isEmpty(common.getValue($("#af0311mCucd")))) {
//    errflg = true;
//    common.addError($("#af0311mCucd"), "入力して下さい。", null, true);
//  }
*}

  if(errflg) {
    alert("エラーがあります");
  } else if( window.confirm('【得意先商品単価マスタExcel出力】をします。よろしいですか？') ){
    let param2 = { "method": "GetWseqMjan" };
    let excelid = "AF0311M";
    $.ajax({
      type: "GET",
      url: "../../api/getWseq.php",
      data: param2,
      dataType: "json",
      scriptCharset: 'utf-8',
      success: function(data, status, xhr) {
        var wurl = "{$_REPORT_URL}" + "AF999JE?WSEQ=" + JSON.parse(data.data)
                + "&IREP=" + excelid
                + "&CHGCD=" + "{$_SYSTEM_NAME_EN_CHGCD}"
                + "&ACCD=" + "{$_SYSTEM_NAME_EN_ACCD}"
                + "&DBNO=" + "{$_SYSTEM_NO}"
                + "&JOKEN1=" + $("#af0311mCucd").val() 
                + "&JOKEN2=" + $("#af0311mJans").val()
                + "&JOKEN3=" + $("#af0311mJane").val()
                + "&JOKEN6=" + $("#af0311mDats").val()
                + "&JOKEN7=" + $("#af0311mDate").val();
        window.open(wurl, excelid+JSON.parse(data.data));
      }
    });
  }
});

/*
$(document).on("change","#af0311mJans, #af0311mJane", function(e) {
  common.clearError("#af0311mJans");
  common.clearError("#af0311mJane");
});
*/
$(document).on("change","#af0311mDats, #af0311mDate", function(e) {
  common.clearError("#af0311mDats");
  common.clearError("#af0311mDate");
});

$(document).on("focus","#af0311mDummy", function(e) {
  $(".popaf0311mFunc9").focus();
});

$("#af0311mClose").on("popClose", function (e) {
  if (e.bubbles == false) {
    return false;
  }
  af0311m.initial();
  af0311m.close();
});

var af0311m = {
  close: function () {
    this.initial();
    popup.closePopup("af0311m");
  },

  initial: function () {
    common.clearInputData($(".af0311m")); //検索画面データのクリア

    $("#af0311mCucd").focus();
    $('input:radio[name="af0311mFlg"]').val(['E']);
  },
}
</script>
