<%@ 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: 1,
    treeSpid: -1,
    treeIdName: 'id',
    treePidName: 'pid',
    treeDefaultClose: false,
    treeLinkage: false,
    elem: '#table1',
    page: false,
    cols: [[ //加载下拉表格二级表头
    {type:'numbers',title: '序号', rowspan: 2, totalRowText: "合计",},
    {field: 'wbsys', title: 'WBS要素',width:200, rowspan:'2'},

    {field:'wbssbm',width:100, align:'center',rowspan:'2',title:"wbs识别码"},
    {field:'fbfxysj', align:'center', title: '分部分项',colspan:'6'},
    //{field:'fbfxtch',align:'center',title:'分部分项(调差后)',colspan:'4'},
    {field:'fbfxtch',align:'center',title:'共性分摊费用',colspan:'7'},

    {field:'hj',align:'center',width:120,title:'合计',rowspan:'2',totalRow: true}
    ],[
    {field:'hjje', width:120,align:'center',title:'合计金额',totalRow: true},
    {field:'zjgcf', width:120,align:'center',title:'直接工程费',totalRow: true},
    {field:'rgf1', width:120,align:'center',title:'人工费',totalRow: true},
    {field:'cbrcg1', width:120,align:'center',title:'承包人采购',totalRow: true},
    {field:'fbrcg1', width:120,align:'center',title:'发包人采购',totalRow: true},
    {field:'jxf1', width:120,align:'center',title:'机械费',totalRow: true},

    //{field:'rgf2', width:120,align:'center',title:'人工费',totalRow: true},
    //{field:'cbrcg2', width:120,align:'center',title:'承包人采购',totalRow: true},
    //{field:'fbrcg2', width:120,align:'center',title:'发包人采购',totalRow: true},
    //{field:'jxf2', width:120,align:'center',title:'机械费',totalRow: true},

    //{field:'rgf3', width:120,align:'center',title:'人工费',totalRow: true},
    //{field:'cbrcg3', width:120,align:'center',title:'承包人采购',totalRow: true},
    //{field:'fbrcg3', width:120,align:'center',title:'发包人采购',totalRow: true},
    //{field:'jxf3', width:120,align:'center',title:'机械费',totalRow: true},

    {field:'csf_1',width:120,title:'措施费-1',align:'center',totalRow: true},
    {field:'csf_2',width:120,title:'措施费-2',align:'center',totalRow: true},
    {field:'csf2',align:'center',width:120,title:'措施费二',totalRow: true},
    {field:'qtf',align:'center',width:120,title:'其他费',totalRow: true},
    {field:'gf',align:'center',width:120,title:'规费',totalRow: true},
    {field:'sf',align:'center',width:120,title:'税金',totalRow: true},
    {field:'rgf3',align:'center',width:120,title:'分摊费用',totalRow: true},
    ]]
    ,data: [ //数据传入
    <c:if test="${ not empty map.list}">
    <c:forEach items="${map.list}" var="data" varStatus="index">
    <c:if test="${data.feeType eq '1'}">
    {
        "id": "${data.wbsCode}",
        "wbsys":"${data.describe}",
        "wbssbm": "${data.wbsCode}",

        "hjje": doIt(${data.originalTotalCost}),
        "zjgcf":doIt(${data.zjgcFee}),
        "rgf1":doIt(${data.originalRgCost}),
        "cbrcg1":doIt(${data.originalCbrCost}),
        "fbrcg1":doIt(${data.originalFbrCost}),
        "jxf1":doIt(${data.originalJxCost}),


        "rgf3": "<c:if test="${ empty data.rgFtFee and not empty data.originalTotalCost}">0.0</c:if><c:if test="${ not empty data.rgFtFee}">${data.rgFtFee}</c:if>",

        "csf_1":doIt(${data.measuresFee1}),
        "csf_2":doIt(${data.measuresFee2}),
        "csf2": "<c:if test="${ empty data.measuresFee3 and not empty data.originalTotalCost}">0.0</c:if><c:if test="${ not empty data.measuresFee3}">${data.measuresFee3}</c:if>",
        "qtf":doIt(${data.otherCost}),
        "gf":doIt(${data.fees}),
        "sf":doIt(${data.tex}),
        "hj": doIt(${data.totalFee}),
        "pid":"${data.parentNode}"
    },
    </c:if>
    </c:forEach>
    </c:if>
    ],
    done: function () {
    layer.closeAll('loading');
}
});
};

    renderTable1(); //表格渲染
    // treetable.foldAll('#table1'); 开启后下拉合并
});
layui.use(['table', 'form', 'element', 'treetable'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    var form = layui.form;
    var element = layui.element;
    var treetable = layui.treetable;

    // 其他部分 表格渲染
    var renderTable2 = function () {
        layer.load(2);
        treetable.render({
            treeColIndex: 1,
            treeSpid: -1,
            treeIdName: 'd_id',
            treePidName: 'd_pid',
            elem: '#table2',
            page: false,
            cols: [[ //其他部分 生产表头
                {type: 'numbers'},
                {field: 'wbsys', title: 'WBS要素'},
                {field: 'wbssbm', title: 'WBS识别码'},
                {field: 'money', title: '金额'},
             ]]
            ,data: [ //其他部分数据传入
                <c:if test="${ not empty map.list}">
                    <c:forEach items="${map.list}" var="data" varStatus="index">
                        <c:if test="${data.feeType eq '0'}">
                            {
                                "d_id": "${data.wbsCode}",
                                "wbsys": "${data.describe}",
                                "wbssbm": "${data.wbsCode}",
                                "money":doIt(${data.totalFee}),
                                "d_pid": "${data.parentNode}"

                            },
                        </c:if>
                    </c:forEach>
                </c:if>
            ],
                done: function () {
                    layer.closeAll('loading');
                }
            });
            };

            renderTable2();
            // treetable.foldAll('#table2');
            });
        layui.use('table', function(){
            var table = layui.table;
        });
        layui.use('table', function(){
            var table = layui.table;
            //未标识部分 表格渲染
            table.render({
                elem: '#xmmc'
                ,title: '未标识'
                ,cols: [[ //渲染 表头
                    {field:'xmmc', width:200,title:'项目名称'}
                    ,{field:'fyje', width:178,title:'费用金额'}
                    ,{width:178,  toolbar: '#barDemo',title:'操作'}
                ]]
                ,data:[ //渲染 数据
                    <c:if test="${ not empty map.list}">
                        <c:forEach items="${map.list2}" var="data" varStatus="index">
                            {
                                "id":"${data.id}",
                                "xmmc": "${data.type}",
                                "fyje": doIt(${data.fee})
                            },
                        </c:forEach>
                    </c:if>
                ]
                ,page: false
            });
            //监听工具条
            table.on('tool(freestr)', function(obj){
                var datacount="";
                var data = obj.data;
                if(obj.event === 'fttz'){ //分摊调整
                    sureradio(data);
                } else if(obj.event === 'ddtz'){ //单独调整
                    sureradio2(data,'${ctx}/jkxl/getft?id='+data.id);
                }
                // alert(datacount);
            });
        });

    function sureradio2(data,url){ //分摊调整 弹出层
        var newid = data.id;   //获取id
        var xmmc = data.xmmc;  //获取项目名称
        var fyje = data.fyje;  //获取 费用金额
        $("#newid").val(newid); //项目 id/名称/金额 写入input当中  子类页面调用
        $("#xmmc1").val(xmmc);
        $("#fyje1").val(fyje);
        layui.use(['table','layer'],function(){

            layer.open({  //弹出层页面
                type: 2,
                title: '单独调整',
                area: ['80%', '95%'], //设置弹出层大小
                shade: 0.8,
                maxmin: true,  //最大最小值
                shadeClose: true,
                content: url  //弹出层路径
                , btn: ['确定','关闭']
                    ,yes: function(index, layero){
                        var bodyparent = layer.getChildFrame('body', index); //当前页面 获取子类（弹出层body）的属性
                        bodyparent.find('#freenl').click();  //获取子类页面的按钮,点击事件。
                    }
                    ,btn2: function(index, layero){
                        layer.close(index); //管理弹出层
                    }
                })
            })
    }
    function sureradio(data,target){ //单独调整
        var newid = data.id; //获取 id/项目名称/项目金额
        var xmmc = data.xmmc;
        var fyje = data.fyje;
        $("#newid").val(newid); //写入当前页面input框中
        $("#xmmc1").val(xmmc);
        $("#fyje1").val(fyje);
        layui.use(['table','layer'],function(){

           layer.open({
                type: 2,
                title: xmmc,
                area: ['47%', '95%'],
                shade: 0.8,
                shadeClose: true,
                content: '${ctxp}/webpage/modules/sg/free/avgpage.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);//关闭对话框。
                }

            })
        })
    }
    layui.use('table', function(){ //结算汇总表部分
        var table = layui.table;
        table.render({
            elem: '#settlement'
            ,limit:Number.MAX_VALUE
            ,title: '结算汇总表'
            ,cols: [[
                {width:50, title: '序号',type:'numbers'}
                ,{field:'setname',title:'项目或费用名称'}
                ,{field:'setmoney',title:'金额'}
                ,{field:'settext', title:'备注'}
                ,{field:'jshj',title:'计算合计'}
                ,{field:'ce',title:'差额'}
                ,{field:'op',align:'center',title:"数据核验", templet:function(d){
                        ////对操作进行初始化
                        var xml = "";
                        if(d.status=="1")
                            xml += "<a style='margin-top: 3px;' class='layui-btn layui-btn-danger layui-btn-xs' lay-event='byz'>不一致</a>";
                        if(d.status == "0")
                            xml+="<a style='margin-top: 3px;' class='layui-btn layui-btn-xs' lay-event='byz'>一致</a>";
                        return xml;
            }}
        ]]
        ,data:[
        <c:if test="${not empty map.list3}">
            <c:forEach items="${map.list3}" var="data">
                {
                    "id":"${data.id}",
                    "setname": "${data.entryName}",
                    "setmoney":doIt(${data.money}),
                    "settext":"${data.remarks}",
                    "status":"${data.status}",
                    "reason":"${data.reason}",
                    "jshj":doIt(${data.totalFee}),
                    "ce":doIt(${data.difference})
                },
            </c:forEach>
        </c:if>
    ]
    // ,page: false
});
//监听行工具事件
table.on('tool(settle)', function(obj){
    var data = obj.data;
    if(obj.event === 'byz'){
        layer.open({
            type: 1,
            title:data.setname,
            // skin: 'layui-layer-rim',
            area: ['70%', '90%'],
            offset:['7%','14%'],
            shade: 0.8,
            shadeClose: true,
            fixed: true, //不固定
            maxmin: true,
            btn:['关闭'],
            // content: "<div style='padding: 16px'>"+data.reason+"</div>"
            content: div_table(data)
        });
    }
});
});
function doIt(val){ //科学计数法
    if(val == null){
        return val;
    }
    var num = new Number(val);
    return num;
}
</script>