<!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>
<style type="text/css">
    .LAY-btns .layui-nav {padding-left:0;padding-right:10px;top:-4px;margin: 0 10px;border: 0;background-color: #009688;}
    .LAY-btns .layui-nav .layui-nav-item{line-height: 30px;}
    .LAY-btns .layui-nav .layui-nav-child{top:34px;}
    .LAY-btns .layui-nav .layui-nav-bar{display: none;}
    .LAY-btns .layui-nav .layui-nav-child dd.layui-this a{color:#333;background-color:#fff;}
    .LAY-btns .layui-nav .layui-nav-child dd.layui-this a:hover {background-color: #f2f2f2;color: #000;}
  </style>
<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_add"><i class="layui-icon layui-icon-add-circle"></i>添加</button>
              <button class="layui-btn layui-btn-sm"  id="btn_del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                <button class="layui-nav" id="show_check">
                <div class="layui-nav-item">
                  <a href="javascript:;" style="color:#fff;">审核</a>
                  <dl class="layui-nav-child"> <!-- 二级菜单 -->
                    <dd><a href="#" id="btn_check">审核</a></dd>
                    <dd><a href="#" id="btn_revoke_check">撤销审核</a></dd>
                  </dl>
                </div>
              </button>
              <button class="layui-btn layui-btn-sm"  id="btn_coupon"><i class="layui-icon layui-icon-add-circle"></i>添加优惠券</button>
              <button class="layui-btn layui-btn-sm"  id="btn_set"><i class="layui-icon layui-icon-ok-circle"></i>购买设置</button>
              <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">
                    <a class="layui-btn layui-btn-xs" lay-event="view">查看</a>
                  <a class="layui-btn layui-btn-xs"  lay-event="edit">修改</a>
                  <a class="layui-btn layui-btn-xs"  lay-event="upload_poster">上传介绍</a>
                  <a class="layui-btn layui-btn-xs"  lay-event="code">二维码</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">
                    <input type="text" name="title" 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="branch_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">
                    <select name="check_status">
                        <option value="">全部</option>
                        <option value="0" selected>未审核</option>
                        <option value="1">已审核</option>
                    </select>
                </div>
            </div>

            <div class="layui-col-xs12 layui-col-sm12">
                <label class="layui-form-label">是否在用：</label>
                <div class="layui-input-block">
                    <select name="enabled">
                        <option value="">全部</option>
                        <option value="1" selected>是</option>
                        <option value="0">否</option>
                    </select>
                </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', 'utils'], function(){
    var $ = layui.$
    ,form = layui.form
    ,utils = layui.utils;
    var table = layui.table;

    var superuser = layui.data(layui.setter.tableName)['superuser'];
      if(!superuser){
          $('#show_check').remove();
      }else {
          $('#btn_add').remove();
          $('#btn_set').remove();
          $('#btn_coupon').remove();
          $('#btn_del').remove();
      }

    table.render({
      elem: '#datagrid'
      ,url: '/activity/activity/data/'
      ,cols: [[
          {type: 'radio', width: 50}
        ,{field:'title', title:'标题', width:200}
        ,{field:'end_date', title:'截止日期',width: 200}
        ,{field:'amount', title:'价格',width: 100}
        ,{field:'rebate', title:'返利',width: 100}
        ,{field:'check_status_text', title:'状态',width: 100}
        ,{field:'branch_name', title:'门店名称',width: 100}
        ,{field:'branch_tel', title:'门店电话',width: 100}
        ,{field:'branch_address', title:'门店地址',width: 100}
        ,{field:'create_time', title:'添加时间', width:300}
        ,{field:'enabled_text', title:'在用', width:90}
        ,{width:220, align:'center', fixed: 'right', toolbar: '#datagrid-operate-bar'}
      ]]
      ,where: {'enabled': 1}
      ,page: true
      ,height: 'full-104'
      ,done: function () {
        layui.index.removeNoPermButtons();
      }
    });

    //监听工具条
    table.on('tool(datagrid-operate)', function(obj){
      var data = obj.data;
      table.editdata = data;
        if(obj.event === 'edit'){
        if (data.check_status == 1) {
            layer.msg('该活动已审核');
            return false;
        }
        layer.open({
          type: 2,
          title: '修改',
          shadeClose: false,
          area: ['70%', '90%'],
          btn: ['保存', '取消'],
          yes: function(index, dom){
             layui.onSubmitChild = function (data) {
              layer.close(index);
              table.reload('datagrid',{});
            };
            layui.submitChild();
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'edit.html?id='+data.id
        });
      }else if(obj.event === 'view'){
        layer.open({
          type: 2,
          title: '查看',
          shadeClose: true,
          area: ['70%', '90%'],
          content: 'details.html?id='+data.id
        });
      }else if(obj.event === 'code'){
        layer.open({
          type: 2,
          title: '二维码',
          shadeClose: true,
          area: ['70%', '90%'],
          content: 'wxapp_code.html?id='+data.id
        });
      }else if(obj.event === 'upload_poster') {
            if (data.check_status == 1) {
                layer.msg('该活动已审核');
                return false;
            }
            layer.open({
                type: 2,
                title: '上传介绍',
                area: ['600px', '450px'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'upload_poster.html?id=' + data.id
            });
        }
    });

    $('#btn_add').on('click', function(){
        layer.open({
          type: 2,
          title: '添加',
          shadeClose: false,
          area: ['70%', '90%'],
          btn: ['保存', '取消'],
          yes: function(index, dom){
             layui.onSubmitChild = function (data) {
              layer.close(index);
              table.reload('datagrid',{});
            };
            layui.submitChild();
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'edit.html'
        });
    });

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

    //删除
    $('#btn_del').on('click', function(){
        var data = utils.getSelectedRow('datagrid');
         if(data == false){
             return false;
         }

         if (data.check_status == 1) {
              layer.msg('该活动已审核');
                return false;
         }

         layer.confirm('确定要删除吗？', function (index) {
            layer.close(index);
            layui.admin.req({
                url: '/activity/activity/delete/?id=' + data.id
                , done: function (res) {
                    table.reload('datagrid', {});
                }
            });
        });
    });

    //审核
    $('#btn_check').on('click', function(){
        var data = utils.getSelectedRow('datagrid');
         if(data == false){
             return false;
         }

         if (data.check_status == 1) {
              layer.msg('该活动已审核');
                return false;
         }

         layer.confirm('确定要审核吗？', function (index) {
            layer.close(index);
            layui.admin.req({
                url: '/activity/activity/check/?id=' + data.id + '&status=1'
                , done: function (res) {
                    table.reload('datagrid', {});
                }
            });
        });
    });

    //撤销审核
    $('#btn_revoke_check').on('click', function(){
        var data = utils.getSelectedRow('datagrid');
         if(data == false){
             return false;
         }

         if (data.check_status == 0) {
              layer.msg('该活动尚未审核');
                return false;
         }

         layer.confirm('确定要撤销审核吗？', function (index) {
            layer.close(index);
            layui.admin.req({
                url: '/activity/activity/check/?id=' + data.id + '&status=0'
                , done: function (res) {
                    table.reload('datagrid', {});
                }
            });
        });
    });

     //必填项设置
    $('#btn_set').on('click', function(){
        var data = utils.getSelectedRow('datagrid');
         if(data == false){
             return false;
         }

         layer.open({
          type: 2,
          title: '购买必填设置',
          shadeClose: true,
          area: ['70%', '90%'],
          btn: ['保存', '取消'],
          yes: function (index, dom) {
            layui.onSubmitChild = function (data) {
                layer.close(index);
                table.reload('datagrid', {});
              };
              layui.submitChild();
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'sale_set.html?id='+data.id + '&required_signs=' + data.required_signs
        });
    });

     //优惠券设置
    $('#btn_coupon').on('click', function(){
        var data = utils.getSelectedRow('datagrid');
         if(data == false){
             return false;
         }

         layer.open({
          type: 2,
          title: '添加优惠券',
          shadeClose: true,
          area: ['70%', '90%'],
          btn: ['保存', '取消'],
          yes: function (index, dom) {
            layui.onSubmitChild = function (data) {
                layer.close(index);
                table.reload('datagrid', {});
              };
              layui.submitChild();
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'coupons.html?id='+data.id + '&coupons=' + data.coupons
        });
    });

    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>

