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

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

    var id = "owl_download_template_user_batch_update_password_v0";
    var jDownloadTemplate = owl_download_templateService.get(id);
    var fileUrl = "";
    if (!jDownloadTemplate) {
        var index = 0;
        var titles = [
            {"index": index++, "columnWidth": "20", "field": "userId", "title": "会员ID"},
            {"index": index++, "columnWidth": "20", "field": "mobile", "title": "手机号"},
            {"index": index++, "columnWidth": "20", "field": "loginId", "title": "登录账号"},
            {"index": index++, "columnWidth": "20", "field": "password", "title": "新密码"}
        ];
        var recordList = [
            {
                userId: "owl_mall_u_50000",
                password: "123456"
            }
        ];

        var file_type_name = "批量修改会员登录密码模板";

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

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