/**
 * <p>
 *  文件预览
 * </p>
 *
 * @author Administrator
 * @since 2021/6/10
 */
layui.use(['layer', 'laytpl', 'dropdown', 'carousel', 'form', 'datalabel'], function () {
    for (let col in file) {
        switch (col) {
            case 'secretLevel':
                $(`label[name="${col}"]`).text(DICT.getText('secret_level', file[col]));
                break;
            case 'taskNature':
                $(`label[name="${col}"]`).text(DICT.getText('task_nature', file[col]));
                break;
            case 'targetNumber':
                $(`label[name="${col}"]`).text(DICT.getText('target_type', file[col]));
                break;
            case 'source':
                $(`label[name="${col}"]`).text(DICT.getText('data_source', file[col]));
                break;
            case 'markRecords':
                let markRecords = file[col]
                if (markRecords) {
                    for (let mark of markRecords) {
                        $(`#marktag-${mark.markType}`).html(MarkTag.getStaticTagHtml(mark.markValue))
                    }
                }
                break;
            case 'exerciseData':
                $(`label[name="${col}"]`).text(file[col] == 0 ? '否' : '是');
                break;
            case '':
                $(`label[name="${col}"]`).text(DICT.getText('secret_level', file[col]));
                break;
            default:
                $(`label[name="${col}"]`).text(file[col] || '');
        }
    }
    if (file.labels) {
        layui.datalabel.setData(file.labels);
    }

    if (file.fileSize === 0) {
        showWarningMsg('该文件中没有任何内容');
        return;
    }

    let office_server = DICT.getOfficeServer();

    let if_src = office_server + '?url=' + encodeURIComponent(Base64.encode(fileViewUrl))
    let if_elem = document.getElementById('office-online');
    let loadLayer = layer.msg('正在将文件转换为可预览格式，请稍后。。。', {
        icon: 16,
        shade: 0.01,
        time: 1000 * 60 * 30,
        closeBtn: 1
    });
    if_elem.onload = function () {
        layer.close(loadLayer);
    };
    if_elem.src = if_src;
});
