<%--
  Created by IntelliJ IDEA.
  User: user
  Date: 2019/8/16
  Time: 14:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title>工程管理</title>
    <link rel="stylesheet" href="${ctxp}/static/plugin/assets/layui/css/layui.css">
    <link rel="stylesheet" href="${ctxp}/static/plugin/assets/common.css"/>
    <link rel="stylesheet" href="${ctxp}/static/plugin/assets/vermeit.css">
    <script type="text/javascript" src="${ctxp}/static/plugin/assets/jquery-3.2.1.min.js"></script>
    <script src="${ctxp}/static/plugin/assets/layui/layui.js"></script>
</head>
<style>
    .layui-input{
        height: 28px;
        margin-top: 5px;
        width: 260px;
    }
    .input-meself-time{
        font-size: 13px;
        width: 140px;
    }
    .btn_out{
        width: 100px;
        margin: 0;
        float: right;
        margin-right:2%;
    }
    .div_main_form{
        width: 50%;
        margin-left: 10px;
    }
    .layui-icon-layer{
        display: none;
    }
    .layui-icon-file{
        display: none;
    }
    .layui-table-view .layui-table {width:100%}
</style>
<body style="height:100%">
<input style="display: none;" id="addtext" value=""/>
<div class="layui-main-bgc">
    <sys:message content="${message}"/>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header layui-card-header-add">工程管理</div>
                <div class="layui-card-body" id="noneDiv" style="display: none">
                   <div class="layui-meself-bgc">
                       <form class="layui-form" action="${ctx}/project/list" style="margin-top: 10px;" method="post">
                           <div class="layui-form-item">
                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4" style="margin-left: 20px">
                                   <label class="layui-font-style">工程名称:</label>
                                       <input type="text" name="projectName"  autocomplete="off" class="layui-input">
                                   </div>

                               </div>
                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4" style="margin-left: 20px">
                                   <label class="layui-font-style">登记人:</label>
                                       <input type="text" name="createBy"  autocomplete="off" class="layui-input">
                                   </div>
                               </div>
                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4" style="margin-left: 20px">
                                       <label class="layui-font-style">工程登记时间:</label>
                                       <table>
                                           <tbody>
                                           <tr>
                                               <td> <input type="text" name="projectStartDate" id="beginDate1"  placeholder="开始时间" autocomplete="off" class="layui-input input-meself-time"></td>
                                               <td>~</td>
                                               <td> <input type="text" name="projectEndDate" id="endDate1"  placeholder="结束时间" autocomplete="off" class="layui-input input-meself-time"></td>
                                           </tr>
                                           </tbody>
                                       </table>
                                   </div>
                               </div>
                           </div>
                           <div class="layui-form-item">
                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4" style="margin-left: 20px">
                                   <label class="layui-font-style">项目名称:</label>
                                       <input type="text" name="itemName"  autocomplete="off" class="layui-input">
                                   </div>
                               </div>
                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4" style="margin-left: 20px">
                                   <label class="layui-font-style">项目划分:</label>
                                       <input type="text" name="type"  autocomplete="off" class="layui-input">
                                   </div>
                               </div>
                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4" style="margin-left: 20px">
                                   <label class="layui-font-style">施工单位:</label>
                                       <input type="text" name="unit"  autocomplete="off" class="layui-input">
                                   </div>
                               </div>
                           </div>
                           <div class="layui-form-item">
                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4" style="margin-left: 20px">
                                   <label class="layui-font-style">项目登记时间:</label>
                                       <table>
                                           <tbody>
                                           <tr>
                                               <td><input type="text" name="itemStartDate" id="beginDate2"  placeholder="开始时间" autocomplete="off" class="layui-input input-meself-time"></td>
                                               <td>~</td>
                                               <td> <input type="text" name="itemEndDate" id="endDate2"  placeholder="结束时间" autocomplete="off" class="layui-input input-meself-time"></td>
                                           </tr>
                                           </tbody>
                                       </table>
                                   </div>
                               </div>

                               <div class="layui-inline">
                                   <div class="col-xs-12 col-sm-6 col-md-4 layui-mesl-mit">

                                    <button class="layui-btn layui-btn-primary layui-btn-radius formbtn" lay-submit="" lay-filter="mybtnsubmit">查询</button>
                                    <button type="reset" class="layui-btn layui-btn-primary layui-btn-radius formbtn" style="margin-left: 1px">重置</button>

                                    </div>
                               </div>
                           </div>
                       </form>
                   </div>
                </div>
                <div class="layui-card-body">
                    <div class="" style="margin-left: 10px;margin-right: 10px;margin-top: 10px;">
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-meself" onclick="addProject()"><i class="layui-icon"></i>新建</button>
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-meself"  onclick="refresh()"><img class="layui-meself-img1" src="${ctxp}/icon/refush.png" alt="">&nbsp;刷新</button>
                        </div>
                        <div class="layui-btn-group" style="float: right;margin-right: 10px;border: 1px solid rgb(204,204,204)">
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="noneBtn"><img class="layui-meself-img" src="${ctxp}/icon/solr.png" alt=""></button>
                            <%--<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>--%>
                            <%--<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>--%>
                            <%--<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>--%>
                        </div>
                        <table id="table1" class="layui-table" lay-filter="table1"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#beginDate1'
        });
        laydate.render({
            elem: '#endDate1'
        });
        laydate.render({
            elem: '#beginDate2'
        });
        laydate.render({
            elem: '#endDate2'
        });
    });
