
    function initApplyPage(){
        // 仅选择日期
        $("#start_time").datetimepicker(
        {
            language:  "zh-CN",
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: "yyyy-mm-dd"
        });
        // 仅选择日期
        $("#end_time").datetimepicker(
        {
            language:  "zh-CN",
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: "yyyy-mm-dd"
        });
        setFeSelect("#fsList");
        //获取页面参数
        var page_params = $.zui.store.get("page_params");
        if(page_params && page_params.status) {
            cur_status = page_params.status;
        }
        if(cur_status==21){
            $("#agreePatchBtn").show();
        }
        queryUnexaminedTask();
    }
//初始化表行按钮
function initTableRowBtn() {
    $.zui.store.set("task_table_btn_21_"+ROLE_JICHA_ADMIN,[{func:'showCheck',text:'复查',icon_class:'icon-eye-open'},
                                                            {func:'showApplyDetail',text:'处理',icon_class:'icon-eye-open'}
                                                            ]);
    $.zui.store.set("task_table_btn_21_"+ROLE_JICHA,[{func:'showApplyDetail1',text:'详情',icon_class:'icon-eye-open'}]);
    $.zui.store.set("task_table_btn_22",[{func:'showApplyDetail1',text:'详情',icon_class:'icon-tasks'}]);
    $.zui.store.set("task_table_btn_23",[{func:'showApplyDetail1',text:'详情',icon_class:'icon-tasks'}]);
}

function queryUnexaminedTask(){
    initTableRowBtn();
    var start_time = "";
    if($("#start_time").val()) start_time = $("#start_time").val()+" 00:00:00";
    var end_time = "";
    if($("#end_time").val()) end_time = $("#end_time").val()+" 23:59:59"; 
    var data = {
        "start_time": start_time,
        "end_time": end_time,
        "checked_dept": $("#fsList").val(),
        "check_status":cur_status
    }
    var hide = false;
    if(hasRole(ROLE_STATION_ADMIN) || hasRole(ROLE_STATION) ||  hasRole(ROLE_JICHA)|| roleContains('STATION')) {
        hide = true;
    }
    var cols = [
                {width: 80, text: '序号', type: 'number', flex: true, colClass: 'text-center',field: 'num'},
                {width: 160, text: '任务名称', type: 'string', flex: true, sort: 'down',field: 'name'},
                {width: 80, text: '考核人员', type: 'string', flex: true, colClass: '',field: 'checked_person_name'},
                {width: 160, text: '考核部门', type: 'string', flex: true, sort: 'down',field: 'checked_dept_name'},
                {width: 80, text: '稽查人员', type: 'string', flex: true, hide:hide,field: 'checkman_name'},
                {width: 160, text: '稽查时间段', type: 'string', flex: true, sort: 'down',field: 'check_period'}
                // {width: 120, text: '状态', type: 'string', flex: true, colClass: '',field: 'check_status_name'},
                // {width: 100, text: '操作', type: 'string', flex: true, field: 'id',
                //     oper:[
                //         {func:'showApplyDetail',text:'处理',icon_class:'icon-hand-up'}
                //     ]
                // }
            ];
    var colFunc = {width: 120, text: '操作', type: 'string', flex: true, field: 'id'};  
    if(cur_status==21){
        if(hasRole(ROLE_JICHA)){
            colFunc.oper = $.zui.store.get("task_table_btn_"+cur_status+"_"+ROLE_JICHA);   
        }else if(ROLE_JICHA_ADMIN){
            colFunc.oper = $.zui.store.get("task_table_btn_"+cur_status+"_"+ROLE_JICHA_ADMIN);  
        }
    }else{
        colFunc.oper = $.zui.store.get("task_table_btn_"+cur_status);
    }
    console.log(colFunc.oper);
    cols.push(colFunc);
    var checkable = false;
    if(cur_status==21){
        checkable = true;
    }
    $('#unexamined_datatable').mytable({'cols':cols,
                            'checkable':checkable,
                            'url':"/task/getTaskList/",
                            'param':data}
                            );
}
//进入稽查页面
function showCheck(id){
    $.checkTask =getItemByIdFromArr(id,$('#unexamined_datatable').mytable('getTableData'));
    $.checkTask.appeal = null;
    //开始稽查
    no_return_common_service('/task/update', {"id":$.checkTask.id,"check_status":21,"record_status":1,"check_status_name":"复查"});
    changePage("/view/mytask/check.html");
}

function showApplyDetail1(id){
    layer.open({
        type: 1,
        area: ['400px','500px'],
        title: '申请处理',
        closeBtn: 1,
        shadeClose: true,
        skin: 'layui-layer-lan',
        content: $('#apply_detail_div'),
        btn: ['关闭'],
        btnAlign: 'c', //按钮居中
        shade: 0 ,//不显示遮罩
        yes: function(index){
            layer.close(index);
        }
    });
    var param = {
        'id':id
    };
    $('#apply_man').val("");
    $('#apply_time').val("");
    $('#apply_reason').val("");
    $('#apply_id').val("");   
    post_common_service('/checkApply/getByTaskId', param, function(data) {
        $('#apply_man').val(data.apply_man_name);
        $('#apply_time').val(data.apply_time);
        $('#apply_reason').val(data.apply_reason);
        $('#apply_id').val(data.id);        
    });
}

function showApplyDetail(id){
    layer.open({
        type: 1,
        area: ['400px','500px'],
        title: '申请处理',
        closeBtn: 1,
        shadeClose: true,
        skin: 'layui-layer-lan',
        content: $('#apply_detail_div'),
        btn: ['同意', '拒绝'],
        btnAlign: 'c', //按钮居中
        shade: 0 ,//不显示遮罩
        yes: function(index){
            aggreeApply(id);
            layer.close(index);
        },
        btn2: function(index){
            refuseApply(id)
            layer.close(index);
        }
    });
    var param = {
        'id':id
    };
    $('#apply_man').val("");
    $('#apply_time').val("");
    $('#apply_reason').val("");
    $('#apply_id').val("");  
    post_common_service('/checkApply/getByTaskId', param, function(data) {
        $('#apply_man').val(data.apply_man_name);
        $('#apply_time').val(data.apply_time);
        $('#apply_reason').val(data.apply_reason);
        $('#apply_id').val(data.id);        
    });
}
function aggreeApply(taskId){
    var param = {
        'id':$('#apply_id').val(),
        'task_id':taskId
    };
    addOrUpdateItem4Common(param,'/checkApply/agree',queryUnexaminedTask);
}

function refuseApply(taskId){
     var param = {
        'id':$('#apply_id').val(),
        'task_id':taskId
    };
    addOrUpdateItem4Common(param,'/checkApply/refuse',queryUnexaminedTask);
}

function agreeApplyTaskPatch(){
    var param = {
        'apply_ids':$('#unexamined_datatable').mytable('getTableCheckedIds')
    };
    addOrUpdateItem4Common(param,'/checkApply/agreePatch',queryUnexaminedTask);
}