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

function main() {
    var id = "owl_download_template_orguser_batch_update";
    var jDownloadTemplate = owl_download_templateService.get(id);
    var fileUrl = "";
    if (!jDownloadTemplate) {
        var index = 0;
        var titles = [
            {"index": index++, "columnWidth": "20", "field": "id", "title": "ID"},
            {"index": index++, "columnWidth": "20", "field": "state", "title": "状态"},
            {"index": index++, "columnWidth": "20", "field": "orgCode", "title": "所属机构编码"},
            {"index": index++, "columnWidth": "20", "field": "orgName", "title": "所属机构名称"},
            {"index": index++, "columnWidth": "20", "field": "department", "title": "所属部门"},
            {"index": index++, "columnWidth": "20", "field": "userId", "title": "用户ID"},
            {"index": index++, "columnWidth": "20", "field": "userName", "title": "姓名"},
            {"index": index++, "columnWidth": "20", "field": "userNo", "title": "员工号"},
            {"index": index++, "columnWidth": "20", "field": "mobile", "title": "手机号"}
        ];
        var recordList = [
            {
                id:"owl_org_user_owl_mall_u_100007",
                state:"正常",
                userId:"owl_mall_u_100007",
                userName:"张三",
                userNo:"102501",
                mobile:"13800138001",
                orgCode:"114",
                orgName:"武商电商",
                department:"技术信息部"
            }
        ];

        var file_type_name = "批量修改集团员工模板";

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

        jDownloadTemplate = {};
        jDownloadTemplate.file_type_id = "orguser_batch_update";
        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();