</script>
<script>
    layui.config({
        base: '${ctxp}/static/plugin/assets/'
    }).extend({
        treetable: 'treetable-lay/treetable'
    }).use(['layer', 'table', 'treetable'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        var treetable = layui.treetable;

        var renderTable1 = function () {
            layer.load(2);
            treetable.render({
                treeColIndex: 0,
                treeSpid: -1,
                treeIdName: 'id',
                treePidName: 'pid',
                treeDefaultClose: false,
                treeLinkage: false,
                elem: '#table1',
                cols: [[
                    {field: 'gcmc',width:200,title: '工程名称'},
                    {field:'xmsl',width:180,title:"项目数量"},
                    {field:'cjsq',width:200,title: '创建时期'},
                    {field:'djr',width:200,title:'登记人'},
                    {field:'op',align:'center',title:"操作",minWidth:200,templet:function(d){
                            ////对操作进行初始化
                            var xml = "";
                            if(d.status==1){
                                xml += "<a class='layui-btn layui-btn-primary layui-btn-xs' onclick=\"look( '${ctx}/project/form?id=" + d.id + "&tabId=1')\">查看</a>"
                                    +"<a class='layui-btn layui-btn-xs'  onclick=\"update( '${ctx}/project/form?id=" + d.id + "&tabId=2')\">修改</a>"
                                    +"<a class='layui-btn layui-btn-normal layui-btn-xs' lay-event='add'>添加项目</a>"
                                    +"<a class='layui-btn layui-btn-warm layui-btn-xs' lay-event=''href=\"${ctx}/project/export?id=" + d.id+"\">导出</a>";
                            }
                            if(d.status==2){
                                xml +="<span class='myspan'>操作</span>";
                            }
                            if(d.status==3){
                                xml +="<a class='layui-btn layui-btn-xs' href=\"${ctx}/jkxl/list?id="+d.id+"&type="+d.type+"\">编辑</a>";
                            }

                            return xml;
                        }}
                ]],
                "data": [
                    <c:if test="${ not empty list}">
                    <c:forEach items="${list}" var="data" varStatus="index">
                    {
                        "id": "${data.id}",
                        "gcmc":"${data.projectName}",
                        "xmsl": "${data.number}",
                        "cjsq": "<fmt:formatDate value="${data.createDate}" pattern="yyyy/MM/dd"/>",
                        "djr":"${data.userName}",
                        "status":"1",
                        "pid": -1
                    },
                    {
                        "id": "2",
                        "gcmc":"项目名称",
                        "xmsl": "施工单位",
                        "cjsq": "项目划分",
                        "djr":"创建时间",
                        "status":"2",
                        "pid": "${data.id}"
                    },
                    </c:forEach>
                    </c:if>
                    <c:forEach items="${list}" var="item" varStatus="index">
                      <c:forEach items="${item.wbsItems}" var="items" varStatus="index">
                    {
                        "id": "${items.id}",
                        "type":"${items.type}",
                        "gcmc":"${items.itemName}",
                        "xmsl": "某施工单位一",
                        <%--"cjsq": <c:if test="${items.type eq '1'}">"架空线路"</c:if><c:if test="${items.type eq '2'}">"电缆线路"</c:if>,--%>
                        "cjsq":<c:if test="${items.type eq '1'}">"架空线路"</c:if><c:if test="${items.type eq '2'}">"电缆线路"</c:if>,
                        "djr":"<fmt:formatDate value="${items.createDate}" pattern="yyyy/MM/dd"/>",
                        "status":"3",
                        "pid": "${items.projectId}"
                    },
                    </c:forEach>
                    </c:forEach>
                ],

                done: function () {
                    $(".myspan").closest("tr").css('background-color','#f2f2f2');
                    layer.closeAll('loading');
                }
            });
        };
        renderTable1();
        treetable.foldAll('#table1');
        table.on('tool(table1)', function(obj,target){
            var data = obj.data;
            //console.log(obj)
            if(obj.event == 'add'){
                $("#addtext").val(data.id);
                layui.use(['table','layer'],function(){
                    layer.open({
                        type: 2,
                        title: '添加工程',
                        area: ['40%', '80%'],
                        shade: 0.8,
                        shadeClose: true,
                        content: '${ctxp}/webpage/modules/sg/project/addItemForm.jsp'
                        , btn: ['确定','关闭']
                        ,yes: function(index, layero){
                            // var bodyparent = layer.getChildFrame('body', index);
                            // bodyparent.find('#newProject').click();
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            var inputForm = body.find('#inputForm');
                            var top_iframe;
                            if(target){
                                top_iframe = target;//如果指定了iframe，则在改frame中跳转
                            }else{
                                top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                            }
                            inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                            iframeWin.contentWindow.doSubmit();

                            layer.close(index);//关闭对话框。

                        }
                        ,btn2: function(index, layero){
                            layer.close(index);
                        }
                    })
                })
            }
        });
    });
