<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../jquery-easyui-1.5.2/themes/icon.css" type="text/css">
    <style type="text/css">
        .table-overlay .layui-table-view,
        .table-overlay .layui-table-header,
        .table-overlay .layui-table-box,
        .table-overlay .layui-table-body {
            overflow: visible;
        }

        .table-overlay .layui-table-cell {
            height: auto;
            overflow: visible;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <form class="layui-form" action="" lay-filter="component-form-element">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-xs6 layui-col-sm4">
                        <label class="layui-form-label">订单费用：</label>
                        <div class="layui-input-block">
                            <input type="text" name="order_amount" lay-verify="number" autocomplete="off" value="0"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-xs6 layui-col-sm4">
                        <label class="layui-form-label">付款账户：</label>
                        <div class="layui-input-block">
                            <select id="id_order_account" name="order_account" lay-search>
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-row layui-col-space10">
                    <div class="layui-col-xs6 layui-col-sm4">
                        <label class="layui-form-label">运输费用：</label>
                        <div class="layui-input-block">
                            <input type="text" name="transport_amount" lay-verify="number" value="0"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-xs6 layui-col-sm4">
                        <label class="layui-form-label">付款账户：</label>
                        <div class="layui-input-block">
                            <select id="id_transport_account" name="transport_account" lay-search>
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-row layui-col-space10">
                    <div class="layui-col-xs6 layui-col-sm4">
                        <label class="layui-form-label">装卸费用：</label>
                        <div class="layui-input-block">
                            <input type="text" name="handing_amount" lay-verify="number" value="0" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-xs6 layui-col-sm4">
                        <label class="layui-form-label">付款账户：</label>
                        <div class="layui-input-block">
                            <select id="id_handing_account" name="handing_account" lay-search>
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                </div>

                <button class="layui-btn" id="material-pay-submit" lay-submit
                        lay-filter="component-form-element" style="display: none">确定
                </button>
            </form>
        </div>
    </div>
</div>

<script src="../../jquery-easyui-1.5.2/jquery.min.js"></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'utils',], function () {
        var $ = layui.$;
        var admin = layui.admin;
        var form = layui.form;
        var id = layui.view.getParameterByName('id');

        admin.req({
            url: '/foundation/search_options/?type=5',
            done: function (res) {
                var data = res.data;
                var order_account = $('#id_order_account');
                var transport_account = $('#id_transport_account');
                var handing_account = $('#id_handing_account');
                for (var i in data) {
                    var pid = data[i].id;
                    var value = data[i].name;
                    order_account.append("<option value='" + pid + "'>" + value + "</option>");
                    transport_account.append("<option value='" + pid + "'>" + value + "</option>");
                    handing_account.append("<option value='" + pid + "'>" + value + "</option>");
                }
                form.render();
            }
        });

        form.on('submit(component-form-element)', function (data) {
            var order_amount = parseFloat(data.field.order_amount)
            var handing_amount = parseFloat(data.field.handing_amount)
            var transport_amount = parseFloat(data.field.transport_amount)

            if (order_amount > 0 && !data.field.order_account) {
                layer.msg('请选择订单费用付款账户！', {icon: 5});
                return false;
            }

            if (handing_amount > 0 && !data.field.handing_account) {
                layer.msg('请选择装卸费用付款账户！', {icon: 5});
                return false;
            }

            if (transport_amount > 0 && !data.field.transport_account) {
                layer.msg('请选择运输费用付款账户！', {icon: 5});
                return false;
            }
            console.log(!order_amount && !handing_amount && !transport_amount)
            if(!order_amount && !handing_amount && !transport_amount){
                layer.msg('请填写费用！', {icon: 5});
                return false;
            }
            admin.req({
                url: '/purchase/purchase_order/payment/?id=' + id
                , data: data.field
                , type: 'post'
                , done: function (res) {
                    parent.layui.onSubmitChild();
                }
            });
            return false;
        });

        parent.layui.submitChild = function () {
            $("#material-pay-submit").click();
        };

    })
</script>
</body>
</html>
