function initCheck() {
    addBreadMenu("/qzd/view/task/check.html", "服务区视频稽查");
    $('#ex1').slider({ tooltip: 'hide' });
    $("#ex1").on("slideStop", function(slideEvt) {
        setVideoProcess(slideEvt.value);
    });

    //滑动快进
    $("#ex1").on("change", function(sender) {
        var width = $("#ex1").siblings(".slider").children(".slider-track").children(".slider-selection").width();
        var total_width = $("#ex1").siblings(".slider").children(".slider-track").width();
        var sp_width = $("#ex1_span").width();


        var left = ((total_width - width) < (sp_width / 2.0)) ? (total_width - sp_width / 2.0 - 25) : (width - sp_width / 2.0) + 25
        $("#ex1_span").css("left", ((left > 25 ? left : 25)) + "px")

        if ($.checkTask) {
            var time = moment($.checkTask.start_time);
            var pos = $("#video_pos").val();
            if ($("#full_video_pos").length > 0) {
                pos = $("#full_video_pos").val();
            }
            var c_time = time.add(sender.value.newValue, "s");
            if (/^(\+|-)?\d+($|\.\d+$)/.test(pos)) {
                if (pos > 0) {
                    c_time = time.add(Math.abs(pos), "s");
                } else {
                    c_time = time.subtract(Math.abs(pos), "s");
                }
            }


            $("#ex1_span").html(c_time.format("YYYY-MM-DD HH:mm:ss"))
        }
    });



    $("#tabcontent").css("height", ($("#video_content").height() - 80) + "px");
    $("#score_datatable").css("height", ($("#video_content").height() - 120) + "px");
    //设置视屏位置
    if (ISCLIENT) {
        event = document.createEvent('MessageEvent');
        var origin = window.location.protocol + '//' + window.location.host;
        event.initMessageEvent('setvideoposition', true, true, getVideoPosition(null), origin, 1234, window, null);
        document.dispatchEvent(event);
    }




    if ($.checkTask) {
        getAreaCheckCount();
        initCheckAppealBtns();

        $("#taskName").html($.checkTask.name);
        $("#ex1_span").html($.checkTask.start_time)
        $("#full_ex1_span").html($.checkTask.start_time)

        $("#lane").val($.checkTask.checked_location);
        $("#check_time").html($.checkTask.check_period);



        //TODO 获取分数
        queryCheckScores();

        var videoids = $.checkTask.areainfo.video_ids;
        if (videoids != "") {
            queryVideoList(videoids);
        } else {
            callFunc("showvideoview", "false");
            layer.msg('该处暂无视屏！', {
                offset: 'r',
                time: 2000, //20s后自动关闭
            });
            callFunc("stop", "");
        }



    }


}

function setfastorslow(type, speed) {
    if (type == 0) {
        $("#fast_info").html("");
        $("#slow_info").html("");
        if ($("#full_fast_info")) {
            $("#full_fast_info").html("");
            $("#full_slow_info").html("");
        }
    }
    if (type == 1) {
        $("#fast_info").html(speed + "x");
        $("#slow_info").html("");
        if ($("#full_fast_info")) {
            $("#full_fast_info").html(speed + "x");
            $("#full_slow_info").html("");
        }
    }
    if (type == 2) {
        $("#slow_info").html(speed + "x");
        $("#fast_info").html("");
        if ($("#full_fast_info")) {
            $("#full_fast_info").html("");
            $("#full_slow_info").html(speed + "x");
        }
    }

}

function normalscreen() {
    if (layer_full) {
        layer.close(layer_full)
        $("#video_pos").val($("#full_video_pos").val());
    }

}
var layer_full = null;

