<%include ./common.html %>
<div class="panel-content">
    <div class="panel-title">
        <div class="title-main">
            <h2>
                <a href="javascript:void(0);" id="save-lib" class="btn btn-primary btn-sm pull-right">保存</a>
                <a href="/compilation/valuation/<%= section %>/<%= valuationId %>" class="btn btn-default btn-sm pull-right">返回</a>
            </h2>
        </div>
    </div>
    <div class="content-wrap">
        <div class="c-header" style="padding:0">
            <ul class="nav nav-tabs">
                <li role="presentation" class="active"><a href="javascript:void(0);"><%= libData.name %> - <%= libData.feeName %></a></li>
            </ul>
        </div>
        <div class="c-body">
            <form method="post" action="/compilation/save-lib" enctype="application/x-www-form-urlencoded21">
                <div class="row">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="form-group col-md-3">
                                <label>标准清单</label>
                                <div class="bill-list">
                                    <% if (Object.keys(libData).length > 0 && libData.bill_lib.length > 0) { %>
                                    <% libData.bill_lib.forEach(function (bill, index){ %>
                                    <p class="form-control-static">
                                        <a class="pull-right text-danger remove-lib" data-model="bill" title="移除">
                                            <span class="glyphicon glyphicon-remove"></span>
                                        </a>
                                        <input type="hidden" name="bill_lib" data-id="<%= bill.id %>" value="<%= JSON.stringify({id: bill.id, name: bill.name}) %>">
                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= bill.name %>
                                    </p>
                                    <% }) %>
                                    <% } %>
                                </div>
                                <a class="btn btn-link btn-sm add-compilation" href="javascript:void(0)" data-model="bill">添加</a>
                            </div>
                            <div class="form-group col-md-3">
                                <label>人材机库</label>
                                <div class="glj-list">
                                    <% if (Object.keys(libData).length > 0 && libData.glj_lib.length > 0) { %>
                                    <% libData.glj_lib.forEach(function (glj, index){ %>
                                    <p class="form-control-static">
                                        <a class="pull-right text-danger remove-lib" data-model="glj" title="移除" data-id="<%= glj.id %>">
                                            <span class="glyphicon glyphicon-remove"></span>
                                        </a>
                                        <input type="hidden" name="glj_lib" data-id="<%= glj.id %>" value="<%= JSON.stringify({id: glj.id, name: glj.name}) %>">
                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= glj.name %>
                                    </p>
                                    <% }) %>
                                    <% } %>
                                </div>
                                <a href="#" class="btn btn-link btn-sm add-compilation" data-model="glj">添加</a>
                            </div>
                            <div class="form-group col-md-3">
                                <label>清单指引库</label>
                                <div class="billsGuidance-list">
                                    <% if (Object.keys(libData).length > 0 && libData.billsGuidance_lib.length > 0) { %>
                                    <% libData.billsGuidance_lib.forEach(function (billsGuidance, index){ %>
                                    <p class="form-control-static">
                                        <a class="pull-right text-danger remove-lib" data-model="billsGuidance" title="移除" data-id="<%= billsGuidance.id %>">
                                            <span class="glyphicon glyphicon-remove"></span>
                                        </a>
                                        <input type="hidden" name="billsGuidance_lib" data-id="<%= billsGuidance.id %>" value="<%= JSON.stringify({id: billsGuidance.id, name: billsGuidance.name}) %>">
                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= billsGuidance.name %>
                                    </p>
                                    <% }) %>
                                    <% } %>
                                </div>
                                <a href="#" class="btn btn-link btn-sm add-compilation" data-model="billsGuidance">添加</a>
                            </div>
                            <div class="form-group col-md-3">
                                <label>人工系数</label>
                                <div class="artificial-list">
                                    <% if (Object.keys(libData).length > 0 && libData.artificial_lib.length > 0) { %>
                                    <% libData.artificial_lib.forEach(function (artificial, index){ %>
                                    <p class="form-control-static">
                                        <a class="pull-right text-danger remove-lib" data-model="artificial" title="移除" data-id="<%= artificial.id %>">
                                            <span class="glyphicon glyphicon-remove"></span>
                                        </a>
                                        <input type="hidden" name="artificial_lib" data-id="<%= artificial.id %>" value="<%= JSON.stringify({id: artificial.id, name: artificial.name}) %>">
                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= artificial.name %>
                                    </p>
                                    <% }) %>
                                    <% } %>
                                </div>
                                <a href="#" class="btn btn-link btn-sm add-compilation" data-model="artificial">添加</a>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group col-md-3">
                                <label>工程特征</label>
                                <div class="feature-list">
                                    <% if (Object.keys(libData).length > 0 && libData.feature_lib && libData.feature_lib.length > 0) { %>
                                    <% libData.feature_lib.forEach(function (feature, index){ %>
                                    <p class="form-control-static">
                                        <a class="pull-right text-danger remove-lib" data-model="feature" title="移除" data-id="<%= feature.id %>">
                                            <span class="glyphicon glyphicon-remove"></span>
                                        </a>
                                        <input type="hidden" name="feature_lib" data-id="<%= feature.id %>" value="<%= JSON.stringify({id: feature.id, name: feature.name}) %>">
                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= feature.name %>
                                    </p>
                                    <% }) %>
                                    <% } %>
                                </div>
                                <a href="#" class="btn btn-link btn-sm add-compilation" data-model="feature">添加</a>
                            </div>
                            <div class="form-group col-md-3">
                                <label>累进区间</label>
                                <div class="progressive-list">
                                    <% if (Object.keys(libData).length > 0 && libData.progressive_lib && libData.progressive_lib.length > 0) { %>
                                    <% libData.progressive_lib.forEach(function (progressive, index){ %>
                                    <p class="form-control-static">
                                        <a class="pull-right text-danger remove-lib" data-model="progressive" title="移除" data-id="<%= progressive.id %>">
                                            <span class="glyphicon glyphicon-remove"></span>
                                        </a>
                                        <input type="hidden" name="progressive_lib" data-id="<%= progressive.id %>" value="<%= JSON.stringify({id: progressive.id, name: progressive.name}) %>">
                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= progressive.name %>
                                    </p>
                                    <% }) %>
                                    <% } %>
                                </div>
                                <a href="#" class="btn btn-link btn-sm add-compilation" data-model="progressive">添加</a>
                            </div>
                            <div class="form-group col-md-3">
                                <label>车船税</label>
                                <div class="vvTax-list">
                                    <% if (Object.keys(libData).length > 0 && libData.vvTax_lib && libData.vvTax_lib.length > 0) { %>
                                    <% libData.vvTax_lib.forEach(function (vvTax, index){ %>
                                    <p class="form-control-static">
                                        <a class="pull-right text-danger remove-lib" data-model="vvTax" title="移除" data-id="<%= vvTax.id %>">
                                            <span class="glyphicon glyphicon-remove"></span>
                                        </a>
                                        <input type="hidden" name="vvTax_lib" data-id="<%= vvTax.id %>" value="<%= JSON.stringify({id: vvTax.id, name: vvTax.name}) %>">
                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= vvTax.name %>
                                    </p>
                                    <% }) %>
                                    <% } %>
                                </div>
                                <a href="#" class="btn btn-link btn-sm add-compilation" data-model="vvTax">添加</a>
                            </div>
                    </div>

                    <div class="col-md-12">
                        <a data-toggle="modal" data-target="#other_setting" class="btn btn-primary btn-sm " style="margin-right:5px">显示设置</a>
                    </div>
                    <div class="col-md-12" style="padding-top:20px">
                        <legend>计算程序/清单模板/列设置/费率标准</legend>
                        <a data-toggle="modal" data-target="#addTaxGroup" class="btn btn-link btn-sm " id="addTaxGroupBtn" style="margin-right:5px">添加</a>
                        <table class="table engineer_table">
                            <thead>
                            <tr>
                                <th>计税方式</th>
                                <th>计算程序</th>
                                <th>清单模板</th>
                                <th>列设置</th>
                                <th>费率标准</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="tax_group_tbody">
                            <% if (Object.keys(libData).length > 0 && libData.tax_group.length > 0) { %>
                                <% for(let tax of libData.tax_group) {%>
                                <% let groupIndex = "";%>
                                <tr class='taxGroup_tr'>
                                    <td>
                                        <% if(tax.taxType === "1") { %>
                                        <%  groupIndex = groupIndex + tax.taxType;%>
                                        <span>一般计税</span>
                                        <% } else if(tax.taxType === "2"){%>
                                        <%  groupIndex = groupIndex + tax.taxType;%>
                                        <span>简易计税</span>
                                        <% } %>
                                    </td>
                                    <td>
                                        <% if(tax.program_lib && tax.program_lib.id) { %>
                                        <%  groupIndex = groupIndex + tax.program_lib.id;%>
                                            <span><%= tax.program_lib.displayName%></span>
                                        <% } %>
                                    </td>
                                    <td>
                                        <% if(tax.template_lib && tax.template_lib.id) { %>
                                        <%  groupIndex = groupIndex + tax.template_lib.id;%>
                                        <span><%= tax.template_lib.name%></span>
                                        <% } %>
                                    </td>
                                    <td>
                                        <% if(tax.col_lib && tax.col_lib.id) { %>
                                        <%  groupIndex = groupIndex + tax.col_lib.id;%>
                                        <span><%= tax.col_lib.name%></span>
                                        <% } %>
                                    </td>
                                    <td>
                                        <% if(tax.fee_lib && tax.fee_lib.id) { %>
                                        <%  groupIndex = groupIndex + tax.fee_lib.id;%>
                                        <span><%= tax.fee_lib.name%></span>
                                        <% } %>
                                    </td>
                                    <td><a class='btn btn-link btn-sm ' style="padding: 0px" onclick='editTaxGroup(this)'>编辑</a>/<a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"taxGroup_tr")'>删除</a>
                                        <input type='hidden' name='tax_group' data-id ="<%= groupIndex%>" value="<%= JSON.stringify(tax) %>">
                                    </td>
                                </tr>
                                <% } %>
                            <% } %>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-md-12" style="padding-top:20px">
                            <legend>定额库</legend>
                            <a data-toggle="modal" data-target="#addRation" class="btn btn-link btn-sm " id="addRatioBtn" style="margin-right:5px">添加</a>
                            <table class="table engineer_table">
                                <thead>
                                <tr>
                                    <th>定额库名称</th>
                                    <th>默认</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="ration_tbody">
                                <% if (Object.keys(libData).length > 0 && libData.ration_lib.length > 0) { %>
                                <% libData.ration_lib.forEach(function (ration, index){ %>
                                <tr class='ration_tr'>
                                    <td>
                                        <span><%= ration.name%></span>
                                    </td>
                                    <td>
                                        <label class="form-check-label">
                                            <% if(ration.isDefault == true){%>
                                                <input class="form-check-input" name="ration_isDefault"  checked value="<%= ration.id %>" type="radio">
                                            <% }else{ %>
                                            <input class="form-check-input" name="ration_isDefault"  value="<%= ration.id %>" type="radio">
                                            <% } %>
                                        </label>
                                    </td>
                                    <td><a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>
                                        <input type="hidden" name="ration_lib" data-id="<%= ration.id %>" value="<%= JSON.stringify(ration) %>">
                                    </td>
                                </tr>
                                <% }) %>
                                <% } %>
                                </tbody>
                            </table>
                        </div>
                </div>
                <input type="hidden" name="glj_col" value="<%= gljCol %>" id="glj_col">
                <input type="hidden" name="isInstall" value="<%= libData.isInstall %>" id="isInstall">
                <input type="hidden" name="engineering" value="<%= libData.engineering %>" id="engineering">
                <input type="hidden" name="section" value="<%= section %>" id="section">
                <input type="hidden" name="id" value="<%= libData._id.toString()%>">
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    let billList = '<%- billList %>';
    let rationList = '<%- rationList %>';
    let gljList = '<%- gljList %>';
    let feeRateList = '<%- feeRateList %>';
    let artificialCoefficientList = '<%- artificialCoefficientList %>';
    let programList = '<%- calculationList %>';
    let billsTemplateData = '<%- billsTemplateData %>';
    let billsGuidanceList = '<%- billsGuidanceList %>';
    let gljCol = '<%- gljCol %>';
    let billTemplateList = '<%- billTemplateList %>';
    let mainTreeColList = '<%- mainTreeColList %>';
    let featureList = '<%- featureList %>';
    let progressiveList = '<%- progressiveList %>';
    let vvTaxList = '<%- vvTaxList %>';
    let colSpread = null;
    let colEditSpread = null;
</script>
<script type="text/javascript" src="/public/web/id_tree.js"></script>
<script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>
<script type="text/javascript" src="/web/users/js/compilation.js"></script>
<%include ../compilation/modal.html %>