/**
 * 开票申请编辑选择对账单返利弹框页面JS
 *
 * Created by li.kui on 2020/8/15.
 */
'use strict';
var el = {
    asIds: '#asIds',
    aeSrIds: '#alreadyExistSrIds',
    tempDelSrId: '#tempDelSrId',
    tb: '#tb',
    bodyHeight: document.documentElement.clientHeight
};


$(function () {
    loadStatementRebateGird();
});


/**
 * 加载对账单返利数据
 */
function loadStatementRebateGird() {
    var asIds = $(el.asIds).val(), aeSrIds = $(el.aeSrIds).val(), tdSrIds = $(el.tempDelSrId).val();
    var asIdsArray = asIds.split(',');
    var aeSrIdsArray = aeSrIds.length === 0 ? [] : aeSrIds.split(',');
    var tdSrIdArray = tdSrIds.length === 0 ? [] : tdSrIds.split(',');


    $(el.tb).datagrid({
        loadMsg: '数据加载中, 请耐心等待......',
        height: el.bodyHeight - 20,
        url: g.ctx + 'fin/account/statement/detail/rest/cia/find/statement/rebate',
        singleSelect: false,
        rownumbers: true,
        pagination: false,
        queryParams: {
            asIds: JSON.stringify(asIdsArray),
            aeSrIds: aeSrIdsArray.length === 0 ? '' : JSON.stringify(aeSrIdsArray),
            tdSrIds: tdSrIdArray.length === 0 ? '' : JSON.stringify(tdSrIdArray)
        },
        frozenColumns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'asNo',
                    title: '对账单号',
                    width: 140
                },
                {
                    field: 'rebateNo',
                    title: '返利单号',
                    width: 140
                },
                {
                    field: 'rebateAmount',
                    title: '含税返利金额(元)',
                    width: 110,
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return formatNumber(value, 2, 1);
                    }
                }
            ]
        ],
        columns: [
            [
                {
                    field: 'taxCodeDesc',
                    title: '税率',
                    width: 160
                },
                {
                    field: 'rebateType',
                    title: '返利类型',
                    width: 120,
                    formatter: function (value) {
                        if(Number(value) === 1){
                            return '购方对供方返利';
                        }else {
                            return '供方对购方返利';
                        }
                    }
                },
                {
                    field: 'rebateTime',
                    title: '返利时间',
                    width: 110,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD");
                        }
                        return '';
                    }
                },
                {
                    field: 'rebateReason',
                    title: '返利原因',
                    width: 300
                },
                {
                    field: 'companyName',
                    title: '公司名称',
                    width: 180
                },
                {
                    field: 'supplierCode',
                    title: '供应商编码',
                    width: 90
                },
                {
                    field: 'supplierName',
                    title: '供应商名称',
                    width: 270
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    width: 140,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    }
                }
            ]
        ]
    });
}


/**
 * 确认选择
 *
 * @param callback 回调函数
 */
function confirmChose(callback) {
    callback($(el.tb).datagrid('getSelections'));
}