<!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">
  <link rel="stylesheet" type="text/css" href="../../layuiadmin/style/formSelects-v4.css"/>
    <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;}
    .seach_items {float:right;margin-left: 5px;display: inline-block; margin-top: 5px;}
  </style>
</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;">
              <div class="layui-col-xs12">
                  <!--<div style="float: left">
                      <button class="layui-btn" id="btn_download" ><i class="layui-icon layui-icon-download-circle"></i>导出</button>
                  </div>-->
                    <form class="layui-form" lay-filter="query-form-element">
                        <div class="seach_items">
                            <button class="layui-btn" lay-submit lay-filter="query-form-element"><i class="layui-icon layui-icon-search"></i>查询</button>
                        </div>
                        <div class="seach_items">
                            <div class="layui-inline">
                              <div class="layui-input-inline">
                                <input type="text" name="range_time" class="layui-input" id="range_time" placeholder="下单时间">
                              </div>
                            </div>
                        </div>
                        <div class="seach_items" style="width: 150px;">
                            <select name="status">
                                <option value="">订单状态</option>
                                <option value="0">待付款</option>
                                <option value="1">待发货</option>
                                <option value="2">已发货</option>
                                <option value="3">已取消</option>
                            </select>
                        </div>
                        <div class="seach_items">
                            <input type="text"  name="tel" autocomplete="off" class="layui-input" placeholder="收货电话"/>
                        </div>
                        <div class="seach_items">
                            <input type="text"  name="customer_tel" autocomplete="off" class="layui-input" placeholder="下单电话"/>
                        </div>
                        <div class="seach_items">
                            <input type="text"  name="no" autocomplete="off" class="layui-input" placeholder="订单号"/>
                        </div>
                    </form>
                </div>
                <div style="clear: both;"></div>
            </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="order_detail">明细</a>
                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="dispatch">发货</a>
                    {{# } }}
                    {{# if(d.status == 0){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="cancel">取消</a>
                    {{# } }}
                </div>
            </script>
          </div>
        </div>
        </div>
    </div>
  </div>

  <script src="../../layuiadmin/layui/layui.js?t=1"></script>
  <script>
  var _params = '';
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
     ,formSelects: 'formSelects-v4'
  }).use(['index', 'table', 'form', 'formSelects', 'upload', 'laydate'], function(){
    var $ = layui.$
            ,table = layui.table
            ,laydate = layui.laydate
            , admin = layui.admin
            ,form = layui.form;
    table.render({
      elem: '#datagrid'
      ,url: '/order/'
      ,title: '订单信息'
      ,id: 'datagrid'
      ,cols: [[
        {field:'no', title:'订单号',width: 150, fixed: 'left'}
       ,{field:'customer_name', title:'下单人',width: 100, fixed: 'left'}
       ,{field:'customer_tel', title:'电话',width: 120, fixed: 'left'}
       ,{field:'total_count', title:'数量',width: 60}
       ,{field:'total_amount', title:'金额',width: 100}
       ,{field:'total_point', title:'积分',width: 60}
       ,{field:'status_text', title:'订单状态',width: 90}
       ,{field:'create_time', title:'下单时间',width: 150}
       ,{field:'name', title:'收货人',width: 80}
       ,{field:'tel', title:'收货电话',width: 120}
       ,{field:'user_address', title:'收货地址',width: 200}
       ,{field:'express_info', title:'快递信息',width: 200}
       ,{field:'dispatch_user_text', title:'发货人',width: 80}
       ,{field:'dispatch_time', title:'发货时间',width: 150}
       ,{field:'cancel_reason', title:'取消订单原因',width: 150}
       ,{field:'cancel_user_text', title:'取消人',width: 80}
       ,{field:'cancel_time', title:'取消时间',width: 150}
       ,{field:'notes', title:'买家留言',width: 150}
        ,{width:150, align:'center', fixed: 'right', toolbar: '#datagrid-operate-bar'}
      ]]
      ,totalRow:false
      , done: function () {
        layui.index.removeNoPermButtons()
      }
      ,page: true
      ,height: 'full-108'
    });
    laydate.render({
        elem: '#range_time'
        ,range:true
    });
    form.on('submit(query-form-element)', function(data){
      //layer.msg(JSON.stringify(data.field));
      table.reload('datagrid', {
          where: data.field
          ,page:{curr:1}
      });
      _params = data.field;
      layer.closeAll();
      return false;
    });
    //监听工具条
    table.on('tool(datagrid-operate)', function(obj){
      var data = obj.data;
      table.editdata = data;
      if(obj.event === 'order_detail'){
        layer.open({
          type: 2,
          title: '订单明细',
          shadeClose: false,
          area: ['60%', '80%'],
          btn: ['关闭'],
          yes: function (index, dom) {
            layer.close(index);//关闭当前按钮
          },
          content: 'order_detail.html?id='+data.id
        });
      } else if (obj.event === 'dispatch') {
          layer.open({
              type: 2,
              title: '发货',
              area: ['40%', '60%'],
              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: 'order_dispatch.html?id=' + data.id
          })
      } else if (obj.event === 'cancel') {
          layer.open({
              type: 2,
              title: '取消订单',
              area: ['40%', '250px'],
                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: 'order_cancel.html?id=' + data.id
          });
      }
    });
    // 导出数据
    $('#btn_download').on('click', function(){
        $.get({
            url: '/order/export/',
            dataType: 'json',
            data: _params,
            success: function (res) {
                if(res.code === 1){
                    layer.msg(res.msg);
                    return;
                }
                table.exportFile('datagrid', res.data, 'xlsx')
            }
        })
    });
  });
  </script>
</body>
</html>

