<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>私塾家</title>
    <script th:include="sys/common/metaCSS" th:remove="tag"></script>
    <script th:include="sys/common/metaJS" th:remove="tag"></script>
    <script src="sys/js/jquery.validate.min.js" th:src="@{/static/sys/js/jquery.validate.min.js}"></script>
</head>
<style>
    .tablelink {
        margin-right: 10px;
    }

    .stylecss {
        color: red;
    }

    .select_width {
        width: 70px;
    }

    .date_width {
        width: 100px;
    }
    .clearfix:after {
        visibility: hidden;
        display: block;
        font-size: 0;
        content: " ";
        clear: both;
        height: 0;
    }
    .clearfix { display: inline-table; }
    * html .clearfix { height: 1%; }
    .clearfix { display: block; }
    .fl{display:inline;float:left}
    clearfix >control-label-error{display:inline;float:left;marign-left:10px}
    label.control-label-error {
        color: Red;
    }
    .lispan {line-height: 34px;}

    .select1{
        width:100%;
        height: 32px;
        line-height: 32px;
        border-top: solid 1px #a7b5bc;
        border-left: solid 1px #a7b5bc;
        border-right: solid 1px #ced9df;
        border-bottom: solid 1px #ced9df;
        opacity:1;
        margin-bottom: 10px;
    }
</style>
<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">电商优惠码兑换</a></li>
        <li><a th:href="@{/sys/codeexchange/codeShopList.html}">兑换码列表</a></li>
    </ul>
</div>
<div class="rightinfo">
    <form id="seachform" th:action="@{/sys/codeexchange/codeShopList.html}" method="post">
        <ul class="seachform">
            <li>
                <label>兑换码：</label>
                <input name="LIKE_code" type="text" class="scinput" th:value="${search.get('LIKE_code')}"/>
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="button" class="scbtn" value="查询"/>
            </li>
            <!--<li>
                <ul class="toolbar">
                    <a th:href="@{/sys/codeexchange/codeDetail.html}"><li class="click"><span><img th:src="@{/static/sys/images/t01.png}" /></span>新增</li></a>
                </ul>
            </li>-->
        </ul>
    </form>
    <table class="tablelist">
        <thead>
        <tr>
            <th>兑换码</th>
            <th>兑换人</th>
            <th>是否有效</th>
            <th>是否被锁定</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="item:${list}">
            <td th:text="${item.code}"></td>
            <td th:text="${item.userName}"></td>
            <td th:switch="${item.isValid}">
                <span th:case="1">有效</span>
                <span th:case="0">无效</span>
            </td>
            <td th:switch="${item.isLock}">
                <span th:case="1">是</span>
                <span th:case="0">否</span>
            </td>
            <td style="width: 141px;" th:text="${#calendars.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
            <td>
                <!--<a th:href="@{/sys/codeexchange/codeDetail.html(id=${item.id})}" class="tablelink">修改</a>-->
                <a href="javascript:;" th:onclick="'edit(\''+${item.id}+'\')'" class="tablelink">修改</a>
                <!--<a href="javascript:;" th:onclick="'deleteById(\''+${item.id}+'\')'" class="tablelink">删除</a>-->
            </td>
        </tr>
        </tbody>
    </table>
    <!--分页-->
    <div class="pagin">
        <div class="message">共<i class="blue">[[${page.rowCnt}]]</i>条记录，当前显示第&nbsp;<i class="blue">[[${page.pageNo }]]&nbsp;</i>页
        </div>
        <div th:utext='${listNavigatHtml}' th:remove="tag"></div>
    </div>
</div>
<div class="formbody">
    <form id="submitFrom" method="post" class="form-horizontal form-validate">
        <ul class="forminfo">
            <li>
                <label>兑换码数量：</label>
                <input type="number" name="number" class="dfinput"/>
            </li>
            <li>
                <label>&nbsp;</label>
                <button type="submit" class="btn">新增</button>
            </li>
        </ul>
    </form>
</div>
</body>
<script type="text/javascript">
    $(function(){
        $("#submitFrom").validate({
            ignore:"",
            rules : {
                number: {
                    required : true
                }
            },
            messages: {
                number: {
                    required : "兑换码数量不能为空"
                }
            },
            errorPlacement : function(error, element) {
                error.appendTo(element.parent());
            },
            submitHandler : function(form) {
                codeGenerate();
            }
        });

    });

    function codeGenerate() {
        var params = $("#submitFrom").serialize();
        console.info(params)
        $.post('[[${sysUrl}]]/sys/codeexchange/shopcodeGenerate', params, function (data) {
            if (data != null) {
                if (data.meta.success) {
                    parent.layer.msg("优惠码操生成成功!", {icon: 1});
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                } else {
                    console.info(data)
                    parent.layer.msg(data.meta.message, {icon: 11});
                }
            }

        });
    }

    function deleteById(id) {
        parent.layer.confirm("确定删除吗？",
            {
                icon: 4, btn: ['确定', '取消']
            }, function () {
                $.ajax({
                    url: '[[${sysUrl}]]/sys/codeexchange/codeDelete',
                    type: "post",
                    data: {
                        'id': id
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.meta.success) {
                            parent.layer.msg("删除成功", {icon: 1});
                            setTimeout(function () {
                                location.reload();
                            }, 1000);
                        } else {
                            parent.layer.msg(data.meta.message, {icon: 11});
                        }
                    }
                });
            });
    }

    function edit(id){
        layer.open({
            type: 2,
            title: '编辑',
            closeBtn: 1, //不显示关闭按钮
            shift: 0.8,
            //offset: '100px',
            area: ['50%', '50%'],
            content: '[[${sysUrl}]]/sys/codeexchange/codeShopEdit.html?id='+id
        });
    }
</script>
</html>