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

'use strict';
var el = {
    tb: '#tb',
    searchForm: '#searchForm',
    paymentTermCode: '#paymentTermCode',
    paymentWay:'#paymentWay',
    supplierName: '#supplierName',
    startPaymentTime: '#startPaymentTime',
    endPaymentTime:'#endPaymentTime',
    accountStatementMonth: '#accountStatementMonth',
    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/finance/budgetReport/rest/export','tb',{accountStatementMonth:$(el.accountStatementMonth).val(),paymentTermCode:$(el.paymentTermCode).val(),paymentWay:$(el.paymentWay).val(),startPaymentTime:$(el.startPaymentTime).val(),endPaymentTime:$(el.endPaymentTime).val(),supplierName:$(el.supplierName).val()});
            }
        }
    ];
    $(el.tb).datagrid({
        url: g.ctx + 'pc/finance/budgetReport/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: 'accountStatementMonth',
                title: '对账单月份',
                width:100
            },
            {
                field: 'supplierCode',
                title: '供应商编码',
                width: 100
            },
            {
                field: 'supplierName',
                title: '供应商名称',
                width: 180
            },
            {
                field: 'factoryCode',
                title: '工厂编码',
                width: 80
            },
            {
                field: 'currencyCode',
                title: '币种',
                width: 80
            },
            {
                field: 'invoiceTaxAmount',
                title: '应付金额',
                width: 80
            },
            {
                field: 'paymentTermCode',
                title: '付款条件',
                width: 80
            },
            {
                field: 'paymentTermDesc',
                    title: '付款条件描述',
                width: 180
            },
            {
                field: 'paymentWay',
                title: '付款方式',
                width: 80
            },
            {
                field: 'paymentWayDesc',
                title: '付款方式描述',
                width: 180
            },
            {
                field: 'purchaseGroupName',
                title: '采购组',
                width: 120
            },
            {
                field: 'paymentMonth',
                title: '付款月',
                width: 80
            },
            {
                field: 'paymentWeek',
                title: '付款周',
                width: 80
            },
            {
                field: 'paymentTime',
                title: '付款到期日',
                width: 140
            },
            {
                field: 'remark',
                title: '备注',
                width: 180
            }
        ]],
        toolbar: toolbar,
        onLoadSuccess: function () {
            //displayButtonByUserRole('Appraisal Manage');
        }
    });
}

/**
 * 初始化下拉框
 */
function initComBoBoxData() {
    $(el.paymentTermCode).combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=payment_method',
        method: 'GET',
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        editable: false
    });
    // 初始化状态下拉框
    $(el.paymentWay).combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=payment_way',
        method: 'GET',
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        editable: false
    });
}





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

/*
// 格式化函数，显示年份
function formatYear(date){
    return date.getFullYear();
}

// 解析函数，解析年份
function parseYear(s){
    if (!s) return new Date();
    var y = parseInt(s, 10);
    return isNaN(y) ? new Date() : new Date(y, 0, 1);
}
*/

