<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="XTSZ_JSJSZ_T" html='<li class="layui-this"><a href="${ctx}/settlementSchemeSet/settleSetPage">结算基础价</a></li>'/>
                <sfTags:pagePermission authFlag="XTSZ_JSJSZ_JLZC_T" html='<li><a href="${ctx}/rewardsPunishWaySet/rewardsWayPage">奖励政策</a></li>'/>
                <sfTags:pagePermission authFlag="XTSZ_JSJSZ_CFZC_T" html='<li><a href="${ctx}/rewardsPunishWaySet/punishWayPage">惩罚政策</a></li>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " lay-submit lay-filter="LAY-user-back-search" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>
            </ul>
        </div>

        <div class="layui-card-body layuiadmin-card-header-auto" >
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">方案编号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" class="layui-input" id="number" >
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">方案名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" class="layui-input" id="name" >
                        </div>
                    </div>

                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">结算方式：</label>
                        <div class="layui-input-block">
                            <select name="type">
                                <option value="">请选择</option>
                                <option value="1">按组件单瓦</option>
                                <option value="2">按组件单块</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">状态：</label>
                        <div class="layui-input-block">
                            <select name="status">
                                <option value="">请选择</option>
                                <option value="1">生效中</option>
                                <option value="2">提前结束</option>
                                <option value="4">正常结束</option>
                                <option value="3">已作废</option>
                            </select>
                        </div>
                    </div>
                  <%--  <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">项目编号：</label>
                        <div class="layui-input-block">
                            <select name="projectId" id="projectId">
                                <option value="">请选择</option>
                                <c:forEach items="${project}" var="ject">
                                    <option value="${ject.columns.id}" title="${ject.columns.name}"
                                            data-anim="${ject.columns.management_type}"
                                            data-key="${ject.columns.install_mode_id}"
                                            data-type="${ject.columns.install_mode_name}">${ject.columns.code}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>--%>
                </div>
            </form>
        </div>
            <div class="layui-card-body">
                <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
                <script type="text/html" id="toolbarDemo">
                    <sfTags:pagePermission authFlag="XTSZ_JSJSZ_DR_B" html=' <button class="layui-btn layui-btn-sm" lay-event="importSettleTheBasePrice"><i class="layui-icon layui-icon-export"></i>导入</button>'/>
                    <sfTags:pagePermission authFlag="XTSZ_JSJSZ_DR_B" html=' <button class="layui-btn layui-btn-sm" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出</button>'/>
                  </script>
            </div>
        </div>
