@extends('admin.layout')

@section('content')
<div class="wrapper wrapper-content animated fadeInRight" id="app">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-title">
					<h5><?php echo isset($data['id']) ? '编辑' : '添加'; ?>用户</h5>
					<div class="ibox-tools">
						<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
						</a>
					</div>
				</div>
				<div class="ibox-content">
                    @if(role('Foundation/User/index'))
				    <div class="row">
    					<div class="col-sm-3 pull-right">
    					   <a href="{{ U('Base/User/index')}}" class="btn btn-sm btn-primary pull-right">返回列表</a>
    					</div>
					</div>
                    @endif
					<div class="row">
            			<div class="col-lg-10">
                            <form name="form_product" id="form-validation" action="" class="form-horizontal form-validation" accept-charset="UTF-8" method="post">

                                <div class="form-group">
                                    <label class="control-label col-sm-3">所属角色</label>
                                    <div class="col-sm-9">
                                        @foreach($roles AS $val)
                                        <label class="checkbox-inline">
                                            <input type="checkbox" name="info[admin_role_id][]" value="{{ $val['id'] }}" @if(isset($data['admin_role_id']) && in_array($val['id'], explode(',', $data['admin_role_id']))) checked @endif>{{ $val['name'] }}
                                        </label>
                                        @endforeach
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-sm-3">账号</label>
                                    <div class="col-sm-9"><input id="txt_username" name="info[name]" class="form-control" value="{{ $data['name'] or ''}}" placeholder="账号名"></div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-sm-3">昵称</label>
                                    <div class="col-sm-9"><input id="txt_name" name="info[real_name]" class="form-control" value="{{ $data['real_name'] or ''}}" placeholder="昵称"></div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-sm-3">E-mail</label>
                                    <div class="col-sm-9"><input id="txt_email" name="info[email]" class="form-control" value="{{ $data['email'] or ''}}" placeholder="邮箱"></div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-sm-3">电话</label>
                                    <div class="col-sm-9"><input id="txt_mobile" name="info[mobile]" class="form-control" value="{{ $data['mobile'] or ''}}"  placeholder="手机"></div>

                                </div>

                                @if($data['is_root'] == 1)
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">选择商户 </label>

                                        <div class="col-sm-6">
                                            <input id="data_store" class="form-control" v-model="checkstore.name"   readonly placeholder="">
                                            <input id="data_store_id" type="hidden" name="info[store_id]" v-model="checkstore.id"  required="" aria-required="true"  placeholder="">
                                        </div>

                                        <div class="col-sm-3">
                                            <button type="button" class="btn btn-w-m btn-primary" data-toggle="modal" data-target="#myModal5" onclick="SearchStore()" @if(!empty($data['mobile'])) disabled="disabled" @endif>选择</button>
                                        </div>
                                    </div>
                                @endif

                                <div class="form-group">
                                    <label class="control-label col-sm-3">密码</label>
                                    <div class="col-sm-9">
                                        <input id="c_page" name="info[password]" class="form-control" value="" @if(isset($data['id']) ) placeholder="不修改请留空" @else placeholder="请输入密码" @endif>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-sm-3">&nbsp;</label>
                                    <div class="col-sm-9">
                                        <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>
										<input type="hidden" name="_referer" value="<?php echo urlencode($_SERVER['HTTP_REFERER']); ?>"/>
                                        <input type="submit" class="btn btn-success" style="margin-right:20px;">
                                        <input type="reset" class="btn btn-default" >
                                    </div>
                                </div>
                            </form>
                        </div>
            			<!-- /.col-lg-10 -->
            		</div>
            		<!-- /.row -->
				</div>
			</div>
		</div>
	</div>
    <div class="modal inmodal fade" id="myModal5" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">选择厂商</h4>
                    <div class="search-form">
                        <div class="input-group">
                            <input type="text" placeholder="厂商名/ID/电话" name="search" class="form-control input-lg">
                            <div class="input-group-btn">
                                <button class="btn btn-lg btn-primary" type="submit" onclick="SearchStore()">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-body app_v" id="userList" style="max-height: 420px;overflow: auto;">
                    <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                        <thead>
                        <tr>
                            <th> ID</th>
                            <th> 名称</th>
                            <th> 电话</th>
                            <th>相关操作</th>
                        </tr>
                        </thead>
                        <tbody style="max-height: 500px;">
                        <tr v-if="list.num == 0">
                            <td colspan="4" style="text-align: center">暂无数据</td>
                        </tr>
                        <tr v-for="item in list.data" v-if="list.num > 0">
                            <td>@{{ item.id }}</td>
                            <td>@{{ item.name }}</td>
                            <td>@{{ item.phone }}</td>
                            <td>
                                <button class="btn btn-sm btn-success"
                                        v-on:click="checkStore(item)" data-dismiss="modal">
                                    选择
                                </button>
                            </td>
                        </tr>

                        </tbody>
                    </table>
                </div>


            </div>
        </div>
    </div>
</div>
<script src="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/js/vue.js"></script>
<link href="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/css/plugins/toastr/toastr.min.css" rel="stylesheet">
<script src="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/js/plugins/toastr/toastr.min.js"></script>
<script>
    toastr.options.positionClass = 'toast-bottom-center';
    var store_id = "{{ $store['store_id'] or '0'}}";
    var store_name = "{{ $store['name'] or ''}}";
    var set = new Vue({
        el:"#app",
        data:{
            list:{
                num:0,
                data:[],
            },
            checkstore:{
                name:'请选择商户',
                id:0
            },
        },
        methods:{
            init:function(){
                if(store_name && store_id!=0){
                    Vue.set(this.checkstore,'name',store_name);
                    Vue.set(this.checkstore,'id',store_id);
                }
            },
            checkStore:function (store) {
                Vue.set(this.checkstore,'name',store.name);
                Vue.set(this.checkstore,'id',store.id);
            },
            changeData:function (e) {
                var num = e.length;
                Vue.set(this.list,'data',e)
                Vue.set(this.list,'num',num)
            }
        }
    });
    set.init();
    function SearchStore(){
        var keywords = $("input[name='search']").val();
        /* if(keywords == ''){
             toastr.error('请输入搜索值!');
             return false;
         }*/
        $.ajax({
            url: "{{ U('Base/User/searchStore') }}",
            method: 'POST',
            data: {
                'keywords':keywords,
                '_token':"{{ csrf_token() }}"
            },
            dataType:'json',

            success: function(data) {
                set.changeData(data.data, 'user');
            }
        });
    }

</script>
@endsection
