<%--
  Created by IntelliJ IDEA.
  User: user
  Date: 2019/8/7
  Time: 18:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
    <title>wbs</title>
    <link rel="stylesheet" href="${ctxp}/static/plugin/assets/layui/css/layui.css">
    <link rel="stylesheet" href="${ctxp}/static/plugin/assets/common.css"/>
    <script type="text/javascript" src="${ctxp}/static/plugin/assets/jquery-3.2.1.min.js"></script>
</head>
<style>
    .btn_out{
        width: 100px;
        margin: 0;
        float: right;
        margin-right:2%;
    }
    .div_main_form{
        width: 50%;
        margin-left: 10px;
    }
</style>
<body style="background-color: white">
    <sys:message content="${message}"/>
    <!-----------本体部分--------->
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>本体部分</legend>
    </fieldset>
    <div class="" style="margin-left: 10px;margin-right: 10px;margin-top: 10px;">
        <%--<button type="button" class="layui-btn layui-btn-fluid btn_out" onclick="export()">导出</button>--%>
       <c:forEach items="${map.list1}" var="data1" varStatus="index">
         <a class="layui-btn" href="${ctx}/jkxl/export?id=${data1.id}">导出</a>
       </c:forEach>
            <%--<table:importExcel url="${ctx}/propertycostreminder/propertyCostReminder/import"></table:importExcel>--%>
        <table id="table1" class="layui-table" lay-filter="table1"></table>
    </div>
    <!-----------其他部分--------->
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>其他部分</legend>
    </fieldset>
    <div class="" style="margin-left: 10px;margin-right: 10px;">
        <table id="table2" class="layui-table" lay-filter="table2"></table>
    </div>
    <!-----------未识别部分--------->
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>未识别部分</legend>
    </fieldset>
    <div class="layui-form div_main_form" >
        <table class="layui-table">
            <colgroup>
                <col width="200">
                <col width="150">
                <col width="200">
            </colgroup>
            <thead>
            <tr>
                <th>项目名称</th>
                <th>费用金额</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:if test="${ not empty map.list2}">
                <c:forEach items="${map.list2}" var="data2" varStatus="index">
            <tr>

                <td id=""><c:if test="${data2.type eq '1'}">补增值税税率调整差额</c:if><c:if test="${data2.type eq '2'}">扣减甲供材超供材料费</c:if></td>
                <td>${data2.fee}</td>
                <td>
                    <%--<input id="type1" hidden value="${data2.type}">--%>
                    <input id ="id1" hidden value="${data2.id}">
                    <input type="button" class="layui-btn layui-btn-primary layui-btn-xs" value="调整" onclick="wbsup(${data2.type});"/>
                </td>
            </tr>
                </c:forEach>
            </c:if>
            <%--<tr>--%>
                <%--<td>扣减甲供材超供材料费</td>--%>
                <%--<td>500</td>--%>
                <%--<td>--%>
                    <%--<input type="button" class="layui-btn layui-btn-primary layui-btn-xs" value="调整" onclick="wbsup();"/>--%>
                <%--</td>--%>
            <%--</tr>--%>
            </tbody>
        </table>
    </div>
    <%----------------jsjdjs-----------%>
    <div id="motaikuang" style="display: none;">
        <div class="layui-form" style="margin-left: 1px;">
            <table class="layui-table" id="mytble">
                <colgroup>
                    <col width="100">
                    <col width="100">
                    <col width="50">
                    <col width="100">
                    <col>
                </colgroup>
                <thead>
                <tr>
                    <th>WBS要素</th>
                    <th>WBS识别码</th>
                    <th>比例</th>
                    <th>分摊金额</th>
                </tr>
                </thead>
                <tbody id="mytbody">
                <tr>
                    <td>基础工程</td>
                    <td>xxx</td>
                    <td>20%</td>
                    <td>20</td>
                </tr>

                </tbody>
            </table>
        </div>
        <div style="margin-top: 30px;margin-left: 70px;">
            <table>
                <thead>
                <tr>
                    <th>
                        <button style="width: 110px" class="layui-btn layui-btn-primary layui-btn-xs">按占比分摊</button>
                    </th>
                    <th>
                        <button style="margin-left: 60px;width: 110px" type="button" class="layui-btn layui-btn-primary layui-btn-xs">平均分摊</button>
                    </th>
                    <th>
                        <button  style="margin-left: 60px;width: 110px"type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="sure();">确认</button>
                    </th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <div style="height: 100px;width: 100%;">
    </div>
