<?php /* /www/wwwroot/jian/resources/views/Admin/you-add.blade.php */ ?>
<?php $__env->startSection('admin'); ?>
<script src="/admin/plugins/jquery/jquery.min.js"></script>
<script src="/admin/layer-v3.1.1/layer/layer.js"></script>
<script src="/img_cate/jquery-1.10.2.js"></script>
<script src="/layDate-v5.0.9/laydate/laydate.js"></script>
<style>
  img {
    max-width: 100%;
  }
  label{
    font-size:14px;
  }
  .label-title{
    font-size:16px;
    color:#7A0008;
  }
</style>
<div class="content-wrapper" style="min-height: 810px;">
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h4>添加优惠券</h4>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/admin/index">首页</a></li>
              <li class="breadcrumb-item active">优惠券管理</li>
              <li class="breadcrumb-item active">优惠券列表</li>
              <li class="breadcrumb-item active">添加优惠券</li>
            </ol>
          </div>
        </div>
      </div>
    </section>
    <div class="col-xs-3">
        <button class="btn btn-danger back" style="margin-left:17px;margin-bottom:15px"> 返回列表</button>
    </div>

    <section class="content">
        
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">
            <div class="card">
              <div class="card-body p-0">
                <!-- 表单 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4 label-title"><span style="color:red">*</span> 优惠券名称　(<span style="font-size:10px;color:red">标题尽量不要超过10字</span>)</label>
                        <input type="text" class="form-control col-md-6 name" autocomplete="off" placeholder="请输入标题 如 新春快乐优惠券">
                    </div>
                </form>
                <!-- 折扣方式 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-3 label-title"><span style="color:red">*</span> 优惠方式</label>
                    </div>
                    <div class="form-group m-4">
                         <label class="col-md-1"><input class="check" type="radio" name="type" value="1" checked> 直减</label> 
                         <label class="col-md-1"><input class="check" type="radio" name="type" value="2"> 折扣</label>
                    </div>
                </form>
                <!-- 折扣或直减金额 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-12 label-title"><span style="color:red">*</span> 折扣或直减金额　(<span style="font-size:10px;color:red">折扣：假如折扣9.5折就填 95 , 填的超过100默认9.9折。直减：优惠30元直接填30</span>)</label>
                        <input type="number" class="form-control col-md-6 price" autocomplete="off">
                    </div>
                </form>
                <!-- 使用门槛 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4 label-title"><span style="color:red">*</span> 使用门槛</label>
                        <select class="form-control col-md-6 use_height_type" id="use_height_type">
                            <option value="1">无门槛</option>
                            <option value="2">满减</option>
                        </select>
                    </div>
                </form>
                <!-- 满减金额 -->
                <form class="form" id="none" style="display:none">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4 label-title"> 满减金额</label>
                        <input type="number" class="form-control col-md-6 use_height" autocomplete="off" id="use_height">
                    </div>
                </form>
                <!-- 发放数量 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4 label-title"><span style="color:red">*</span> 发放类型</label>
                        <select class="form-control col-md-6 send_type" id="send_type">
                            <option value="1">无限制</option>
                            <option value="2">自定义</option>
                        </select>
                    </div>
                </form>
                <!-- 发放数量限制 -->
                <form class="form" id="send_none" style="display:none">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4 label-title"> 发放数量</label>
                        <input type="number" class="form-control col-md-6 send_num" autocomplete="off">
                    </div>
                </form>
                <!-- 有效期 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4 label-title"><span style="color:red">*</span> 有效期至</label>
                        <input type="text" class="form-control col-md-6 end_date" autocomplete="off" id="date">
                    </div>
                </form>
                <!-- 门店选择 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4 label-title"><span style="color:red">*</span> 门店可用</label>
                        <select class="form-control col-md-6 md" id="md">
                            <option value="0" selected>全部门店</option>
                            <?php $__currentLoopData = $md; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($v -> id); ?>"><?php echo e($v -> md_name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                </form>

                <!-- 适用范围 -->
                <div class="form-group m-4">
                    <label for="name" class="col-sm-4 control-label label-title"><span style="color:red">*</span> 适用范围</label>
                      <div class="col-sm-4">
                        <div class="radio">
                            <label>
                                <input type="radio" class="use_type" name="use_type" value="1" checked> 全部商品
                            </label>
                        </div>
                        <hr>
                                                    <!-- 指定以下商品可用 -->
                        <div class="radio">
                            <label>
                                <input type="radio" class="use_type" name="use_type" value="2" > 指定以下商品可用
                            </label>
                                <div class="checkbox aa">
                                  <?php $__currentLoopData = $goods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <label style="margin-left:20px">
                                        <input type="checkbox" class="use_size2" value="<?php echo e($val -> id); ?>"> <?php echo e($val -> goods_name); ?>

                                    </label>
                                  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </div>
                        </div>
                        <hr>
                                                     <!-- 指定以下商品不可用 -->
                        <div class="radio">
                            <label>
                                <input type="radio" class="use_type" name="use_type" value="3" > 指定以下商品<span style="color:red">不可用</span>
                            </label>
                                <div class="checkbox bb">
                                   <?php $__currentLoopData = $goods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <label style="margin-left:20px">
                                        <input type="checkbox" class="use_size3" value="<?php echo e($val -> id); ?>"> <?php echo e($val -> goods_name); ?>

                                    </label>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </div>
                        </div>
                     </div>
                  </div>
                <!-- 发放对象 -->
                <div class="form-group m-4">
                    <label for="name" class="col-sm-4 control-label label-title"><span style="color:red">*</span> 发放对象</label>
                      <div class="col-sm-4">
                        <div class="radio">
                            <label>
                                <input type="radio" value="1" class="all_user" name="user_type" checked> 所有用户
                            </label>
                        </div>
                        <hr>
                        <div class="radio">
                            <label>
                                <input type="radio" value="2" class="type_user" name="user_type"> 指定类型
                            </label>
                                <div class="checkbox">
                                  
                                    <label style="margin-left:20px">
                                        <input type="checkbox" class="user_arr" value="1"> 会员
                                    </label>
                                    <label style="margin-left:20px">
                                        <input type="checkbox" class="user_arr" value="2"> 非会员
                                    </label>
                                    <label style="margin-left:20px">
                                        <input type="checkbox" class="user_arr" value="3"> 新用户
                                    </label>
                                </div>
                        </div>
                        <hr>
                         <div class="radio">
                            <label>
                                <input type="radio" value="3" class="one_user" name="user_type"> 指定用户
                            </label>
                         </div>
                        <hr>
                     </div>
                  </div>
                  <form class="form-group m-4 new" style="display:none">
                      <div class="input-group input-group-sm">
                      <input type="text" placeholder="输入用户微信昵称" class="form-control col-sm-4 keywords">
                        <span class="input-group-append">
                          <a href="javascript:void(0)" class="btn btn-info btn-flat search">搜索</a>
                        </span>
                      </div>
                      <br>
                      <ul class="list-group col-sm-4 new2" style='display:none'>
                        
                      </ul>
                  </form>

                  <!-- 优惠详细说明 -->
                  <form class="form">
                    <div class="form-group m-4">
                      <label class="label-title">优惠券说明</label>
                      <textarea class="form-control col-md-6 tips" rows="3" cols="25" placeholder="Enter ..."></textarea>
                    </div>
                  </form>

                <form class="form">
                    <div class="form-group m-4 col-sm-6">
                        <a class="btn btn-success ok" style="color:white">发送</a>
                    </div>
                </form>
                <!-- 表单结束 --> 

              </div>
            </div>
          </div>
        </div>
    </section>
  </div>

