<!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: 10px;}
  </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;">

                <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">
                        <input type="text"  name="tel" autocomplete="off" class="layui-input" placeholder="电话"/>
                    </div>

                    <div class="seach_items">
                        <input type="text"  name="name" autocomplete="off" class="layui-input" placeholder="试驾人"/>
                    </div>
                    <div class="seach_items">
                         <select  name="shop" id="seach_shop">
                            <option value="">门店</option>
                        </select>
                    </div>
                    <div class="seach_items">
                       <select  name="status">
                            <option value="">状态</option>
                            <option value="1">待试驾</option>
                            <option value="2">已试驾</option>
                            <option value="3">已取消</option>
                        </select>
                    </div>

                </form>
                <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="images">驾证</a>
                    <a class="layui-btn layui-btn-xs" lay-event="finish">完成</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="revoke">取消</a>
                </div>
            </script>
          </div>
        </div>
        </div>
    </div>
  </div>

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

    admin.req({
        url: '/store/search/',
        done: function (res) {
            var shops = res.data;
            var shop_node = $('#seach_shop');
            for (var i in shops) {
                var pid = shops[i].id;
                var value = shops[i].name;
                shop_node.append("<option value='" + pid + "'>" + value + "</option>");
            }
            form.render();
        }
    });

    table.render({
      elem: '#datagrid'
      ,url: '/vehicle_order/drive_reserve/'
      ,cols: [[
        {field:'shop_name', title:'门店',width: 100}
       ,{field:'status_text', title:'状态',width: 100}
       ,{field:'customer_name', title:'客户',width: 100}
       ,{field:'brand_name', title:'品牌',width: 100}
       ,{field:'series_name', title:'车系',width: 100}
       ,{field:'model_name', title:'车型',width: 150}
       ,{field:'name', title:'试驾人',width: 100}
       ,{field:'tel', title:'电话',width: 120}
       ,{field:'date', title:'预约日期',width: 150}
       ,{field:'create_time', title:'创建时间',width: 150}
       ,{field:'notes', title:'备注',width: 150}
        ,{width:150, align:'center', fixed: 'right', toolbar: '#datagrid-operate-bar'}
      ]]
      ,page: true
      ,height: 'full-108'
      , done: function () {
        layui.index.removeNoPermButtons()
      }
    });
    form.on('submit(query-form-element)', function(data){
      //layer.msg(JSON.stringify(data.field));
      table.reload('datagrid', {
          where: data.field
          ,page:{curr:1}
      });
      layer.closeAll();
      return false;
    });
    //监听工具条
    table.on('tool(datagrid-operate)', function(obj){
      var data = obj.data;
      table.editdata = data;
        if(obj.event === 'finish'){
            if (data.status !== 1){
                 layer.msg('当前状态不允许修改');
                return;
            }
         layer.confirm('确定订单已完成吗？', function(index){
             layer.close(index);
            admin.req({
                url: '/vehicle_order/drive_reserve/'+data.id + '/change_status/?status=2'
                ,type: 'post'
                ,done: function(res){
                    if(res.code === 1){
                        layer.msg(res.msg);
                        return;
                    }
                    table.reload('datagrid',{});
                }
            });
        });
      }else if(obj.event === 'revoke'){
             if (data.status !== 1){
                 layer.msg('当前状态不允许修改');
                return;
            }
         layer.confirm('确定取消预约单吗？', function(index){
             layer.close(index);
            admin.req({
                url: '/vehicle_order/drive_reserve/'+data.id + '/change_status/?status=3'
                ,type: 'post'
                ,done: function(res){
                    if(res.code === 1){
                        layer.msg(res.msg);
                        return;
                    }
                    table.reload('datagrid',{});
                }
            });
        });
        }else if(obj.event === 'images'){
        layer.open({
          type: 2,
          title: '驾驶证',
          area: ['800px', '500px'],
          yes: function(index, dom){
              table.reload('datagrid',{});
             layer.close(index);
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'drive_reserve_imgs.html?id='+data.id
        });
      }
    });
  });
  </script>
</body>
</html>

