/**
 * guoj
 * 2018.11.06
 * 仓资料
 */

 import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE,UPCLOUD_RDC_TMS_BUSINESS_SERVICE,UPCLOUD_RDC_TMS_INTERFACE_SERVICE} from '@/config/serviceSettings.js';
 import { getSelectGJ, querySysPicture } from '@/utils/prolog.ajax.js';
 export default () => {

    var comp_data;
    //按钮
    var batton = {
        //        del: '删除',
        //        update: '更新',
        //        run: '详情',
        onLoad: "模板下载"
    };
    getSelectGJ([{ "objectcode": "wmsRegion" }, { "objectcode": "ware_status" }], function(data) {
        $("#warehou_select").attr("consignor", JSON.stringify(data.data));
    });
    var province;
    //查询省
    utilSyncAjaxGJ(UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/zone/get-by-pid", "post", JSON.stringify({ "fatherid": "01" }), function(data) {
        province = data.data;
        for (x in province) {
            province[x].text = province[x].keyvalue;
            province[x].value = province[x].zoneid;
        }
    }, "application/json");
    //查询
    queryGj();

    function queryGj() {
        $("#warehou_div").empty();
        //查询数据
        utilSyncAjaxGJ(UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/branch/list-by-areas", "post", "{}", function(data) {
            comp_data = data.data;
            //companyid必须唯一
            comp_data = [{
                    "areaid": { "value": "BD", "text": "主数据模板" },
                    "listCompany": [
                        { "companyid": "01", "companycode": "01", "locname": "货主模板", "areaid": "HD" },
                        { "companyid": "02", "companycode": "02", "locname": "承运商模板", "areaid": "HD" },
                        { "companyid": "03", "companycode": "03", "locname": "仓资料模板", "areaid": "HD" },
                        { "companyid": "04", "companycode": "04", "locname": "门店模板", "areaid": "HD" },
                        { "companyid": "05", "companycode": "05", "locname": "商品资料模板", "areaid": "HD" },
                        { "companyid": "06", "companycode": "06", "locname": "贸易伙伴模板", "areaid": "HD" }
                    ]


                },
                {
                    "areaid": { "value": "CD", "text": "基础资料模板" },
                    "listCompany": [
                        { "companyid": "07", "companycode": "07", "locname": "库区信息模板", "areaid": "HD" },
                        { "companyid": "08", "companycode": "08", "locname": "货位信息模板", "areaid": "HD" },
                        { "companyid": "09", "companycode": "09", "locname": "工作台信息模板", "areaid": "HD" },
                        { "companyid": "10", "companycode": "10", "locname": "容器信息模板", "areaid": "HD" },
                        { "companyid": "11", "companycode": "11", "locname": "用户信息模板", "areaid": "HD" },
                        { "companyid": "12", "companycode": "12", "locname": "集货区信息模板", "areaid": "HD" }
                    ]
                }

            ];

            for (var i = 0; i < comp_data.length; i++) {
                var div = "<div style=\"padding: 15px;\" id=" + comp_data[i].areaid.value + " ></div>";
                $("#warehou_div").append(div);
                if (comp_data[i].listCompany.length > 0) {
                    for (var y = 0; y < comp_data[i].listCompany.length; y++) {
                        var jsonData = {
                            "areaid": comp_data[i].listCompany[y].areaid,
                            "companyid": comp_data[i].listCompany[y].companyid,
                            "companycode": comp_data[i].listCompany[y].companycode
                        };
                        comp_data[i].listCompany[y].name = comp_data[i].listCompany[y].locname;
                        comp_data[i].listCompany[y].description = "";
                        comp_data[i].listCompany[y].useNo = comp_data[i].listCompany[y].companyid;
                        comp_data[i].listCompany[y].btns = batton;
                        comp_data[i].listCompany[y].id = JSON.stringify(jsonData);
                    }
                }
                //渲染数据
                var config = {
                    renderer: comp_data[i].areaid.value,
                    data: {
                        zoneId: comp_data[i].areaid.value,
                        zoneName: comp_data[i].areaid.text,
                        isShowAdd: true,
                        customerList: comp_data[i].listCompany
                    }
                };
                var plgCard = new PlgCardList(config);
                //                //新增
                plgCard.on("add", function(ind) {
                    setInd(ind);
                });
                if (comp_data[i].listCompany.length > 0) {
                    //模板下载
                    plgCard.on("onLoad", function(ind) {
                        var companyid = ind.companyid;
                        if ("01" == companyid) {
                            window.open("/download/货主模板导入.xlsx");
                        }
 else if ("02" == companyid) {
                            window.open("/download/承运商模板导入.xlsx");
                        }
                        if ("03" == companyid) {
                            window.open("/download/仓资料模板导入.xlsx");
                        }
                        if ("04" == companyid) {
                            window.open("/download/门店模板导入.xlsx");
                        }
                        if ("05" == companyid) {
                            window.open("/download/商品资料导入模板.xlsx");
                        }
                        if ("06" == companyid) {
                            window.open("/download/贸易伙伴模板导入.xlsx");
                        }
                        if ("07" == companyid) {
                            window.open("/download/库区导入模板.xlsx");
                        }
                        if ("08" == companyid) {
                            window.open("/download/货位导入模板 .xlsx");
                        }
                        if ("09" == companyid) {
                            window.open("/download/工作台导入模板.xlsx");
                        }
                        if ("10" == companyid) {
                            window.open("/download/容器导入模板.xlsx");
                        }
                        if ("11" == companyid) {
                            window.open("/download/用户导入模板.xlsx");
                        }
                        if ("12" == companyid) {
                            window.open("/download/集货区导入模板.xlsx");
                        }

                    });

                }
            }
        }, "application/json");
    }

    function setInd (ind) {
        ware_from.enableAllItem();
        ware_from.clear();
        $("#warehou_title").html("新增");
        set_from({ "areaid": ind });
        $("#warehou_div9").css("display", "none");
        $("#warehou_div1").css("display", "block");
        $("#warehou_div3").css("display", "none");
    }
    //跳转页面
    var carousel = layui.carousel;
    carousel.render({
        elem: "#warehou_div2",
        autoplay: false,
        index: 0,
        arrow: "none",
        indicator: "none",
        anim: "fade",
        width: "100%", //设置容器宽度
        height: "100%"
    });
}