</body>
<script src="${ctxp}/static/plugin/assets/layui/layui.js"></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: 1,
                treeSpid: -1,
                treeIdName: 'id',
                treePidName: 'pid',
                treeDefaultClose: false,
                treeLinkage: false,
                elem: '#table1',
                <%--url: '${ctxp}/webpage/modules/sys/free/selfwbs.json',--%>
                page: false,
                cols: [[
                    {type: 'numbers',align:'center',width:50, rowspan:'3'},
                    {field: 'wbsys', title: 'WBS要素', align:'center',width:200, rowspan:'3'},
//                  {field: 'cj', title: '层级',align:'center',width:60, rowspan:'3'},
                    {field:'wbssbm',width:100, align:'center',rowspan:'2',title:"wbs识别码",rowspan:3},
                    {field:'fbfxysj', align:'center', title: '分布分项(原数据)',colspan:'5'},
                    {field:'fbfxtch',align:'center',title:'分布分项(调差后)',colspan:'4'},
                    {field:'csf1',align:'center',title:'措施费一',colspan:'2'},
                    {field:'csf2',align:'center',width:90,title:'措施费二',rowspan:'3'},
                    {field:'qtf',align:'center',width:80,title:'其他费',rowspan:'3'},
                    {field:'gf',align:'center',width:60,title:'规费',rowspan:'3'},
                    {field:'sf',align:'center',width:60,title:'税金',rowspan:'3'},
                    {field:'hj',align:'center',width:80,title:'合计',rowspan:'3'}
//                  {field:'11',align:'center',width:40,title:'',rowspan:'3'}
//                  {templet: '#oper-col', title: 'oper'}
                ],[
                    {field:'hjje', width:90,align:'center',title:'合计金额',rowspan:'2'},
                    {field:'rgf', width:80,align:'center',title:'人工费',rowspan:'2'},
                    {field:'cl', width:80,align:'center',title:'材料',colspan:'2'},
                    {field:'jxf1', width:80,align:'center',title:'机械费',rowspan:'2'},

                    {field:'rgf2', width:80,align:'center',title:'人工费',rowspan:'2'},
                    {field:'cl2', width:80,align:'center',title:'材料',colspan:'2'},
//              	 {field:'cbrcg2', width:100,title:'承包人采购'},
//              	 {field:'fbrcg2', width:100,title:'发包人采购'},
                    {field:'jxf2', width:80,align:'center',title:'机械费',rowspan:'2'},

                    {field:'csf_1', width:100,align:'center',title:'措施费-1',rowspan:'2'},
                    {field:'csf_2', width:100,align:'center',title:'措施费-2',rowspan:'2'}
                ],[
                    {field:'cbrcg', width:100,align:'center',title:'承包人采购'},
                    {field:'fbrcg', width:100,align:'center',title:'发包人采购'},
                    {field:'cbrcg2', width:100,align:'center',title:'承包人采购'},
                    {field:'fbrcg2', width:100,align:'center',title:'发包人采购'},

                ]]
                ,data: [
                <c:if test="${ not empty map.list}">
                <c:forEach items="${map.list}" var="data" varStatus="index">
                    <c:if test="${data.state eq '1'}">
                {
                    "id": "${data.wbsCode}",
                    "wbsys":"${data.describe}",
                    "wbssbm": "${data.wbsCode}",
                    "hjje": "${data.originalTotalCost}",
                    "rgf": "${data.originalRgCost}",
                    "cbrcg": "${data.originalCbrCost}",
                    "fbrcg": "${data.originalFbrCost}",
                    "jxf1": "${data.originalJxCost}",
                    "rgf2": "${data.rgCost}",
                    "cbrcg2": "${data.cbrCost}",
                    "fbrcg2":"${data.fbrCost}",
                    "jxf2": "${data.jxCost}",
                    "csf_1": "${data.measuresFee1}",
                    "csf_2": "${data.measuresFee2}",
                    "csf2": "${data.measuresFee3}",
                    "qtf":"${data.otherCost}",
                    "gf":"${data.fees}",
                    "sf":"${data.tex}",
                    "hj": "${data.totalFee}",
                    "pid": "${data.parentNode}"
                },
                    </c:if>
                </c:forEach>
                </c:if>
            ],
                done: function () {
                    layer.closeAll('loading');
                }
            });
        };

        renderTable1();
    });
