var cur_status;
function initAppealPage() {
    initQueryParams();
    initTableRowBtn();
    queryAppeal();
}
function initQueryParams() {
    // 仅选择日期
    $("#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;
    }
}
//初始化表行按钮
function initTableRowBtn() {
    $.zui.store.set("task_table_btn_11",[{func:'seeCheckAudit',text:'处理',icon_class:'icon-tasks'}]);
    $.zui.store.set("task_table_btn_12",[{func:'showCheck',text:'开始稽查',icon_class:'icon-eye-open'}]);
    $.zui.store.set("task_table_btn_13",[{func:'showCheck',text:'开始稽查',icon_class:'icon-eye-open'}]);
    $.zui.store.set("task_table_btn_17",[{func:'showContinueCheck',text:'继续稽查',icon_class:'icon-eye-open'}]);
    $.zui.store.set("task_table_btn_14",[{func:'seeCheckAudit',text:'详情',icon_class:'icon-tasks'},
                                        {func:'dispatchAppealTaskById',text:'下发',icon_class:'icon-signin'}]);
    // $.zui.store.set("task_table_btn_14",[{func:'showTaskDetail',text:'详情',icon_class:'icon-tasks'}]);
    $.zui.store.set("task_table_btn_15",[{func:'seeCheckAudit',text:'详情',icon_class:'icon-tasks'}]);
    $.zui.store.set("task_table_btn_16",[{func:'seeCheckAudit',text:'详情',icon_class:'icon-tasks'}]);
}

function initAppealList() {
    queryTable();   
}

function queryAppeal(){
    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: 30, text: '序号', flex: true, colClass: 'text-center',field:'num'},
            {width: 100, text: '任务名称', flex: true,colClass: '',field:'name'},
            {width: 80, text: '申诉人员',  flex: true, colClass: '',field:'checked_person_name'},
            {width: 100, text: '申诉部门',  flex: true, colClass: '',sort: 'down',field:'checked_dept_name'},
            {width: 80, text: '稽查人员', type: 'string', flex: true, hide:hide,field:'checkman_name'},
            {width: 80, text: '复核人员', type: 'string', flex: true, hide:hide,field:'recheckman_name'},
            {width: 120, text: '稽查时间段', type: 'string', flex: true, colClass: '',field:'check_period'},
            // {width: 80, text: '状态', type: 'string', flex: true, colClass: '',field:'check_status_name'},
        ];
    var colFunc = {width: 120, text: '操作', type: 'string', flex: true, field: 'id'};   
    colFunc.oper = $.zui.store.get("task_table_btn_"+cur_status);
    cols.push(colFunc);
    if(cur_status==12 || cur_status==13){
        data.check_status_arr = [12,13];
    }
    $('.datatable').mytable({'cols':cols,
                            'url':"/checkAppeal/getTaskList",
                            'param':data}
                            );
    }
//查看稽查结果
function seeCheckAudit(id,task_id){
    // alert("task_id:"+task_id+"---id:"+id)
    // function showTaskDetail1(id){
    var rowData=getItemByIdFromArr(id,$('.datatable').mytable('getTableData'));
    post_common_service("/checkAppeal/getByTaskId", {"task_id":rowData.id}, function(data){
        $.checkTask = rowData;
        $.checkTask.appeal = data;
        console.log("申诉："+$.checkTask.appeal.id);
        changePage("/view/mytask/taskDetail.html");
    });
// }
}
//再分配
function distributionAgain(id,task_id){
    alert("task_id:"+task_id+"---id:"+id)
}

//详情
function seeDetail(id,task_id){
    alert("task_id:"+task_id+"---id:"+id)
}

function queryUnAssignedTable(){
        var data = {
            "start_time": $("#start_time").val(),
            "end_time": $("#end_time").val(),
            "checked_dept": $("#dept_select").val(),
        }
        var hide = false;
        if(hasRole(ROLE_STATION_ADMIN) || hasRole(ROLE_STATION)) {
            hide = true;
        }
        var cols = [
                        // {width: 30, text: '序号', flex: false, colClass: 'text-center',field:'num'},
                        // {width: 100, text: '任务名称', flex: false,colClass: '',field:'name'},
                        // {width: 80, text: '考核人员',  flex: false, colClass: '',field:'appeal_man_name'},
                        // {width: 100, text: '考核部门',  flex: false, colClass: '',sort: 'down',field:'appeal_dept_name'},
                        // {width: 80, text: '稽查人员', type: 'string', flex: false, hide:true,colClass: '',field:'verify_person_name'},
                        // {width: 120, text: '稽查时间段', type: 'string', flex: false, colClass: '',field:'start_time'},
                        // {width: 80, text: '状态', type: 'string', flex: false, colClass: '',field:'code_name'},
                        // {width: 120, text: '上次稽查时间', type: 'string', flex: false, colClass: '',field:'start_time'},
                        {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, 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: 80, text: '状态', type: 'string', flex: true, colClass: '',field: 'check_status_name'},
                        {width: 100, text: '操作',  flex: false, colClass: '',field:'id',field_other:'task_id',oper:[
                            {func:'seeCheckAudit1',text:'查看稽查结果',col_class:''},{func:'seeDetail',text:'详情',col_class:''}
                        ]},
                    ] ;
        
        $('.datatable').mytable({'cols':cols,
                                'url':"checkAppeal/getList",
                                'param':data}
                                );
    }
//进入稽查页面
function showCheck(id){
    // $('#myModal').modal({name:"dd"});
    // alert(id);
    var rowData=getItemByIdFromArr(id,$('.datatable').mytable('getTableData'));
    post_common_service("/checkAppeal/getByTaskId", {"task_id":rowData.id}, function(data){
        $.checkTask = rowData;
        $.checkTask.appeal = data;
        console.log("申诉："+$.checkTask.appeal.id);
        no_return_common_service('/task/update', {"id":id,"check_status":13})
        changePage("/view/mytask/check.html");
    });
}
//进入继续稽查页面
function showContinueCheck(id){
    // $('#myModal').modal({name:"dd"});
    var rowData=getItemByIdFromArr(id,$('.datatable').mytable('getTableData'));
    post_common_service("/checkAppeal/getByTaskId", {"task_id":rowData.id}, function(data){
        $.checkTask = rowData;
        $.checkTask.appeal = data;
        changePage("/view/mytask/check.html");
    });
}

//再分配
function distributionAgain(id,task_id){
    alert("task_id:"+task_id+"---id:"+id)
}

//详情
function seeDetail(id,task_id){
    alert("task_id:"+task_id+"---id:"+id)
}

//下发单条任务
function dispatchAppealTaskById(id){
    layer.confirm('确定下发任务？', {
        btn: ['确定','取消'] //按钮
    }, function(){
       var rowData=getItemByIdFromArr(id,$('.datatable').mytable('getTableData'));
       var param = {
            "id": rowData.id,
            "check_status":15
        }
       no_return_common_service('/task/dispatchById', param, function(data){
            queryAppeal();
            layer.msg(data, {
                time: 2000//20s后自动关闭
            });
        });
    }, function(index){
        layer.close(index);
    });
    
}
