<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('代理相关')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-damai-edit" th:object="${kylinPerformanceDamaiVo}">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">performances_id：</label>
            <div class="col-sm-8">
                <input name="performancesId" th:field="*{performancesId}" class="form-control" type="text" readonly>
            </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" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否同步：</label>
            <div class="col-sm-8" th:if="*{syncDamai==1}">
                <div class="radio check-box">
                    <input type="radio" value="1" name="performance_sync_damai" checked>同步</label>
                </div>
                <div class="radio check-box">
                    <input type="radio" value="0" name="performance_sync_damai">不同步</label>
                </div>
            </div>
            <div class="col-sm-8" th:if="*{syncDamai==0}">
                <div class="radio check-box">
                    <input type="radio" value="1" name="performance_sync_damai">同步</label>
                </div>
                <div class="radio check-box">
                    <input type="radio" value="0" name="performance_sync_damai" checked> 不同步</label>
                </div>
            </div>
        </div>
        <div th:each="tickets : ${kylinPerformanceDamaiVo.damaiTickets}">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">票种名称：</label>
                <div class="col-sm-8">
                    <input name="title" th:value="${tickets.title}" class="form-control" type="text" readonly>
                    <input name="ticketsId" th:value="${tickets.ticketsId}" 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" th:if="${tickets.syncDamai==1}">
                    <div class="radio check-box">
                        <input type="radio" value="1" th:name="'ticket_syncDamai:'+${tickets.ticketsId}"
                               checked>同步</label>
                    </div>
                    <div class="radio check-box">
                        <input type="radio" value="0" th:name="'ticket_syncDamai:'+${tickets.ticketsId}">不同步</label>
                    </div>
                </div>
                <div class="col-sm-8" th:if="${tickets.syncDamai==0}">
                    <div class="radio check-box">
                        <input type="radio" value="1" th:name="'ticket_syncDamai:'+${tickets.ticketsId}">同步</label>
                    </div>
                    <div class="radio check-box">
                        <input type="radio" value="0" th:name="'ticket_syncDamai:'+${tickets.ticketsId}" checked>
                        不同步</label>
                    </div>
                </div>
            </div>
        </div>

        <button type="button" class="btn btn-w-m btn-success" 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() {
        const paramList = [];
        var param = {
            id: '[[${kylinPerformanceDamaiVo.performancesId}]]'.replaceAll("\"", ""),
            type: "performance",
            status: parseInt($("input[name^='performance_sync_damai']:checked").val())
        }
        paramList.push(param)
        var ticketObj = JSON.parse('[[${kylinPerformanceDamaiVo.damaiTickets}]]');
        $.each(ticketObj, function (i, damaiTickets) {
            var param = {
                id:damaiTickets.ticketsId,
                type:"ticket",
                status:parseInt($("input[name^='ticket_syncDamai:"+damaiTickets.ticketsId+"']:checked").val())
            }
            paramList.push(param)
        });

        $.operate.post(prefix + "/damai/change",
            {params:JSON.stringify(paramList)},
            function (res) {
                location.reload();
            });
    }
</script>
</body>
</html>