<div class="panel-content">
    <div class="panel-title fluid">
        <div class="title-main">
            <h2>
                <%= libInfo.filename %>
                <a href="/lib/detail/<%= ctx.params.id %>" class="btn btn-primary btn-sm pull-right">填写项目节参数</a>
            </h2>
        </div>
    </div>
    <div class="content-wrap">
        <div class="c-header p-0 col-12">
            <ul class="nav nav-tabs">
                <li class="nav-item">
                    <a class="nav-link active" href="javascript:void(0);">全局参数</a>
                </li>
                <li class="nav-item">
                    <% if(libInfo.openitem_tab === 0) { %>
                    <a class="nav-link disabled"  data-container="body" data-toggle="popover" data-placement="right" data-content="请点击右上角「填写项目节参数」">项目节参数</a>
                    <% } else { %>
                    <a class="nav-link" href="/lib/detail/<%= ctx.params.id %>">项目节参数</a>
                    <% } %>
                </li>
            </ul>
        </div>
        <div class="c-body">
            <div class="row">
                <div class="col-5">
                    <div class="sjs-height-1">
                        <!--全局参数-->
                        <table class="table table-bordered table-sm table-hover">
                            <tr><th colspan="4" class="text-center">全局参数</th></tr>
                            <tr><th colspan="4" class="text-center"><b class="text-danger">*全局参数影响所有指标，谨慎修改</b></th></tr>
                            <tr>
                                <th>参数名称</th><th>绑定分项节点</th><th>参数数值</th>
                            </tr>
                            <% for (const p of globalParams) { %>
                            <tr code="<%= p.code %>">
                                <td><%= p.name %></td>
                                <td>
                                    <% if (p.match_type === paramConst.matchType.fixed_id) { %>
                                    <small class="text-muted">(自动绑定)</small>
                                    <% } else { %>
                                    <%- p.match_key %>
                                    <% } %>
                                </td>
                                <td><input name="param-value" class="form-control form-control-sm text-right" value="<%- p.calc_value %>" org-value="<%- p.calc_value %>"></td>
                            </tr>
                            <% } %>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        // 全局参数，修改参数数值
        $('input[name=param-value]').blur(function () {
            const self = $(this);
            if (self.val() === self.attr('org-value')) { return; }
            const data = {
                lib_id: window.location.pathname.split('/')[3],
                node_id: 0,
                code: self.parent().parent().attr('code'),
                value: self.val(),
                updateType: 'modify',
            }
            postData('/lib/updateParamValue', data, function (data) {
                self.attr('org-value', data.param.calc_value);
            }, function () {
                self.val(self.attr('org-value'));
            });
        });
    });
</script>