/**
 * 供应商绩效考核报表 首页JS
 *
 * Created by likui on 2019/8/24.
 */

'use strict';
var el = {
    tb: '#tb',
    searchForm: '#searchForm',
    year: '#year',
    supplierName: '#supplierName',
    bodyHeight: document.documentElement.clientHeight
};

$(function () {
    initComBoBoxData();
    initDataGrid();
});

/**
 * 初始化数据表格
 */
function initDataGrid() {
    var searchHeight = $(el.searchForm).outerHeight() - 10;
    var pager = initGridPager(el.bodyHeight - searchHeight * 2 - 120, 40);
    var toolbar = [
        {
            text: '导出',
            iconCls: 'icon-import',
            handler: function () {
                openExportDialog('pc/spe/appraisalScoreReport/rest/export','tb',{year:$(el.year).val(),supplierName:$(el.supplierName).val()});
                setOperationLog("导出按钮", "绩效考核报表");
            }
        }
    ];
    $(el.tb).datagrid({
        url: g.ctx + 'pc/spe/appraisalScoreReport/rest/list',
        method: "GET",
        loadMsg: '数据远程载入中,请等待...',
        singleSelect: true,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        checkbox: true,
        rownumbers: true,
        height: el.bodyHeight - searchHeight - 20,
        columns: [[
            {
                field: 'year',
                title: '年度',
                width: 80
            },
            {
                field: 'supplierName',
                title: '供应商',
                width: 180
            },
            {
                field: 'oneMonth',
                title: '1月份',
                width: 80
            },
            {
                field: 'twoMonth',
                title: '2月份',
                width: 80
            },
            {
                field: 'threeMonth',
                title: '3月份',
                width: 80
            },
            {
                field: 'oneQuarterAvg',
                title: '平均值',
                width: 80
            },
            {
                field: 'oneQuarterLevel',
                    title: 'Q1',
                width: 80
            },
            {
                field: 'fourMonth',
                title: '4月份',
                width: 80
            },
            {
                field: 'fiveMonth',
                title: '5月份',
                width: 80
            },
            {
                field: 'sixMonth',
                title: '6月份',
                width: 80
            },
            {
                field: 'twoQuarterAvg',
                title: '平均值',
                width: 80
            },
            {
                field: 'twoQuarterLevel',
                title: 'Q2',
                width: 80
            },
            {
                field: 'sevenMonth',
                title: '7月份',
                width: 80
            },
            {
                field: 'eightMonth',
                title: '8月份',
                width: 80
            },
            {
                field: 'nineMonth',
                title: '9月份',
                width: 80
            },
            {
                field: 'threeQuarterAvg',
                title: '平均值',
                width: 80
            },
            {
                field: 'threeQuarterLevel',
                title: 'Q3',
                width: 80
            },
            {
                field: 'tenMonth',
                title: '10月份',
                width: 80
            },
            {
                field: 'elevenMonth',
                title: '11月份',
                width: 80
            },
            {
                field: 'twelveMonth',
                title: '12月份',
                width: 80
            },
            {
                field: 'fourQuarterAvg',
                title: '平均值',
                width: 80
            },
            {
                field: 'fourQuarterLevel',
                title: 'Q4',
                width: 80
            },
            {
                field: 'yearAvg',
                title: '年度平均分',
                width: 80
            },
            {
                field: 'yearLevel',
                title: '年度总评',
                width: 80
            }
        ]],
        toolbar: toolbar,
        onLoadSuccess: function () {
            //displayButtonByUserRole('Appraisal Manage');
        }
    });
}

/**
 * 初始化下拉框
 */
function initComBoBoxData() {
    var type = [
        {label: '全部', value: ''},
        {label: '月度', value: '3'}
    ];
    // 初始化考核周期下拉框
    $(el.evaluationCycle).combobox({
        valueField: 'value',
        textField: 'label',
        value: '',
        data: type,
        editable: false,
        panelHeight: 'auto'
    });

    // 初始化状态下拉框
    $(el.status).combobox({
        valueField: 'value',
        textField: 'label',
        value: '',
        data: [
            {label: '全部', value: ''},
            {label: '新建', value: '0'},
            {label: '评分中', value: '1'},
            {label: '已评分', value: '3'}
        ],
        editable: false,
        panelHeight: 'auto'
    });
}

function closeDialog() {
    el.addEditDialog.dialog('close');
    $(el.tb).datagrid('reload');
}

