@extends('admin.layout')
@section('header')

    <link href="{{ session()->get('is_we7')=='true'?'/addons/online_album/public':'' }}/base/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />

    <script src="{{ session()->get('is_we7')=='true'?'/addons/online_album/public':'' }}/base/js/fileinput.js" type="text/javascript"></script>
    <script src="{{ session()->get('is_we7')=='true'?'/addons/online_album/public':'' }}/base/js/fileinput_locale_zh.js" type="text/javascript"></script>

@endsection
@section('content')

    <?php
    if(!isset($data)) $data = array();
    if(!$data && session("data")){
        $data = session("data");
    }
    if(!$data && session('_old_input')){
        $data = session("_old_input");
    }
    ?>
    <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">
                        @if(role('Album/Product/index'))
                            <div class="row">
                                <div class="col-sm-3 pull-right">
                                    <a href="{{ U('Album/Product/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" enctype="multipart/form-data" accept-charset="UTF-8" method="post" onsubmit="return checkLevel()">


                                    <div class="form-group">

                                        <label class="control-label col-sm-3">产品名称</label>

                                        <div class="col-sm-9">
                                            <input id="data_store_id" name="data[name]" class="form-control" value="{{ $data['name'] or ''}}" required="" aria-required="true"  placeholder="">
                                        </div>
                                    </div>
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">分类</label>

                                        <div class="col-sm-3">
                                            <select id="data_parent_id" class="form-control" name="data[cat_id]" >
                                                @if(isset($category))
                                                    @foreach($category as $key=>$val)
                                                        <option value="0" disabled="disabled">|--{{$val['name']}}</option>
                                                        @foreach($val['son'] as $index=>$item)
                                                            <option value="{{$item->id}}"  @if($item['id'] == (isset($data['cat_id'])? $data['cat_id']:''))selected @endif>&nbsp&nbsp|-{{$item->name}}</option>
                                                        @endforeach
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                        {{--<div class="col-sm-3" id="app">
                                            <select name="data[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>
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">默认价格</label>

                                        <div class="col-sm-9">
                                            <input id="data_store_id" name="data[price_default]" type="number" class="form-control" value="{{ $data['price_default'] or ''}}" required="" aria-required="true"  placeholder="">
                                        </div>
                                    </div>
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">出厂价格</label>

                                        <div class="col-sm-9">
                                            <input id="data_ma_price" name="data[ma_price]" type="number" class="form-control" value="{{ $data['ma_price'] or ''}}" required="" aria-required="true"  placeholder="">
                                        </div>
                                    </div>
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">出厂价备注</label>

                                        <div class="col-sm-9">
                                            <input id="data_ma_price_comment" name="data[ma_price_comment]" class="form-control" value="{{ $data['ma_price_comment'] or ''}}"  placeholder="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-sm-3">排序</label>
                                        <div class="col-sm-9">
                                            <input id="data_sort" name="data[sort]" class="form-control" value="{{ $data['sort'] or '0'}}" required="" aria-required="true"  placeholder="数值越大越靠前">
                                            <span class="help-block m-b-none">数值越大越靠前</span>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-sm-3">是否促销新品</label>

                                        <div class="col-sm-9">
                                            @if(dict()->get('album','new') != null)
                                                @foreach(dict()->get('album','new') as $key=>$val)
                                                    <label class="radio-inline">
                                                        <input type="radio" name="data[hot_cake]" value="{{$key}}" @if(isset($data['hot_cake']) && $data['hot_cake'] == $key)checked="checked" @endif/>{{$val}}
                                                    </label>
                                                @endforeach
                                            @else
                                                <label class="radio-inline">
                                                    <input type="radio" name="data[hot_cake]">
                                                </label>
                                            @endif
                                        </div>

                                    </div>
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">尺寸图片
                                            <br/>
                                            <small class="text-navy">(1920像素 * 1080像素)</small>
                                            </label>
                                        <div class="col-sm-9">
                                            {{--{!!  widget('Tools.ImgUpload')->single2('/upload/attr','attr',"attr",  isset($data['attr'])? $data['attr'] : '',array("sizex"=>1920,"sizey"=>1080)) !!}--}}
                                            {!!  widget('Tools.ImgUpload')->multi2('/upload/specifications_img','specifications_img',"data[specifications_img]",  isset($data['specifications_img'])? $data['specifications_img'] : '',array("sizex"=>1920,"sizey"=>1080)) !!}
                                        </div>
                                    </div>

                                    <div class="form-group">

                                        <label class="control-label col-sm-3">安装图片<br/>
                                            <small class="text-navy">(1920像素 * 1080像素)</small></label>
                                        <div class="col-sm-9">
                                            {!!  widget('Tools.ImgUpload')->multi2('/upload/install_img','install_img',"data[install_img]",  isset($data['install_img'])? $data['install_img'] : '',array("sizex"=>1920,"sizey"=>1080)) !!}
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-sm-3">首页图片<br/>
                                            <small class="text-navy">(480像素 * 270像素)</small></label>
                                        <div class="col-sm-9">
                                            {{--{!!  widget('Tools.ImgUpload')->single2('/upload/cover_pic','cover_pic',"cover_pic",  isset($data['cover_pic'])? $data['cover_pic'] : '',array("sizex"=>662,"sizey"=>510)) !!}--}}
                                            {!!  widget('Tools.ImgUpload')->single2('/upload/thumb','thumb',"thumb",  isset($data['thumb'])? $data['thumb'] : '',array("sizex"=>480,"sizey"=>270)) !!}
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">高清主图<br/>
                                            <small class="text-navy">高清：(1920像素 * 1080像素)</small></label>
                                        <div class="col-sm-9">
                                            {{--{!!  widget('Tools.ImgUpload')->single2('/upload/cover_pic','cover_pic',"cover_pic",  isset($data['cover_pic'])? $data['cover_pic'] : '',array("sizex"=>662,"sizey"=>510)) !!}--}}
                                            {!!  widget('Tools.ImgUpload')->single2('/upload/cover_pic','cover_pic',"cover_pic",  isset($data['cover_pic'])? $data['cover_pic'] : '',array("sizex"=>1920,"sizey"=>1080)) !!}
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">搭配图片<br/>
                                            <small class="text-navy">(1920像素 * 1080像素)</small></label>
                                        <div class="col-sm-9">
                                            {!!  widget('Tools.ImgUpload')->single2('/upload/detail_pic','detail_pic',"detail_pic",  isset($data['detail_pic'])? $data['detail_pic'] : '',array("sizex"=>1920,"sizey"=>1080)) !!}
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-sm-3">产品详情</label>
                                        <div class="col-sm-9">
                                            {{--     //{!! ueditor('') !!}--}}
                                            {!!  widget('Tools.ImgUpload')->multi2('/upload/detail','detail',"data[detail]",  isset($data['detail'])? $data['detail'] : '') !!}
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-sm-3">安装视频</label>
                                        <div class="col-sm-9">
                                            <div style="height: auto;width: 200px;">
                                                <video controls width="100px" height="100px">
                                                    <source src="{{$data['upload_video'] ?? ''}}" type="video/mp4">
                                                </video>
                                            </div>
                                            <input id="file-0b" class="file" type="file" name="upload_video" value="">
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label class="control-label col-sm-3">&nbsp;</label>
                                        <div class="col-sm-9">
                                            <input type="hidden" name="_referer" value="<?php echo urlencode(request()->server('HTTP_REFERER'));?>"/>
                                            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>
                                            <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>
    <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();
              $.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();*/


        function checkLevel(){
            var second = $('#data_cat_id').val();
            if (second == 0) {
                toastr.error('请选择二级分类!');
                return false;
            }
            return true;
        }
    </script>
@endsection