{extend name="Public/base" /}
{block name="css"}
<link rel="stylesheet" href="__PUBLIC__/css/set.css?v={$Think.const.APP_VERSION}">
{/block}
{block name="js"}
<script>
    $(function(){
        $(".nul_bli").eq(7).find(".navb").addClass("active");
    })
</script>
{/block}
<style>
    {block name="style"}
    .layui-table-page {
        height: 50px;
    }
    {/block}
</style>
{block name="main"}
<div class="if_wrap">
    <div class="cus-con">
        <div class="set_tit"><span>体验拍</span></div>
        <div class=" set-top layui-form layui-form-item">
            <label style="width:60px; padding-left: 5px;padding-right: 10px;" class="layui-form-label mkz_t1" style="width:50px;">客资姓名：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="customer_name">
            </div>
            <label style="width:60px; padding-left: 5px;padding-right: 10px;" class="layui-form-label mkz_t1" style="width:50px;">手机：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="customer_tel">
            </div>
            <label style="width:60px; padding-left: 5px;padding-right: 10px;" class="layui-form-label mkz_t1" style="width:50px;">开始时间：</label>
            <div class="layui-input-inline w-120">
                <input type="text" class="layui-input" id="start" name="timeArea" readonly="readonly" value="{$yestoday}">
            </div>
            <label style="width:60px; padding-left: 5px;padding-right: 10px;" class="layui-form-label mkz_t1" style="width:50px;">结束时间：</label>
            <div class="layui-input-inline w-120">
                <input type="text" class="layui-input" id="end" name="timeArea" readonly="readonly" value="{$yestoday}">
            </div>
            <input type="hidden" id="did" value="{$did}">
            <label style="width:60px; padding-left: 5px;padding-right: 10px;" class="layui-form-label mkz_t1 input" style="width:50px;">核销码：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="search_code">
            </div>
            <button class="layui-btn layui-btn-primary cus-model-btn" id="sub" >
                查询
            </button>
        </div>
        <table class="layui-table" lay-data="{limit:200,page:true,height:800, url:'/erp/Erp/customerList.html', id:'idTest'}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{width:100,field:'id',align:'center',sort: true,templet: '#titleTpl'}">序号</th>
                <th lay-data="{width:200,field:'score',align:'center', toolbar: '#barDemo'}">操作</th>
                <th lay-data="{width:80,field:'cid',align:'center'}">客资ID</th>
                <th lay-data="{width:150,field:'time',align:'center',sort: true}">时间点</th>
                <th lay-data="{width:100,field:'customer_name',align:'center'}">客资姓名</th>
                <th lay-data="{width:110,field:'customer_tel',align:'center'}">客资手机</th>
                <th lay-data="{width:110,field:'is_success',align:'center',templet:'#order'}">转单状态</th>
                <th lay-data="{width:110,field:'result',align:'center',templet:'#result'}">拍摄状态</th>
                <th lay-data="{width:150,field:'remark',align:'center'}">备注</th>
                <th lay-data="{width:110,field:'code',align:'center'}">核销码</th>
                <th lay-data="{width:110,field:'is_hx',align:'center',templet:'#code'}">核销状态</th>
                <th lay-data="{width:150,field:'hx_time',align:'center',sort: true}">核销时间</th>
                <th lay-data="{width:110,field:'staff_name',align:'center'}">核销人</th>
                <th lay-data="{width:150,field:'pc_time',align:'center',sort: true}">排控时间</th>
                <th lay-data="{width:150,field:'area_name',align:'center'}">分区</th>
                <th lay-data="{width:120,field:'shop_name',align:'center'}">所属店</th>
                <th lay-data="{width:120,field:'pc_shop_name',align:'center'}">预约店</th>
                <th lay-data="{width:100,field:'cameraman_name',align:'center'}">摄影师</th>
                <th lay-data="{width:100,field:'sale_name',align:'center'}">销售</th>
                <th lay-data="{width:100,field:'tutor_name',align:'center'}">导师</th>
                <th lay-data="{width:110,field:'hd_name',align:'center'}">活动名称</th>
                <th lay-data="{width:150,field:'customer_address',align:'center'}">客资地址</th>
            </tr>
            </thead>
        </table>

    </div>
