/**
 * 初始化人才认定申报详情对话框
 */
var locked = false;
var IntegralInfoDlg = {
    integralInfoData: {},
    validateFields: {
        name: {validators: {notEmpty: {message: '姓名不能为空'}}},
        card_type: {validators: {notEmpty: {message: '证件类型不能为空'}}},
        card_number: {
            validators: {
                notEmpty: {message: '证件号码不能为空'},
                regexp: {
                    regexp: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
                    message: "身份证号码格式不正确"
                }
            }
        },
        phone: {
            validators: {
                notEmpty: {
                    message: '手机号码不能为空'
                },
                regexp: {
                    regexp: /0?(13|14|15|16|17|18|19)[0-9]{9}/,
                    message: "手机号码格式不正确"
                }
            }
        },
        email: {
            validators: {
                notEmpty: {
                    message: '电子邮箱不能为空'
                },
                emailAddress: {
                    message: "电子邮箱格式不正确"
                }
            }
        }
    }
};
/**
 * 清除数据
 */
IntegralInfoDlg.clearData = function () {
    this.integralInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
IntegralInfoDlg.set = function (key, val) {
    var dis = $("#" + key).attr("disabled");
    if (dis == "disabled") {
        $("#" + key).removeAttr("disabled");
    }
    this.integralInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    if (dis == "disabled") {
        $("#" + key).prop("disabled", true);
    }
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
IntegralInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
IntegralInfoDlg.close = function () {
    parent.layer.close(window.parent.Integral.layerIndex);
}

/**
 * 收集数据
 */
IntegralInfoDlg.collectData = function () {
    this
            .set('id')
            .set('type')
            .set('name')
            .set('card_type')
            .set('card_number')
            .set('phone')
            .set('email');
}

/**
 * 验证数据
 */
IntegralInfoDlg.validate = function () {
    $('#integralInfoForm').data("bootstrapValidator").resetForm();
    $('#integralInfoForm').bootstrapValidator('validate');
    return $("#integralInfoForm").data('bootstrapValidator').isValid();
}
/**
 * 初始化表格的列
 */
IntegralInfoDlg.initFileTypeColumn = function () {
    return [
        {field: 'selectItem', checkbox: false, visible: false},
        {title: '附件列表（带*号的附件必需上传）', field: 'name', visible: true, align: 'left', valign: 'middle', width: "100%", 'class': 'uitd_showTip',
            formatter: function (value, row, index) {
                if (row.id != 0) {
                    return '<span style="color:#000000;font-weight:bold;">申报"' + value + '"积分项目需要上传以下附件</span>';
                }
                return '<span style="color:#000000;font-weight:bold;">公共附件</span>';
            }
        },
        {title: '模板', field: 'templateUrl', visible: true, align: 'center', valign: 'middle', width: "8%"},
        {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle', width: "10%"}
    ]
};
IntegralInfoDlg.addItem = function () {
    var html = '<table style="width:100%;border-collapse: collapse;" class="table table-bordered">' +
            '                             <tr>' +
            '                                 <td style="width:40px;">' +
            '                                     <div class="rowGroup">' +
            '                                         <label class="control-label spacing td-label">选择</label>' +
            '                                         <input type="checkbox" name="chk[]" class="form-control"/>' +
            '                                 </td>' +
            '                                 <td>' +
            '                                     <div class="rowGroup">' +
            '                                         <label class=" control-label spacing td-label"><span style="color: red">*</span>项目类别</label>' +
            '                                         <select class="form-control" name="projectType[]" value="" onchange="IntegralInfoDlg.onProjectTypeChange(this);">' +
            '                                             <option value="">请选择</option>' +
            '                                             <!--<option value="1">基础分</option>-->' +
            '                                             <option value="2">贡献分</option>' +
            '                                             <option value="3">资历分</option>' +
            '                                         </select>' +
            '                                     </div>' +
            '                                 </td>' +
            '                                 <td>' +
            '                                     <div class="rowGroup">' +
            '                                         <label class=" control-label spacing td-label"><span style="color: red">*</span>积分项目</label>' +
            '                                         <select class="form-control" name="projectId[]" value="" onchange="IntegralInfoDlg.onProjectChange(this);">' +
            '                                             <option value="">请选择</option>' +
            '                                         </select>' +
            '                                     </div>' +
            '                                 </td>' +
            '                                 <td>' +
            '                                     <div class="rowGroup">' +
            '                                         <label class=" control-label spacing td-label"><span style="color: red">*</span>积分标准</label>' +
            '                                         <select class="form-control" name="item_id[]" value="" onchange="IntegralInfoDlg.onItemChange(this);">' +
            '                                             <option value="">请选择</option>' +
            '                                         </select>' +
            '                                     </div>' +
            '                                 </td>' +
            '                                 <td>' +
            '                                     <div class="rowGroup">' +
            '                                         <label class="control-label spacing td-label"><span style="color: red">*</span>数额<span class="unit"></span></label>' +
            '                                         <input type="text" class="form-control" name="amount[]" value="" onkeyup="IntegralInfoDlg.onAmountChange(this);"/>' +
            '                                     </div>' +
            '                                 </td>' +
            '                                 <td>' +
            '                                     <div class="rowGroup">' +
            '                                         <label class=" control-label spacing td-label">预估积分</label>' +
            '                                         <div class="form-control points" style="border: none">-</div>' +
            '                                     </div>' +
            '                                  </td>' +
            '                             </tr>' +
            '                         </table>';
    /*
     * 
     '                             <tr>' +
     '                                 <td colspan="5">' +
     '                                     <table class="fileTable"></table>' +
     '                                 </td>' +
     '                             </tr>' +
     * 
     */
    $("#toolbar").before(html);
}
IntegralInfoDlg.changeAndLoadFile = function () {
    var table = $(".fileTable");
    var items = $("select[name='item_id[]']");
    var item_id = [];
    for (var i = 0; i < items.length; i++) {
        let _id = items.eq(i).val();
        if (_id) {
            item_id.push(_id);
        }
    }
    if (item_id.length == 0) {
        //table.bootstrapTable("destroy");
        //return;
    }
    var ajax = new $ax("/common/api/findCommonFileType", function (data) {
        table.bootstrapTable("destroy");
        if (data == null || data.length == 0) {
            return;
        }
        table.bootstrapTable({
            columns: IntegralInfoDlg.initFileTypeColumn(),
            data: data.rows,
            showHeader: true,
            rowStyle: function (row, index) {
                return {classes: ""};
            },
            onPostBody: function (data) {
                for (var i in data) {
                    var fileTypes = data[i].fileTypes;
                    for (var k in fileTypes) {
                        var fileType = fileTypes[k];
                        /**-- 构造附件类型标题栏  --**/

                        let name = '<div class="word-wrap">';
                        if (fileType.must == 1) {
                            name = name + '<i class="fa fa-paste"></i><span style="font-weight:bold;color:red;font-size:14px;font-family:宋体"> * </span> ' + fileType.name;
                        }
                        if (fileType.must == 2) {
                            name = name + '<i class="fa fa-paste"></i>' + fileType.name;
                        }
                        name = name + '<br />' + fileType.description + '</div>'

                        var template = "";
                        if (fileType.templateUrl == null || fileType.templateUrl == '' || fileType.templateUrl == 'null') {
                            template = '无';
                        } else {
                            template = "<button type='button' onclick=\"IntegralInfoDlg.downloadFile('" + fileType.id + "',3)\" style='margin-right: 10px' class=\"btn btn-xs btn-primary\">" +
                                    "<i class=\"fa fa-download\"></i>下载" +
                                    "</button>";
                        }
                        var uploadBtn = IntegralInfoDlg.validUploadButton(1, fileType.id, '', data[i].id);

                        var tr = '<tr class="subTitleLine"><td class="uitd_showTip" style="text-align: left; vertical-align: middle; width: 82%; ">'
                                + name +
                                '</td>\n\
                                \n\
                                <td style="text-align: center; vertical-align: middle; width: 8%; ">' + template +
                                '</td>\n\
                                <td style="text-align: center; vertical-align: middle; width: 10%; ">' + uploadBtn +
                                '</td></tr>';

                        /**-- --**/
                        var typeId = fileType.id;
                        var files = fileType.files;
                        var html = '<ul class="imgs"><li style="width: 70%;font-weight: bold;padding-top: 5px;">附件原名</li><li style="width: 10%;font-weight: bold;padding-top: 5px;">预览</li><li style="width: 20%;font-weight: bold;padding-top: 5px;">操作</li>';
                        for (var key in files) {
                            var btn = "";
                            btn = IntegralInfoDlg.validUploadButton(2, typeId, files[key].id, files[key].relationId);
                            var sn = files[key].url.lastIndexOf(".");
                            var suffix = files[key].ext; //files[key].url.substring(sn + 1, files[key].url.length);
                            var imgStr = "";
                            if (suffix == "pdf" || suffix == "PDF") {
                                imgStr = "<button type='button'  onclick=\"Feng.showPdf('" + files[key].url + "','" + files[key].id + "','" + files[key].orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-pdf-o\" aria-hidden=\"true\"></i></button>";
                            } else if (suffix == "xlsx" || suffix == "XLSX" || suffix == 'xls' || suffix == 'XLS' || suffix == 'docx' || suffix == 'doc' || suffix == 'DOCX' || suffix == 'DOC') {
                                imgStr = "<button type='button'  onclick=\"Feng.showExcel('" + files[key].url + "','" + files[key].id + "','" + files[key].orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-excel-o\" aria-hidden=\"true\"></i></button>";
                            } else {
                                imgStr = '<img class=\"imgUrl\" onclick=\"Feng.showImg(this)\" src=\"' + files[key].url + '\" style=\"width:25px;height:25px;\">';
                            }

                            html += '<li data-id="' + files[key].id + '">\n\
                                    <div><input type="hidden" name="uploadFiles[]" value="' + files[key].id + '"></div>\n' +
                                    '<div style="width: 70%;">' + files[key].orignName + '</div>\n' +
                                    '<div style="width: 10%;">' + imgStr + '</div>\n' +
                                    '<div style="width: 20%;">' + btn + '</div>\n\
                                    </li>';
                        }
                        html = html + '</ul>';
                        table.find("tr[data-index='" + i + "'] td").eq(0).attr("colspan", 3);
                        table.find("tr[data-index='" + i + "'] td").eq(1).remove();
                        table.find("tr[data-index='" + i + "'] td").eq(2).remove();
                        table.find("tr[data-index='" + i + "']").after(tr);
                        table.find("tr[data-index='" + i + "']").next(".subTitleLine").after('<tr class="detail-view"><td colspan="5">' + html + '</td></tr>');
                    }
                }
                $("td.uitd_showTip").bind("mouseover", function () {
                    var htm = $(this).html();
                    $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
                });
            },
        });
    }, function (data) {
        Feng.error("查询失败!" + data.responseJSON.message + "!");
    });
    var queryData = {};
    queryData["mainId"] = $("#id").val();
    queryData['project'] = CONFIG.project_integral_apply;
    queryData['type'] = $("#type").val();
    queryData['pageToken'] = $("input[name=__token__]").val();
    queryData["itemId"] = item_id;
    queryData['checkState'] = $("#checkState").val();
    ajax.set(queryData);
    ajax.start();
}
IntegralInfoDlg.deleteItem = function () {
    var len = $("input[name='chk[]']:checked").length;
    if (len == 0) {
        Feng.info("请选择要移除的项目");
    }
    for (var i = 0; i < len; i++) {
        $("input[name='chk[]']:checked").eq(0).parents("table").remove();
    }
    IntegralInfoDlg.changeAndLoadFile();
}
IntegralInfoDlg.onProjectTypeChange = function (obj) {
    var projectType = $(obj).val();
    var projectObj = $(obj).parents("table").find("select[name='projectId[]']")
    Feng.addAjaxSelect({
        "obj": projectObj,
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": "/common/api/getIntegralProjectsByType/projectType/" + projectType
    });
    IntegralInfoDlg.calIntegral(obj);
}
IntegralInfoDlg.onProjectChange = function (obj) {
    var projectId = $(obj).val();
    var itemObj = $(obj).parents("table").find("select[name='item_id[]']");
    if (projectId) {
        Feng.addAjaxSelect({
            "obj": itemObj,
            "displayCode": "id",
            "displayName": "name",
            "bindData": "unit",
            "type": "GET",
            "url": "/common/api/getIntegralItemsByProject/projectId/" + projectId
        });
        IntegralInfoDlg.calIntegral(obj);
    }
}
IntegralInfoDlg.onItemChange = function (obj) {
    var unit = $(obj).find("option:selected").data("unit");
    var parent = $(obj).parents("table");
    if (typeof unit != "undefined" && unit) {
        parent.find(".unit").html("（" + unit + "）");
    } else {
        parent.find(".unit").html("");
    }
    IntegralInfoDlg.changeAndLoadFile();
    IntegralInfoDlg.calIntegral(obj);
}
IntegralInfoDlg.timeout = null;
IntegralInfoDlg.delay = 500;
IntegralInfoDlg.onAmountChange = function (obj) {
    clearTimeout(IntegralInfoDlg.timeout);
    IntegralInfoDlg.timeout = setTimeout(function () {
        IntegralInfoDlg.calIntegral(obj);
    }, IntegralInfoDlg.delay);
}
IntegralInfoDlg.calIntegral = function (obj) {
    var parent = $(obj).parents("table");
    var cardType = $("#card_type").val();
    var cardNumber = $("#card_number").val();
    var itemId = parent.find("select[name='item_id[]']").val();
    var amount = parent.find("input[name='amount[]']").val();
    var cardTypeArr = ["1", "2", "3"];
    if (cardTypeArr.indexOf(cardType) > -1 && cardNumber != "" && itemId > 0 && !isNaN(amount) && amount != "") {
        //条件齐全就可以查询积分        
        var ajax = new $ax(Feng.ctxPath + "/common/api/calIntegral", function (data) {
            /*let point1 = typeof data.projectRemainderPoints != "undefined" ? (data.projectRemainderPoints > data.points ? data.points : data.projectRemainderPoints) : data.points;
             let point2 = typeof data.itemRemainderPoints != "undefined" ? (data.itemRemainderPoints > data.points ? data.points : data.itemRemainderPoints) : data.points;
             let points = point1 > point2 ? point2 : point1;*/
            parent.find(".points").html(data.points);
        }, function (data) {
            Feng.error("预估积分失败!" + data.responseJSON.message + "!");
        });
        ajax.set("cardType", cardType);
        ajax.set("cardNumber", cardNumber);
        ajax.set("itemId", itemId);
        ajax.set("amount", amount);
        ajax.start();
    } else {
        parent.find(".points").html("-");
    }
}

IntegralInfoDlg.multipleRefreshPoints = function () {
    if ($("#card_type").val() > 0 && $("#card_number").val() != "") {
        var ajax = new $ax(Feng.ctxPath + "/common/api/getIntegralRecordByIdCard", function (data) {
            $("#tips").html(data.tips);
        }, function (data) {
            Feng.error("获取个人相关信息失败!");
        });
        ajax.set("cardType", $("#card_type").val());
        ajax.set("cardNumber", $("#card_number").val());
        ajax.start();
    }
    var count = $("#itemList").find("table").length;
    for (var i = 0; i < count; i++) {
        var table = $("#itemList").find("table").eq(i);
        IntegralInfoDlg.calIntegral(table.find(".points")[0]);
    }
}

/**
 * 提交添加
 */
IntegralInfoDlg.addSubmit = function () {
    this.clearData();
    this.collectData();
    if (!IntegralInfoDlg.validate()) {
        return;
    }
    var id = $('#id').val();
    if (id != null && id != '') {
        if (!IntegralInfoDlg.validateIsEdit())
            return;
    }
    $("select").each(function () {
        $(this).removeAttr("disabled");
    });
    if (locked) {
        //return;
    }
    locked = true;
    $("#integralInfoForm").attr("action", "/enterprise/integral/apply");
    $("#integralInfoForm")[0].submit();
}

//回调
IntegralInfoDlg.infoCallback = function (data) {
    locked = false;
    IntegralInfoDlg.setNoChangeField();
    Feng.info(data.msg);
    if (data.code == 200) {
        window.parent.Integral.table.refresh();
        $("#id").val(data.obj.id);
        $("#fileLi").removeAttr("style");
        $("#checkState").val(data.obj.checkState);
    }
    return;
}

//校验是否保存基础信息
IntegralInfoDlg.validId = function () {
    var id = $("#id").val();
    if (id != null && id != '') {
        $("#fileLi").removeAttr("style");
    } else {
        $("#fileLi").attr("style", "pointer-events: none");
    }
}
var currentTr = null;
//选择附件并显示附件名
IntegralInfoDlg.checkFile = function (content, fileTypeId, fileId, itemId) {
    var curTr = $(content).parents("tr");
    var index = curTr.index();
    if (curTr.hasClass("subTitleLine")) {
        index++;
    }
    currentTr = index;
    if (!IntegralInfoDlg.validateIsEdit())
        return;
    $("#upload_file").unbind("change");
    $("#upload_file").change(function () {
        if (!Feng.chkFileInvalid(this.files[0], 5, 10))
            return;
        IntegralInfoDlg.upload(fileTypeId, fileId, itemId);
    });
    $('#upload_file').val("");
    $('#upload_file').click();
}
//上传附件
IntegralInfoDlg.upload = function (fileTypeId, fileId, itemId) {
    var id = $("#id").val();
    if (!IntegralInfoDlg.validateIsEdit())
        return;
    if (fileId != null && fileId != 'null') {
        $("#fileId").val(fileId)
    } else {
        $("#fileId").val("");
    }
    $("#mainId").val(id);
    $("#fileTypeId").val(fileTypeId);
    var index = layer.load(0, {shade: false, time: 0});
    $("#index").val(index);
    $("#relationId").val(itemId);
    $("#pageToken").val($("input[name=__token__]").val());
    $("#uploadForm").submit();
}
//删除附件
IntegralInfoDlg.deleteFile = function (id, state) {
    if (!IntegralInfoDlg.validateIsEdit())
        return;
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/common/api/deleteFile", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                $("input[name='uploadFiles[]'][value='" + id + "']").parents("li").remove();
                //$("#fileTable").bootstrapTable("refresh", {});
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id", id);
        ajax.set("type", 20);
        ajax.start();
    }
    Feng.confirm("删除后无法恢复，确认删除吗?", operation);
}

/**
 * 提交审核
 */
IntegralInfoDlg.submitToCheck = function () {
    /*if (!IntegralInfoDlg.validate()) {
     return;
     }*/
    var id = $("#id").val();
    /*if (id == null || id == "") {
     Feng.info("请先填写基础信息并上传附件");
     return;
     }*/
    if (!IntegralInfoDlg.validateIsEdit())
        return;
    var operation = function () {
        IntegralInfoDlg.clearData();
        IntegralInfoDlg.collectData();
        /*if (!IntegralInfoDlg.validate()) {
         return;
         }*/
        var id = $('#id').val();
        if (id != null && id != '') {
            if (!IntegralInfoDlg.validateIsEdit())
                return;
        }
        $("select").each(function () {
            $(this).removeAttr("disabled");
        });
        if (locked) {
            return;
        }
        locked = true;
        $("#integralInfoForm").attr("action", "/enterprise/integral/submitToCheck");
        $("#integralInfoForm")[0].submit();
    }
    Feng.confirm("请确认积分申报内容已核对无误，相应附件已上传，一旦提交，无法修改", operation);
}
//回调
IntegralInfoDlg.submitCallback = function (data) {
    locked = false;
    IntegralInfoDlg.setNoChangeField();
    if (data.code == 200) {
        Feng.success(data.msg);
        // $("#checkState").val(data.obj);
        window.parent.Integral.table.refresh();
        IntegralInfoDlg.close();
    } else {
        Feng.error(data.msg);
    }
}

/**
 * 校验是否可以修改/提交审核
 */
IntegralInfoDlg.validateIsEdit = function () {
    var checkState = $("#checkState").val();
    if (checkState != 0 && checkState != 1) {
        if (checkState == 5 || checkState == 8) {
            Feng.error("您的申报审核不通过，无法再修改");
            return false;
        } else if (checkState == 28) {
            Feng.error("申报已完成");
            return false;
        } else if (checkState == 6) {
            Feng.error("您的申报已审核通过，无法再修改");
            return false;
        } else if (checkState == 22 || checkState == 25 || checkState == 27) {
            Feng.error("该申报已终止");
            return false;
        } else {
            Feng.error("您的申报正在审核中，请耐心等待");
            return false;
        }
    }
    return true;
}

/**
 * 校验是否显示按钮
 * @param type      类型  1-上传按钮，2-修改删除按钮
 * @param row
 * @returns {string}
 */
IntegralInfoDlg.validUploadButton = function (type, fileTypeId, fileId, itemId) {
    var files = $("#files").val();
    files = files.split(",");
    var checkState = $("#checkState").val();
    var realState = $("#realState").val();
    if (Feng.isEmptyStr(checkState) || checkState == 0 || (checkState == 1 && realState == 1) || (realState == 4 && files[0] == 1)) {
        if (type == 1) {          //上传
            return "<button type='button' onclick=\"IntegralInfoDlg.checkFile(this," + fileTypeId + "," + null + "," + itemId + ")\" style='margin-right: 10px' class=\"btn btn-xs btn-info\">" +
                    "<i class=\"fa fa-upload\"></i>上传" +
                    "</button>";
        } else {
            return "<button type=\'button\' onclick=\"IntegralInfoDlg.checkFile(this," + fileTypeId + "," + fileId + "," + itemId + ")\" style=\'margin-right: 10px\' class=\"btn btn-xs btn-info\">" +
                    "<i class=\"fa fa-paste\"></i>修改" +
                    "</button>" +
                    "<button type='button' onclick=\"IntegralInfoDlg.deleteFile(" + fileId + ")\" class=\"btn btn-xs btn-danger\">" +
                    "<i class=\"fa fa-times\"></i>删除" +
                    "</button>";
        }
    } else {
        return "";
    }
}


//回调
IntegralInfoDlg.callBack = function (data) {
    layer.close(data.obj);
    Feng.info(data.msg);
    if (data.code == 200) {
        var sn = data.info.lastIndexOf(".");
        var suffix = data.ext; //data.info.substring(sn + 1, data.info.length);
        var imgStr = "";
        if (suffix == "pdf" || suffix == "PDF") {
            imgStr = "<button type='button'  onclick=\"Feng.showPdf('" + data.info + "','" + data.id + "','" + data.orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-pdf-o\" aria-hidden=\"true\"></i></button>";
        } else if (suffix == "xlsx" || suffix == "XLSX" || suffix == 'xls' || suffix == 'XLS' || suffix == 'docx' || suffix == 'doc' || suffix == 'DOCX' || suffix == 'DOC') {
            imgStr = "<button type='button'  onclick=\"Feng.showExcel('" + data.info + "','" + data.id + "','" + data.orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-excel-o\" aria-hidden=\"true\"></i></button>";
        } else {
            imgStr = '<img class="imgUrl"  src="' + data.info + '" style="width:25px;height:25px;">';
        }
        var li = $("input[name='uploadFiles[]'][value='" + data.id + "'").parents("li");
        if (li.length > 0) {
            li.find("div").eq(1).html(data.orignName);
            li.find("div").eq(2).html(imgStr);
        } else {
            var html = '<li data-id="' + data.id + '">\n\
<div><input type="hidden" name="uploadFiles[]" value="' + data.id + '"></div>\n\
<div style="width: 70%;">' + data.orignName + '</div>\n\
<div style="width: 10%;">' + imgStr + '</div>\n\
<div style="width: 20%;">\n\
<button type="button" onclick="IntegralInfoDlg.checkFile(this,' + data.typeId + ',' + data.id + ',' + data.itemId + ')" style="margin-right: 10px" class="btn btn-xs btn-info"><i class="fa fa-paste"></i>修改</button>\n\
<button type="button" onclick="IntegralInfoDlg.deleteFile(' + data.id + ')" class="btn btn-xs btn-danger"><i class="fa fa-times"></i>删除</button>\n\
</div></li></ul>';
            $(".fileTable tbody tr").eq(currentTr).find(".imgs").append(html);
        }
    }
}
IntegralInfoDlg.downloadFile = function (id, type) {
    window.location.href = Feng.ctxPath + "/api/common/downloadFile?id=" + id + "&type=" + type;
}

//设置不可修改的字段
IntegralInfoDlg.setNoChangeField = function () {
    var checkState = $("#checkState").val();
    var fields = $("#fields").val();
    var allowedModifyItem = $("#files").val() == "1" ? true : false;
    var realState = $("#realState").val();
    if (realState == 4 || checkState == 2) {
        $("input,textarea").each(function () {
            $(this).attr("readonly", "readonly");
        });
        $("select,input[type=radio]").each(function () {
            $(this).attr("disabled", "disabled");
        });
        if (fields != null && fields != '') {
            var arr = fields.split(",");
            for (var key in arr) {
                if (arr[key] != "") {
                    var name = $("#" + arr[key]).prop("tagName");
                    if (name == 'select' || name == 'SELECT') {
                        $("#" + arr[key]).removeAttr("disabled");
                    } else if (name == "input" || name == 'textarea' || name == "INPUT" || name == 'TEXTAREA') {
                        $("#" + arr[key]).removeAttr("readonly");
                    } else {
                        if (typeof name == "undefined") {
                            $("input[name=" + arr[key] + "]").removeAttr("disabled").removeAttr("readonly");
                        }
                    }
                }
            }
        }

        if (!allowedModifyItem) {
            $("#toolbar").css("display", "none");
        } else {
            $("#itemList :input").removeAttr("readonly");
            $("#itemList :input").removeAttr("disabled");
        }
    }
}
$(function () {
    IntegralInfoDlg.setNoChangeField();
    $('#integralInfoForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        container: 'tooltip',
        group: '.rowGroup',
        fields: IntegralInfoDlg.validateFields,
        live: 'enabled',
        message: '该字段不能为空'
    }).on('error.field.bv', function (e, data) {
        // Get the tooltip
        var $parent = data.element.parents('#integralInfoForm'),
                $icon = $parent.find('.form-control-feedback[data-bv-icon-for="' + data.field + '"]'),
                title = $icon.data('bs.tooltip').getTitle();
        $icon.tooltip('show').tooltip({
            html: true,
            placement: 'right',
            title: title,
            container: 'body'
        });
    });
    var id = $("#id").val();
    var checkState = $("#checkState").val();
    if (id != null && id != '') {
        //select初始化
        $("select").each(function () {
            $(this).val($(this).attr("value")).trigger("change");
        });
        Feng.getCheckLog("logTable", {"type": CONFIG.project_integral_apply, "mainId": id, "typeFileId": "", "active": 1})
    }
    $("#card_type").val($("#card_type").attr("value"));
    IntegralInfoDlg.validId();
    IntegralInfoDlg.changeAndLoadFile();
});


