var gridManager = null;
var  canEdit=true;

$(document).ready(function () {
    initialize();
    bindDetailEvent();
});
function initialize(){
    UICtrl.layout("#layout", {leftWidth: 3});
    if ($("#isReadOnly").val()=="true") {
         disableForm("infoRecord","disable");
    } else {
         var readwriteList = UICtrl.getUIElementPermissions(UIPO.READWRITE, UIPK.DETAIL);
        // alert("dsd=="+readwriteList.length); alert(TaskKind.isReplenishTask(taskKindId)); //打回的
        if (($("#statusId").val() == 1 && readwriteList.length > 0&&TaskKind.isReplenishTask(taskKindId)!=true)) {
             disableForm("infoRecord", "disable");
            $.each(readwriteList, function (i, o) {
                $("#" + o).removeAttr('disabled');
            });
        }
    }
}


function disableForm(formId,isDisabled) {

    var attr="disable";
    if(!isDisabled){
        attr="enable";
    }
    $("form[id='"+formId+"'] :text").attr("disabled",isDisabled);
    $("form[id='"+formId+"'] textarea").attr("disabled",isDisabled);
    $("form[id='"+formId+"'] select").attr("disabled",isDisabled);
    $("form[id='"+formId+"'] :radio").attr("disabled",isDisabled);
    $("form[id='"+formId+"'] :checkbox").attr("disabled",isDisabled);

    //禁用jquery easyui中的下拉选（使用input生成的combox）

    $("#" + formId + " input[class='combobox-f combo-f']").each(function () {
        if (this.id) {alert("input"+this.id);
            $("#" + this.id).combobox(attr);
        }
    });

    //禁用jquery easyui中的下拉选（使用select生成的combox）
    $("#" + formId + " select[class='combobox-f combo-f']").each(function () {
        if (this.id) {
            alert(this.id);
            $("#" + this.id).combobox(attr);
        }
    });

    //禁用jquery easyui中的日期组件dataBox
    $("#" + formId + " input[class='datebox-f combo-f']").each(function () {
        if (this.id) {
            alert(this.id)
            $("#" + this.id).datebox(attr);
        }
    });
}

function bindDetailEvent(){
    $('#waersName').searchbox({
        type: "system", name: "selectSupplierWaers",
        getParam: function (item) {
            return {
                partner: $('#lifnr').val(),
               // werks: $('#werks').val()
            }
        },
        onChange: function (value, data) {
            $('#waers').val(data.waers);
            $('#waersName').val(data.waersName);
            $('#ltsnr').val(data.ltsnr);
            $('#ltsbz').val(data.ltsbz);
            //$('#name1').val(data.nameOrg1);
        }
    });

    $('#bprmeName').searchbox({
        type: "system", name: "dictionary",
        getParam: function (item) {
            return {fieldName: "MEINS"}
        },
        onChange: function (value, data) {
            $('#bprme').val(data.MSEH3);
            $('#bprmeName').val(data.MSEHL);
        }
    });

    $('#urzlaName').searchbox({
        type: "system", name: "dictionarySelect",
        getParam: function (item) {
            return {fieldName: "country",displayNames:"国家",displayLens:"180"}
        },
        onChange: function (value, data) {
            $('#urzla').val(data.value);
            $('#urzlaName').val(data.name);
        }
    });

    $('#regioName').searchbox({
        type: "system", name: "getArea",
        getParam: function (item) {
            if (Public.isBlank($('#urzla').val())){
                Public.tip("请先选择原产地国!")
                return false;
            }
            return {
                LAND1: $('#urzla').val()
            }
        },
        onChange: function (value, data) {
            $('#regio').val(data.BLAND);
            $('#regioName').val(data.BEZEI);
        }
    });
    $('#kbetr').on('input', function() {
        let inputValue = $(this).val();
        if (isNaN(Number(inputValue))) {
            Public.errorTip("等级金额1必须输入数字!");
        }else {
            if (Public.isNotBlank(inputValue)) {
                UICtrl.disable($('#netpr'))
                $('#netpr').val(inputValue);
            }else {
                UICtrl.enable($('#netpr'))
            }
        }
    });
}
