<%@ 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" />
</head>
<body>
<div class="layui-card">
  <div class="layui-card-body">
    <div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin">
      <div id="textDiv">
        <div class="layui-form-item">
          <div class="contentBody ">
            <label class="layui-form-label"><i class="mark">*</i>购买渠道：</label>
            <div class="layui-input-inline">
              <input type="text" name="mallName" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
            <div class="f-l layui-word-aux lh-30"></div>
            <label class="layui-form-label"><i class="mark">*</i>排序：</label>
            <div class="layui-input-inline">
              <input type="text" name="sort" lay-verify="required" autocomplete="off" class="layui-input">
            </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>
        </div>
      </div>
      <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
      </div>
    </div>
  </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    var count = 1;
    layui.use(['form','jquery','layedit'], function () {
        $ = layui.$,
            form = layui.form,
            layer = layui.layer;

        form.verify({
            hour: [
                /^[1-9]\d{0,2}$/
                ,'时间只能为不超过3位的整数'
            ]
            ,price:[
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
                ,'加急费用格式不正确'
            ]
        });
    });

    function addBtn(that){
        var html = '<div class="layui-form-item">' +
            '            <div class="contentBody">' +
            '                <label class="layui-form-label"><i class="mark">*</i>购买渠道：</label>' +
            '                <div class="layui-input-inline">' +
            '                    <input type="text" name="mallName" lay-verify="required" autocomplete="off" class="layui-input">' +
            '                </div>' +
            '                <div class="f-l layui-word-aux lh-30"></div>' +
            '                <label class="layui-form-label"><i class="mark">*</i>排序：</label>' +
            '                <div class="layui-input-inline">' +
            '                    <input type="text" name="sort" lay-verify="required" autocomplete="off" class="layui-input">' +
            '                </div>' +
            '            <div class="layui-word-aux btnDiv">' +
            //   '                <button class="layui-btn layui-btn-sm" onclick="addBtn(this)"><i class="layui-icon">&#xe654;</i></button>' +
            '            </div>' +
            '            </div>' +
            '        </div>';
        $("#textDiv").append(html);
        count++;
        btnUpdate();

    };

    function delBtn(that){
        $(that).parent().parent().remove();
        count--;
        btnUpdate();
    }

    function btnUpdate(){
        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>';

        $(".contentBody").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);
            }
        })
    }

</script>
</body>
</html>