var file_src = "";
var imgs_src = [];
var idUpdate;
var check_id;
var check_type;
var check_item_tree = null;
var edittype = "add";
var al_data = [];
var isconfirmC = false;
// 页面初始化
function init() {
    $(document).delegate("#editImage img", "mouseenter", function() {
        var myself = $(this);
        var xx = $("<i class='icon-remove' img_src='" + $(this).attr('img_src') + "'></i>");
        xx.css({ "position": "absolute", "display": "" });
        $(this).parent().append(xx);
        $(".icon-remove").click(function() {
            myself.hide();
            imgs_src.push($(this).attr("img_src"));
        });
    })
    $(document).delegate("#editImage div", "mouseleave", function() {
            $(".icon-remove").hide();
        })
        // 初始化上传
    refreshUploader();
    setVisit();
    $.jeDate("#month_date", {
        isinitVal: true,
        format: 'YYYY/MM' // 分隔符可以任意定义，该例子表示只显示年月
    });
    $.jeDate("#month_date2", {
        isinitVal: true,
        format: 'YYYY-MM-DD hh:mm',
        zIndex: 300000000000 // 分隔符可以任意定义，该例子表示只显示年月日
    });
    $("#month_date").val(getCurrentTimeFormat());
    var road_manager;
    if (roleContains("STATION") || roleContains("WRECKER")) {
        road_manager = getCurrentUser().road_manager_id;
    }
    if (roleContains("ROAD_MANAGER")) {
        road_manager = getCurrentUser().organid;
    }
    // 设置道管
    setRoadManagerSelect("#first", road_manager, true);
    // 设置服务区
    var checked_dept = null;
    if (roleContains("FWQ")) {
        checked_dept = getCurrentUser().organid;
    }
    setSASelect("#fsList", checked_dept);

    // 新增服务区下拉框
    var dept;
    if (roleContains("STATION") || roleContains("WRECKER")) {
        dept = getCurrentUser().organid;
    }
    var roadManager2;
    if (roleContains("ROAD_MANAGER")) {
        roadManager2 = getCurrentUser().organid;
    }
    var feeList = getOrganList(roadManager2);
    setSASelectValueNoAll(feeList, "#select-dept", dept);
    // setPersonal();// 2期不需要人员显示
    var zTreeObj;
    var zNodes = [];
    check_item_tree = $.fn.zTree.init($("#check_rule_tree2"), {}, zNodes);

    getOtherCheckItems();

    $("#check_item_select input").on("click", function() {
        //debugger;
        var nodedata;
        if ($("#check_item_select input") != undefined && $("#check_item_select input") != "") {
            nodedata = check_item_tree.getNodeByParam("name", $("#check_item_select input").val(), null);
        }
        $("#add_btn").data("tree_flag", 1);
        loadData(nodedata);
        $("#add_btn").data("tree_flag", 0);
    })

    setCheckTypeSelect('#speacial_type_select', '', 'special_check_type', true);
    queryTable();
    setCheckTypeSelect('#select-check-type', '', 'wrecker_group_check_type');
    setCheckTypeSelect('#select-special-check-type', '', 'special_check_type');
}

//关闭弹窗
$("#close-layer").click(function() {
        layer.closeAll();
    })
    //条件查询
$("#conditional_query").click(function() {
        queryTable();
    })
    //保存修改或添加
