<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('修改演出')"/>
</head>
<style>
    td {
        horiz-align: center;
        text-align: left;
        padding: 10px;
    }

</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-member-edit" th:object="${performanceMemberAuditDao}">
        <div class="form-group">
            <div class="col-sm-8">
                <input name="performancesId" th:field="*{performancesId}" class="form-control" type="hidden" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">演出名称：</label>
            <div class="col-sm-8">
                <input name="title" th:field="*{title}" class="form-control" type="text" required readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">该演出是否关联会员：</label>
            <div class="col-sm-8" th:if="*{isMember==1}">
                <div class="radio check-box">
                    <input type="radio" value="1" name="isMember" checked> 关联会员</label>
                </div>
                <div class="radio check-box">
                    <input type="radio" value="0" name="isMember"> 不关联会员</label>
                </div>
            </div>
            <div class="col-sm-8" th:if="*{isMember==0}">
                <div class="radio check-box">
                    <input type="radio" value="1" name="isMember"> 关联会员</label>
                </div>
                <div class="radio check-box">
                    <input type="radio" value="0" name="isMember" checked> 不关联会员</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">该演出是否会员专属：</label>
            <div class="col-sm-8" th:if="*{isExclusive==1}">
                <div class="radio check-box">
                    <input type="radio" value=1 name="isExclusive" checked> 会员专属</label>
                </div>
                <div class="radio check-box">
                    <input type="radio" value=0 name="isExclusive"> 不专属</label>
                </div>
            </div>
            <div class="col-sm-8" th:if="*{isExclusive==0}">
                <div class="radio check-box">
                    <input type="radio" value=1 name="isExclusive"> 会员专属</label>
                </div>
                <div class="radio check-box">
                    <input type="radio" value=0 name="isExclusive" checked> 不专属</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">票种列表：（限购数量0为不限购）：</label>
        </div>
        <div class="form-group">
            <table id="ticket-table" th:border="1">
                <tr>
                    <td hidden>票种id</td>
                    <td>票种名</td>
                    <td>适用时间</td>
                    <td>售票状态</td>
                    <td>开售时间</td>
                    <td>普通票价</td>
                    <td>会员优惠</td>
                    <td>限购数</td>
                    <td>提前分钟</td>
                    <td>操作</td>
                <tr/>
                <div th:each="ticket : ${performanceMemberAuditDao.ticketMemberAudit}">
                    <tr class="content-tr">
                        <td style="text-align: left" hidden>
                            <input name="ticketsId" th:value="${ticket.ticketsId}" class="form-control" type="text"
                                   readonly>
                        </td>
                        <td name="title" th:value="${ticket.title}" th:text="${ticket.title}">
                        </td>
                        <td name="useStart" th:value="${ticket.useStart}" th:text="${ticket.useStart}">
                        </td>

                        <td name="status" th:if="${ticket.status == 1}">审核中</td>
                        <td name="status" th:if="${ticket.status == 3}">审核通过</td>
                        <td name="status" th:if="${ticket.status == 4}">未通过</td>
                        <td name="status" th:if="${ticket.status == 6}">在售</td>
                        <td name="status" th:if="${ticket.status == 7}">下架</td>
                        <td name="status" th:if="${ticket.status == 8}">售罄</td>
                        <td name="status" th:if="${ticket.status == 9}">未开始</td>
                        <td name="status" th:if="${ticket.status == 10}">已结束</td>

                        <td name="timeStart" th:value="${ticket.timeStart}" th:text="${ticket.timeStart}">
                        </td>
                        <td name="price" th:value="${ticket.price}" th:text="${ticket.price}">
                        </td>
                        <td>
                            <input name="priceDiscountMember" th:value="${ticket.priceDiscountMember}"
                                   class="form-control" type="text" readonly>
                        </td>
                        <td>
                            <input name="memberLimitCount" th:value="${ticket.memberLimitCount}" class="form-control"
                                   type="text" readonly/>
                        </td>
                        <td>
                            <input name="advanceMinuteMember" th:value="${ticket.advanceMinuteMember}"
                                   class="form-control" type="text" readonly/>
                        </td>
                        <td>
                            <button type="button" class="btn btn-w-m btn-success" onclick="changeInfo(this)">
                                修改
                            </button>
                        </td>
                    </tr>
                </div>
            </table>
        </div>
<!--        <button type="button" class="btn btn-w-m btn-success">-->
<!--            审核记录-->
<!--        </button>-->
        <button type="button" class="btn btn-w-m btn-success" th:if="*{isSubmit==0}" onclick="submitHandler()">
            提交审核
        </button>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "kylin/performances";
    $("#form-performances-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        var performanceMemberAuditParam = {
            "performancesId": $("input[name^='performancesId']").val(),
            "title": $("input[name^='title']").val(),
            "isMember": parseInt($("input[name^='isMember']:checked").val()),
            "isExclusive": parseInt($("input[name^='isExclusive']:checked").val())
        }
        if ($.validate.form()) {

            var canSubmit = 1;

            $("#ticket-table").find('.content-tr').each(function (i, tr) {
                $(tr).find('td').each(function (y, td) {
                    var inputName = $(td).find("input").attr("name");
                    var inputValue = $(td).find("input").val();
                    if (inputName == "priceDiscountMember") {//过滤修改列
                        performanceMemberAuditParam["ticketMemberAudit[" + i + "].priceDiscountMember"] = parseFloat(inputValue);
                        if (parseFloat($("td[name^='price']").text()) - parseFloat(inputValue) < 0) {
                            canSubmit = 0;
                        }
                    }
                    if (inputName == "memberLimitCount") {//过滤修改列
                        performanceMemberAuditParam["ticketMemberAudit[" + i + "].memberLimitCount"] = parseInt(inputValue);
                    }
                    if (inputName == "advanceMinuteMember") {
                        performanceMemberAuditParam["ticketMemberAudit[" + i + "].advanceMinuteMember"] = parseInt(inputValue);
                    }
                    if (inputName == "ticketsId") {
                        performanceMemberAuditParam["ticketMemberAudit[" + i + "].ticketsId"] = inputValue;
                    }
                });
            });

            if (canSubmit == 1) {
                $.operate.post(prefix + "/memberInfo/submit", performanceMemberAuditParam, function (res) {
                    location.reload();
                });
            } else {
                alert("会员优惠后不能小于0")
            }
        }
    }

    function changeInfo(changeBtn) {
        var tr = $(changeBtn).parent().parent();//tr对象
        tr.find('td').each(function (i, td) {
            // if ($(td).find("input").attr("name") == "priceDiscountMember") {//过滤修改列
            //     $(td).find("input").removeAttr("readonly")
            // }
            if ($(td).find("input").attr("name") == "memberLimitCount") {//过滤修改列
                $(td).find("input").removeAttr("readonly")
            }
            if ($(td).find("input").attr("name") == "advanceMinuteMember") {//过滤修改列
                $(td).find("input").removeAttr("readonly")
            }
        });
        $(changeBtn).css("visibility", "hidden");
    }


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