<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>编辑</title>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="formDemo">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 10%">序号</label>
            <div class="layui-input-inline" style="width: 70%">
                <input type="number" id="xh" name="xh" min = "0" autocomplete="off" lay-verify="required" lay-reqtext="序号不能为空" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 10%">材料名称</label>
            <div class="layui-input-inline" style="width: 70%">
                <input type="text" id="clmc" name="clmc" lay-verify="required" lay-reqtext="材料名称不能为空"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 10%">物料编码</label>
            <div class="layui-input-inline" style="width: 70%">
                <input type="text" id="wlbm" name="wlbm" lay-verify="required" lay-reqtext="物料编码不能为空"
                       class="layui-input">
            </div>
        </div>
<!--        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 10%">税率</label>
            <div class="layui-input-inline" style="width: 70%px">
                <input type="text" id="sl" name="sl" class="layui-input" min="0" lay-verify="requird" lay-reqtext="税率不能为空" autocomplete="off">
            </div>
        </div>-->

           <!-- <label class="layui-form-label required" style="width: 10%">申请金额</label>
            <div class="layui-input-inline" style="width: 265px">
                <input type="text" id="sqje" name="sqje" lay-verify="required" lay-reqtext="申请金额不能为空" autocomplete="off" class="layui-input">
            </div>-->

        <!--<div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 10%">含税金额</label>
            <div class="layui-input-inline" style="width: 265px">
                <input type="number" id="hsje" name="hsje" min="0" lay-verify="required" lay-reqtext="含税金额不能为空"
                       autocomplete="off" class="layui-input" oninput="calculateBhsje()">
            </div>
            <label class="layui-form-label required" style="width: 10%">不含税金额</label>
            <div class="layui-input-inline" style="width: 265px">
                <input type="number" id="bhsje" name="bhsje" class="layui-input" min = "0"
                       lay-verify="required" lay-reqtext="不含税金额不能为空" autocomplete="off" oninput="calculateHsje()">
            </div>
        </div>-->
        <div class="layui-form-item layui-inline" style="width: 100%">

            <label class="layui-form-label required" style="width: 10%">单价(元)</label>
            <div class="layui-input-inline" style="width: 70%">
                <input type="number" id="cgdj" name="cgdj" min="0" lay-verify="required" lay-reqtext="单价不能为空"
                       autocomplete="off" class="layui-input">
            </div>
           <!-- <label class="layui-form-label required" style="width: 10%">数量</label>
            <div class="layui-input-inline" style="width: 265px">
                <input type="number" id="sll" name="sll" class="layui-input" min = "0" lay-verify="required" lay-reqtext="数量不能为空" autocomplete="off">
            </div>-->
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label" style="width: 10%">备注</label>
            <div class="layui-input-inline" style="width: 70%">
                <textarea id="bz" name="bz" class="layui-textarea" style="width: 100%;height: 200px"></textarea>
            </div>
        </div>
        <!-- 右侧悬浮按钮 -->
        <div class="right-bottom-btn">
            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn">
                <i class="layui-icon layui-icon-ok"></i>确定
            </button>
            <button class="layui-btn" lay-filter="cancleBtn">
                <i class="layui-icon layui-icon-close"></i>取消
            </button>
        </div>
    </div>
</form>
<script>
    function calculateBhsje() {
        var hsje = parseFloat(document.getElementById('hsje').value);
        var sl = parseFloat(document.getElementById('sl').value);

        if (isNaN(hsje) || isNaN(sl) || sl < 0) {
            document.getElementById('bhsje').value = '';
        } else {
            var bhsje = hsje / (1 + sl / 100); // 如果需要，将税率转换为小数形式
            document.getElementById('bhsje').value = bhsje.toFixed(2); // 根据需要调整小数位数
        }
    }

    function calculateHsje() {
        var bhsje = parseFloat(document.getElementById('bhsje').value);
        var sl = parseFloat(document.getElementById('sl').value);

        if (isNaN(bhsje) || isNaN(sl) || sl < 0) {
            document.getElementById('hsje').value = '';
        } else {
            var hsje = bhsje * (1 + sl / 100); // 如果需要，将税率转换为小数形式
            document.getElementById('hsje').value = hsje.toFixed(2); // 根据需要调整小数位数
        }
    }
</script>


<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/lib/xm-select-v1.2.2/xm-select.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>

<script type="text/javascript" th:inline="javascript">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
    layui.use(['form', 'tableSelect', 'laydate'], function () {
        var form = layui.form;
        var materialCost = parent.getMatCost();
        console.log(materialCost);

        $("#clmc").val(materialCost.clmc);
        $("#wlbm").val(materialCost.wlbm);
        $("#sqje").val(materialCost.sqje);
        $("#cgdj").val(materialCost.cgdj);
        $("#bhsje").val(materialCost.bhsje);
        $("#hsje").val(materialCost.hsje);
        $("#bz").val(materialCost.bz);
        $("#xh").val(materialCost.xh);
        $("#sl").val(materialCost.sl);
        $("#sll").val(materialCost.sll);


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            parent.setMatCost(data.field)
            parent.setUpdateFlag();
            parent.layer.close(parent.layer.getFrameIndex(window.name));// 关闭子窗口
        });

        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function () {
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });
    });
</script>
</body>
</html>