</script>
<script>
    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',
                <%--url: '${ctxp}/webpage/modules/sys/free/other.json',--%>
                page: false,
                cols: [[
                    {type: 'numbers'},
//                  {field: 'id', title: 'WBS要素'},
                    {field: 'wbsys', title: 'WBS要素'},
                    {field: 'wbssbm', title: 'WBS识别码'},
                    {field: 'money', title: '金额'},
//                  {field: 'pid', title: 'pid'},
                ]]
                ,data: [
                <c:if test="${ not empty map.list}">
                <c:forEach items="${map.list}" var="data" varStatus="index">
                <c:if test="${data.state eq '0'}">
                {
                    "d_id": "${data.wbsCode}",
                    "wbsys": "${data.describe}",
                    "wbssbm": "${data.wbsCode}",
                    "money": "${data.totalFee}",
                    "d_pid": "${data.parentNode}"

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

        renderTable2();
    });
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;
    });
</script>
<script>
    function wbsup(type){
        var id = $("#id1").val();
        // var type = $("#type1").val();
        $.post(
            // type : "post",
            "${ctx}/jkxl/gettz",
            {"id":id},
            function(result) {
                var trlue="";
                if(type == '1') {
                    for (var i = 0; i < result.length; i++) {
                        trlue = trlue + "<tr><td>" + result[i].describe + "</td><td>" + result[i].wbsCode + "</td><td>" + result[i].originalRate + "</td><td>" + result[i].bzFee + "</td></tr>";
                    }
                } else {
                    for (var i = 0; i < result.length; i++) {
                        trlue = trlue + "<tr><td>" + result[i].describe + "</td><td>" + result[i].wbsCode + "</td><td>" + result[i].originalRate + "</td><td>" + result[i].jkFee + "</td></tr>";
                    }
                }

                trlue=trlue+"<tr><td>合计</td><td></td><td>100%</td><td></td></tr>";
                $("#mytbody").html(trlue);
            }
        );
//		var trlue="";
//		for(var i=0;i<=3;i++){
//			trlue = trlue + "<tr><td>基础工程</td><td>xxx</td><td>20%</td><td>20</td></tr>";
//		}
//			trlue=trlue+"<tr><td>合计</td><td></td><td>100%</td><td>500</td></tr>";
//		$("#mytbody").html(trlue);
        layer.open({
            type:1,
            area:['600px','400px'],
            title:['调整','color:#fff;background-color:#999999;'],
            shadeClose:false,
            content: $('#motaikuang'),
        });
    }
    function sure(){
        var tr = $("#mytble tr");
        var result = []; // 数组
        for (var i = 0; i < tr.length; i++) {
            var tds = $(tr[i]).find("td");
            if (tds.length > 0) {
                result.push({
                    "wbsys" : $(tds[0]).val(),
                    "wbssbm" : $(tds[1]).val(),
                    "bili" : $(tds[2]).val(),
                    "ftje" : $(tds[3]).val()
                })
            }
        }

        var jsonData = {
            "personLst" : result
        }
        // alert(jsonData);

        // $.ajax({
        //     type : "post",
        //     url : "#",
        //     contentType : "application/json;charset=UTF-8",
        //     data:JSON.stringify(jsonData),
        //     success : function(result) {
        //         window.location.reload();
        //     }
        // });
    }
</script>
</html>
