{layout:default} {class:Shop.admin.product.datainout}
<lbhead>
    <title>
        <%=Tag("数据导入导出")%>-<%=site.title%></title>
</lbhead>
<lbfile>
    <link href="<%=site.AdminAssetsPath %>/plugins/multiselect/css/jquery.multiselect2side.css" rel="stylesheet">
</lbfile>
<lbpath>
    <h3 class="text-themecolor m-b-0 m-t-0"><%=Tag("数据导入导出")%></h3>
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="<%=site.AdminPath %>/Ajax/ajax_admin.aspx?__Action=MenuJump&pid=0"><%=Tag("管理首页")%></a></li>
        <li class="breadcrumb-item active"><%=Tag("数据导入导出")%></li>
    </ol>
</lbpath>
<lbbody>
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <h4 class="card-title"><%=Tag("数据导入")%></h4>
                <form action="javascript:tb_product_in();" novalidate>
                    <div class="form-group">
                        <label for="tb_typeid"><%=Tag("导入分类")%>：</label>
                        <div id="shopnick" class="input-group">
                            <select id="tb_typeid" name="tb_typeid" shop="true" class="form-control">
                                <%=Shop.Bussiness.EX_Product.TypeOption(0,0,0,CurrentLanguage.Code)%>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="datatype"><%=Tag("数据格式")%>：</label>
                        <div class="input-group">
                            <label class="custom-control custom-radio">
                                <input type="checkbox" id="datatype" name="datatype" value="1" class="custom-control-input" shop="true" checked>
                                <span class="custom-control-label"><%=Tag("淘宝CSV")%></span>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tb_file"><%=Tag("数据文件")%>：</label>
                        <div class="input-group">
                            <input type="text" id="tb_file" name="tb_file" shop="true" class="form-control">
                            <div class="input-group-append fileupload">
                                <span class="input-group-text" id="image_tb_file"><i class="ti-upload"></i></span>
                                <input type="file" id="file_tb_file" name="file_tb_file" class="upload" onchange="uploadImage('tb_file')">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tb_folder"><%=Tag("图片文件夹")%>：</label>
                        <input type="text" id="tb_folder" name="tb_folder" class="form-control" shop="true">
                        <small class="form-text text-muted"><%=Tag("相对安装路径，以/开头和结尾")%></small>
                    </div>
                    <div class="form-group">
                        <label for="tb_split_2"><%=Tag("分隔符")%>：</label>
                        <div class="input-group">
                            <label class="custom-control custom-radio m-r-20">
                                <input type="radio" id="tb_split_2" name="tb_split" value="2" class="custom-control-input" shop="true" checked>
                                <span class="custom-control-label"><%=Tag("逗号(,)")%></span>
                            </label>
                            <label class="custom-control custom-radio">
                                <input type="radio" id="tb_split_1" name="tb_split" value="1" class="custom-control-input" shop="true">
                                <span class="custom-control-label"><%=Tag("制表符(/t)")%></span>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tbin_lang"><%=Tag("语言")%>：</label>
                        <select id="tbin_lang" name="tbin_lang" class="form-control" shop="true">
                            <%=Shop.Bussiness.Language.LanguageOption(CurrentLanguage.Code)%>
                        </select>
                    </div>
                    <%if (PageReturnMsg == ""){%>
                    <button type="submit" class="btn btn-success"><i class="ti-check"></i> <%=Tag("提交")%></button>
                    <%}%>
                </form>
            </div>
        </div>
        <div class="card">
            <div class="card-body">
                <h4 class="card-title"><%=Tag("数据导出")%></h4>
                <form action="javascript:tb_product_out();" novalidate>
                    <div class="form-group">
                        <label for=""><%=Tag("导出范围")%>：</label>
                        <div class="input-group">
                            <a href="javascript:void(0);" onclick="SearchWindow();"><%=Tag("高级搜索")%></a>
                            <%=sp.Description%>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Wornings"><%=Tag("数量")%>：</label>
                        <div class="input-group">
                            <%=DB.LebiShop.B_Lebi_Product.Counts("Product_id=0 "+sp.SQL) %>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tb_lang"><%=Tag("语言")%>：</label>
                        <select id="tb_lang" name="tb_lang" class="form-control" shop="true">
                            <%=Shop.Bussiness.Language.LanguageOption(CurrentLanguage.Code)%>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="datatype2"><%=Tag("数据格式")%>：</label>
                        <div class="input-group">
                            <label class="custom-control custom-radio">
                                <input type="checkbox" id="datatype2" name="datatype2" value="1" class="custom-control-input" shop="true" checked>
                                <span class="custom-control-label"><%=Tag("淘宝CSV")%></span>
                            </label>
                        </div>
                    </div>
                    <div id="tr_down" class="form-group">
                        <label for=""><%=Tag("下载")%>：</label>
                        <div id="down_url" class="input-group">
                        </div>
                    </div>
                    <%if (PageReturnMsg == ""){%>
                    <button type="submit" class="btn btn-success"><i class="ti-check"></i> <%=Tag("提交")%></button>
                    <%}%>
                </form>
            </div>
        </div>
    </div>
</lbbody>
<lbscripts>
    <script src="<%=site.AdminJsPath %>/ajaxfileupload.js"></script>
    <script src="<%=site.AdminAssetsPath %>/plugins/multiselect/js/jquery.multiselect2side.js"></script>
    <script>
        function tb_product_in() {
            var tb_typeid = $("#tb_typeid").val();
            var tb_file = $("#tb_file").val();
            var tb_folder = $("#tb_folder").val();
            var tb_split = $("input[name='tb_split']:checked").val();
            var tbin_lang = $("#tbin_lang").val();
            var url = "<%=site.AdminPath %>/ajax/export.aspx?__Action=taobao_product_in";
            var postData = { "tb_typeid": tb_typeid, "tb_file": tb_file, "tb_folder": tb_folder, "tb_split": tb_split, "tbin_lang": tbin_lang };
            $.ajax({
                type: "POST",
                url: url,
                data: postData,
                dataType: 'json',
                beforeSend: function () {
                    MsgBox(4, "正在处理 ……", "-");
                },
                success: function (res) {
                    if (res.msg == "OK") {
                        MsgBox(1, "<%=Tag("操作成功") %>：" + res.count, "");
                    }
                    else {
                        MsgBox(2, res.msg, "");
                        return false;
                    }
                }
            });
        }
        function SearchWindow() {
            var url_ = "../product/product_search_window.aspx?callback=search_&<%=sp.URL %>";
            $("#EditModal").modal("show");
            $.ajax({
                url: url_,
                type: "GET",
                cache: false,
                data: {},
            }).done(function (result) {
                $("#EditModal .modal-content").html(result);
            });
        }
        function search_(scurl) {
            window.location = "?" + scurl;
        }
        function tb_product_out() {
            var lang = $("#tb_lang").val();
            var url = "<%=site.AdminPath %>/ajax/export.aspx?__Action=taobao_product_out&lang=" + lang + "&<%=sp.URL %>";
            $.ajax({
                type: "POST",
                url: url,
                data: '',
                dataType: 'json',
                beforeSend: function () {
                    MsgBox(4, "<%=Tag("正在处理") %> ……", "-");
                },
                success: function (res) {
                    if (res.msg == "OK") {
                        $("#tr_down").show()
                        $("#down_url").html("<a href=\"" + res.url + "\" target=\"_blank\">" + res.url + "</a>");
                        MsgBox(1, "<%=Tag("操作成功") %>", "");
                    }
                    else {
                        MsgBox(2, res.msg, "");
                        return false;
                    }
                }
            });
        }
    </script>
</lbscripts>