<script type="text/javascript">

    $(document).ready(function(){
		var page_length = 10;

        $("#btn_upload").click(function(){
            var files = document.getElementById('input_file').files;
            if(files.length> 0){
                var file = files[0];
				var formData = new FormData();
                formData.append('file',file);
                $.ajax({
                    type: 'post',
                    url: '/company/use_excel_upload_companies/',
                    data: formData,
					contentType: false,
					processData: false,
					cache: false,

                    success:function(res){
                        if(res.e===''){
							toastr.success("导入成功", "操作提示：",
								{ timeOut: 800, positionClass: "toast-center-center" }
							);
							if(res.repeatAgent.length>0){
								$("#tb_agent").fadeIn();
								initTable("#tb_agent table",res.repeatAgent)
							}
							if(res.repeatUser.length>0){
								$("#tb_user").fadeIn();
								initTable("#tb_user table",res.repeatUser)
							}
						}
						else{
							toastError(res.e)
						}
                    },
                    error: function(){
                        toastError('网络超时')
                    }
                })
            }
            else{
                toastError('请选择上传文件')
            }
        })

        function toastError(text){
            toastr.error(text, "操作错误：",
                    { timeOut: 800, positionClass: "toast-center-center" }
                );
        }
		
		function initTable(el, data) {
			var tb = $(el).DataTable({
				dom: 'Bfrtip',
				autoWidth: true,
				destroy: true,
				pageLength: page_length,
				buttons: [{ extend: 'excelHtml5', text: '导出到Excel' }],
				language: lng,
				data,
				drawCallback: function () {

				},
				createdRow: function (nRow, aData, iDataIndex) {

				}
			});
			tb.columns().every(function () {
				var that = this;
				$('input', this.footer()).on('keyup change clear', function () {
					if (that.search() !== this.value) {
						that.search(this.value).draw();
					}
				});
			});
		}

    })

</script>


<ol class="breadcrumb">
    <li>经销商管理</li>
    <li>经销商导入</li>
</ol>


<div>
    
    <!--<button class="btn btn-primary" id="btn_down">模板下载</button>-->
    <input type="file" id="input_file"><button class="btn btn-primary" id="btn_upload">上传</button>

	
	<div id='tb_agent' style="display:none;margin-top:20px">
		
		<div class="panel panel-default">
			<div class="panel-heading">
				<h3 class="panel-title">存在重复的经销商数据</h3>
			</div>
			<div class="panel-body">
				<div class='col-md-12 form-group' >
						<div class="table-responsive">
								<table class="table table-striped table-bordered dt-responsive nowrap tb"
									cellspacing="0" width="100%">
									<thead>
										<tr>
											<th>经销商名称</th>
											<th>经销商级别</th>
											<th>上级经销商</th>
											<th>地址</th>
											<th>省份</th>
											<th>城市</th>
											<th>区县</th>
											<th>战区</th>
											<th>分区</th>
											<th>经销商电话</th>
											<th>联系人</th>
										</tr>
									</thead>
									<tbody>

									</tbody>
									<tfoot>
										<th><input type="text" placeholder="经销商名称"></th>
										<th><input type="text" placeholder="经销商级别"></th>
										<th><input type="text" placeholder="上级经销商"></th>
										<th><input type="text" placeholder="地址"></th>
										<th><input type="text" placeholder="省份"></th>
										<th><input type="text" placeholder="城市"></th>
										<th><input type="text" placeholder="区县"></th>
										<th><input type="text" placeholder="战区"></th>
										<th><input type="text" placeholder="分区"></th>
										<th><input type="text" placeholder="经销商电话"></th>
										<th><input type="text" placeholder="联系人"></th>
									</tfoot>
								</table>
						</div>
				</div>
			</div>
		</div>
	</div>
	
	
	<div id='tb_user' style="display:none;margin-top:20px">
		
		<div class="panel panel-default">
			<div class="panel-heading">
				<h3 class="panel-title">存在重复的用户帐号数据</h3>
			</div>
			<div class="panel-body">
				<div class='col-md-12 form-group' >
						<div class="table-responsive">
								<table class="table table-striped table-bordered dt-responsive nowrap tb"
									cellspacing="0" width="100%">
									<thead>
										<tr>
											<th>帐号</th>
											<th>经销商</th>
											<th>注册时间</th>
										</tr>
									</thead>
									<tbody>

									</tbody>
									<tfoot>
										<th><input type="text" placeholder="帐号"></th>
										<th><input type="text" placeholder="经销商"></th>
										<th><input type="text" placeholder="注册时间"></th>
									</tfoot>
								</table>
						</div>
				</div>
			</div>
		</div>
	</div>
</div>