/**
 * channelplanInfo管理初始化
 */
var ChannelplanBasicinfo = {
    id: "ChannelplanBasicinfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ChannelplanBasicinfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '唯一标志', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '申报批次', field: 'batchId', visible: true, align: 'center', valign: 'middle',width:70},
            {title: '申报项目', field: 'project', visible: true, align: 'center', valign: 'middle',class:"uitd_showTip"},
            {title: '申报类型', field: 'type', visible: true, align: 'center', valign: 'middle',class:"uitd_showTip"},
            {title: '承载单位', field: 'enterprise', visible: true, align: 'center', valign: 'middle',class:"uitd_showTip"},
            {title: '专业领域', field: 'field', visible: true, align: 'center', valign: 'middle'},
            {title: '联系人', field: 'contactsName', visible: true, align: 'center', valign: 'middle'},
            {title: '评审分组', field: 'group', visible: true, align: 'center', valign: 'middle'},
            {title: '填表时间', field: 'createTime', visible: true, align: 'center', valign: 'middle',class:"uitd_showTip"},
            {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle',
                formatter:function (value) {
                    if(value==1){
                        return "待提交";
                    }else if(value==5){
                        return "待初审";
                    }else if(value==10){
                        return "待函审";
                    }else if(value==15){
                        return "待现场审核";
                    }else if(value==20){
                        return "待终审";
                    }else if(value==25){
                        return "审核通过";
                    }else if(value==30){
                        return "退回";
                    }
                }
            },
            {title: '评审操作', field: 'checkState', visible : true, align: 'center', valign: 'middle',class:"uitd_showTip", formatter: assessAction},
            {title: '操作日志', field: 'operationLogId', visible : true, align: 'center', valign: 'middle', formatter: operationAction}
    ];
};

/**
 * 检查是否选中
 */
ChannelplanBasicinfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ChannelplanBasicinfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加channelplanInfo
 */
ChannelplanBasicinfo.openAddChannelplanBasicinfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加申报信息',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanBasicinfo/channelplanBasicinfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看channelplanInfo详情
 */
ChannelplanBasicinfo.openChannelplanBasicinfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '申报信息详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/channelplanBasicinfo/channelplanBasicinfo_update/' + ChannelplanBasicinfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除channelplanInfo
 */
