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

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

    var id = "owl_download_template_org_batch_update_state";
    var jDownloadTemplate = owl_download_templateService.get(id);
    var fileUrl = "";
    if (!jDownloadTemplate) {
        var index = 0;
        var titles = [
            {"index": index++, "columnWidth": "22", "field": "merchantId", "title": "商家ID"},
            {"index": index++, "columnWidth": "22", "field": "orgType", "title": "组织类型"},
            {"index": index++, "columnWidth": "22", "field": "merType", "title": "商家类型"},
            {"index": index++, "columnWidth": "22", "field": "deliveryMode", "title": "配送方式"},
            {"index": index++, "columnWidth": "22", "field": "certifyState", "title": "审核状态"},
            {"index": index++, "columnWidth": "22", "field": "publishState", "title": "发布状态"},
            {"index": index++, "columnWidth": "22", "field": "enableState", "title": "冻结状态"},
            {"index": index++, "columnWidth": "22", "field": "productCanBuyState", "title": "商品可否购买"},
            {"index": index++, "columnWidth": "22", "field": "canGiveIntegral", "title": "可否赠送积分"}
        ];
        var recordList = [
            {
                merchantId:"owl_orgs_100001",
                name:"商家A",
                orgType:"",
                merType:"",
                deliveryMode:"",
                certifyState:"",
                publishState:"",
                enableState:"",
                productCanBuyState:"",
                canGiveIntegral:""
            }
        ];

        var file_type_name = "批量修改商家状态模板";

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

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