@extends('admin.master')

@section('top')
	<div class="top-breadcrumb">
        <h5>系统语言包</h5>
    </div>
@endsection

@section('ordersearch')
<div class="order-search mb-10">
	<div class="clearfix">
	@if(auth()->user()->isMaster())
	    <div class="top-btn-group pull-left">
			<a href="{{ url('admin/system-lang/create') }}" class="btn btn-primary">
				<i class="iconfont icon-plus"></i><span>添加</span>
			</a>
		</div>
	@endif
	</div>
</div>		
@endsection

@section('content')
{{--<ul class="nav nav-tabs nav-tabs system-tab mt-15 mb-15 clearfix">--}}
{{--	@foreach ($langs as $key => $value)--}}
{{--        <li role="presentation" class="pull-left @if($value->slug == $lang)active @endif">--}}
{{--            <a href="{{ url('admin/system-lang?lang='.$value->slug) }}"><img src="{{ url($value->img) }}"> {{ $value->name }}</a>--}}
{{--        </li>--}}
{{--    @endforeach--}}
{{--</ul>--}}
{!! Form::model($data, ['route' => ['admin.system-lang.update', $lang], 'method'=>'put', 'class'=>'form-horizontal form-ajax']) !!}
<table class="table table-hover">
	<thead>
		<tr>
			<th>中文备注</th>
			<th>标签名</th>
			<th>标签内容</th>
			@if(auth()->user()->isMaster())
			<th width="110" class="text-center">操作</th>
			@endif
		</tr>
	</thead>
	<tbody>
	@if(!empty($data['list']))
		@foreach ($data['list'] as $key => $value)
			<tr>
				<td>{{ $data['map'][$key] or '' }}</td>
				<td>{{ $key }}</td>
				<td>
					<input name="names[{{ $key }}]" value="{{ $value }}" class="form-control len">
				</td>
				@if(auth()->user()->isMaster())
				<td class="text-center">
					<div class="toolbar">
						<a href="javascript:void(0);" data-id="{{ $key }}" class="btn-link delete-item">删除</a>
					</div>
				</td>
				@endif
			</tr>
		@endforeach
		<tr>
			<td>
				<div class="foot-wrap">
					<div class="pull-left">
						<span class="inline-block mr-10">共 {{ count($data['list']) }} 条记录</span>
						{!! Form::submit('更新保存', ['class'=>'btn btn-primary']) !!}
					</div>
				</div>
			</td>
			<td class="text-left" colspan="5"></td>
		</tr>
	@endif
	</tbody>
</table>
@if(empty($data['list']))
	<div class="nodata-wrap">
		<div class="notice-null"><span class="inline-block">暂无数据</span></div>
	</div>
@endif
{!! Form::close() !!}
@endsection

@section('notice')
<!-- Modal -->
<div class="modal fade" id="dialog" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
            <div class='col-sm-1 text-center'><i class='iconfont icon-zhuyi'></i></div>
            <div class='col-sm-11 breakall'><p>删除后您将无法恢复，请谨慎操作</p><p class='text-muted'>您确认要删除吗？</p></div>
        </div>
        <div class="modal-footer">
        	<button type="button" class="btn btn-primary btn-modal-ok">确定</button>
        	<button class="btn btn-default btn-modal-cancel btn-modal-close" data-dismiss="modal">取消</button>
        </div>
    </div>
  </div>
</div>
<!-- Modal End -->
<!-- Modal -->
<div class="modal fade" id="dialog-tip" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
			<div class='col-sm-1 text-center'><i class='fa fa-times-circle text-size-32 text-warning'></i></div>
			<div class='col-sm-11 breakall'><p class="delete-error">删除失败！</p></div>
		</div>	
        <div class="modal-footer">
			<button class="btn btn-primary btn-modal-close" data-dismiss="modal">确定</button>
        </div>
    </div>
  </div>
</div>
<!-- Modal End -->
@endsection

@section('foot')
<script type="text/javascript">
// 删除
$('.delete-item').on('click', function(e) {
	var deleteAction = location.pathname;
	var id = $(this).data('id');
	url = deleteAction + '/' + id;

	$('#dialog').modal('show');
	return false;		
});

$('body').on('click', '.btn-modal-common', function(){
	$(this).parents('#dialog-common').modal('hide');
});

$('body').on('click', '.btn-modal-ok', function() {
	$(this).parents('#dialog').modal('hide');
	$.ajax({
		type: "DELETE",
		url: url,
		success: function(data) {
			if (data.code == 200) {
				swal({
					title: "", 
					text: "信息删除成功！",
					type: "success",
					showConfirmButton: false,
					timer: 1200,
				});
				setTimeout("location.reload()", 1200);
			} else {
				$('.delete-error').html(data.error);
				$('#dialog-tip').modal('show');
			}
		}
	});
});
</script>
@endsection
