@extends('admin.layout') 

@section('content')
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-title">
					<h5>价格列表</h5>
					<div class="ibox-tools">
						<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
						</a>
					</div>
				</div>
				<div class="ibox-content">
				    <div class="row">
				        <form method="GET" action="" accept-charset="UTF-8">
							<div class="col-sm-2">
								<select id="data_parent_id" class="form-control" onchange="getLevelSecondCategory()">
									<option value="0">全部</option>
									@if(isset($cat))
										@foreach($cat as $key=>$val)
											<option value="{{$val->id}}" >{{$val->name}}</option>
										@endforeach
									@endif
								</select>
							</div>
							<div class="col-sm-2" id="app">
								<select name="cat_id" id="data_cat_id" class="form-control"  required="" aria-required="true">
									<option v-for="item in list.data" :value="item.id">@{{ item.name }}</option>
								</select>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<input type="text" value="{{Request::get('keyword')}}"	placeholder="请输入关键词" name="keyword"class="input-sm form-control">
									<span class="input-group-btn">
										<button type="submit" class="btn btn-sm btn-primary">搜索</button>
									</span>
								</div>
							</div>
				        </form>
						@if(role('Album/Product/Price/create'))
    					<div class="col-sm-3 pull-right">
    					   <a href="{{ U('Album/Agent/index')}}" class="btn btn-sm btn-primary pull-right">返回</a>
    					</div>
						@endif
					</div>
					
					<table class="table table-striped table-bordered table-hover dataTables-example dataTable">
						<thead>
    						<tr>
								
            <th class="sorting" data-sort="id"> ID </th>
            <th> 商品名 </th>
            <th> 商品分类 </th>
            <th> 商品图片 </th>
            <th class="sorting" data-sort="product_id"> 商品ID </th>
            <th class="sorting" data-sort="mobile"> 经销商电话 </th>
            <th> 厂家价 </th>
            <th class="sorting" data-sort="price"> 价格 </th>
        						{{--<th width="22%">相关操作</th>--}}
        					</tr>
						</thead>
						<tbody>
						@if(isset($list))
							@foreach($list as $key => $item)							<tr>
								
            <td>{{ $item->id }}</td>
            <td>{{ $item->product_name }}</td>
            <td>{{ $item->cat }}</td>
            <td><img src="{{ $item->product_pic }}" width="50"/></td>
            <td>{{ $item->product_id }}</td>
            <td>{{ $item->mobile }}</td>
            <td>{{ $item->product_ma_price_comment }}</td>
            <td>{{ $item->price }}</td>
								{{--<td>
									<div class="btn-group">
										<button data-toggle="dropdown"
											class="btn btn-warning btn-sm dropdown-toggle"
											aria-expanded="false">
											操作 <span class="caret"></span>
										</button>
										<ul class="dropdown-menu">


											@if(role('Album/Product/Price/update'))
											<li><a href="{{ U('Album/Product/Price/update',['id'=>$item->id])}}" class="font-bold">修改</a></li>
											@endif

											@if(role('Album/Product/Price/destroy'))
											<li class="divider"></li>
											<li><a href="{{ U('Album/Product/Price/destroy',['id'=>$item->id])}}" onclick="return confirm('你确定执行删除操作？');">删除</a></li>
											@endif

										</ul>
									</div>
								@if(role('Album/Product/Price/view'))
										<button onclick="layer.open({type: 2,area: ['80%', '90%'],content: '{{ U('Album/Product/Price/view',['id'=>$item->id])}}'});"  class="btn btn-primary ">查看</button>
									@endif
								</td>--}}
							</tr>
							@endforeach
							@endif

						</tbody>
					</table>
					<div class="row">
						<div class="col-sm-6">
							<div class="dataTables_info" id="DataTables_Table_0_info"
								role="alert" aria-live="polite" aria-relevant="all">每页{{ $list->count() }}条，共{{ $list->lastPage() }}页，总{{ $list->total() }}条。</div>
						</div>
						<div class="col-sm-6">
						<div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
						{!! $list->setPath('')->appends(Request::all())->render() !!}
						</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="/base/js/vue.js"></script>
<link href="/base/css/plugins/toastr/toastr.min.css" rel="stylesheet">
<script src="/base/js/plugins/toastr/toastr.min.js"></script>
<script>
    toastr.options.positionClass = 'toast-bottom-center';
    toastr.options.timeOut = '4000';

    var level = new Vue({
        el:"#app",
        data:{
            list:{
                data:[
                    {'id':0,'name':'请先选择一级类目'},
                ],
            },
            //      num:0
        },
        methods:{
            changeData:function (e) {
                Vue.set(this.list,'data',e)
            }
        }
    });

    function getLevelSecondCategory(){
        var first = $('#data_parent_id').val();
        if (first == 0) {
            level.changeData([{'id':-1,'name':'全部'}]);
            return;
		}
        $.ajax({
            url: "{{ U('Album/Product/getSecondCategory') }}",
            method: 'POST',
            data: {
                'cat_id':first,
                '_token':"{{ csrf_token() }}"
            },
            dataType:'json',

            success: function(data) {
                if (data.code == 0) {
                    level.changeData(data.data);
                } else {
                    toastr.error(data.message);
                }
            }
        });
    }
    getLevelSecondCategory();

</script>
@endsection