$("#save-check").click(function() {
        var dept_id = $("#select-dept").val();
        // var user_id = $("#select-personal").val();
        var check_item_id = dept_selectinput != null ? dept_selectinput.value : null;
        var remark = $("#remark").val();
        var check_score = $("#check_score").val();
        var check_time = $("#month_date2").val();
        var check_num = $("#check_num").val();
        var wrecker_check_type = $("#select-check-type").val();
        var special_check_type = $("#select-special-check-type").val();
        if (idUpdate) {
            if ($("#editImage").attr("file_src") != '') {
                var src = $("#editImage").attr("file_src").split(",");
                var flag = 1;
                for (var i = 0; i < src.length; i++) {
                    for (var j = 0; j < imgs_src.length; j++) {
                        if (src[i] == imgs_src[j]) {
                            flag = 0;
                            break;
                        }
                    }
                    if (flag == 1) {
                        file_src += src[i] + ",";
                    }
                }
            }
        }
        var file_ids = (file_src.substring(file_src.length - 1) == ',') ? file_src.substring(0, file_src.length - 1) : file_src;

        // var check_time_name = timeStamp2String(new Date(),"yyyy/MM");
        var check_time_name = timeStamp2String(new Date((check_time + ":00").replace("-g-/", "")), "yyyy/MM");
        var timeday = moment(check_time);
        var timec = moment(timeday.get("year") + "-" + (timeday.get('month') + 1) + "-26 00:00:00");


        if (timeday.valueOf() > timec.valueOf()) {
            var year = timeday.get("year");
            var month = timeday.get('month') + 2;

            if (month > 12) {
                year += 1;
                month -= 12;
            }
            check_time_name = year + "/" + (month > 9 ? month : ("0" + month));
        } else {
            var year = timeday.get("year");
            var month = timeday.get('month') + 1;

            if (month > 12) {
                year += 1;
                month -= 12;
            }
            check_time_name = year + "/" + (month > 9 ? month : ("0" + month));
        }


        if (dept_id == null || dept_id == undefined || dept_id == "") {
            layer.msg('请选择服务区');
            return;
        } else if (check_item_id == null || check_item_id == undefined || check_item_id == "") {
            layer.msg('请选择扣分类别');
            return;
        } else if (check_score == null || check_score == undefined || check_score == "") {
            layer.msg('请选择扣分值');
            return;
        }
        data = {
            "id": check_id,
            "dept_id": dept_id,
            // "user_id": user_id,
            "check_item_id": check_item_id,
            "check_type": check_type,
            "remark": remark,
            "check_score": check_score,
            "file_ids": file_ids,
            "check_time": check_time,
            "check_time_name": check_time_name,
            "check_num": check_num,
            "wrecker_check_type": wrecker_check_type,
            "special_check_type": special_check_type
        }
        console.log(data);
        if (idUpdate) {
            post_common_service("f/checkOther/update", data, function(data) {
                file_src = "";
                imgs_src = [];
                layer.closeAll();
                queryTable();
            }, function() {

            });
        } else {
            post_common_service("f/checkOther/add", data, function(data) {
                file_src = "";
                imgs_src = [];
                layer.closeAll();
                queryTable();
            }, function() {

            });
        }
    })
    //添加稽查记录
$("#add_btn").click(function() {
    idUpdate = false;
    edittype = "add";
    check_id = null;
    $("#select-dept").val("");
    // $("#select-personal").val("");
    $(".treeSelect-input").val("");
    $("#remark").val("");
    $("#check_score").val("");
    $("#month_date2").val(timeStamp2String(new Date(), "yyyy-MM-dd HH:mm"));
    $("#check_num").val(1);
    $("#editImage").empty();
    layerUpdateTeam('form-div', '稽查记录新增', '550px');
    $("#save-check").html("保存");

    // if (check_type == 2) {
    //     //特情稽查处理
    //     $("#confirmC").prop('checked', false);
    //     isconfirmC = false;
    // }

    //debugger;
    var nodedata;
    $("#add_btn").data("tree_flag", 1);
    loadData(nodedata);
    $("#add_btn").data("tree_flag", 0);


    $("#check_item_select input").on("click", function() {
        //debugger;
        // var nodedata;
        // $("#add_btn").data("tree_flag",1);
        // loadData(nodedata);
        // $("#add_btn").data("tree_flag",0);
    })
})

function confirmCfun() {
    isconfirmC = $("#confirmC").prop("checked");
}