</div>
<script type="text/html" id="titleTpl">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<script type="text/html" id="order">
    {{#  if(d.is_success == '2'){ }}
    未转单
    {{#  } else { }}
    已转单
    {{#  } }}
</script>
<script type="text/html" id="result">
    {{#  if(d.result == '2'){ }}
    已完成
    {{#  } else { }}
    未完成
    {{#  } }}
</script>
<script type="text/html" id="code">
    {{#  if(d.is_hx == 2){ }}
    已核销
    {{#  } else { }}
    未核销
    {{#  } }}
</script>
<!--核销-->
<div id="add-hx" style="display: none;padding:20px;">
    <div class="set-row layui-form">
        <div class="layui-inline">
            <label class="layui-form-label">核销码：</label>
            <div class="layui-input-block w-200">
                <input type="text" class="layui-input" id="hx_code"onkeyup="value=value.replace(/[^\d]/g,'')">
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="barDemo">
    {{#  if(d.result == '2' && d.is_success == 2){ }}
    <a class="layui-btn layui-btn-mini" lay-event="order">转订单</a>
    {{#  } }}
    {{#  if(d.is_hx == 1){ }}
    <a class="layui-btn layui-btn-mini" lay-event="hx">核销</a>
    {{#  } }}
    {{#  if(d.result == '1'){ }}
    <a class="layui-btn layui-btn-mini" lay-event="result">拍摄完成</a>
    {{#  } }}
</script>
<script>
    document.getElementById("search_code").focus();
    //回车事件
    $(function() {
            $(document).keydown(function (event) {
                if (event.keyCode == 13) {
                    var res = $('#search_code').val();
                    if(res.length > 0) {
                        load_page(
                                '/erp/Erp/tan_code/code/'+$('#search_code').val(),
                                '核销',
                                function(){
                                    tan_hx();
                                },['确定','关闭'],450,400
                        );
                    }
                }
            })
    })
    layui.use('form', function(){
        var form = layui.form;
        form.render();
    });
    $('#sub').click(function(){
        table.reload('idTest', {
            url: 'customerList'
            ,where: {customer_name:$('#customer_name').val(),customer_tel:$('#customer_tel').val(),start:$('#start').val(),end:$('#end').val()} //设定异步数据接口的额外参数
            ,done:function(index){

            }
        });
    })
    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function(){
        var laydate = layui.laydate //日期
                ,laypage = layui.laypage //分页
        layer = layui.layer //弹层
                ,table = layui.table //表格
                ,carousel = layui.carousel //轮播
                ,upload = layui.upload //上传
                ,element = layui.element; //元素操作

        //监听工具条
        table.on('tool(demo)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值

            if (layEvent === 'detail') {
                layer.msg('查看操作');
            }else if(layEvent === 'hx') {
                layer.open({
                    title: '核销',
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['405px', '200px'],
                    content: $('#add-hx'),
                    btn: ['提交']
                    , yes: function(index) {
                        var code = $('#hx_code').val();
                        $.ajax({
                            type: "POST",
                            url: "{:Url('erp/Erp/markHX')}",
                            data: {cid:obj.data.cid,code:code},
                            dataType:'json',
                            success: function(ret){
                                if(ret.code == 200){
                                    layer.alert(ret.msg);
                                    table.reload('idTest', {
                                    });
                                }else{
                                    layer.alert(ret.msg);
                                }
                            },
                            error:function(XMLHttpRequest, textStatus, errorThrown){
                                var ret = XMLHttpRequest.responseJSON
                                layer.alert('操作失败');
                            }
                        })
                        //最后关闭弹出层
                        layer.close(index);
                    }
                });
            }else if (layEvent === 'result') {
                layer.confirm('真的确认拍摄完成么', function (index) {
                    $.ajax({
                        type: "POST",
                        url: "{:Url('erp/Erp/markResult')}",
                        data: {id:obj.data.id,result:2},
                        dataType:'json',
                        success: function(ret){
                            if(ret.code == 200){
                                layer.alert(ret.msg);
                                table.reload('idTest', {
                                });
                            }else{
                                layer.alert(ret.msg);
                            }
                        },
                        error:function(XMLHttpRequest, textStatus, errorThrown){
                            var ret = XMLHttpRequest.responseJSON
                            layer.alert('操作失败');
                        }
                    })
                })
            }else if(layEvent === 'order'){
                var id = obj.data.cid;
                load_page(
                        '/erp/Erp/order/id/'+id,
                        // '/crm/Customer/orderManager/id/'+id,
                        '网付订单',
                        function(){
                            orderManager();
                        },
                        ['保存','取消'],
                        500,320
                );
                table.reload('idTest', {
                });
            }
        });

        //日历
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            //单控件
            lay('.test-item').each(function () {
                laydate.render({
                    elem: this
                    , format: 'yyyyMMdd'
                    , value: new Date()
                    , trigger: 'click'
                });
            });
        });
        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            ,count: 100 //总页数
            ,skin: '#1E9FFF' //自定义选中色值
            //,skip: true //开启跳页
            ,jump: function(obj, first){
                if(!first){
                    layer.msg('第'+ obj.curr +'页');
                }
            }
        });
    })
    //日历
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#start'
            , format: 'yyyy-MM-dd'
            , value: new Date()
        });
        laydate.render({
            elem: '#end'
            , format: 'yyyy-MM-dd'
            , value: new Date()
        });
    })
</script>
{/block}