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


$(function () {
    loadStatementDeductionGird();
});


/**
 * 加载对账单返利数据
 */
function loadStatementDeductionGird() {
    var asIds = $(el.asIds).val(), aeSdIds = $(el.aeSdIds).val(), tdSdIds = $(el.tempDelSdId).val();
    var asIdsArray = asIds.split(',');
    var aeSdIdsArray = aeSdIds.length === 0 ? [] : aeSdIds.split(',');
    var tdSdIdArray = tdSdIds.length === 0 ? [] : tdSdIds.split(',');

    $(el.tb).datagrid({
        loadMsg: '数据加载中, 请耐心等待......',
        height: el.bodyHeight - 20,
        url: g.ctx + 'fin/account/statement/detail/rest/cia/find/statement/deduction',
        singleSelect: false,
        rownumbers: true,
        pagination: false,
        queryParams: {
            asIds: JSON.stringify(asIdsArray),
            aeSdIds: aeSdIdsArray.length === 0 ? '' : JSON.stringify(aeSdIdsArray),
            tdSdIds: tdSdIdArray.length === 0 ? '' : JSON.stringify(tdSdIdArray)
        },
        frozenColumns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'asNo',
                    title: '对账单号',
                    width: 140
                },
                {
                    field: 'deductionNo',
                    title: '扣款编号',
                    width: 140
                },

                {
                    field: 'deductionTypeDesc',
                    title: '扣款类型',
                    width: 90
                },
                {
                    field: 'deductionAmount',
                    title: '含税扣款金额(元)',
                    width: 110,
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return formatNumber(value, 2, 1);
                    }
                }
            ]
        ],
        columns: [
            [
                {
                    field: 'taxCodeDesc',
                    title: '税率',
                    width: 160
                },
                {
                    field: 'deductionTime',
                    title: '扣款时间',
                    width: 90,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD");
                        }
                        return '';
                    }
                },
                {
                    field: 'deductionReason',
                    title: '扣款原因',
                    width: 300
                },
                {
                    field: 'associatedNo',
                    title: 'SRM业务单据',
                    width: 140,
                    formatter: function (value, row) {
                        if (!row.associatedRowNo) {
                            return value;
                        } else {
                            return value + '|' + row.associatedRowNo;
                        }
                    }
                },
                {
                    field: 'associatedOaNo',
                    title: 'OA流程单号',
                    width: 120
                },
                {
                    field: 'companyCode',
                    title: '公司名称',
                    width: 70
                },
                {
                    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'));
}