<script>
//优惠券有效期
laydate.render({
  elem: '#date'
  ,type: 'datetime'
});
//返回列表
$('.back').click(function(){
    window.location.href="/admin/you/list";
})
//无门槛或者满减联动
$('#use_height_type').change(function(){
    var id = $('#use_height_type option:selected').val();
    if(id == 1){
        $('#none').attr('style','display:none');
    }else{
        $('#none').attr('style','display:block');
    }
})
//发放数量限制联动
$('#send_type').change(function(){
    var id = $('#send_type option:selected').val();
    if(id == 1){
        $('#send_none').attr('style','display:none');
    }else{
        $('#send_none').attr('style','display:block');
    }
})
//门店联动获取商品
$('#md').change(function(){
    var md_id = $('#md option:selected').val();
    $.get('/admin/you/getGoods',{md_id:md_id},function(res){
        $('.aa').html(' ');
        $('.bb').html(' ');
      for(x in res){
        $('.aa').append('<label style="margin-left:20px"><input type="checkbox" class="use_size2" value='+res[x].id+'>'+res[x].goods_name+'</label>');
        $('.bb').append('<label style="margin-left:20px"><input type="checkbox" class="use_size3" value='+res[x].id+'>'+res[x].goods_name+'</label>');
      }
    })
})
//指定单个用户
$('.one_user').change(function(){
    if($(this).prop('checked')) {
      $('.new').attr('style','display:block');
    }  
})
$('.all_user').change(function(){
  $('.new').attr('style','display:none');
})
$('.type_user').change(function(){
  $('.new').attr('style','display:none');
})
//搜索
$('.search').click(function(){
    var kw = $('.keywords').val();
    if(!kw){
      layer.alert('搜索条件不能为空');
      return false;
    }
    $.get('/admin/you/search',{kw:kw},function(res){
      if(res.code == '1000') {
        //干掉旧的
        $('.new2').html(' ');
        if(res.result.length){
          for(x in res.result) {
            $('.new2').attr('style','display:block');
            $('.new2').append('<li class="list-group-item" style="font-size:14px"><input type="checkbox" value='+ res.result[x].id +' class="search_user">　　<img style="height:30px;width:30px" src='+ res.result[x].header +'>　'+res.result[x].nickname+'</li>');
          }
        }else{
            $('.new2').attr('style','display:block');
            $('.new2').append('<li class="list-group-item" style="font-size:14px">暂无结果</li>');
        }
      }
    })
})
//发送优惠券
$('.ok').click(function(){
    var name = $('.name').val();if(!name){ layer.alert('请填写优惠券名称');return false;}    //优惠券名称
    var type = $('input:radio[name="type"]:checked').val(); if(!type){ layer.alert('请选择优惠方式');return false;}  //优惠券折扣或直减类型
    var price = $('.price').val(); if(!price){ layer.alert('请填写优惠/折扣金额');return false;} //优惠券价格
    var use_height_type = $('.use_height_type').val();if(!use_height_type){ layer.alert('请选择使用门槛');return false;}   //优惠券使用门槛 1无门槛
    var use_height = $('.use_height').val();if(use_height_type == 2 && !use_height){ layer.alert('请填写满减金额');return false;}   //使用门槛金额
    var send_type = $('.send_type').val();if(!send_type){ layer.alert('请选择发放类型');return false;}   //发放类型
    var send_num = $('.send_num').val();if(send_type == 2 && !send_num){ layer.alert('请填写发放数量');return false;}   //发放数量
    var end_date = $('.end_date').val();if(!end_date){ layer.alert('请填写截止时间');return false;}   //截止时间
    var md = $('.md').val();if(md === ''){ layer.alert('请选择门店');return false;}   //门店
    var use_type = $('input:radio[name="use_type"]:checked').val(); if(!use_type){ layer.alert('请选择使用范围');return false;}  //请选择使用范围
    var use_size2 = [];   //可用商品
    $('.use_size2').each(function(k,v){
      if($(v).prop('checked')){
        use_size2.push($(v).val());
      }
    })
    if(use_type == 2 && !use_size2.length){ layer.alert('请至少选择一件可用商品');return false;}

    var use_size3 = [];   //不可用商品
    $('.use_size3').each(function(k,v){
      if($(v).prop('checked')){
        use_size3.push($(v).val());
      }
    })
    if(use_type == 3 && !use_size3.length){ layer.alert('请至少选择一件不可用商品');return false;}

    var user_type = $('input:radio[name="user_type"]:checked').val(); if(!user_type){ layer.alert('请选择指定类型用户群体');return false;}  //发放用户类型
    var user_arr = [];  //指定用户类型
    $('.user_arr').each(function(k,v){
      if($(v).prop('checked')){
        user_arr.push($(v).val());
      }
    })
    if(user_type == 2 && !user_arr.length){ layer.alert('请至少选择一个用户类型');return false;}
    var search_user = [];
    $('.search_user').each(function(k,v){
      if($(v).prop('checked')){
        search_user.push($(v).val());
      }
    })
    if(user_type == 3 && !search_user.length){ layer.alert('请至少选择一个指定用户');return false;}
    var tips = $('.tips').val();
    console.log('名称:'+ name,'优惠券类型:'+ type,'直减或者折扣价格:'+ price,'优惠券使用门槛:'+ use_height_type,'门槛金额:'+ use_height,'发放类型:'+ send_type,'发放数量:'+ send_num,'结束时间:'+ end_date,'门店:'+ md,'使用范围:'+ use_type,'可用商品:'+ use_size2,'不可用商品:'+ use_size3,'发放用户类型:'+ user_type,'指定用户类型会员 非会员:'+ user_arr,'自定义用户Id'+ search_user,'优惠券介绍:'+ tips);
    $.post('/admin/you/doadd',{name:name,type:type,price:price,use_height_type:use_height_type,use_height:use_height,send_type:send_type,send_num:send_num,end_date:end_date,md:md,use_type:use_type,use_size2:use_size2,use_size3:use_size3,user_type:user_type,user_arr:user_arr,search_user:search_user,tips:tips},function(res){
      console.log(res);
    })
})
</script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('title','优惠券列表'); ?>
<?php $__env->startSection('youhui','menu-open'); ?>
<?php $__env->startSection('youhui2','active'); ?>
<?php $__env->startSection('youhui-list','active'); ?>
<?php echo $__env->make('Public.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>