<!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.split_button){ }}
                    {{# if(d.split_button === '2'){ }}
                  <a class="layui-btn layui-btn-xs"  lay-event="view_split">分账</a>
                    {{# } }}
                    {{# if(d.split_button === '1'){ }}
                  <a class="layui-btn layui-btn-xs"  lay-event="view_update_split">刷新分账</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="status">
                        <option value="">全部</option>
                        <option value="0">待付款</option>
                        <option value="1">已完成</option>
                        <option value="2">失败</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="delete">
                        <option value="1">是</option>
                        <option value="0" selected>否</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="branch_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', 'utils'], function(){
    var $ = layui.$
    ,form = layui.form
    ,utils = layui.utils;
    var table = layui.table;

    table.render({
      elem: '#datagrid'
      ,url: '/activity/order/data/'
        ,where: {'delete': 0}
      ,cols: [[
          {type: 'radio', width: 50}
        ,{field:'branch_name', title:'门店', width:100}
        ,{field:'activity_name', title:'活动名称', width:200}
        ,{field:'member_name', title:'会员名称',width: 120}
        ,{field:'member_tel', title:'会员电话',width: 120}
        ,{field:'amount', title:'费用', width:120}
        ,{field:'model', title:'车型', width:200}
        ,{field:'name', title:'姓名', width:100}
        ,{field:'tel', title:'电话', width:120}
        ,{field:'number', title:'车牌号', width:110}
        ,{field:'status_text', title:'状态', width:90}
        ,{field:'recommend_member_name', title:'推荐人', width:90}
        ,{field:'rebate', title:'返利', width:90}
        ,{field:'split_status_text', title:'分账状态', width:90}
        ,{field:'delete_text', title:'是否删除', width:100}
        ,{field:'create_time', title:'创建时间', width:180}
        ,{width:90, align:'center', fixed: 'right', toolbar: '#datagrid-operate-bar'}
      ]]
      ,page: true
      ,height: 'full-104'
      ,totalRow: true
      ,parseData:function(res) {
        var cols = this.cols[0];
        for (var i in cols) {
            if (cols[i].field == 'rebate') {
                cols[i].totalRowText = res.more.sum_rebate;
            }

            if (cols[i].field == 'amount') {
                cols[i].totalRowText = res.more.sum_amount;
            }
        }
        return {
          "code": res.code, //解析接口状态
          "count": res.count, //解析数据长度
          "data": res.data //解析数据列表
        };
      }
      ,done: function () {
        layui.index.removeNoPermButtons();
      }
    });


    //监听工具条
    table.on('tool(datagrid-operate)', function(obj){
      var data = obj.data;
        if(obj.event === 'view_split'){

            // if (data.split_status_text !== '已关闭') {
            //   layer.msg('该订单当前状态不允许分账');
            //     return false;
            // }

            layer.confirm('确定要对该订单分账吗？', function(index){
                layer.close(index);
                layui.admin.req({
                    notice: true
                    ,url: '/activity/order/split_account/?id=' + data.id
                    ,type: 'post'
                    ,done: function(res){
                        table.reload('datagrid',{});
                    }
                });
            });
      } else if (obj.event === 'view_update_split'){
            layui.admin.req({
                url: '/activity/order/update_split/?id=' + data.id
                , type: 'post'
                , done: function (res) {
                    table.reload('datagrid', {});
                }
            });
        }
    });

    $('#btn_query').on('click', function(){
        layer.open({
          type: 1,
          shadeClose: true,
          area: ['400px', '500px'],
          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>

