//#import excel.js
//#import $owl_download_template:services/modelService.jsx

function main() {
    var params = JSON.parse($body);

    var id = "owl_download_template_orguser_batch_import";
    var jDownloadTemplate = owl_download_templateService.get(id);
    var fileUrl = "";
    if (!jDownloadTemplate) {
        var index = 0;
        var titles = [
            {"index": index++, "columnWidth": "20", "field": "userName", "title": "姓名"},
            {"index": index++, "columnWidth": "20", "field": "userNo", "title": "员工编号"},
            {"index": index++, "columnWidth": "20", "field": "mobile", "title": "移动电话"},
            {"index": index++, "columnWidth": "30", "field": "orgName", "title": "单位名称"},
            {"index": index++, "columnWidth": "20", "field": "department", "title": "部门名称"}
        ];
        var recordList = [
            {
                userName:"张三",
                userNo:"102501",
                mobile:"13800138001",
                orgName:"武商电商",
                department:"技术信息部"
            }
        ];

        var file_type_name = "批量导入集团员工模板";

        fileUrl = Excel.createExcelList(file_type_name, titles, recordList);

        jDownloadTemplate = {};
        jDownloadTemplate.file_type_id = "orguser_batch_import";
        jDownloadTemplate.file_type_name = file_type_name;
        jDownloadTemplate.file = {url: fileUrl, name: file_type_name};
        owl_download_templateService.add(jDownloadTemplate);
    } else {
        fileUrl = jDownloadTemplate.file.url;
    }

    var ret = {
        state: 'ok',
        action: 'navigate',
        target: "_blank",
        url: fileUrl
    }
    out.print(JSON.stringify(ret));

}

main();