function fullscreen() {
    var height = window.innerWidth * 0.8 * 1 / 2.0 + 110

    var contenthtml = ' <div class="tab-content" id="full_tabcontent" style="height:400px;text-align: center;background:black;">' +
        '                                    <p style="padding-top:180px;font-size:20px">加载中...</p>' +
        '                                    <!--<i class="icon icon-spin icon-spinner  icon-5x" style="margin-top:100px"></i>-->' +
        '                                </div>' +
        '                                <div class="row" class="col-md-12" style="padding:5px 10px 25px 10px;text-align:center;margin:0px">' +
        '                                    <input id="full_ex1" class="col-md-12" type="text" data-slider-min="0" data-slider-max="100" data-slider-step="1" data-slider-value="0"/>' +
        '                                   <br/> <span id="full_ex1_span" style="position: absolute;left: 25px;">2017-06-12 23:00:00</span>' +
        '                                    ' +
        '                                </div>' +
        '                                <div class="row" style="padding:0px 5px 0px 5px;text-align:center;margin:0px">' +
        '                                    <select class="form-control" id="full_video_list" style="width:200px;float:left;display:none;"></select>' +
        '                                      <div class="col-md-4 " style="padding-left:0">' +
        '                                                                      <div class="input-group" style="padding-left:0">' +
        '                                                                          <input type="text" id="full_video_pos" style="height:42px" class="form-control" placeholder="时间偏移值">' +
        '                                                                         <span class="input-group-btn">' +
        '                                                                              <button class="btn btn-default" onclick="setVideoPos()" style="height:42px" type="button">校正</button>' +
        '                                                                          </span>' +
        '                                                                      </div>' +
        '                                                                     </div>' +
        '                                    <div class="btn-group1" style="float:right;">' +
        '                                        <button type="button" class="btn btn-info1" style="width:41px;height:41px" onclick="doAction(\'start\')"><i class="icon icon-play-circle icon-2x"></i></button>' +
        '                                        <button type="button" class="btn btn-info1" style="width:41px;height:41px" onclick="doAction(\'stop\')"><i class="icon icon-pause icon-2x"></i></button>' +
        '                                        <button type="button" class="btn btn-info1" style="width:41px;height:41px" onclick="doAction(\'fast\')"><i class="icon icon-forward icon-2x"></i><span id=\"full_fast_info\"></span></button>' +
        '                                        <button type="button" class="btn btn-info1" style="width:41px;height:41px" onclick="doAction(\'slow\')"><span id=\"full_slow_info\"></span><i class="icon icon-backward icon-2x"></i></button>' +
        '                                        <button type="button" class="btn btn-info1" style="width:41px;height:41px" style="width:51px;height:42px" id="full_video_btn_start" onclick="doAction(\'video_start\')"><img id="full_video_btn_start_img" style="width:30px" src="/images/video.png"></img></i></button>' +
        '                                        <button type="button" class="btn btn-info1 hidden" style="width:41px;height:41px" id="full_video_btn_stop" onclick="doAction(\'video_stop\')"><i class="icon icon-stop icon-2x"></i></button>' +
        '                                        <button type="button" class="btn btn-info1" style="width:41px;height:41px" onclick="doAction(\'screenshot\')"><i class="icon icon-camera icon-2x"></i></button>' +
        '                                    </div>' +
        '                                </div>';


    layer_full = layer.open({
        area: ['80%', height + "px"],
        type: 1,
        title: false,
        anim: -1,
        closeBtn: 0,
        shadeClose: false,
        content: "<div id='layer_content' style='padding-bottom:10px' >" + contenthtml + "</div>",
        success: function(layero, index) {

            // slider_current_value = 90;
            $("#full_video_pos").val($("#video_pos").val());

            $('#full_ex1').slider({ tooltip: 'hide' });
            $("#full_ex1").on("slideStop", function(slideEvt) {
                setVideoProcess(slideEvt.value);
            });

            $("#full_video_btn_start").mouseover(function() {
                $("#full_video_btn_start_img").attr("src", "/images/movie.png");
            });
            $("#full_video_btn_start").mouseout(function() {
                $("#full_video_btn_start_img").attr("src", "/images/video.png");
            });

            $("#full_ex1").on("change", function(sender) {
                var width = $("#full_ex1").siblings(".slider").children(".slider-track").children(".slider-selection").width();
                var total_width = $("#full_ex1").siblings(".slider").children(".slider-track").width();

                var sp_width = $("#full_ex1_span").width();


                var left = ((total_width - width) < (sp_width / 2.0)) ? (total_width - sp_width + 10) : (width - sp_width / 2.0) + 10
                $("#full_ex1_span").css("left", ((left > 0 ? left : 10)) + "px")

                if ($.checkTask) {
                    var time = moment($.checkTask.start_time);
                    var pos = $("#video_pos").val();
                    if ($("#full_video_pos").length > 0) {
                        pos = $("#full_video_pos").val();
                    }
                    var c_time = time.add(sender.value.newValue, "s");
                    if (/^(\+|-)?\d+($|\.\d+$)/.test(pos)) {
                        if (pos > 0) {
                            c_time = time.add(Math.abs(pos), "s");
                        } else {
                            c_time = time.subtract(Math.abs(pos), "s");
                        }
                    }



                    $("#full_ex1_span").html(c_time.format("YYYY-MM-DD HH:mm:ss"))
                }
            });

            $("#full_ex1").slider({ step: 5, min: 0, max: maxVV });

            $("#full_ex1").slider('setValue', slider_current_value);



            $("#full_fast_info").html($("#fast_info").html());
            $("#full_slow_info").html($("#slow_info").html());


            $("#full_tabcontent").css("height", (height - 110) + "px");
            $("#full_tabcontent").css("width", "100%");
            setTimeout(function() {
                callFunc("setvideoposition", getVideoPosition($("#full_tabcontent")))
            }, 800)

        }
    });

}

