var id = helper.request.queryString("id");
$(document).ready(function () {
    if (id) {
        $.ajax({
            type: "get",
            url: huayi.config.callcenter_url + "HotspotGlossary/GetModel",
            async: true,
            dataType: "json",
            data: {
                token: $.cookie("token"),
                id: id,
            },
            success: function (result) {
                if (result.state.toLowerCase() == "success") {
                    var model = result.data.model;
                    var dtkey = result.data.dtkey;
                    var dtfile = result.data.dtfile;

                    $("#publishUnit").val(model.F_FaBuDanWei);
                    $("#publishPersonal").val(model.F_FaBuRen);
                    $("#industry").val(model.F_HangYe);
                    $("#address").val(model.F_DiQu);
                    $("#publishTime").val(model.F_FaBuShiJian);
                    $("#effectiveTime").val(model.F_ShengXiaoShiJian);
                    $("#invalidTime").val(model.F_ShiXiaoShiJian);
                    $("#documentNumber").val(model.F_FaWenWenHao);
                    $("#documentUnit").val(model.F_FaWenDanWei);
                    $("#identifyEncoding").val(model.F_BiaoShiBianMa);
                    $("#policyName").val(model.F_ZhengCeMingCi);
                    $("#answeringUnit").val(model.F_JieDaDanWei);
                    $("#hotIssues").val(model.F_ReDianWenTi);
                    $("#contentAnswer").val(model.F_WenTiJieDa);
                    $("#reflectCategory").val(dtkey[0].name);
                    $("#keyId").val(dtkey[0].id);

                    var htmls = "";
                    $(dtfile).each(function (j, m) {
                        var FileHtmls;
                        if (m.F_FileType == ".jpg" || m.F_FileType == ".png") {
                            FileHtmls = '<img style="width: 80px; height: 80px" border="0" onclick="viewImage(this)" src="' + m.F_FileUrl + '" alt="' + m.F_FileName + '" fileId="' + m.F_FileId +'">';
                        } else {
                            FileHtmls = '<div><a style="margin-right:5px;" target="view_window" href="' + m.F_FileUrl + '" download="' + m.F_FileName + '">' + m.F_FileName.substring(19) + '</a></div>'
                        }
                        htmls += FileHtmls;
                    })
                    $("#file").append(htmls);
                }
            },
        });
    }
});

function viewImage(file) {
    var json = {
        "title": "", //相册标题
        "id": 1, //相册id
        "start": 0, //初始显示的图片序号，默认0
        "data": [ //相册包含的图片，数组格式
            {
                "alt": $(file).attr("alt"),
                "pid": $(file).attr("fileId"), //图片id
                "src": $(file).attr("src"), //原图地址
                "thumb": "" //缩略图地址
            }
        ]
    }
    layer.photos({
        photos: json,
        anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });
}