function queryTable() {
    $(".datatable").empty();
    var data = {
        "check_time_name": $("#month_date").val(),
        "dept_id": $("#fsList").val(),
        "check_type": check_type,
        "special_check_type": $("#speacial_type_select").val()
    }
    var hide = true;
    // if (check_type == 5) {
    //     hide = false;
    // }
    operation = true;
    var hide1 = true;
    // if (check_type == 2) {
    //     hide1 = false;
    // }

    // if (check_type == 4) {
    //     data["scoretype"] = $("#scoretype").val();
    // }

    var cols = [
        { width: 20, text: '序号', flex: false, colClass: 'text-center', field: 'num' },
        { width: 70, text: '时间', flex: false, colClass: '', field: 'check_time' },
        { width: 50, text: '部门', flex: false, colClass: '', field: 'organ_name' },
        // {
        //     width: 30,
        //     text: '人员',
        //     flex: false,
        //     colClass: '',
        //     field: 'username',
        //     func: function(obj) {
        //         if (obj == null || obj == undefined) {
        //             return "站部";
        //         }
        //         return obj;
        //     }
        // },// 2期以服务区维度
        { width: 50, text: '扣分类型', flex: false, colClass: '', field: 'pcheckname' },
        { width: 50, text: '扣分项', flex: false, colClass: '', field: 'check_item_name' },
        { width: 30, text: '扣分值', flex: false, colClass: '', field: 'check_score' },
        { width: 120, text: '扣分描述', flex: false, colClass: '', field: 'remark' },
        { width: 30, text: '检查类型', flex: false, hide: hide, field: 'wrecker_check_type_name' },
        { width: 50, text: '稽查类型', flex: false, hide: hide1, field: 'special_check_type_name' },
        { width: 70, text: '附件', type: 'imagedd', flex: false, colClass: '', field: 'file_ids' }
    ];
    if (roleContains("JICHA") || hasRole("ROLE_ADMIN")) {
        cols.push({
            width: 60,
            text: '操作',
            flex: false,
            field: 'id',
            oper: [
                { func: 'updateCheckTeam', text: '修改', icon_class: 'icon-edit' }, { func: 'deleteCheckTeam', text: '删除', icon_class: 'icon-remove-circle' }
            ]
        });
    }
    $('.datatable').mytable({
        'cols': cols,
        'url': "f/checkOther/getAllCheckOther",
        'param': data
    });
}

function deleteCheckTeam(id) {
    deleteItem4Common(id, "f/checkOther/delete", queryTable);
}

function updateCheckTeam(id) {
    check_id = id;
    data = {
        "id": id
    }
    post_common_service("f/checkOther/getCheckById", data, function(data) {
        var select_road = $(".div-roadManage select").val();
        var feeList = getOrganList(select_road);
        setSASelectValueNoAll(feeList, "#select-dept", data.dept_id);
        // setPersonal(data.user_id);
        // $("#select-dept").val(data.dept_id);
        // $("#select-personal").val(data.user_id);
        $("#check_item_select input").val(data.check_item_name);
        $("#remark").val(data.remark);
        $("#check_score").val(data.check_score);
        var time = data.check_time;
        $("#month_date2").val(data.check_time);
        $("#check_num").val(data.check_num);
        setCheckTypeSelect('#select-check-type', data.wrecker_check_type, "wrecker_group_check_type");
        setCheckTypeSelect('#select-special-check-type', data.special_check_type, 'special_check_type');
        $("#editImage").empty();
        if (data.file_ids != null && data.file_ids != "") {
            var ids = data.file_ids.split(",");
            var str = "";
            for (i = 0; i < ids.length; i++) {
                str += ids[i] + ",";
                $("#editImage").append("<div style='float:left;width:60px;'><img  img_src='" + ids[i] + "' class='pic-class  img-thumbnail' style='width:50px;height:50px;' alt='' src='http://file_release_yanhai.jsxt.jsjtyxt.com/" + ids[i] + "' ></div>");
            }
            $("#editImage").attr("file_src", (str.substring(str.length - 1) == ',') ? str.substring(0, str.length - 1) : str);
        }

        idUpdate = true;
        edittype = "edit";
        layerUpdateTeam('form-div', '稽查记录修改', '550px');
        $("#save-check").html("修改");

        var nodedata;
        if ($("#check_item_select input") != undefined && $("#check_item_select input") != "") {
            nodedata = check_item_tree.getNodeByParam("name", $("#check_item_select input").val(), null);
        }
        loadData(nodedata);


        $("#check_item_select input").on("click", function() {
            //debugger;
            // var nodedata;
            // if($("#check_item_select input") != undefined && $("#check_item_select input") != ""){
            //     nodedata = check_item_tree.getNodeByParam("name",$("#check_item_select input").val(), null);
            // }
            // $("#add_btn").data("tree_flag",1);
            // loadData(nodedata);
            // $("#add_btn").data("tree_flag",0);
        })
    }, function() {

    });

}