function getAreaCheckCount() {
    var index = layer.load(1, {
        shade: [0.1, '#fff'] //0.1透明度的白色背景
    });
    var param = {
        "period_id": $.checkTask.period_id,
        "area_id": $.checkTask.area_id
    };
    post_common_service("/f/task/getall/0/0", param, function(userList) {
        var param = {
            "id": $.checkTask.area_id
        };
        post_common_service("/f/area/getall", param, function(data) {
            layer.closeAll('loading');
            $.checkTask.areainfo = data.areas[0];
            $("#checked_area").html(data.areas[0].name);
            if (userList) {
                $("#checked_count").html(userList.length);
            } else {
                $("#checked_count").html(0);
            }
        });

    });
}



//显示考核次数
function showCheckDetailCount() {
    scoreDetailLayer = showPopup4Common('本周期已考核任务', null, ['450px', '350px'], '#checked_task_list_div', 'r', '确定');
    var param = {
        "period_id": $.checkTask.period_id,
        "area_id": $.checkTask.area_id
    };

    var cols = [
        { width: 40, text: '序号', type: 'number', flex: true, colClass: 'text-center', field: 'num' },
        { width: 80, text: '任务名称', type: 'string', flex: true, sort: 'down', field: 'name' },
        { width: 50, text: '考核区域', type: 'href_link', flex: true, colClass: '', field: $.checkTask.areainfo.name },
        { width: 80, text: '扣分情况', type: 'string', flex: true, sort: 'down', field: 'score_details' },
        { width: 70, text: '稽查时间段', type: 'string', flex: true, sort: 'down', field: 'check_period' }
    ];
    $('#checked_user_task_datatable').mytable({
        'cols': cols,
        'url': "/f/task/getall/",
        'param': param,
        'isShoWPager': false
    });
}

function initCheckAppealBtns() {
    if ($.checkTask.appeal) {
        $("#btn_appeal_task").show();
        $("#btn_task").hide();
        // $("#appeal_div").show();
        $("#appeal_time").html($.checkTask.appeal.appeal_time);
        $("#appeal_reason").html($.checkTask.appeal.appeal_reason);
        $("#appeal_file_list").html(genAppeaFiles($.checkTask.appeal.file_src));
        $("#recheck_result").html($.checkTask.appeal.recheck_result);
        showAppealLayer();
    } else {
        // $("#appeal_div").hide();
        $("#btn_appeal_task").hide();
        $("#btn_task").show();
    }
}

