<%@ 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">
    <style>
        .layui-table-cell {
            height:auto;
            overflow:visible;
            text-overflow:inherit;
            white-space:normal;
            word-break: break-all;
        }
    </style>
</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><a href="${ctx}/settlementSchemeSet/settleSetPage">结算基础价</a></li>'/>
                <sfTags:pagePermission authFlag="XTSZ_JSJSZ_JLZC_T" html='<li class="layui-this"><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">
                            <select name="traderId">
                                <option value="">请选择</option>
                                <c:forEach var="trader" items="${traders}">
                                    <option value="${trader.columns.id}">${trader.columns.name}</option>
                                </c:forEach>
                            </select>
                        </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="status">
                                <option value="">请选择</option>
                                <option value="1">启用中</option>
                                <option value="2">已禁用</option>
                            <%--    <option value="3">作废失效</option>--%>
                            </select>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" id="add" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>
                </div>
            </script>
        </div>

    </div>
</div>
</div>
<script type="text/html" id="table-toolbar">
    <sfTags:pagePermission authFlag="XTSZ_JSJSZ_JLZC_BJ_B" html='<a class="layui-table-opt-link" lay-event="editWay">编辑</a>'/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <sfTags:pagePermission authFlag="XTSZ_JSJSZ_JLZC_BGJL_B" html='<a class="layui-table-opt-link" lay-event="lookRecord">变更记录</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-150'
            , defaultToolbar: false
            , limits: [20, 50, 100]
            , limit: 20
            , page: true //开启分页
            , url: '${ctx}/rewardsPunishWaySet/rewardsPunishWayListDate'
            , cols: [[
                {field: 'number', title: '序号', align: 'center', type: 'numbers'}
                ,{field:'id', title: '操作',minWidth: 150,toolbar: '#table-toolbar',align: 'center'}
                , {field: 'status', title: '状态', minWidth: 80, align: 'center',templet: function (d) {
                        if (d.status == "1") {
                            return "启用中";
                        }else if (d.status == "2") {
                            return "已禁用";
                        }
                        return "--";
                    }}
                , {field: 'number', title: '方案编号', minWidth: 100, align: 'center'}
                , {field: 'name', title: '方案名称', minWidth: 100, align: 'center'}
                , {field: 'status', title: '方案详情', minWidth:550, align: 'center'
                    ,templet: function (d) {
                        var str='';
                        str+='<p>当月完成安装容量大于等于'+d.low_data+'MW，';
                        str+='小于'+d.high_data+'MW，';
                        str+='奖励当月安装容量x'+d.ratio_data+'元/W；</p>';
                        str+='<p>当月完成安装容量大于等于'+d.max_high_data+'MW，';
                        str+='奖励当月安装容量x'+d.max_high_data_radio+'元/W。</p>';
                        return str;
                    }
                }, {field: 'trader_ids', title: '适用代理商', minWidth:120, align: 'center'
                    ,templet: function (d) {
                        if(isBlank(d.trader_ids) || '-1'==d.trader_ids){
                            return "不限";
                        }else{
                            return "指定("+(d.trader_ids.split(",").length) +')';
                        }
                    }
                }
                , {field: 'settlement_nodes', title: '结算节点', minWidth: 120, align: 'center'}
                , {field: 'low_time', minWidth: 200, title: '安装完成时间', align: 'center'
                    ,templet: function (d){
                      return d.low_time+' 至 '+d.high_time;
                    }
               }
                ,{field: 'createTime', title: '创建时间', minWidth: 120, align: 'center'}
            ],
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '奖励政策',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '奖励政策',
                where: function (){
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            switch (obj.event){
                case 'add':
                    layer.open({
                        title:'新增',
                        type: 2,
                        area: ["80%", "90%"],
                        content: '${ctx}/rewardsPunishWaySet/addRewardsWayPage'
                    })
                    break;

            }
        })

        table.on('tool(test)',function(obj) {
            var data = obj.data;
            var id = data.id;
            if (obj.event === 'editWay') {
                layer.open({
                    title:'编辑',
                    type: 2,
                    area: ["80%", "90%"],
                    content: '${ctx}/rewardsPunishWaySet/addRewardsWayPage?id='+id
                })
            } if (obj.event === 'lookRecord') {
                layer.open({
                    title:'变更记录',
                    type: 2,
                    area: ["60%", "50%"],
                    content: '${ctx}/rewardsPunishWaySet/getChangeRecord?id='+id
                })
            }
        });

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

        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }

    });

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

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

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