function refreshUploader() {
    // 文件上传
    $('#uploaderExample').uploader({
        autoUpload: true, // 当选择文件后立即自动进行上传操作
        unique_names: true, // 生成唯一名称
        url: base_image_server_url + 'fileServer/file/upload', // 文件上传提交地址
        filters: {
            mime_types: [
                { title: '图片', extensions: 'jpg,gif,png' },
                { title: '图标', extensions: 'ico' },
                { title: '视频', extensions: 'mp4,avi' },
                { title: '文档', extensions: 'doc,docx' }
            ],
            // 不允许上传重复文件
            prevent_duplicates: true
        },
        fileTemplate: '<div class="file"><div class="file-progress-bar"></div><div class="file-wrapper"><div class="file-icon"><i class="icon icon-file-o"></i></div><div class="content"></div><div class="actions"><div class="file-status" data-toggle="tooltip"><i class="icon"></i> <span class="text"></span></div><a data-toggle="tooltip" class="btn btn-link btn-download-file" target="_blank"><i class="icon icon-download-alt"></i></a><button type="button" data-toggle="tooltip" class="btn btn-link btn-reset-file" title="Repeat"><i class="icon icon-repeat"></i></button><button type="button" data-toggle="tooltip" class="btn btn-link btn-rename-file" title="Rename"><i class="icon icon-pencil"></i></button><button type="button" data-toggle="tooltip" title="Remove" class="btn btn-link btn-delete-file"><i class="icon icon-trash text-danger"></i></button></div></div></div>', // 设置模板
        onFileUploaded: function(file, responseObject) {
            var datas = eval('(' + responseObject.response + ')');
            file_src += datas.result_data.path + ",";
            //$(".file").append("<div style='float:left;width:60px;'><img  img_src='"+datas.result_data.path+"' class='pic-class  img-thumbnail' style='width:50px;height:50px;' alt='' src='http://file_release_yanhai.jsxt.jsjtyxt.com/"+datas.result_data.path+"' ></div>");
        },
        onInit: function() {
            $("#file-list").empty();
        },
        onFilesRemoved: function(files) {
            // alert(files);
        }
    });
}

function setVisit() {
    if (roleContains("STATION") || roleContains("WRECKER")) {
        $("#first").attr("disabled", "disabled");
        $("#second").attr("disabled", "disabled");
    }
    if (roleContains("ROAD_MANAGER")) {
        $("#first").attr("disabled", "disabled");
    }

    if (!(roleContains("JICHA") || hasRole("ROLE_ADMIN"))) {
        $("#add_btn").hide();
        // $("#second").hide();
    }
}
/**
 * 根据道管中心获取服务区列表（下拉框）
 */
$(".div-roadManage select").change(function() {
    setSASelect("#fsList", null);
    flag = true;
});

function getOrganList(select_road) {
    var organList;
    if (select_road) {
        // if (check_type == 5) {
        //     organList = cache_road_manager_wrecker_group_map.get(select_road);
        // } else {
        organList = cache_service_area_map.get(select_road);
        // }
    } else {
        // if (check_type == 5) {
        //     organList = $.zui.store.get("cache_wrecker_group_list");
        // } else {
        organList = $.zui.store.get("cache_service_area_list");
        // }
    }
    return organList;
}

// function setSecond() {
//     var select_road = $(".div-roadManage select").val();
//     var feeList = getOrganList(select_road);
//     var dept;
//     if (roleContains("STATION") || roleContains("WRECKER")) {
//         dept = getCurrentUser().organid;
//     }
//     refreshFee(feeList, dept);
// }

function setscoretype() {
    var sec = document.getElementById('scoretype');
    var tempStr = '<option value="all" selected>全部</option>'
    if (all_data.length > 0) {
        if (all_data[0].children.length > 0) {
            all_data[0].children.forEach(child => {
                tempStr += "<option value=" + child.name + " >" + child.name + "</option>";
            });
            sec.innerHTML = tempStr;
        } else {
            sec.innerHTML = '';
        }
    } else {
        sec.innerHTML = '';
    }
}


