//#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_v3";
    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": "name", "title": "商家名称"},
            {"index": index++, "columnWidth": "22", "field": "name_en", "title": "英文名称"},
            {"index": index++, "columnWidth": "22", "field": "regionName", "title": "所在地区"},
            {"index": index++, "columnWidth": "22", "field": "contact", "title": "联系人"},
            {"index": index++, "columnWidth": "22", "field": "mobile", "title": "联系手机"},
            {"index": index++, "columnWidth": "22", "field": "phone", "title": "座机"},
            {"index": index++, "columnWidth": "22", "field": "email", "title": "邮箱"},
            {"index": index++, "columnWidth": "22", "field": "storeAddress", "title": "门店地址"},
            {"index": index++, "columnWidth": "22", "field": "address", "title": "退货地址"},
            {"index": index++, "columnWidth": "22", "field": "businessTime", "title": "开业时间"},
            {"index": index++, "columnWidth": "22", "field": "openTime", "title": "营业时间"},
            {"index": index++, "columnWidth": "22", "field": "shopAddress", "title": "店铺网址"},
            {"index": index++, "columnWidth": "22", "field": "siteId", "title": "站点Id"},
            {"index": index++, "columnWidth": "22", "field": "homePageId", "title": "移动端首页Id"},
            {"index": index++, "columnWidth": "22", "field": "pcHomePageId", "title": "PC端首页Id"},
            {"index": index++, "columnWidth": "40", "field": "kefuUrl", "title": "客服链接"},
            {"index": index++, "columnWidth": "40", "field": "memo", "title": "备注"},
            {"index": index++, "columnWidth": "40", "field": "deliveryMemo", "title": "配送备注"},
            {"index": index++, "columnWidth": "60", "field": "moduleIds", "title": "权限组织类型ID"},
            {"index": index++, "columnWidth": "60", "field": "deliveryPriceTemplates", "title": "默认运费模板ID"},
            {"index": index++, "columnWidth": "60", "field": "platformCategories", "title": "经营范围"},
            {"index": index++, "columnWidth": "30", "field": "tag", "title": "商家标签"},
            {"index": index++, "columnWidth": "30", "field": "orgCode", "title": "统一组织机构代码"},
            {"index": index++, "columnWidth": "30", "field": "registrationNumber", "title": "工商登记号"},
            {"index": index++, "columnWidth": "30", "field": "address", "title": "注册地址"},
            {"index": index++, "columnWidth": "30", "field": "businessRange", "title": "营业范围"},
            {"index": index++, "columnWidth": "30", "field": "showLicImage", "title": "营业执照"},
            {"index": index++, "columnWidth": "30", "field": "licBeginDate", "title": "营业执照有效期开始时间"},
            {"index": index++, "columnWidth": "30", "field": "licEndDate", "title": "营业执照有效期结束时间"}
        ];
        var recordList = [
            {
                merchantId:"owl_orgs_100001",
                name:"商家A",
                name_en:"",
                regionName:"湖北省武汉市汉阳区",
                moduleIds:"owl_org_modules_102;owl_org_modules_103",
                deliveryPriceTemplates:"owl_delivery_price_template_210004;owl_delivery_price_template_250000",
                platformCategories:"全部商品|食品酒水饮料;全部商品|进口食品;全部商品|数码家电",
            }
        ];

        var file_type_name = "批量修改商家信息模板";

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

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