<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">
    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:330,templet:function(d){
    ////对操作进行初始化
    var xml = "";
    if(d.status==1){ //工程 表头
    xml += "<div><a class='layui-btn layui-btn-primary layui-btn-xs' onclick=\"look( '${ctx}/project/tem/form?id=" + d.id + "&tabId=1')\">查看</a>"
        +"<a class='layui-btn layui-btn-xs'  onclick=\"update( '${ctx}/project/tem/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'onclick=\"withhold( '${ctx}/project/withholdform?id=" + d.id + "&tabId=1')\">诚信扣款</a></div>";
        // +"<a  class='layui-btn layui-btn-warm layui-btn-xs'onclick=\"materialOffset( '${ctx}/project/materialOffsetForm?id=" + d.id + "&tabId=1')\">甲供材抵扣</a>"
        // +"<a  class='layui-btn layui-btn-warm layui-btn-xs'onclick=\"taxDeductions( '${ctx}/project/taxDeductionsForm?id=" + d.id + "&tabId=1')\">税额扣减</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+"&projectId="+d.pid+"\">编辑</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": "${items.unit}",
    "cjsq":"<c:if test="${items.type eq '1'}">架空线路</c:if><c:if test="${items.type eq '2'}">电缆线路</c:if><c:if test="${items.type eq '3'}">变电站工程</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: ['60%', '90%'],
        offset:['7%','20%'],
        shade: 0.8,
        shadeClose: true,
        content: '${ctxp}/webpage/modules/sg/projecttem/addItem.jsp'
        , btn: ['确定','关闭']
        ,yes: function(index, layero){
        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);
}
})
})
}
});
});
function refresh(){
    window.location.reload()
}
function look(url) { //查看工程下项目
    layer.open({
        type: 2,
        title: '查看',
        area: ['70%', '90%'],
        offset:['7%','14%'],
        shade: 0.8,
        shadeClose: true,
        fixed: true, //不固定
        maxmin: true,
        content: url
        , btn: ['关闭']
    })
}
function update(url) {//修改工程下项目
    layer.open({
        type: 2,
        title: '修改工程',
        area: ['70%', '90%'],
        offset:['7%','14%'],
        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);
        }
    })
}

    function withhold(url) { //诚信扣款
    layer.open({
        type: 2,
        title: '诚信扣款',
        area: ['70%', '90%'],
        offset:['7%','14%'],
        shade: 0.8,
        shadeClose: true,
        fixed: true, //不固定
        maxmin: true,
        content: url,//查看的路径
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var bodyparent = layer.getChildFrame('body', index); //获取子类页面body下内容
            bodyparent.find('#updatebtn').click(); // 点击修改页面隐藏的按钮
        }
        ,btn2: function(index, layero){
            layer.close(index);
        }

    })
}
    function materialOffset(url) { //甲供材扣抵
    layer.open({
        type: 2,
        title: '甲供材扣抵',
        area: ['70%', '90%'],
        offset:['7%','14%'],
        shade: 0.8,
        shadeClose: true,
        fixed: true, //不固定
        maxmin: true,
        content: url,//查看的路径
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var bodyparent = layer.getChildFrame('body', index); //获取子类页面body下内容
            bodyparent.find('#updatebtn').click(); // 点击修改页面隐藏的按钮
        }
        ,btn2: function(index, layero){
            layer.close(index);
        }

    })
}

    function taxDeductions(url) { //税金处理
    layer.open({
        type: 2,
        title: '税金处理',
        area: ['70%', '90%'],
        offset:['7%','14%'],
        shade: 0.8,
        shadeClose: true,
        fixed: true, //不固定
        maxmin: true,
        content: url,//查看的路径
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var bodyparent = layer.getChildFrame('body', index); //获取子类页面body下内容
            bodyparent.find('#updatebtn').click(); // 点击修改页面隐藏的按钮
        }
        ,btn2: function(index, layero){
            layer.close(index);
        }
    })
}
</script>

