<!DOCTYPE html>
<html lang="zh">
<#include "/include/header.html">
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <#include "/include/left.html">
        <!--End 左侧导航-->
        <!--头部信息-->
        <#include "/include/topbar.html">
        <!--End 头部信息-->
        <!--页面主要内容-->-
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="panel" style="margin-bottom: auto">
                                <div class="panel-heading">
                                    <h3 class="panel-title">
                                        组合条件筛选
                                    </h3>
                                </div>
                                <!--组合条件组件-->
                                <#include "/include/table/table-query.html">

                            </div>
                            <div class="card-toolbar clearfix" style="padding: 0px 24px 0px 24px">
                                <div class="toolbar-btn-action" id="toolBar">
                                    <button id="batch_recover" class="btn btn-info m-r-5"
                                            onclick="onHuiFu('table')"><i class="mdi mdi-backup-restore">恢复</i>
                                    </button>
                                    <button id="batch_finish" class="btn btn-success m-r-5"
                                            onclick="onLaHei('table')"><i class="mdi mdi-check"></i>拉黑
                                    </button>
                                    <button id="batch_bindBack" class="btn btn-warning m-r-5"
                                            onclick="bindBack()"><i class="mdi mdi-check"></i>发放优惠卷
                                    </button>
                                    <#include "/include/table/table-batch.html">
                                </div>
                            </div>
                            <!--快速搜索框-->
                            <div class="card-body" style="padding: 10px 15px">
                                <div class="pull-right" id="id_search_column"
                                     style="position: absolute;right: 295px;margin-top: 10px;">
                                    <input type="hidden" name="search_field" id="search-field" value="">
                                    <button class="btn btn-default dropdown-toggle" id="search-btn"
                                            data-toggle="dropdown" type="button" aria-haspopup="true"
                                            aria-expanded="false">
                                        全部 <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu" style="min-width: auto">
                                        <li><a tabindex="-1" href="javascript:void(0)" data-field="">全部</a></li>
                                        <#list pageTemplate.tableSearch as search>
                                        <li><a tabindex="-1" href="javascript:void(0)" data-field="${search.key!}">${search.name}</a></li>
                                    </#list>
                                    </ul>
                                </div>
                                <!--Bootstarp Table插入-->
                                <#include "/include/table/table-data.html">

                            </div>
                        </div>

                    </div>

                </div>
            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<#include "/include/footer.html">
<#include "/include/table/table-event.html">
<#include "/include/table/table-model.html">
<div>
    <div class="modal fade" id="id_customerBig_model" tabindex="-1" role="dialog" aria-labelledby="bindModalLabel" data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="bindModalLabel">为客户发放优惠卷</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="control-label">当前客户：</label>
                        <input id="id_customerBig_model_order" class="form-control" disabled>
                    </div>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="control-label">选择优惠卷：</label>
                        <select id="id_customerBig_model_select" class="selectpicker form-control" data-live-search="true">
                            <option value="0" selected="selected">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="okZhiPai()">确认提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--以下为业务流程处理-->
<script>

    /**
     * 绑定三方
     */
    function bindBack() {
        let clm=getTableSelectOne();
        $("#id_customerBig_model_order").val("客户名称："+clm.customerName);
        $("#id_customerBig_model").modal("show");
    }

    /**
     * 拉入黑名单
     * @param table
     */
    function onLaHei(table) {
        var ids=getCheckIds(table);
        //alert(Array)
        $.ajax({
            type: "post",
            dataType:"json",
            url: "${ctx!}/customer/blacklist?ids="+ids,
            success : function (data) {
                if (data.status==200){
                    lightyear.notify('操作成功!', 'success');
                    search();
                    return data;
                }
                if (data.status!=200){
                    lightyear.notify("操作失败", 'danger');
                    search();
                    return data;
                }
                lightyear.notify(data.message, 'danger');
            }
        });
    }

    /**
     * 从黑名单中拉出
     * @param table
     */
    function onHuiFu(table) {
        var ids=getCheckIds(table);
        //alert(Array)
        $.ajax({
            type: "post",
            dataType:"json",
            url: "${ctx!}/customer/recovery?ids="+ids,
            success : function (data) {
                if (data.status==200){
                    lightyear.notify('操作成功!', 'success');
                    search();
                    return data;
                }
                if (data.status!=200){
                    lightyear.notify("操作失败", 'danger');
                    search();
                    return data;
                }
                lightyear.notify(data.message, 'danger');
            }
        });
    }

    /**
     * 为选择快递员绑定搜索输入事件
     */
    $("#id_customerBig_model_select").on('shown.bs.select',function(e){
        //获取输入框对象
        let clm=getTableSelectOne();
        let search_input=$(this).next().next().find("input");
        search_input.attr('placeholder',"请输入优惠卷名称");
        if($("search_input option").length==0){
            $.ajax({
                data:{
                    key:search_input.val(),
                    customerId:clm.customerId
                },
                type: 'get',
                url: "${ctx}/discount/search/key",
                success: function (data) {
                    if (data.status!=200){
                        lightyear.notify("系统繁忙，请尝试重新登陆。", 'danger');
                        return;
                    }
                    $("#id_customerBig_model_select").empty();
                    if (data.body.length>0){
                        console.log(data);
                        $.each(data.body, function (i, item) {
                            let tempId = '<option  value="' + item.id + '">优惠卷名称：' +item.disName+'</option>';
                            $("#id_customerBig_model_select").append(tempId);
                        });
                    }else{
                        lightyear.notify("没有可选择的优惠卷，请新增新的优惠卷！", 'warning');
                    }
                    $('#id_customerBig_model_select').selectpicker('refresh');
                }
            });
        }
        search_input.keyup(function(){
            let clm=getTableSelectOne();
            $.ajax({
                data:{key:search_input.val(),
                      customerId:clm.customerId},
                type: 'get',
                url: "${ctx}/discount/search/key",
                success: function (data) {
                    if (data.status!=200){
                        lightyear.notify("系统繁忙，请尝试重新登陆。", 'danger');
                        return;
                    }
                    $("#id_customerBig_model_select").empty();
                    if (data.body.length>0){
                        $.each(data.body, function (i, item) {
                            let tempId = '<option  value="' + item.id + '">优惠卷名称：' +item.couponName+'</option>';
                            $("#id_customerBig_model_select").append(tempId);
                        });
                    }
                    $('#id_customerBig_model_select').selectpicker('refresh');
                }
            });
        });
    });

    /**
     * 指派提交
     */
    function okZhiPai() {
        let clm=getTableSelectOne();
        let data={
            customerId:clm.customerId,
            disId:$("#id_customerBig_model_select").val(),
        }
        runAjax("${ctx!}/discount/grant/submit","GET",data,function (res) {
            $("#id_customerBig_model").modal("hide");
            lightyear.notify('操作成功!', 'success');
            search();
        });

    }

</script>
</body>
</html>