function refreshFee(data, selectId) {
    var sec = document.getElementById('second');
    var tempStr = '<option value="">全部</option>'
    if (data.length != 0) {
        for (var i = 0; i < data.length; i++) {
            if (data[i].deptid == selectId)
                tempStr += "<option value=" + data[i].deptid + " selected>" + data[i].name + "</option>";
            else
                tempStr += "<option value=" + data[i].deptid + ">" + data[i].name + "</option>";
            // }
            sec.innerHTML = tempStr;
        }

    } else {
        sec.innerHTML = '';
    }
}

// /**
//  * 部门人员下拉框
//  */
// function setPersonal(selectUserId) {
//     var select_road = $("#select-dept").val();
//     var sec = document.getElementById('select-personal');
//     var tempStr = ''
//     var param = {
//         "organid": select_road
//     }
//     var url = "user/getFsUserList";
//     if (check_type == 5) {
//         url = "user/getWGUserList";
//     }
//     post_common_service(url, param, function(data) {
//         console.log(data);
//         if (data.length != 0) {
//             var userId;
//             if (hasRole("ROLE_STATION")) {
//                 userId = getCurrentUser().id;
//             } else {
//                 userId = selectUserId;
//             }
//             // console.log(data);
//             if (check_type != 2) {
//                 tempStr += "<option value=0>收费站</option>";
//             }
//             for (var i = 0; i < data.length; i++) {
//                 // for (var j = 33; j <= 53; j++) {
//                 // if (select_road == j) {
//                 var workno = data[i].workno;
//                 if (workno) workno = workno.substring(workno.length - 3);
//                 if (data[i].id == userId) {
//                     tempStr += "<option value='" + data[i].id + "' selected='selected' > " + workno + data[i].truename + "</option>";
//                 } else {
//                     tempStr += "<option value='" + data[i].id + "'" + (i == 0 ? " selected='selected'" : "") + "”>" + workno + data[i].truename + "</option>";
//                 }
//                 // }
//                 // }


//                 sec.innerHTML = tempStr;
//             }

//             sec.innerHTML = tempStr;
//         } else {
//             sec.innerHTML = '';
//         }
//     }, function(error) {
//         return "";
//     });
// }
// 部门改变后 重新生成人员下拉框
// $("#select-dept").change(function() {
//     if (check_type == 2) {
//         if (isconfirmC) return;
//     }
//     setPersonal();
// });

$("#check_item_select").delegate("div[id*='treeSelect_panel_'] ", "blur", function() {
    // alert(1)
    if ($(this).is(":hidden")) {
        if (map[dept_selectinput.value] != null) {
            $("#check_score").val(map[dept_selectinput.value]);
        } else {
            $("#check_score").val("");
        }
    }
})

function layerUpdateTeam(domId, title, area) {
    var uploader = $('#uploaderExample').data('zui.uploader');
    uploader.destroy();
    refreshUploader();
    $(".file-list").empty();
    file_src = "";
    imgs_src = [];
    layer.open({
        type: 1,
        title: false,
        closeBtn: 1,
        title: title,
        shadeClose: true,
        skin: 'yourclass',
        area: area,
        content: $("#" + domId)
    });
}

// 增加和编辑框
var dept_selectinput;

function loadData(nodedata) {
    var pnode = nodedata;
    if (pnode != null) {
        dept_selectinput = new TreeSelect({
            element: '#check_item_select',
            data: all_data,
            valueKey: "id",
            placeholder: "请选择扣分类别",
            selectvalue: pnode.id
        });
    } else {
        if ($("#add_btn").data("tree_flag") == 1) {
            dept_selectinput = new TreeSelect({
                element: '#check_item_select',
                data: all_data,
                valueKey: "id",
                placeholder: "请选择扣分类别"
            });
        } else {

        }
    }
}

