<%@ 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="FAGL_ZHFAGL_ZJPZ_T" html='<li class=""><a href="${ctx}/planManage/togetherProgram">支架配置</a></li>'/>
                <sfTags:pagePermission authFlag="FAGL_ZHFAGL_DQPZ_T" html='<li class="layui-this"><a href="${ctx}/planManage/electricProgram">电气配置</a></li>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn" 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="assembly" class="layui-input" id="assembly" >
                        </div>
                    </div>
                    <div class="layui-col-lg3 layui-col-sm2">
                        <label class="layui-form-label">组件块数：</label>
                        <div class="layui-input-block">
                            <div class="layui-col-xs3">
                             <input type="text" name="assemblyMin" class="layui-input" id="assemblyMin" >
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                ~
                            </div>
                            <div class="layui-col-xs3">
                                <input type="text" name="assemblyMax" class="layui-input" id="assemblyMax" >
                            </div>
                        </div>

                    </div>

                    <div class="layui-col-lg4 layui-col-sm6">
                        <label class="layui-form-label">创建时间：</label>
                        <div class="layui-input-block">
                            <div class="layui-col-xs3">
                                <input type="text" name="createTimeSta" class="layui-input" id="createTimeSta" placeholder="开始日期">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs3">
                                <input type="text" name="createTimeEnd" class="layui-input" id="createTimeEnd" placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="FAGL_DQPZ_TJ_B" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加 </button>'/>
    <sfTags:pagePermission authFlag="FAGL_DQPZ_XG_B" html='<button class="layui-btn layui-btn-sm" id="editBtn" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑 </button>'/>
    <sfTags:pagePermission authFlag="FAGL_DQPZ_SC_B" html='<button class="layui-btn layui-btn-sm" id="deleteBtn" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除 </button>'/>
</div>
</div>

<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 excel = layui.excel;

        //开始日期
        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
                });
            }
        });

        var download = '${fns:checkPagePermission(request, "FAGL_DQPZ_XZ_B")}';
        //方案信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/planManage/electriclistDate'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar:"#toolbarDemo"
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', minWidth: 50, title: '序号', align: 'center', type: 'numbers',rowspan:'2', fixed: 'left'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',rowspan:'2' , fixed: 'left'}
                , {field: 'assembly', title: '组件规格(W)', minWidth: 150, align: 'center',exportable:true ,rowspan:'2', fixed: 'left'}
                , {field: 'assembly_max', title: '组件块数(块)', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'
                  ,templet:function(d){
                     return d.assembly_min+"~"+d.assembly_max;
                    }
                }
                , {field: 'inverter1', title: '逆变器1', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'inverter2', title: '逆变器2', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'inverter3', title: '逆变器3', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'box1', title: '并网箱1', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'box2', title: '并网箱2', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'box3', title: '并网箱3', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'id', minWidth: 150, title: '电气辅材清单', align: 'center',exportable:true ,rowspan:'2',
                    templet: function (d) {
                        if (download == '0') {
                            return '<a href="${ctx}/planManage/downLoadMaterilList?id='+d.id+'" class="layui-table-link">下载</a>';
                        }
                        return "";
                    }
                }
                , {field: 'create_time', minWidth: 200, title: '创建时间', align: 'center',exportable:true ,rowspan:'2'}
            ],
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '方案信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '方案信息',
                where: function (){
                    console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('toolbar(test)',function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'add') {
                layer.open({
                    type: 2,
                    title: '新增',
                    content: '${ctx}/planManage/toAddElectric',
                    area: ['80%','80%'],
                    success: function(layero, index) {
                        childWin = window[layero.find('iframe')[0]['name']];
                    }
                });
            } else if (obj.event === 'edit') {
                if(checkStatus.data.length < 1){
                    layer.msg("请先选择数据",{icon:5,anim:6});
                    return;
                }else if(checkStatus.data.length > 1){
                    layer.msg("只能选择一条数据",{icon:5,anim:6});
                    return;
                }
                layer.open({
                    type: 2,
                    title: '编辑',
                    content: '${ctx}/planManage/toAddElectric?id=' + checkStatus.data[0].id,
                    area: ['80%','80%'],
                    success: function(layero, index) {
                        childWin = window[layero.find('iframe')[0]['name']];
                    }
                });
            } else if (obj.event === 'delete') {
                var data = checkStatus.data;
                if (data.length < 1) {
                    layer.msg("请先选择数据",{icon:5,anim:6});
                    return;
                }
                var ids="";
                for(var i=0;i<data.length;i++){
                    ids+=data[i].id+",";
                }
                var indexla = layer.confirm('您确定要删除方案吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/planManage/deleteElectricPlan",
                        data: {
                            ids: ids
                        },
                        success: function (result) {
                            if(result.code=='200'){
                                layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            }else {
                                layer.msg('删除失败!', {icon: 2});
                            }
                        },
                        error:{
                        }
                    })
                }, function () {
                    layer.close(indexla);
                });
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {

        });

        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', {
            where: {
                assembly: $('#assembly').val().trim(),
                assemblyMax:$("#assemblyMax").val().trim(),
                assemblyMin:$("#assemblyMin").val().trim(),
                createTimeSta:$("#createTimeSta").val().trim(),
                createTimeEnd:$("#createTimeEnd").val().trim(),
            }
        });
    }

    window.importMaterial = function(materials){
        childWin.importMaterial(materials);
    }


    function  denglsj(id,userId) {
        console.log("siteInfo" + id +" userId : "+ userId)
        parent.denglusdj(id,userId);
    }

    /*方案详情*/
   /* function siteDetail(id) {
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/planManage/toAdd?type=3&mode=view&id=' + id,
            area: ['80%','80%']
        });
    }*/

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