</div>
</div>
<script type="text/html" id="table-toolbar">
<%--    <sfTags:pagePermission authFlag="XTSZ_JSJSZ_JSJSZ_LOOK_B" html='<a class="layui-table-opt-link" lay-event="look">查看</a>'/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--%>
<%--<sfTags:pagePermission authFlag="XTSZ_JSJSZ_JSJSZ_STOP_B" html='<a class="layui-table-opt-link" lay-event="stop">提前结束</a>'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--%>
<%--<sfTags:pagePermission authFlag="XTSZ_JSJSZ_JSJSZ_DELETE_B" html='<a class="layui-table-opt-link" lay-event="delete">作废</a>'/>--%>
</script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        laydate = layui.laydate;
        table = layui.table;

        //开始日期
        var disStartTime = laydate.render({
            elem: '#createTimeSta'
            ,done: function(value, date){
                //更新结束日期的最小日期
                disEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                disEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var disEndTime = laydate.render({
            elem: '#createTimeEnd'
            ,done: function(value, date){
                //更新开始日期的最大日期
                disStartTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        //方案信息列表
        tableExt.render({
            elem: '#test'
            ,toolbar: '#toolbarDemo'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/settlementSchemeSet/settleSetListDate'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', title: '序号', align: 'center', type: 'numbers'}
                ,{field:'id', title: '操作',minWidth: 150,align: 'center',templet: function (d) {
                        var html="";
                        // var fg=d.audit;
                        if(d.status==1) {
                            html += "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' lay-event=\"stop\">提前结束</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        }
                        if(d.status==1||d.status==2){
                        html += "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' lay-event=\"delete\">作废</a>";
                        }
                        return html;
                    }
                }
                , {field: 'status', title: '状态', minWidth: 100, align: 'center',exportable:true , templet: function (d) {
                        if (d.status == "1") {
                            return "生效中";
                        } else if (d.status == "2") {
                            return "提前结束";
                        } else if (d.status == "3") {
                            return "已作废";
                        } else if (d.status == "4") {
                            return "正常结束";
                        }
                        return "--";
                    }, expFormat: function (d) {
                        //格式导出的化字段
                        if (d.status == "1") {
                            return "生效中";
                        } else if (d.status == "2") {
                            return "提前结束";
                        } else if (d.status == "3") {
                            return "已作废";
                        } else if (d.status == "4") {
                            return "正常结束";
                        }
                        return "--";
                    }}
                , {field: 'number', title: '方案编号', minWidth: 130, align: 'center',exportable:true,
                    templet: function (d) {
                        var html="";
                        return html + '<a href="#" class="layui-table-link" onclick="showDetail(\'' + d.id + '\',\''+d.apply_id+'\')">' + d.number + '</a>';
                    }}
                , {field: 'name', title: '方案名称', minWidth: 200, align: 'center',exportable:true }
                , {field: 'amount', title: '结算基础价', minWidth: 200, align: 'center',exportable:true }
                , {field: 'finish_time', minWidth: 200, title: '生成时间', align: 'center',exportable:true}
                , {field: 'create_time', minWidth: 200, title: '生效开始时间', align: 'center',exportable:true}
                , {field: 'cancel_time', minWidth: 200, title: '生效结束时间', align: 'center',exportable:true}
                , {field: 'end_time', minWidth: 200, title: '失效时间', align: 'center',exportable:true}
            ],
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '结算基础价',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '结算基础价',
                where: function (){
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('tool(test)',function(obj) {
            var data = obj.data;
            var id = data.id;
            var applyId=data.apply_id;
            if (obj.event === 'look') {
                layer.open({
                    title:'查看',
                    type: 2,
                    area: ["60%", "70%"],
                    content: '${ctx}/apply/standardPrice/standardPriceApplyDetailPage?id='+applyId+'&detailId='+id
                })
            }  else if (obj.event === 'delete') {
                if(data.status=='0'||data.status=='3'){
                    layer.msg('已作废的不能再次作废!', {icon: 2});
                    return;
                }
                layer.confirm('确认作废该方案？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                deleteSettleSet(id);
                                //关闭弹窗
                                layer.close(index);
                                console.log("回车确认时事件")
                                //取消连续回车键，导致不断弹出询问框
                                $(':focus').blur();
                            }
                        };
                        //监听键盘事件
                        $(document).on('keydown', this.enterEsc);
                        //esc键触发取消
                        this.escQuit = (ev) => {
                            let code_val = ev.which;
                            if(code_val == 0x1B){
                                $('.layui-layer-btn1').click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.escQuit);
                    },
                    end: function () {
                        //取消键盘监听事件
                        $(document).off('keydown', this.enterEsc);
                        $(document).off('keydown', this.escQuit);
                    },
                    yes: function () {
                        //确认执行的代码
                        deleteSettleSet(id);
                    },
                    no: function () {

                    }
                });
            } else if (obj.event === 'stop') {
                if(data.status=='0'||data.status=='2'){
                    layer.msg('已提前结束的不能再次提前结束!', {icon: 2});
                    return;
                }
                if(data.status=='3'){
                    layer.msg('已作废的不能再次提前结束!', {icon: 2});
                    return;
                }
                layer.confirm('确认终止该方案？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                stopSettleSet(id);
                                //关闭弹窗
                                layer.close(index);
                                console.log("回车确认时事件")
                                //取消连续回车键，导致不断弹出询问框
                                $(':focus').blur();
                            }
                        };
                        //监听键盘事件
                        $(document).on('keydown', this.enterEsc);
                        //esc键触发取消
                        this.escQuit = (ev) => {
                            let code_val = ev.which;
                            if(code_val == 0x1B){
                                $('.layui-layer-btn1').click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.escQuit);
                    },
                    end: function () {
                        //取消键盘监听事件
                        $(document).off('keydown', this.enterEsc);
                        $(document).off('keydown', this.escQuit);
                    },
                    yes: function () {
                        //确认执行的代码
                        stopSettleSet(id);
                    },
                    no: function () {

                    }
                });
            }
        });

        table.on('toolbar(test)', function(obj){
            if (obj.event === 'importSettleTheBasePrice'){
                layer.open({
                    title: '导入',
                    type: 2,
                    area: ['550px', '300px'],
                    content: '${ctx}/settlementSchemeSet/importSettleTheBasePriceFrom'
                });
            }
        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });

        function deleteSettleSet(id){
            $.ajax({
                type: "POST",
                url: "${ctx}/settlementSchemeSet/delSettleData",
                data: {
                    id: id
                },
                success: function (result) {
                    if(result.code=='200'){
                        layer.msg('作废成功！', {icon: 1, time: 1000}, function () {
                            reload();
                        });
                    }else {
                        layer.msg('作废失败!', {icon: 2});
                    }
                },
                error:{
                }
            })
        }
        function stopSettleSet(id){
            $.ajax({
                type: "POST",
                url: "${ctx}/settlementSchemeSet/stopSettleData",
                data: {
                    id: id
                },
                success: function (result) {
                    if(result.code=='200'){
                        layer.msg('终止成功！', {icon: 1, time: 1000}, function () {
                            reload();
                        });
                    }else {
                        layer.msg('终止失败!', {icon: 2});
                    }
                },
                error:{
                }
            })
        }
        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                reload();
            }
        };
    });

    function reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
    function showDetail(id,applyId) {
        layer.open({
            title:'查看',
            type: 2,
            area: ["60%", "70%"],
            content: '${ctx}/apply/standardPrice/standardPriceApplyDetailPage?id='+applyId+'&detailId='+id
        });
    }
</script>
</body>
</html>