function getOtherCheckItems() {
    function zTreeOnRename(event, treeId, treeNode, isCancel) {
        alert(treeNode.tId + ", " + treeNode.name);
    }

    function zTreeOnRemove(event, treeId, treeNode) {
        alert(treeNode.tId + ", " + treeNode.name);
    }


    function getTreeData(c_obj, id) {
        if (c_obj.id == id) {
            return c_obj;
        } else {
            if (c_obj.subCheckItem != null) {
                for (var i = 0; i < c_obj.subCheckItem.length; i++) {
                    var tmp = getTreeData(c_obj.subCheckItem[i], id);
                    if (tmp != null) {
                        return tmp;
                    }
                }
            }
            return null;
        }
    }

    var seq = 0;

    function getTree(obj, rowObj) {
        var userdata = {};
        userdata["checked"] = false;
        if (obj.score != null) {
            userdata["data"] = [++seq, obj.name, (obj.score != null ? obj.score : ""), '<a href="javascript:void(0)" onclick="modify_check_item(' + obj.id + ')"  ><i class="icon icon-edit"></i> 修改</a><a href="javascript:void(0)" onclick="delete_check_item(' + obj.id + ')" ><i class="icon icon-remove-circle"></i> 删除</a>'];
            rowObj.push(userdata);
        }

        if (obj.subCheckItem != null) {
            for (var i = 0; i < obj.subCheckItem.length; i++) {
                getTree(obj.subCheckItem[i], rowObj);
            }
        }
        return rowObj;
    }

    function zTreeOnClick(event, treeId, treeNode) {
        var rowdata = [];

        seq = 0;

        for (var i = 0; i < z_cache.length; i++) {
            var treeObj = getTreeData(z_cache[i], treeNode.id);
            if (treeObj != null) {
                rowdata = getTree(treeObj, rowdata);
                break;
            }
        }

        // 使用data参数更新数据：
        $('.datatable').datatable('load', {
            cols: cols,
            rows: rowdata
        });
    };

    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: null
            }
        },
        view: { //表示tree的显示状态
            selectMulti: false //表示禁止多选
        },
        check: { //表示tree的节点在点击时的相关设置
            enable: false, //是否显示radio/checkbox
            chkStyle: "checkbox", //值为checkbox或者radio表示
            checkboxType: { p: "", s: "" }, //表示父子节点的联动效果
            radioType: "level" //设置tree的分组
        },
        callback: {
            onRename: zTreeOnRename,
            //  beforeDrop: zTreeBeforeDrop,
            onRemove: zTreeOnRemove,
            onClick: zTreeOnClick
        },
        edit: {
            enable: true,
            drag: {
                autoExpandTrigger: true,
                isMove: true,
                prev: false,
                next: true,
                inner: true,
                autoOpenTime: 0
            },
            showRenameBtn: false,
            showRemoveBtn: false
        }
    };

    var param = {};
    // rule_type=8,服务区暗访考核办法.rule_type=9,服务区现场考核办法
    // check_type=8,服务区第三方暗访，check_type=9，服务区现场稽查
    if (check_type == 8) {
        param.rule_type = 8;
    } else if (check_type == 9) {
        param.rule_type = 9;
    }
    post_common_service('checkRule/getItemListByRuleType', param, function(data) {
        all_data = [];
        z_cache = data;
        if (data) {
            for (var i = 0; i < data.length; i++) {
                var m = data[i];
                var zdataItem = {};
                zdataItem["id"] = m.id;
                zdataItem["value"] = m.id;
                zdataItem["pId"] = null;
                zdataItem["score"] = m.score;
                zdataItem["name"] = m.name;
                zdataItem["open"] = true;
                zdataItem["children"] = addobj(m);
                zdataItem.open = true;
                all_data.push(zdataItem);
            }
            check_item_tree = $.fn.zTree.init($("#check_rule_tree2"), setting, all_data)

            // if (check_type == 4) {
            //     setscoretype();
            // }
        }
    }, function(error) {})
}

function addobj(data) {
    var zdata = [];
    if (typeof(data.subCheckItem) != "undefinde" && data.subCheckItem != null &&
        data.subCheckItem.length > 0) {
        for (var i = 0; i < data.subCheckItem.length; i++) {
            var m = data.subCheckItem[i];
            var zdataItem = {};
            //   if(m.score != null){
            //      continue;
            //   }
            zdataItem["id"] = m.id;
            zdataItem["value"] = m.id;
            zdataItem["pId"] = data.id;
            zdataItem["score"] = m.score;
            zdataItem["icon"] = "";
            zdataItem["name"] = m.name;
            zdataItem["children"] = addobj(m);
            zdataItem.open = false;
            zdata.push(zdataItem);
            map[m.id] = m.score;
        }
        return zdata;
    } else {
        return [];
    }
}

var map = {};

