/**
 * 对账模块-查看并下载扣款或返利附件信息弹框JS
 *
 * Created by li.kui on 2020/10/22.
 */
'use strict';
var el = {
    drId: '#drId',
    attType: '#attType',
    tb: '#tb',
    bodyHeight: document.documentElement.clientHeight
};


/**
 * 文档就绪
 */
$(function () {
    loadAttGrid();
});


/**
 * 初始化附件表格
 */
function loadAttGrid() {
    $(el.tb).datagrid({
        loadMsg: '数据加载中, 请耐心等待...',
        url: g.ctx + 'fin/ded/reb/attachment/rest/find/ded/reb/attachment',
        height: el.bodyHeight - 10,
        singleSelect: true,
        rownumbers: true,
        pagination: false,
        queryParams: {
            drId: $(el.drId).val(),
            attachmentType: $(el.attType).val()
        },
        columns: [
            [
                {
                    field: 'fileName',
                    title: '文件名',
                    width: 360
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    width: 150,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    }
                },
                {
                    field: 'url',
                    title: '操作',
                    width: 80,
                    formatter: function (value, row) {
                        var html = '';
                        html += '<a href="javascript:void(0)" onclick="lookDedAtt(this)" data-url="' + value + '">查看</a>';
                        html += '&nbsp;&nbsp;&nbsp;';
                        html += '<a href="javascript:void(0)" onclick="downloadDedAtt(this)" data-url="' + value + '" data-aid="'+ row.id +'">下载</a>';
                        return html;
                    }
                }
            ]
        ]
    });
}


/**
 * 查看附件
 *
 * @param ele 当前操作节点
 */
function lookDedAtt(ele) {
    var url = g.ctx + 'static/' + $(ele).data('url');
    window.open(url);
}


/**
 * 下载附件
 *
 * @param ele 当前操作节点
 */
function downloadDedAtt(ele) {
    var url = g.ctx + 'fin/common/rest/ded/reb/attachment/download?attId=' + $(ele).data('aid');
    window.open(url);
}