$(document).ready(function () {
    initializateUI();
    bindEvent();
});

function initializateUI() {
    UICtrl.layout("#layout", {leftWidth: 3});

    $('#nonOrderStorageList').fileList({
        bizId : $("#id").val()
    });
    var isCharge = $("#isCharge").val();
    amountController(isCharge)
}

function bindEvent() {

    $('#werksName').searchbox({
        type: "system", name: "dictionary",
        getParam: function (item) {
            return {fieldName: "WERKS"}
        },
        onChange: function (value, data) {
            $('#werks').val(data.WERKS);
            $('#werksName').val(data.NAME1);
        }
    });
    $('#storeName').searchbox({
        type: "system", name: "dictionary",
        getParam: function (item) {
            if (Public.isBlank($('#werks').val())){
                Public.tip("请先选择工厂");
                return false;
            }
            return {fieldName: "LGORT"}
        },
        onChange: function (value, data) {
            $('#store').val(data.LGORT);
            $('#storeName').val(data.LGOBE);
        }
    });
    $('#unitName').searchbox({
        type: "system", name: "dictionary",
        getParam: function (item) {
            return {fieldName: "MEINS"}
        },
        onChange: function (value, data) {
            $('#unit').val(data.MSEH3);
            $('#unitName').val(data.MSEHL);
        }
    });
    $("#isCharge").combox({onChange:function(data){
            amountController(data.value)
        }
    })

    $('#productName').searchbox({
        type: "system", name: "sapMaterialSelect",
        getParam: function (item) {
            if (Public.isBlank($('#werks').val())){
                Public.tip("请先选择工厂！")
                return false
            }
            return {
                ///  fieldName: "sapMaterialSelect",
                filterValue: $('#werks').val()
            }
        },
        onChange: function (value, data) {
            $('#productCode').val(data.MATNR);
            $('#productName').val(data.MAKTX);
            $('#unit').val(data.MEINS);
            $('#unitName').val(data.MSEHL);
            $('#store').val(data.LGFSB);
            $('#storeName').val(data.LGOBE);
        }
    });

    $('#supplierName').searchbox({
        type: "system", name: "selectSuppliersDatas",
        getParam: function (item) {
            return {
               // filterValue: $('#werks').val()
            }
        },
        onChange: function (value, data) {
            $('#supplier').val(data.partner);
            $('#supplierName').val(data.nameOrg1);
        }
    });
}

function amountController(value){
    if ("1" == value){
        UICtrl.setElHideOrShow("#amount",false)
        UICtrl.setElRequiredFlag("#amount",true);
    }else {
        UICtrl.setElRequiredFlag("#amount",false);
        UICtrl.setElHideOrShow("#amount",true)
    }
}
function setId(value) {
    $('#id').val(value);
    $('#nonOrderStorageList').fileList({
        bizId : value
    });
}

function getId() {
    return $("#id").val();
}