function showAppealLayer() {
    layer.open({
        type: 1,
        area: ['400px', "400px"],
        title: "申诉详情",
        closeBtn: 1,
        shade: false,
        maxmin: false,
        shadeClose: true,
        offset: 'rb',
        content: $('#appeal_div'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        cancel: function(index) {
            layer.close(index);
            layer.open({
                type: 1,
                title: "",
                closeBtn: 0,
                shade: false,
                maxmin: false,
                shadeClose: true,
                content: $('#hide_div'),
                offset: 'rb',
                btn: ['申诉详情'],
                yes: function(index) {
                    layer.close(index);
                    showAppealLayer();
                }
            });
            return false;
        }
    });
}
// 使用data参数更新数据：
function queryCheckScores() {
    //$('#score_datatable').score_datatable("");
    // console.log("任务id：" + $.checkTask.id);
    var data = {
            "task_id": $.checkTask.id
        }
        // alert("ff");
    var cols = [
        { width: 40, text: '序号', type: 'number', flex: true, colClass: 'text-center', field: 'num' },
        { width: 100, text: '评分记录', type: 'string', flex: true, sort: 'down', field: 'content' },
        { width: 40, text: '分数', type: 'string', flex: true, colClass: '', field: 'check_item_score' },
        { width: 100, text: '备注', type: 'string', flex: true, colClass: '', field: 'remark' },

        // {width: 80, text: '图片', type: 'imagedd', flex: true, colClass: '',field: 'pics'},
        // {
        //     width: 150,
        //     text: '操作',
        //     type: 'string',
        //     flex: true,
        //     field: 'id',
        //     oper: [
        //         { func: 'showEditCheckScore', text: '修改', icon_class: 'icon-edit' },
        //         { func: 'showEditPic', text: '图片', icon_class: 'icon-edit' },
        //         { func: 'deleteCheckScore', text: '删除', icon_class: 'icon-remove-circle' }
        //     ]
        // }
    ];

    var colFunc = { width: 170, text: '操作', type: 'string', flex: true, field: 'id' };
    colFunc.oper = [
        { func: 'showEditCheckScore', text: '修改', icon_class: 'icon-edit' },
        { func: 'showEditPic', text: '图片', icon_class: 'icon-edit' }
    ];
    if ($.checkTask.appeal) {
        colFunc.oper.push({ func: 'backoutCheckScore', text: '撤销', icon_class: 'icon-reply' });
    } else {
        colFunc.oper.push({ func: 'deleteCheckScore', text: '删除', icon_class: 'icon-remove-circle' });
    }
    cols.push(colFunc);

    // var pager = {
    //     page_size:10
    // }
    $('#score_datatable').mytable({
        'cols': cols,
        'url': "/f/score/getScoreList/",
        'param': data
    });
}

function showEditPic(id) {
    var rowData = getItemByIdFromArr(id, $('#score_datatable').mytable('getTableData'));
    showPics(rowData.pics);
    $("#saveEditBtn").show();
    editScoreId = id;
}

function showEditCheckScore(id) {
    // deleteItem4Common(id,"/score/delete/",queryCheckScores);
    var rowData = getItemByIdFromArr(id, $('#score_datatable').mytable('getTableData'));
    scoreDetailLayer = showPopup4Common('修改考核项', function(data) {
        saveScoreEdit();
    }, ['350px', '550px'], '#score-detail-div', 'r');

    $("#score_id_text").val(rowData.id);
    $("#check_item_text").val(rowData.content);
    $("#check_score_text").val(rowData.check_item_score);
    // setFeeUserSelect("#check_checked_person_select", rowData.checked_person);
    // $("#check_checked_person_select").val(rowData.checked_person);
    $("#check_remark_text").tagsInput({ 'defaultText': '添加备注', 'width': '240px' });
    $("#check_remark_text").importTags('');
    $("#check_remark_text").addTag(rowData.remark);
    getTags("/f/score/getTopRemark", '#score_remark_div', '#check_remark_text', 'remark');
}

function setFeeUserSelect(div, selectId) {
    var param = {
        'organid': $.checkTask.checked_dept
    };
    post_common_service("/user/getUserList/", param, function(userList) {
        // setFeeUserSelect("#check_checked_person_select",rowData.checked_person,data);
        var optStr = '';
        for (var i in userList) {
            if (userList[i].id == selectId)
                optStr += '<option value="' + userList[i].id + '" selected="selected">' + userList[i].truename + '</option>';
            else
                optStr += '<option value="' + userList[i].id + '">' + userList[i].truename + '</option>';
        }
        $(div).html('');
        $(div).html(optStr);

        $('#check_checked_person_select').chosen({
            // width:'200px',
            height: '100px',
            no_results_text: '没有找到', // 当检索时没有找到匹配项时显示的提示文本
            disable_search_threshold: 10, // 10 个以下的选择项则不显示检索框
            search_contains: true // 从任意位置开始检索
        });
    });

}

function saveScoreEdit() {
    var param = {
        'id': $("#score_id_text").val(),
        'content': $("#check_item_text").val(),
        'check_item_score': $("#check_score_text").val(),
        'remark': $("#check_remark_text").val(),
        'checked_person': $("#check_checked_person_select").val(),
    };
    editScoreId = null;
    $("#saveEditBtn").hide();
    no_return_common_service("/f/score/update", param, function(data) {
        if (scoreLayer) layer.close(scoreLayer);
        //查询评分情况
        queryCheckScores();
        // layer.msg(data, {
        //     time: 2000//20s后自动关闭
        // });
    });
}
var editScoreId;

function saveEdit() {
    if (editScoreId) {
        var imgArr = $("#img_container .pic-class");
        var picsStr = "";
        if (imgArr && imgArr.length > 0) {
            for (var i = 0; i < imgArr.length; i++) {
                picsStr += imgArr[i].attributes.getNamedItem("path").textContent + ","
            }
            picsStr = picsStr.substr(0, picsStr.length - 1);
        }
        var param = {
            'id': editScoreId,
            'pics': picsStr
        };
        editScoreId = null;
        $("#saveEditBtn").hide();
        no_return_common_service("/f/score/update", param, function(data) {
            if (scoreLayer) layer.close(scoreLayer);
            //查询评分情况
            queryCheckScores();
            layer.msg(data, {
                offset: 'r',
                time: 2000 //20s后自动关闭
            });
        });
    }
}

function deleteCheckScore(id) {
    deleteItem4Common(id, "/f/score/delete/", queryCheckScores, 'r');
}

function backoutCheckScore(id) {
    layer.confirm('是否要撤销扣分？', {
        btn: ['是', '否'], //按钮
        shadeClose: true,
        shade: 0, //不显示遮罩
        offset: 'r'
    }, function() {
        var param = {
            "id": id,
            "check_item_score": 0
        };
        post_common_service("/f/score/backoutScore/", param, function(data) {
            layer.msg('撤销成功！', {
                offset: 'r',
                time: 2000, //20s后自动关闭
            });
            queryCheckScores();
        });
    }, function() {

    });
}

function setVideoList(videos) {
    var videoArr;
    if (videos) {
        videoArr = videos.split("|");
        var selectStr = "";
        for (var i in videoArr) {
            if (i == 0)
                selectStr += '<option value="' + videoArr[i] + '" selected="selected">视频' + (videoArr[i] + 1) + '</option>'
            else
                selectStr += '<option value="' + videoArr[i] + '">视频' + (videoArr[i] + 1) + '</option>';
        }
    }
    $('#video_list').html(selectStr);
}

function addPic(pic) {
    if (pic) {
        var i = 0;
        // var imgArr = $("#img_container .pic-class");
        // if(imgArr && imgArr.length>0) i = imgArr.length;

        if (pic.startWith("http"))
            pic = pic.replace(base_image_server_url, "/");

        var picStr = genPicstr(pic);
        $('#img_container').append(picStr);
        $('a.lightbox-toggle').lightbox();
    }
}

function showPics(pics, divId) {
    var picStr = '';
    if (!divId) divId = '#img_container';
    $(divId).html(picStr);
    if (pics) {
        var picArr = pics.split(',');
        for (var i in picArr) {
            var pic = genPicstr(picArr[i]);
            picStr += pic;
        }
        $(divId).html(picStr);
        $('a.lightbox-toggle').lightbox();
    }
}

function genPicstr(imgSrc) {
    var src = imgSrc;
    if (!src.startWith("http"))
        src = base_image_server_url + src;

    var ispic = true;
    var videosrc = src;
    if (src.indexOf('.avi') != -1) {
        src = src.split('.avi')[0] + "_screen_0.png"
        ispic = false;
    }
    if (src.indexOf('.mov') != -1) {
        src = src.split('.mov')[0] + "_screen_0.png"
        ispic = false;
    }
    if (src.indexOf('.mp4') != -1) {
        src = src.split('.mp4')[0] + "_screen_0.png"
        ispic = false;
    }

    var pic = '<div class="img_item" style="width:100px;height:90px;float:left;">' +
        '<a href="javascript:void(0)" onclick="removeImg(this)" style="float:right;position:relative;z-index:100;"><span class="label label-danger"><i class="icon icon-remove-circle"></i> 删除</span></a>' +
        (ispic ? '<a class="card lightbox-toggle" data-group="image-group-1" data-lightbox-group="example-3" href="' + src + '" style="position:absolute">' : '<a class="card" onclick="video_paly(\'' + videosrc + '\')" href="javascript:void(0)" style="position:absolute">') +
        '<img class="pic-class img-thumbnail" path="' + imgSrc + '" style="width:100px;height:70px;" src="' + src + '" alt="">' + (ispic ? '' : '<i class="icon icon-play-circle" style=" font-size: 30px;position: absolute;top: 20px;left: 40px;color: white;"></i>') +
        '</a>' +
        '</div>';
    if (ISCLIENT) {
        pic = '<div class="img_item" style="width:100px;height:90px;float:left;">' +
            '<a href="javascript:void(0)" onclick="removeImg(this)" style="float:right;position:relative;z-index:100;"><span class="label label-danger"><i class="icon icon-remove-circle"></i> 删除</span></a>' +
            '<a class="card" onclick="' + (ispic ? 'showClientImg(\'' + src + '\')' : 'showClientVideo(\'' + videosrc + '\')') + '" href="javascript:void(0)" style="position:absolute">' +
            '<img class="pic-class img-thumbnail" path="' + imgSrc + '" style="width:100px;height:70px;" src="' + src + '" alt="">' + (ispic ? '' : '<i class="icon icon-play-circle" style=" font-size: 30px;position: absolute;top: 20px;left: 40px;color: white;"></i>') +
            '</a>' +
            '</div>';
    }
    return pic;
}


function removeImg(this1) {
    $(this1).parent('.img_item').remove();
}

function clearAllImg() {
    $('#img_container').empty();
}
var changePersonLayer;




function checkHasScore(id, old_person) {
    var param = {
        "task_id": $.checkTask.id,
        "checked_person": old_person
    };
    post_common_service("/score/getScoreList/1/10", param, function(data) {
        if (data.list && data.list.length > 0) {
            layer.confirm('是否要同步更改扣分人？', {
                btn: ['是', '否'], //按钮
                shadeClose: true,
                shade: 0, //不显示遮罩
                offset: 'r'
            }, function() {
                var param = {
                    "task_id": $.checkTask.id,
                    "checked_person": old_person,
                    "new_checked_person": id
                };
                post_common_service("/score/updateByTaskIdAndPerson/", param, function(data) {
                    layer.msg('更改成功！', {
                        offset: 'r',
                        time: 2000, //20s后自动关闭
                    });
                    queryCheckScores();
                });
            }, function() {

            });
        }
    });
}





function changePersonContent(data) {
    resetUserImgInfo();
    var name = data.truename;
    if (data.workno) name = data.workno + " " + data.truename;
    $("#checked_person").html(name);
    var imgSrc = base_image_server_url + data.pic;
    $("#person_img > img").attr("src", imgSrc);
    if (ISCLIENT) {
        $("#person_img").attr("href", "javascript:void(0)");
        $("#person_img").removeClass("lightbox-toggle");
        $("#person_img").click(function() {
            showClientImg(imgSrc);
        });
        $("#person_img > img").attr("src", imgSrc);
        return;
    } else {
        $("#person_img").attr("href", imgSrc);
        $('a.lightbox-toggle').lightbox();
    }
    getUserCheckCount();
}
var scoreLayer;

function showScore() {
    scoreLayer = showPopup4Common('选择考核项', null, ['400px', '500px'], '#items-div', 'r');
    buildTree();
}

function buildTree() {
    var zTreeObj;
    var zNodes = [];
    check_item_tree = $.fn.zTree.init($("#items_tree"), {}, zNodes);
    getCheckItems();
}

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

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


    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: {
            onDblClick: 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": 10 };

    post_common_service('checkRule/getItemListByRuleType', param, function(data) {
        // console.log(data);
        zdata = [];
        for (var i = 0; i < data.length; i++) {
            var m = data[i];
            zdata.push(genNode(m));
        }
        // console.log(zdata);
        menu_tree = $.fn.zTree.init($("#items_tree"), setting, zdata)
    }, function(error) {

    });
}

function addobj_checkitem(data) {
    // console.log(data.subCheckItem);
    var zdata = [];
    if (typeof(data.subCheckItem) != "undefined" && data.subCheckItem != null &&
        data.subCheckItem.length > 0) {
        for (var i = 0; i < data.subCheckItem.length; i++) {
            var m = data.subCheckItem[i];
            zdata.push(genNode(m));
        }
        return zdata;
    } else {
        return [];
    }
}

function genNode(m) {
    var zdataItem = {};
    zdataItem["id"] = m.id;
    zdataItem["value"] = m.name;
    zdataItem["pId"] = m.parent_id;
    zdataItem["score"] = m.score;
    zdataItem["icon"] = "";
    zdataItem["name"] = m.name;
    //zdataItem["content"] = m.name;
    if (m.score) zdataItem["name"] = m.name + '(' + m.score + ')';
    zdataItem["open"] = true;
    // console.log(m.subCheckItem);
    zdataItem["children"] = addobj_checkitem(m);
    return zdataItem;
}

function zTreeOnClick(event, treeId, treeNode) {
    var imgArr = $("#img_container .pic-class");
    var picsStr = "";
    if (imgArr && imgArr.length > 0) {
        for (var i = 0; i < imgArr.length; i++) {
            picsStr += $(imgArr[i]).attr("path") + ","
        }
        picsStr = picsStr.substr(0, picsStr.length - 1);
    }
    var param = {
        'task_id': $.checkTask.id,
        'pics': picsStr,
        'name': treeNode.value,
        'check_item_score': treeNode.score,
        'content': treeNode.value,
        'check_item_id': treeNode.id,
        'checkman': $.checkTask.checkman,
        'checked_area': $.checkTask.area_id,
        'checked_dept': $.checkTask.checked_dept
    };
    no_return_common_service("/f/score/add", param, function(data) {
        if (scoreLayer) layer.close(scoreLayer);
        clearAllImg();
        //查询评分情况
        queryCheckScores();
        layer.msg(data, {
            offset: 'r',
            time: 2000 //20s后自动关闭
        });
    });

}

function submitCheck() {
    var param = {
        "id": $.checkTask.id,
        "check_status": 4
    }
    no_return_common_service("/f/task/update/", param, function(data) {
        layer.msg("提交成功", {
            offset: 'r',
            time: 2000 //20s后自动关闭
        });
        redirectLastPage();
    });

}

function showPre(id) {
    // $('#myModal').modal({name:"dd"});
    //预览提交把任务状态改为待提交
    no_return_common_service('/f/task/update', { "id": $.checkTask.id, "check_status": 7 })
    changePage("/qzd/view/task/taskDetail.html");
}

var isappeal = false;

function appeal_showInvalid() {
    isappeal = true;
    showInvalidView();
}

function showInvalid() {
    isappeal = false;
    showInvalidView();
}

function showInvalidView() {
    invalidLayer = showPopup4Common('申请无效', function() {
        saveValidReason();
    }, ['400px', '500px'], '#invalid_div', 'r');

    $('#apply_reason').tagsInput({ 'defaultText': '添加原因' });
    getTags("/f/checkApply/getTopReason", "#top_reason_div", '#apply_reason', 'apply_reason');
}



function submitCheck4AppealDirect() {
    var appeal_result = 1;
    //询问框
    layer.confirm('该申诉是否成功？', {
        offset: 'r',
        btn: ['成功', '失败'], //按钮
        // shadeClose: true,
        shade: 0 //不显示遮罩
    }, function() {
        appeal_result = 1;
        submitCheck4AppealResult(appeal_result);
    }, function() {
        appeal_result = 2;
        submitCheck4AppealResult(appeal_result);
    });


}

function submitCheck4AppealResult(appeal_result) {
    var param = {
        "id": $.checkTask.id,
        "check_status": 14,
        "appeal_id": $.checkTask.appeal.id,
        "appeal_result": appeal_result
    }
    no_return_common_service("/f/task/update/", param, function(data) {
        layer.msg("提交成功", {
            offset: 'r',
            time: 2000 //20s后自动关闭
        });
        redirectLastPage();
    });
}

function showPre4Appeal(id) {
    // $('#myModal').modal({name:"dd"});
    //预览提交把任务状态改为待提交
    no_return_common_service('/f/task/update', { "id": $.checkTask.id, "check_status": 17 })
    changePage("/qzd/view/task/taskDetail.html");
}

function saveValidReason() {
    var param = {
        "task_id": $.checkTask.id,
        "apply_reason": $('#apply_reason').val(),
        "isappeal": isappeal
    };


    no_return_common_service("/f/checkApply/add/", param, function(data) {
        layer.msg("申请提交成功", {
            offset: 'r',
            time: 2000 //20s后自动关闭
        });
        redirectLastPage();
    });
}


function score(score) {
    alert("扣分：" + score);
    $('#scoreWin').modal('toggle');
}

function refuseApply() {
    alert("拒绝申请");
    $('#refuseApplyWin').modal('toggle');
}

function agreeApply() {
    alert("同意申请");
}


function getVideoPosition(obj) {
    if (obj == null) obj = $('#tabcontent');
    var X = obj.offset().top;
    var Y = obj.offset().left;
    var width = obj.width();
    var height = obj.height();
    return parseInt(Y) + "|" + parseInt(X) + "|" + parseInt(width) + "|" + parseInt(height);
}

function initUpLoad() {

    var uploader = WebUploader.create({

        // swf文件路径
        swf: 'lib/webuploader/js/Uploader.swf',

        // 文件接收服务端。
        server: base_image_server_url + '/filesSrver/' + FILE_UPLOAD,

        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#picker',

        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
        resize: false
    });
}

function saveRecheckResult() {
    var param = {
        "id": $.checkTask.appeal.id,
        "recheck_result": $("#recheck_result").val()
    }
    post_common_service("/f/checkAppeal/update", param, function(data) {
        layer.msg("保存成功", {
            offset: 'r',
            time: 2000 //20s后自动关闭
        });
        $.checkTask.appeal = data;
    });
}

function addTag(text, tagDiv) {
    if (!$(tagDiv).tagExist(text)) {
        $(tagDiv).addTag(text);
    }
}

// function getTags(){
//     post_common_service("/checkApply/getTopReason", null, function(data) {
//         if(data){
//             var str="";
//             for(var i=0;i<data.length;i++){
//                 str+='<a href="javascript:void(0)" onclick="addTag(\''+data[i].apply_reason+'\')" style="float:left;margin:5px;"><span class="label label-success" style="padding:5px;">'+data[i].apply_reason+'</span></a>';
//             }
//             $("#top_reason_div").html(str);
//         }
//     });
// }