@extends('admin.master')

@section('style')
<link href="{{ asset('data/assets/css/bootstrap-datetimepicker.css') }}" rel="stylesheet">
@endsection

@section('top')
	<div class="top-breadcrumb pull-left">
		<h5>谷歌推广关键词</h5>
	</div>
@endsection

@section('ordersearch')
<div class="order-search mb-10">
	@if(auth()->user()->isMaster())
	<input type="file" id="file" style="display: none;">
	<div class="top-btn-group font-14">
		<a href="http://cn86-test.oss-cn-hangzhou.aliyuncs.com/data/upload/2018/01/06f024e892kdmhfw.csv" class="btn-link pl-5 pr-5" download="关键词模板">导入关键词模板下载</a> | 
		<a href="javascript:void(0)" id="import" class="btn-link pl-5 pr-5">关键词导入</a> | 
		<a href="{{ url('admin/sem-keyword/export') }}" class="btn-link pl-5 pr-5">关键词导出</a>
	</div>
	@endif
	</div>
@endsection

@section('content')
{!! Form::open(['route' => 'admin.sem-keyword.index', 'method' => 'post', 'class'=>'form-ajax']) !!}
<table class="table table-hover">
	<thead>
		<tr>
			<th width="60" class="text-center">序号</th>
			<th>名称</th>
		</tr>
	</thead>
	<tbody>
	@if(!$data->isEmpty())
		@foreach ($data as $key => $value)
			<tr>
				<td>{{ $key + 1 }}</td>
				<td>{{ $value->name }}</td>
			</tr>
		@endforeach
	@endif
	</tbody>
</table>
@if($data->isEmpty())
	<div class="nodata-wrap">
		<div class="notice-null"><span class="inline-block">暂无数据</span></div>
	</div>
@endif
{!! Form::close() !!}
@endsection


@section('foot')
@if(auth()->user()->isMaster())
<script>
$(function(){
	$('#import').on('click', function(){	
		$('#file').trigger('click');
	});
	$("body").on('change','#file',function () {
        var file = $('#file')[0].files[0];
        var pos = file.name.lastIndexOf(".");
        var type = file.name.substring(pos + 1).toLowerCase();
        if (type != 'csv') {
        	swal({
        		title: '关键词导入',
				text: "文件格式必须是 csv！",
				timer: 4000,
				type: "warning",
				confirmButtonText: "关闭"
			});
        }
        var formData = new FormData();
        formData.append('file', file);

		$.ajax({
            type: "POST",
            data: formData,
            contentType: false,
            processData: false,
            url: HOME_URL + '/admin/sem-keyword/import',
            success: function(data) {
                if (data.status == 'success') {
                	swal({
		        		title: '',
						text: "关键词导入成功！",
						timer: 1200,
						type: "success",
						showConfirmButton: false
					});
					setTimeout("location.reload()", 1200);
                }
            }
        });

        $('#file').replaceWith('<input type="file" id="file" style="display: none;">');
    });
})
</script>
@endif
@endsection
