var gridManager = null;
//applyType=0 新建 1 变更 2 扩展

$(document).ready(function () {
    initialize();
    bindEvent();
});
function initialize(){
    var mainFileTable = $('#nonProApplyInfoList').fileList();
    mainFileTable.find('table').css({
        borderTopWidth : 0
    });
    $('#nonProApplyInfoList').fileList({
        bizId : $("#attbizId").val()
    });
    let isDetailPage = ($("#isDetailPage").val() === "true");
    if (isDetailPage) {
        $("#jobPageTop").hide();
    }
   // $("[name='maintenanceType'][value='new']").prop("checked","checked");
    $('#businessUsage').attr('disabled', "disabled");
    UICtrl.disable($("#businessUsage"));
    var businessUsage = $("#businessUsage").find("checkbox");
    businessUsage.attr("disabled", "disabled");
    UICtrl.setDisable("#maintenanceType");
    if (applyType=="1") { //变更

        $('#maintenanceType').attr('disabled', "disabled");
        UICtrl.disable($("#maintenanceType"));
        var maintenanceType = $("#maintenanceType").find("radio");
        maintenanceType.attr("disabled", "disabled");

    } else  if (applyType=="2") { //扩展
        UICtrl.disable($("#genericName"));
        UICtrl.disable($("#applicableStandard"));
        UICtrl.disable($("#baseUnit"));
        UICtrl.disable($("#specifications"));
        UICtrl.disable($("#material"));
        UICtrl.disable($("#design"));
        UICtrl.disable($("#size"));
        UICtrl.disable($("#brand"));
        UICtrl.disable($("#materialUsage"));
        UICtrl.disable($("#itemAttributes"));
        UICtrl.setDisable("#businessUsageDiv")
    }

    if (isAll=="1"){
        $('input[name="isAll"]').attr("checked",true);
    }

    $('input[name="isAll"]').change(function () {
        if ($(this).is(':checked')) {  //alert("全选");
           // $("#busiLens").val(dictUsage.length);
            for (var x=0;x<$("input[name='businessUsage']").length;x++) {
                $("input[name='businessUsage']")[x].checked = true;
            }
        } else {
            $("input[name='businessUsage']").each(function(){
                $(this).attr("checked",false);
            })
        }
    });

    $('input[name="businessUsage"]').change(function () {
           let isAll = 1;
          for (var x=0;x<$("input[name='businessUsage']").length;x++) {
            if ($("input[name='businessUsage']")[x].checked != true){
                isAll=0;
                break;
            }
          }
        if ($(this).is(':checked')) {

            if (isAll==1) {
               $('input[name="isAll"]')[0].checked = true;
            }
        } else {
            if (isAll==0) {
                $('input[name="isAll"]').attr("checked",false);
            }
        }
    });
}

/**
 * 流程引擎回调设置打样的id
 * @param value 打样申请的id
 */
function setId(id) {
    $("#id").val(id);
    $('#nonProApplyInfoList').fileList({
        bizId : id
    });
}

/**
 * 流程引擎获取打样申请id的回掉方法。
 * @return 打样申请的id
 */
function getId() {
    return $("#id").val() || "";
}

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

    //正面图片
    var _img=$('#showFrontPicture');
    var _frontPicturePath=$('#frontPicturePath').val();
    if (Public.isNotBlank(_frontPicturePath)) {
        _img[0].src = $.getCSRFUrl('attachment/downFileBySavePath.ajax',{file:_frontPicturePath});
    }
    $('#addFrontPicture').uploadButton({
        filetype: ['jpg','gif','jpeg','png','bmp'],
        afterUpload: function(data){
            _img[0].src = $.getCSRFUrl('attachmentDownFile.ajax',{id:data.id});
        },
        param: function(){
            return {bizCode: 'frontPicture', bizId: $("#attbizId").val(), flag: 'false', deleteOld: 'true', returnPath: 'true'};
        }
    });

    //反面图片
    var back_img=$('#showBackPicture');
    var _backPicturePath=$('#backPicturePath').val();
    if (Public.isNotBlank(_backPicturePath)) {
        back_img[0].src = $.getCSRFUrl('attachment/downFileBySavePath.ajax',{file:_backPicturePath});
    }
    $('#addBackPicture').uploadButton({
        filetype: ['jpg','gif','jpeg','png','bmp'],
        afterUpload: function(data){
            back_img[0].src = $.getCSRFUrl('attachmentDownFile.ajax',{id:data.id});
        },
        param: function(){
            return {bizCode: 'backPicture', bizId: $("#attbizId").val(), flag: 'false', deleteOld: 'true', returnPath: 'true'};
        }
    });
}