<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!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">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css"/>
    <style>
        html {
            background-color: #fff;
        }

        .layui-col-xs4 {
            width: 28%;
        }

        .btnDiv button {
            margin-left: 10px;
        }

        #detailDiv {
            padding-bottom: 50px;
        }
    </style>
</head>
<body>
<div class="layui-form mb-0 pr-30" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin">
    <input type="hidden" name="id" value="${deliveryMethod.id}" autocomplete="off" class="layui-input">
    <div id="textDiv" class="layui-card-body over">
        <div class="layui-col-xs12 mb-10">
            <label class="layui-form-label"><i class="mark">*</i>方式名称：</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="${deliveryMethod.name}" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>
   <%-- <div class="layui-card-body over" id="detailDiv">
        <c:forEach items="${details}" var="detail">
            <div class="layui-form-item detail">
                <div class="layui-col-xs4 mb-10">
                    <label class="layui-form-label">司机：</label>
                    <div class="layui-input-block">
                        <input type="text" name="driverName" lay-verify="required" value="${detail.columns.driver_name}" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-xs4 mb-10">
                    <label class="layui-form-label">联系电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" lay-verify="required" value="${detail.columns.mobile}"  class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-col-xs4 mb-10">
                    <label class="layui-form-label">车牌号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="carNumber" lay-verify="required" value="${detail.columns.car_number}" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-word-aux btnDiv">
                    <button class="layui-btn layui-btn-sm" onclick="addBtn(this)"><i class="layui-icon">&#xe654;</i>
                    </button>
                    <button class="layui-btn delBtn layui-btn-sm layui-hide" onclick="delBtn(this)"><i
                            class="layui-icon">&#xe640;</i></button>
                </div>
            </div>
        </c:forEach>
        <c:if test="${empty details}">
            <div class="layui-form-item detail">
                <div class="layui-col-xs4 mb-10">
                    <label class="layui-form-label">司机：</label>
                    <div class="layui-input-block">
                        <input type="text" name="driverName" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-xs4 mb-10">
                    <label class="layui-form-label">联系电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" lay-verify="required" class="layui-input"
                               lay-verify="required">
                    </div>
                </div>
                <div class="layui-col-xs4 mb-10">
                    <label class="layui-form-label">车牌号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="carNumber" lay-verify="required" class="layui-input"
                               lay-verify="required">
                    </div>
                </div>
                <div class="layui-word-aux btnDiv">
                    <button class="layui-btn layui-btn-sm" onclick="addBtn(this)"><i class="layui-icon">&#xe654;</i></button>
                    <button class="layui-btn delBtn layui-btn-sm layui-hide" onclick="delBtn(this)"><i class="layui-icon">&#xe640;</i></button>
                </div>
            </div>
        </c:if>
    </div>--%>
    <div class="layui-form-item text-c operate-footer">
        <button class="layui-btn " lay-submit lay-filter="component-form-element" <%--onclick="addRole()"--%>>保存
        </button>
        <button class="layui-btn layui-btn-primary" onclick="cancel()">取消</button>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/font/iconfont.js"></script>
<script>

    layui.use(['form', 'jquery', 'layedit'], function () {
        $ = layui.$,
            form = layui.form,
            layer = layui.layer;

        form.on('submit(component-form-element)', function (data) {
            var field = data.field; //获取提交的字段
           /* var jsonArry = [];
            $("#detailDiv").find(".detail").each(function (index) {
                var driverName = $(this).find("input[name='driverName']").val();
                var mobile = $(this).find("input[name='mobile']").val();
                var carNumber = $(this).find("input[name='carNumber']").val();
                var obj = {
                    driverName: driverName,
                    mobile: mobile,
                    carNumber: carNumber
                };
                jsonArry.push(obj);
            })*/
            $.ajax({
                url: '${ctx}/deliveryMethodSetting/saveDeliveryMethod',
                type: 'post',
                data: {
                    id: field.id,
                    name: field.name,
                  /*  jsonData: JSON.stringify(jsonArry)*/
                },
                success: function (data) {
                    if (data.code === "200") {
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg('操作成功！', {icon: 1, time: 1000}, function () {
                            parent.layer.close(index);
                            parent.window.reload(); //刷新父页面
                        })
                    } else if (data.code === "501") {
                        layer.msg(data.errMsg, {icon: 5, anim: 6});
                    } else {
                        layer.msg("添加失败！", {icon: 5, anim: 6});
                    }
                },
                complete: function () {

                }
            });

        })

    });

   /* function addBtn(that) {
        var html = '<div class="layui-form-item detail">' +
            '<div class="layui-col-xs4 mb-10">' +
            '<label class="layui-form-label">司机：</label>' +
            '<div class="layui-input-block">' +
            '<input type="text" name="driverName" lay-verify="required" class="layui-input">' +
            '</div>' +
            '</div>' +
            '<div class="layui-col-xs4 mb-10">' +
            '<label class="layui-form-label">联系电话：</label>' +
            '<div class="layui-input-block">' +
            '<input type="text" name="mobile" lay-verify="required" class="layui-input" lay-verify="required">' +
            '</div>' +
            '</div>' +
            '<div class="layui-col-xs4 mb-10">' +
            '<label class="layui-form-label">车牌号：</label>' +
            '<div class="layui-input-block">' +
            '<input type="text" name="carNumber" lay-verify="required" class="layui-input" lay-verify="required">' +
            '</div>' +
            '</div>' +
            ' <div class="layui-word-aux btnDiv">' +
            '<button class="layui-btn layui-btn-sm" onclick="addBtn(this)"><i class="layui-icon">&#xe654;</i></button>' +
            '<button class="layui-btn delBtn layui-btn-sm" onclick="delBtn(this)"><i class="layui-icon">&#xe640;</i></button>' +
            '</div>' +
            '</div>';
        $("#detailDiv").append(html);

        btnUpdate();

    };

    function delBtn(that) {

        $(that).parent().parent().remove();

        btnUpdate();
    }

    function btnUpdate() {
        var count = $("#detailDiv").find(".btnDiv").length;
        console.log(count);
        var addBtn = '<button class="layui-btn layui-btn-sm" onclick="addBtn(this)"><i class="layui-icon">&#xe654;</i>';
        var delBtn = '<button class="layui-btn delBtn layui-btn-sm" onclick="delBtn(this)"><i class="layui-icon">&#xe640;</i></button>';

        $("#detailDiv").find(".btnDiv").each(function (index) {
            if (count == 1) {
                $(this).empty().append(addBtn);
            } else if (count != (index + 1)) {
                $(this).empty().append(delBtn);
            } else {
                $(this).empty().append(addBtn + delBtn);
            }
        })
    }*/

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function cancel() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
</body>
</html>