</script>
<script>
    function refresh(){
        window.location.reload();
    }
    function addProject(){
        layer.prompt({title: '请输入工程名称', formType: 3}, function(text, index){
            layer.close(index);
            $.ajax({
                type: "post",
                url: "${ctx}/project/save",
                data:{projectName:text},
                dataType: "json",
                success: function(data){
                    if(data.success){
                        layer.msg(data.msg, {icon: 1});
                        window.location.reload();
                    }else{
                        layer.msg('添加失败', {icon: 1});
                    }
                }
            });

        });
    }
</script>
<script>
    function look(url) {
        layer.open({
            type: 2,
            title: '查看',
            area: ['70%', '90%'],
            shade: 0.8,

            shadeClose: true,
            fixed: true, //不固定
            maxmin: true,
            content: url
            , btn: ['关闭']
        })
    }
    function update(url) {
        layer.open({
            type: 2,
            title: '修改工程',
            area: ['70%', '90%'],
            shade: 0.8,
            shadeClose: true,
            fixed: false, //不固定
            maxmin: true,
            content: url
            , btn: ['确定','关闭']
            ,yes: function(index, layero){
                var bodyparent = layer.getChildFrame('body', index);
                bodyparent.find('#updatebtn').click();
            }
            ,btn2: function(index, layero){
                layer.close(index);
            }
        })
    }
</script>
<script>
    $(document).ready(function(e) {

        $("#noneBtn").click(function(e) {
            $("#noneDiv").toggle(400);
        });
    });
</script>
</body>
</html>