ChannelplanBasicinfo.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/channelplanBasicinfo/delete", function (data) {
            Feng.success("删除成功!");
            ChannelplanBasicinfo.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("channelplanBasicinfoId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询channelplanInfo列表
 */
ChannelplanBasicinfo.search = function () {
    var queryData = {};
    queryData['field'] = $("#field").val();
    queryData['type'] = $("#type").val();
    queryData['checkState'] = $("#checkState").val();
    queryData['project'] = $("#project").val();
    ChannelplanBasicinfo.table.refresh({query: queryData});
};

/**
 * 初始化评审操作
 */
function assessAction(value,row,index){
    var str = JSON.stringify(row);
    if(value==10||value==15||value==25||value==20){
        return "<button class='btn btn-info btn-xs' onclick='popOperation("+str+")'>审核/查看</button>"
    }
}

/**
 * 初始化操作日志按钮
 */
function operationAction(value,row,index){
    var cpId = row.id;
    return "<button class='btn btn-primary btn-xs' onclick='popCheckLog(\""+cpId+"\")'>查看日志</>"
}

/**
 * 弹出审核步骤选择界面
 * @param row
 *
 */
function popOperation(row){
    if(row.checkState==10){
        $('#operation1').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckSec(\""+row.id+"\")' onclick='popScoreCheck("+row.id+")'>审核</a>");
    }
    if(row.checkState==15){
        $('#operation1').children().eq(1).html("已通过");
        $('#operation1').css("background-color","#f0f6ff");
        $('#operation1').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckSecDetail(\""+row.id+"\")'>查看详情</a>")
        $('#operation2').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckLive(\""+row.id+"\")'>审核</a>")
    }
    if(row.checkState==20){
        $('#operation1').children().eq(1).html("已通过");
        $('#operation1').css("background-color","#f0f6ff");
        $('#operation1').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckSecDetail(\""+row.id+"\")'>查看详情</a>")
        $('#operation2').children().eq(1).html("已通过");
        $('#operation2').css("background-color","#f0f6ff");
        $('#operation2').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckLiveDetail(\""+row.id+"\")'>查看详情</a>")
        $('#operation3').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckFinal(\""+row.id+"\")'>审核</a>")
    }
    if(row.checkState==25){
        $('#operation1').children().eq(1).html("已通过");
        $('#operation1').css("background-color","#f0f6ff");
        $('#operation1').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckSecDetail(\""+row.id+"\")'>查看详情</a>")
        $('#operation2').children().eq(1).html("已通过");
        $('#operation2').css("background-color","#f0f6ff");
        $('#operation2').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckLiveDetail(\""+row.id+"\")'>查看详情</a>")
        $('#operation3').children().eq(1).html("已通过");
        $('#operation3').css("background-color","#f0f6ff");
        $('#operation3').children().eq(2).html("<a href='javascript:void(0)' onclick='popScoreCheckFinalDetail(\""+row.id+"\")'>查看详情</a>")
    }

    $('#operationChoice').modal('show');
}

/**
 * 弹出函审窗口
 */
function popScoreCheckSec(cpId){
    var index = layer.open({
        type: 2,
        title: '函审',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpert?cpId='+cpId
    });
    this.layerIndex = index;
}


/**
 * 弹出函审详情窗口
 */
function popScoreCheckSecDetail(cpId){
    var index = layer.open({
        type: 2,
        title: '函审详情',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpert/indexDetail?cpId='+cpId
    });
    this.layerIndex = index;
}

/**
 * 弹出现场评审窗口
 */
function popScoreCheckLive(cpId){
    var index = layer.open({
        type: 2,
        title: '现场评审',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpert/Live?cpId='+cpId
    });
    this.layerIndex = index;
}

/**
 * 弹出现场评审详情窗口
 */
function popScoreCheckLiveDetail(cpId) {
    var index = layer.open({
        type: 2,
        title: '现场评审详情',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpert/LiveDetail?cpId='+cpId
    });
}


/**
 * 弹出终审窗口
 */
function popScoreCheckFinal(cpId){
    var index = layer.open({
        type: 2,
        title: '终审',
        area: ['400px','420px'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpert/final?cpId='+cpId
    });
}

/**
 * 弹出终审详情窗口
 */
function popScoreCheckFinalDetail(cpId){
    var index = layer.open({
        type: 2,
        title: '终审',
        area: ['400px','420px'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpert/finalDetail?cpId='+cpId
    });
}


/**
 * 弹出申报日志窗口
 */
function popCheckLog(cpId){
    var index = layer.open({
        type: 2,
        title: '操作日志',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanChecklog?cpId='+cpId
    });
    ChannelplanBasicinfo.layerIndex = index;
}



$(function () {
    var defaultColunms = ChannelplanBasicinfo.initColumn();
    var table = new BSTable(ChannelplanBasicinfo.id, "/channelplanBasicinfo/list", defaultColunms);
    table.setPaginationType("client");
    ChannelplanBasicinfo.table = table.init();
    //初始化select选项
    var arr = new Array();
    arr.push({"id":"field","code":"un_professionalField"});       //专业领域
    arr.push({"id":"type","code":"un_declareSort"});              //申报类别
    for(var key in arr){
        Feng.addAjaxSelect({
            "id": arr[key].id,
            "displayCode": "code",
            "displayName": "name",
            "type": "GET",
            "url": Feng.ctxPath + "/channelplanBasicinfo/findChildDictByCode?code="+arr[key].code
        });
    }
});