function setCheckTypeSelect(div, selectId, codeFlag, hasAll) {
    post_common_service("/constant/getConstantByFlag", { code_flag: codeFlag }, function(data) {
        var optStr = '';
        if (hasAll) optStr = '<option value="">全部</option>';
        for (var i in data) {
            if (data[i].code_value == selectId)
                optStr += '<option value="' + data[i].code_value + '" selected="selected">' + data[i].code_name + '</option>';
            else
                optStr += '<option value="' + data[i].code_value + '">' + data[i].code_name + '</option>';
        }
        $(div).html('');
        $(div).html(optStr);
    });
}




function static() {

    var type = $("#speacial_type_select").val();

    if (check_type == 8 || check_type == 9) {
        var p = {
            "check_type": check_type,
            "check_period": $("#month_date").val(),
            "special_check_type": type
        };


        post_common_service("f/checkOther/getOtherCheckStatistics", p, function(data) {

            var names = new Array();
            var totalnamesvalue = new HashMap();
            var itemsname = "";
            var datas = '';
            var t8 = 0;
            var title = "";
            if (check_type == 8) title = "服务区第三方暗访情况";
            if (check_type == 9) title = "服务区现场检查情况";
            // if (check_type == 4) title = "数据平台应用情况";
            // if (check_type == 2 && type == "1") title = "公司特情稽查情况";
            // if (check_type == 2 && type == "2") title = "联网特情稽查情况";
            for (var key in data) {
                for (var i in data[key]) {
                    itemsname = "";
                    var itemvalue = "";
                    names = new Array();
                    for (var name in data[key][i].scoremap) {
                        names.push(name);
                        itemsname += '<td style="width:78px">' + name + '</td>';
                        itemvalue += '<td>' + data[key][i].scoremap[name] + '</td>';

                        var v = totalnamesvalue.get(name);
                        if (v == null || v == undefined) v = 0;
                        v += data[key][i].scoremap[name];
                        totalnamesvalue.set(name, v);
                    }


                    datas += '<tr>';
                    if (i == 0) {
                        datas += '<td rowspan=' + data[key].length + '>' + key + "</td>";
                    }
                    datas += '<td>' + data[key][i].deptname + "</td>";
                    datas += itemvalue;
                    datas += '<td>' + data[key][i].totalScore + '</td>';
                    datas += '<td>' + data[key][i].level + '</td>';
                    datas += '</tr>';

                    t8 += data[key][i].totalScore;
                }
            }

            datas += '<tr><td colspan=2>合计</td>';
            for (var i in names) {
                datas += '<td>' + totalnamesvalue.get(names[i]) + '</td>';
            }
            datas += '<td>' + t8 + '</td><td> - </td></tr>';

            var html = ' <table class="statable">' +
                '            <thead style="font-size:  20px;text-align:  center;border:  0px;">' +
                '                <tr>' +
                '                    <td colspan="13" style="padding:  10px;border:  0px;">' + $("#month_date").val().replace("/", "-") + '月份' + title + '</td>' +
                '                </tr>' +
                '            </thead>' +
                '            <tbody>' +
                '                <tr>' +
                '                    <td style="width:40px">道管</td>' +
                '                    <td style="width:78px">服务区</td>' +
                itemsname +
                '                    <td>得分<br>（1000）</td>' +
                '                    <td>服务<br>评价</td>' +
                '                </tr>' +
                datas +
                '            </tbody>' +
                '        </table>';

            layer.open({
                area: ["800px", "500px"],
                type: 1,
                title: '统计',
                maxmin: true,
                closeBtn: 1,
                shadeClose: true,
                skin: '#fff', //没有背景色
                resize: true,
                content: "<div style='width:100%;background: #fff;text-align: center;padding:10px'>   <button class=\"btn btn-info3\" type=\"button\" style=\"    position: absolute;right: 10px;top: 17px;\" onclick=\"exportThirds()\"> 导出Excel</button>" + html + "</div>"
            });
        });
    }

    // if (check_type == 2 && type == "") {

    //     var p = {
    //         "check_type": check_type,
    //         "check_period": $("#month_date").val()
    //     };


    //     post_common_service("/f/checkOther/getOtherCheckStatistics", p, function(data) {

    //         var names = new Array();
    //         var totalnamesvalue = new HashMap();
    //         var itemsname = "";
    //         var datas = '';
    //         var t8 = 0;
    //         var t1 = 0;
    //         var t2 = 0;
    //         var t3 = 0;

    //         //key 盐城道管
    //         for (var key in data) {
    //             //i list 盐城
    //             for (var i in data[key]) {

    //                 var itemvalue = "";
    //                 //type 1
    //                 for (var j in data[key][i].scoretypemap) {
    //                     var scoremap = data[key][i].scoretypemap[j];
    //                     names = new Array();
    //                     itemsname = "";
    //                     var totalvalue = 0;
    //                     for (var name in scoremap) {
    //                         names.push(name);
    //                         itemsname += '<td style="width:78px">' + name + '</td>';
    //                         itemvalue += '<td>' + scoremap[name] + '</td>';

    //                         totalvalue += scoremap[name];

    //                         var v = totalnamesvalue.get(name + j);
    //                         if (v == null || v == undefined) v = 0;
    //                         v += scoremap[name];
    //                         totalnamesvalue.set(name + j, v);
    //                     }
    //                     itemvalue += '<td>' + totalvalue + '</td>';

    //                     if (j == "1") t2 += totalvalue;
    //                     if (j == "2") t3 += totalvalue;

    //                 }

    //                 datas += '<tr>';
    //                 if (i == 0) {
    //                     datas += '<td rowspan=' + data[key].length + '>' + key + "</td>";
    //                 }
    //                 datas += '<td>' + data[key][i].deptname + "</td>";
    //                 datas += '<td>' + data[key][i].totalcheck + "</td>";
    //                 datas += itemvalue;
    //                 datas += '<td>' + data[key][i].totalScore + '</td>';
    //                 datas += '</tr>';

    //                 t1 += data[key][i].totalcheck;
    //                 t8 += data[key][i].totalScore;
    //             }
    //         }

    //         datas += '<tr><td colspan=2>合计</td>';
    //         datas += '<td>' + t1 + '</td>';
    //         for (var i in names) {
    //             datas += '<td>' + totalnamesvalue.get(names[i] + "1") + '</td>';
    //         }
    //         datas += '<td>' + t2 + '</td>';
    //         for (var i in names) {
    //             datas += '<td>' + totalnamesvalue.get(names[i] + "2") + '</td>';
    //         }
    //         datas += '<td>' + t3 + '</td>';
    //         datas += '<td>' + t8 + '</td></tr>';

    //         var html = ' <table class="statable">' +
    //             '            <thead style="font-size:  20px;text-align:  center;border:  0px;">' +
    //             '                <tr>' +
    //             '                    <td colspan="13" style="padding:  10px;border:  0px;">' + $("#month_date").val().replace("/", "-") + '月份特情稽查情况汇总</td>' +
    //             '                </tr>' +
    //             '            </thead>' +
    //             '            <tbody>' +
    //             '                <tr>' +
    //             '<td rowspan=2>道管</td>' +
    //             '<td rowspan=2>服务区</td>' +
    //             '<td rowspan=2>存在问题特情数量</td>' +
    //             '<td colspan=' + (names.length + 1) + '>内部特情稽查存在问题数量</td>' +
    //             '<td colspan=' + (names.length + 1) + '>联网中心特情稽查存在问题数量</td>' +
    //             '<td rowspan=2>合计扣分</td>' +
    //             '                </tr>' +
    //             '                <tr>' +
    //             itemsname +
    //             '<td >合计</td>' +
    //             itemsname +
    //             '<td >合计</td>' +
    //             '                </tr>' +
    //             datas +
    //             '            </tbody>' +
    //             '        </table>';
    //         layer.open({
    //             area: ["800px", "500px"],
    //             type: 1,
    //             title: '统计',
    //             maxmin: true,
    //             closeBtn: 1,
    //             shadeClose: true,
    //             skin: '#fff', //没有背景色
    //             resize: true,
    //             content: "<div style='width:100%;background: #fff;text-align: center;padding:10px'>   <button class=\"btn btn-info3\" type=\"button\" style=\"    position: absolute;right: 10px;top: 17px;\" onclick=\"exportThirds()\"> 导出Excel</button>" + html + "</div>"
    //         });
    //     });
    // }
}