<!-- include 'headAndLeftWrapper' -->
<div class="mainWrapper container-fluid">
  <div class="page-header pageTop">
    <h3>代金券</h3>
  </div>
  <div class="tableContent">
    <div class="tab-content">
      <div class="tabMain">
        <div class="shopContent clearfix">
          <div class="sort" style="margin-right:20px;">
            <button class="btn btn-primary" data-toggle="modal" data-target="#addVoucher">添加代金券</button>
          </div>
          <div class="sort" style="margin-right:20px;">
            <select class="form-control" id="searchList">
              <option value="-1">全部状态</option>
              <option value="1" <!-- if isset({{status}}) && {{status}} == 1 -->selected<!-- endif -->>进行中</option>
              <option value="2" <!-- if isset({{status}}) && {{status}} == 2 -->selected<!-- endif -->>已结束</option>
              <option value="0" <!-- if isset({{status}}) && {{status}} == 0 -->selected<!-- endif -->>未开始</option>
            </select>
          </div>
        </div>
        <div class="tableContent">
          <table class="table table-hover">
            <thead>
              <th width="300">活动名</th>
              <th width="100">领取码</th>
              <th width="100">金额</th>
              <th width="100">数量/领取</th>
              <th width="150">开始时间</th>
              <th width="150">结束时间</th>
              <th width="100">状态</th>
              <th width="100">操作</th>
            </thead>
            <tbody>
            <!-- if isset({{voucherlist}}) -->
            <!-- loop voucherlist -->
            <tr>
              <td>{{voucherlist' value.vname}}</td>
              <td>{{voucherlist' value.vcode}}</td>
              <td>￥{{voucherlist' value.vcost}}</td>
              <td <!-- if {{voucherlist' value.vcount}} != 0 && {{voucherlist' value.hadnum}} >= {{voucherlist' value.vcount}} -->class="text-danger"<!-- endif -->><!-- if {{voucherlist' value.vcount}} == 0 -->不限/{{voucherlist' value.hadnum}}<!-- else -->{{voucherlist' value.vcount}}/{{voucherlist' value.hadnum}}<!-- endif --></td>
              <td>{{formatDate(voucherlist' value.vstarttime)}}</td>
              <td <!-- if {{thistime}} >= {{voucherlist' value.vendtime}} -->class="text-danger"<!-- endif -->>{{formatDate(voucherlist' value.vendtime)}}</td>
              <td><!-- if {{voucherlist' value.status}} == 0 --><span class="text-warning">未开始</span><!-- elseif {{voucherlist' value.status}} == 1 --><span class="text-success">进行中</span><!-- elseif {{voucherlist' value.status}} == 2 --><span class="text-muted">已结束</span><!-- endif --></td>
              <td><!-- if {{voucherlist' value.status}} == 0 --><a href="/m/delvoucher/{{voucherlist' value.id}}" class="text-danger"><i class="glyphicon glyphicon-remove"></i> 删除</a><!-- endif --></td>
            </tr>
            <!-- endloop -->
            <!-- endif -->
            </tbody>
          </table>
          <nav style="margin: 30px 0">
            {{pager}}
          </nav>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- mainWrapper end -->
</div>
<!-- 添加限期代金券开始 -->
<div class="modal fade" id="addVoucher" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <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" id="myModalLabel">添加代金券</h4>
      </div>
      <form role="form" action="/m/setvoucher" onsubmit="return checksubmit();" method="post">
      <div class="modal-body">
        <div class="form-group">
          <label>活动名称</label>
          <input type="text" name="vname" id="vname" class="form-control" placeholder="输入活动名称">
        </div>
        <div class="form-group">
          <label>单张代金券金额（限额20）</label>
          <input type="number" name="vcost" id="vcost" max="20" step="0.01" class="form-control" placeholder="输入单张代金券金额">
        </div>
        <div class="form-group">
          <label>发放数量（限额100）</label>
          <input type="number" name="vcount" max="100" class="form-control" placeholder="输入代金券数量">
          <p class="help-block text-danger">数量为空，则为不限量，代金券领取完毕，活动也将结束</p>
        </div>
        <div class="form-group">
          <div>
            <label>活动时间</label>
            <input type="date" name="starttime" id="starttime" class="form-control" value="{{formatDateTime(starttime)}}">00:00:00
            <p class="text-center">至</p>
            <input type="date" name="endtime" id="endtime" class="form-control">23:59:59
            <p class="help-block text-danger">开始时间不能为活动添加当天</p>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary">确定添加</button>
      </div>
      </form>
    </div>
  </div>
</div>
<script>
  $(function(){
    $('#searchList').change(function(){
      var html = '';
      if($(this).val() != -1){
        html += '/status/'+$(this).val();
      }
      window.location.href = '/m/voucher'+html;
    })

  });
  function checksubmit(){
    if($('#vname').val() == ''){
      alert('活动名不能为空');
      return false;
    }
    if($('#vcost').val() == ''){
      alert('金额不能为空');
      return false;
    }
    if($('#starttime').val() == ''){
      alert('请选择开始日期');
      return false;
    }
    if($('#endtime').val() == ''){
      alert('请选择结束日期');
      return false;
    }
    var time = new Date($('#starttime').val()+' 00:00:00');
    if(time.getTime()/1000 < {{starttime}}){
      alert('开始时间不能小于或等于活动添加当天');
      return false;
    }
    if(new Date($('#endtime').val()+' 23:59:59').getTime()/1000 < time/1000){
      alert('结束时间不能小于开始时间');
      return false;
    }
  }
</script>

</body>
</html>
