/**
 * 供应商绩效考核整改审批首页
 *
 */
'use strict';
var el = {
    noticeCode: '#noticeCode',
    supplierCode: '#supplierCode',
    supplierName: '#supplierName',
    status: '#status',
    dataType: '#dataType',
    tb: '#tb',
    searchForm: '#searchForm',
    rectifiedExamineDialog: null,
    bodyHeight: document.documentElement.clientHeight
};

$(function () {
    var dataType = $(el.dataType).val();
    initDataGrid(dataType);
});


/**
 * 初始化数据表格
 */
function initDataGrid(dataType) {
    var searchHeight = $(el.searchForm).outerHeight() - 10;
    var pager = initGridPager(el.bodyHeight - searchHeight * 2 - 120, 40);

    $(el.tb).datagrid({
        url: g.ctx + 'pc/spe/rectifiedNotice/rest/allList',
        method:"GET",
        loadMsg: '数据远程载入中,请等待...',
        singleSelect: true,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        checkbox: true,
        rownumbers: true,
        height: el.bodyHeight - searchHeight - 20,
        columns: [[
            {
                field: 'ck',
                checkbox: true
            },
            {
                field: 'status',
                title: '状态',
                width: 80,
                formatter: function (value) {
                    if (value === -1) {
                        return '<span style="color: red;">待发布</span>';
                    }
                    if (value === 0) {
                        return '<span style="color: red;">待整改</span>';
                    }
                    if (value === 2) {
                        return '<span style="color: grey;">已提交整改</span>';
                    }
                    if (value === 4) {
                        return '<span style="color: orange;">待确认</span>';
                    }
                    if (value === 6) {
                        return '<span style="color: red;">审批不通过,待整改</span>';
                    }
                    if (value === 10) {
                        return '<span style="color: orange;">待跟踪</span>';
                    }
                    if (value === 20) {
                        return '<span style="color: blue;">待审批</span>';
                    }
                    if (value === 30) {
                        return '<span style="color: green;">已完结</span>';
                    }
                    return '';
                }
            },
            {
                field: 'noticeCode',
                title: '通知单编码',
                width: 130
            },
            {
                field: 'supplierCode',
                title: '供应商编码',
                width: 130
            },
            {
                field: 'supplierName',
                title: '供应商名称',
                width: 260
            },
            {
                field: 'evaluationCycle',
                title: '考核周期',
                width: 90,
                formatter: function (value) {
                    if (!value) {
                        return '';
                    }
                    if (value === 1) {
                        return '年度';
                    }
                    if (value === 2) {
                        return '季度';
                    }
                    if (value === 3) {
                        return '月度';
                    }
                }
            },
            {
                field: 'level',
                title: '考核等级',
                width: 60
            },
            {
                field: 'achievementStartDate',
                title: '绩效考核期间',
                width: 200,
                formatter: function (value, row, index) {
                    if (row.evaluationCycle === 1) {
                        return row.year + '年';
                    } else if (row.evaluationCycle === 2) {
                        return row.year + '年第' + row.quarter + '季';
                    } else if (row.evaluationCycle === 3) {
                        return row.year + '年第' + row.month + '月';
                    }
                }
            },
            {
                field: 'templateName',
                title: '所选考核模板',
                width: 160
            },
            {
                field: 'createUserName',
                title: '创建人',
                width: 100
            },
            {
                field: 'createTime',
                title: '创建时间',
                width: 130,
                formatter: function (value) {
                    if (value) {
                        return moment(value).format('YYYY-MM-DD HH:mm:ss');
                    }
                    return '';
                }
            },
            {
                field: 'updateUserName',
                title: '最后一次更新人',
                width: 100
            },
            {
                field: 'updateTime',
                title: '最后一次更新时间',
                width: 130,
                formatter: function (value) {
                    if (value) {
                        return moment(value).format('YYYY-MM-DD HH:mm:ss');
                    }
                    return '';
                }
            }
        ]],
        toolbar: [
            {
                text : '查看',
                hide:true,
                iconCls : 'icon-find',
                handler : function() {
                    rectifiedConfirm();
                    setOperationLog("查看按钮", "整改通知单");

                }
            }
        ]
    });
}

/**
 * 绩效考核整改审批
 */
function rectifiedConfirm() {
    var row = $(el.tb).datagrid('getSelected');
    if (!row) {
        layer.msg('请选中一条记录进行操作', {icon: 0});
        return false;
    }
    var url = g.ctx + 'pc/spe/rectifiedNotice/page/confirmDetail?optType=20&id=' + row.id;
    el.rectifiedExamineDialog = openDialog('rectifiedConfirm', url, {
        title: '绩效考核整改查看',
        width: "90%",
        height: "100%",
        cache: false,
        modal: true,
        border: 'thin',
        onClose : function() {
            el.rectifiedExamineDialog.dialog('destroy');
        },
        buttons:[
            {
                text:'关闭',
                handler:function(){
                    el.rectifiedExamineDialog.dialog('close');
                }
            }
        ]
    });
}
