<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>门店管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
        <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">

            <div class="LAY-btns" style="margin-bottom: 10px;">
              <button class="layui-btn layui-btn-sm" id="btn_query"><i class="layui-icon layui-icon-search"></i>查询</button>
            </div>

            <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>

            <script type="text/html" id="datagrid-operate-bar">
                <div class="layui-btn-group">
                  {{# if(!d.write_off){ }}
                  <a class="layui-btn layui-btn-danger layui-btn-xs"  lay-event="write_off">核销</a>
                  {{# } }}
                  {{# if(d.write_off){ }}
                  <a class="layui-btn layui-btn-xs"  lay-event="cancel_write_off">撤销核销</a>
                  {{# } }}
                </div>
            </script>
          </div>
        </div>
        </div>
    </div>
  </div>

  <div id="dlg_query" style="display: none">
    <div class="layui-card-body" pad15>
        <form class="layui-form" lay-filter="query-form-element">
          <div class="layui-row layui-col-space10 layui-form-item">
              <div class="layui-col-xs12 layui-col-sm12">
                <label class="layui-form-label">是否核销：</label>
                <div class="layui-input-block">
                    <select name="write_off">
                        <option value="">全部</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
            </div>
              <div class="layui-col-xs12 layui-col-sm12">
                <label class="layui-form-label">活动名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="activity_name" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm12">
                <label class="layui-form-label">优惠券名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="coupon_name" autocomplete="off" class="layui-input">
                </div>
            </div>

          </div>
          <div class="layui-form-item" style="display: none">
                <button id="query_search" class="layui-btn" lay-submit lay-filter="query-form-element">查询</button>
          </div>
        </form>
    </div>
   </div>

  <script src="../../layuiadmin/layui/layui.js?t=1"></script>
  <script>
  var _params = '';
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var $ = layui.$
    ,form = layui.form;
    var table = layui.table;
    var id = layui.view.getParameterByName('id');

    table.render({
      elem: '#datagrid'
      ,url: '/activity/member_coupon/data/'
      ,where: {'member': id}
      ,cols: [[
        {field:'activity_name', title:'活动名称', width:200}
        ,{field:'coupon_name', title:'优惠券名称', width:200}
        ,{field:'end_date', title:'有效期', width:120}
        ,{field:'write_off_text', title:'是否核销', width:90}
        ,{field:'write_off_time', title:'核销时间', width:170}
        ,{width:100, align:'center', fixed: 'right', toolbar: '#datagrid-operate-bar'}
      ]]
      ,page: true
      ,height: 'full-104'
      ,done: function () {
        layui.index.removeNoPermButtons();
      }
    });

    //监听工具条
    table.on('tool(datagrid-operate)', function(obj){
        var data = obj.data;
        if(obj.event === 'write_off'){
            layer.confirm('确定要核销该会员优惠券吗？', function(index){
                layer.close(index);
                layui.admin.req({
                    notice: true
                    ,url: '/activity/member_coupon/write_off/?id='+ data.id
                    ,type: 'post'
                    ,done: function(res){
                        table.reload('datagrid',{});
                    }
                });
            });
          } else if(obj.event === 'cancel_write_off'){
            layer.confirm('确定要撤销核销该会员优惠券吗？', function(index){
                layer.close(index);
                layui.admin.req({
                    notice: true
                    ,url: '/activity/member_coupon/cancel_write_off/?id='+ data.id
                    ,type: 'post'
                    ,done: function(res){
                        table.reload('datagrid',{});
                    }
                });
            });
        }
    });

    $('#btn_query').on('click', function(){
        layer.open({
          type: 1,
          shadeClose: true,
          area: ['400px', '400px'],
          title: '查询',
          btn: ['查询'],
          yes: function(index, dom){
             $('#query_search').click();
          },
          content: $('#dlg_query')
        });
    });

    form.on('submit(query-form-element)', function(data){
      //layer.msg(JSON.stringify(data.field));
      _params = data.field;
      table.reload('datagrid', {
          where: data.field,
          page:{curr:1}
      });
      layer.closeAll();
      return false;
    });

  });
  </script>
</body>
</html>

