<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('会员设置')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<style>
    .avatar_img {
        float: left;
    }
    .text_menber {
        width: 600px;
        height: 100px !important;
    }
    .price_item .col-sm-10{
        width: 200px;
    }
    .interests_column {
        width: 100%;
        float: left;
    }
    .interests_column:after {
        clear: both;
    }
    .interests_item {
        width: 500px;
        height: 700px;
        float: left;
        margin-left: 126px !important;
    }
    .interests_item .form-control {
        margin-bottom: 10px;
    }
    .interests_item .member-coupes {
        padding: 10px 0;
        border: 1px solid #e5e6e7;
        margin-bottom: 10px;
    }
    .interests_item .go-member-item {
        display: inline-block;
        width: 80px;
        padding: 5px 0;
        text-align: center;
        background: #0d8ddb;
        color: #fff;
    }
    .interests_item .go-member-item.del_mermber {
        background: #f00;
    }
    .coupe_pop, .cover_pop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, .5);
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .pop_inner {
        width: 500px;
        height: 600px;
        padding: 10px;
        background: #fff;
    }
    .pop_inner .control-label{
        width: 100%;
    }
    .pop_inner .col-sm-10{
        width: 100%;
    }
    .pop_inner .form-group {
        float: left;
        padding-top: 20px;
    }
    .pop_inner .form-group .discount {
        padding-top: 10px;
    }
    .pop_btns {
        float: left;
        width: 100%;
        text-align: right;
    }
    .pop_btns .confirm_btn{
        display: inline-block;
        width: 80px;
        padding: 5px 0;
        text-align: center;
        background: #0d8ddb;
        color: #fff;
    }
    .member-coupes-item ul{
        padding-left: 0;
        text-align: left;
        padding: 10px;
        border: 1px solid #e5e6e7;
        margin-bottom: 10px;
    }
    .member-coupes-item ul .member-coupes-inner{
        display: flex;
        justify-content: space-between;
    }
    .member-coupes-item ul .member-coupes-inner .member-coupes-detail{
        display: flex;
        align-items: center;
    }
    .member-coupes-item ul .member-coupes-inner .member-coupes-detail span{
        padding-right: 10px;
    }
    .member-coupes-item ul .member-coupes-inner .member-coupes-bth{

    }
    .member-coupes-bth span {
        display: inline-block;
        width: 40px;
        padding: 5px 0;
        text-align: center;
        background: #0d8ddb;
        color: #fff;
    }
    .member-coupes-bth .delCoupes{
        margin-left: 5px;
        background: #f00;
    }
</style>
<body class="gray-bg" style="font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif !important;">
<section class="section-content">
    <div class="row">
        <div class="col-sm-12 about">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="nav-tabs-custom">
                        <ul class="nav nav-tabs">
                            <li class="tabs_inner active" onclick="tabChange(0)"><a href="#memberinfo" data-toggle="tab" aria-expanded="true">基础信息</a></li>
                            <li class="tabs_inner" onclick="tabChange(1)"><a href="#membership" data-toggle="tab" aria-expanded="false">会员套餐</a></li>
<!--                            <li><a href="#membercode" data-toggle="tab" aria-expanded="false">会员码</a></li>-->
                        </ul>
                        <div class="tab-content">
                            <!--基础信息-->
                            <div class="tab-pane active" id="memberinfo" th:object="${member}">
                                <form class="form-horizontal" id="form-member-edit">
                                    <!--隐藏ID-->
                                    <input name="memberId" id="id" type="hidden" th:field="*{memberId}" readonly>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">会员标题：</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="title" th:field="*{title}" placeholder="请输入标题">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">会员说明：</label>
                                        <div class="col-sm-10">
                                            <textarea class="form-control" name="subTitle" th:field="*{subTitle}" placeholder="简略描述会员功能"/>
                                            <!--                                        <input type="text" class="form-control" name="subTitle" th:field="*{subTitle}" placeholder="简略描述会员功能">-->
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">会员banner：</label>
                                        <div class="text-center">
                                            <p class="user-info-head avatar_img" onclick="icon(this, 1)">
                                                <img class="img-circle img-lg memberBanner" th:src="(${#strings.isEmpty(member.avatar)}) ? @{/img/profile.jpg} : @{${member.avatar}}" th:onerror="'this.src=\'' + @{'/img/profile.jpg'} + '\''">
                                            </p>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">会员小尾巴：</label>
                                        <div class="text-center">
                                            <p class="user-info-head avatar_img" onclick="icon(this ,2)" >
                                                <img class="img-circle img-lg memberLast" th:src="(${#strings.isEmpty(member.icon)}) ? @{/img/log.png} : @{${member.icon}}" th:onerror="'this.src=\'' + @{'/img/log.png'} + '\''">
                                            </p>
                                        </div>
                                    </div>
                                    <!--                                    <div class="form-group">-->
                                    <!--                                        <label class="col-sm-2 control-label">是否限购：</label>-->
                                    <!--                                        <div class="col-sm-10">-->
                                    <!--                                            <div class="radio-box">-->
                                    <!--                                                <input type="radio" id="radio1" th:field="*{limitation}" name="limitation" value="0">-->
                                    <!--                                                <label for="radio1">否</label>-->
                                    <!--                                            </div>-->
                                    <!--                                            <div class="radio-box">-->
                                    <!--                                                <input type="radio" id="radio2" th:field="*{limitation}" name="limitation" value="1">-->
                                    <!--                                                <label for="radio2">是</label>-->
                                    <!--                                            </div>-->
                                    <!--                                        </div>-->
                                    <!--                                    </div>-->
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">会员弹窗文案：</label>
                                        <div class="col-sm-10">
                                            <textarea class="form-control text_menber" name="interestsDetail" size="10" th:field="*{interestsDetail}"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">注意事项：</label>
                                        <div class="col-sm-10">
                                            <textarea class="form-control text_menber" name="notes" th:field="*{notes}"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">是否开售：</label>
                                        <div class="col-sm-10">
                                            <div class="radio-box">
                                                <input type="radio" id="radio1" th:checked="*{onsale==2}" name="onsale" value="2">
                                                <label for="radio1">否</label>
                                            </div>
                                            <div class="radio-box">
                                                <input type="radio" id="radio2" th:checked="*{onsale==1}" name="onsale" value="1">
                                                <label for="radio2">是</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="button" class="btn btn-sm btn-primary" onclick="submitMemberInfo()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                                            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <!--会员套餐-->
                            <div class="tab-pane" id="membership">
                                <form class="form-horizontal" id="form-membership-edit">
                                    <div class="form-group price_item">
                                        <label class="col-sm-2 control-label">会员价格：</label>
                                        <div class="col-sm-10">
                                            <label>原价(元)</label>
                                            <input type="text" class="form-control" name="price" placeholder="请输入原价" th:value="${memberPrice.price}"/>
                                        </div>
                                        <div class="col-sm-10">
                                            <label>购买价格(元)</label>
                                            <input type="text" class="form-control" name="priceFixed" placeholder="请输入购买价格" th:value="${memberPrice.priceFixed}"/>
                                        </div>
                                        <div class="col-sm-10">
                                            <label>首年优惠(元)</label>
                                            <input type="text" class="form-control" name="priceSpecial" placeholder="请输入优惠价格" th:value="${memberPrice.priceSpecial}"/>
                                        </div>
                                        <div class="col-sm-10">
                                            <label>有效时间(天)</label>
                                            <input type="text" class="form-control" name="days" placeholder="请输入有效时间" th:value="${memberPrice.days}"/>
                                        </div>
                                    </div>
                                    <div class="form-group" disabled="none">
                                        <label class="col-sm-2 control-label">双倍积分：</label>
                                        <div class="col-sm-10">
                                            <div class="radio-box">
                                                <input type="radio" id="integral1" name="integralRate" value="1" th:attr="checked=${member.integralRate == 1}"/>
                                                <label for="radio1">否</label>
                                            </div>
                                            <div class="radio-box">
                                                <input type="radio" id="integral2" name="integralRate" value="2" th:attr="checked=${member.integralRate == 2}"/>
                                                <label for="radio2">是</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="button" class="btn btn-sm btn-primary" onclick="submitMemberShip()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                                            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                                        </div>
                                    </div>
                                </form>
                                <form class="form-horizontal" id="form-membercoupe-edit">
                                    <div class="interests_column">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">权益描述：</label>
                                        </div>

                                        <div th:if="${#lists.isEmpty(memberRightsList)}">
                                            <div class="form-group interests_item">
                                                <div class="text-center">
                                                    <p class="user-info-head avatar_img vip_icon" onclick="icon(this)">
                                                        <img class="img-circle img-lg interestsIcon" id="interestsIcon"/>
                                                    </p>
                                                    <input type="text" class="form-control" id="interestsTitle" name="interestsTitle" placeholder="请输入标题"/>
                                                    <input type="text" class="form-control" id="interestsSubTitle" name="interestsSubTitle" placeholder="请输入副标题"/>
                                                    <textarea class="form-control" id="interestsDesc" name="interestsDesc" placeholder="详情内容"></textarea>
                                                    <div class="member-coupes-item">
                                                        <ul>
                                                            <div class="member-coupes-inner">
                                                                <div class="member-coupes-detail">
                                                                    <input type="hidden"/>
                                                                    <span class="member-coupes-mcouponId" hidden></span>

                                                                    <span class="member-coupes-busiType"></span>

                                                                    <span class="member-coupes-type"></span>

                                                                    <span class="member-coupes-title"></span>

                                                                    <span class="member-coupes-mark"></span>

                                                                    <span class="member-coupes-num"></span>

                                                                    <span class="member-coupes-time"></span>
                                                                </div>
                                                                <div class="member-coupes-bth">
                                                                    <!--                                                                    <span onclick="">编辑</span>-->
                                                                    <span onclick="editCoupes(this)">编辑</span>
                                                                    <span class="delCoupes" onclick="delCoupes(this)">删除</span>
                                                                </div>
                                                            </div>
                                                        </ul>
                                                    </div>
                                                    <div class="member-coupes" onclick="addCoupes(this)">+添加券<br/>*全场券不需要重复添加</div>
                                                    <div class="go-member-item" onclick="addColumn(this)">继续添加</div>
                                                    <div class="go-member-item save_mermber" onclick="saveColumn(this, 1)">保存</div>
                                                </div>
                                            </div>
                                        </div>
                                        <div th:each="mr:${memberRightsList}" class="interests_inner">
                                            <div class="form-group interests_item">
                                                <div class="text-center">
                                                    <p class="user-info-head avatar_img vip_icon" onclick="icon(this)">
                                                        <img class="img-circle img-lg interestsIcon" id="interestsIcon" th:src="${mr.cover}"/>
                                                    </p>
                                                    <input type="text" class="form-control" id="interestsTitle" name="interestsTitle" placeholder="请输入标题" th:value="${mr.title}"/>
                                                    <input type="text" class="form-control" id="interestsSubTitle" name="interestsSubTitle" placeholder="请输入副标题" th:value="${mr.subTitle}"/>
                                                    <textarea class="form-control" id="interestsDesc" name="interestsDesc" placeholder="详情内容" th:text="${mr.detail}"></textarea>
                                                    <div class="member-coupes-item">
                                                        <ul th:each="mrc:${couponMemberDtoListMap.get(mr.mrightsId)}">
                                                            <div class="member-coupes-inner">
                                                                <div class="member-coupes-detail">
                                                                    <input type="hidden" id="mrcmcouponId" th:value="${mrc.mcouponId}"/>
                                                                    <input type="hidden" id="mrccouponId" th:value="${mrc.couponId}"/>
                                                                    <input type="hidden" id="mrcbusiType" th:value="${mrc.busiType}"/>
                                                                    <input type="hidden" id="mrccouType" th:value="${mrc.couType}"/>
                                                                    <input type="hidden" id="mrctitle" th:value="${mrc.title}"/>
                                                                    <input type="hidden" id="mrceventAmt" th:value="${mrc.eventAmt}"/>
                                                                    <input type="hidden" id="mrcdays" th:value="${memberPrice.days}"/>
                                                                    <input type="hidden" id="mrvalFace" th:value="${mrc.valFace}"/>
                                                                    <input type="hidden" id="mrcoverlay" th:value="${mrc.overlay}"/>
                                                                    <input type="hidden" id="mrcvalMinus" th:value="${mrc.valMinus}"/>
                                                                    <input type="hidden" id="mrcvalOver" th:value="${mrc.valOver}"/>
                                                                    <span class="member-coupes-mcouponId" th:text="${mrc.mcouponId}" hidden></span>
                                                                    <span class="member-coupes-busiType" th:if="${mrc.busiType == 0}">全场</span>
                                                                    <span class="member-coupes-busiType" th:if="${mrc.busiType == 1}">演出</span>
                                                                    <span class="member-coupes-busiType" th:if="${mrc.busiType == 2}">商品</span>
                                                                    <span class="member-coupes-busiType" th:if="${mrc.busiType == 3}">优先购</span>

                                                                    <span class="member-coupes-type" th:if="${mrc.couType == 1}">代金券</span>
                                                                    <span class="member-coupes-type" th:if="${mrc.couType == 2}">满减券</span>
                                                                    <span class="member-coupes-type" th:if="${mrc.couType == 101}">优先券</span>

                                                                    <span class="member-coupes-title" th:text="${mrc.title}"></span>

                                                                    <span class="member-coupes-mark">通用</span>

                                                                    <span class="member-coupes-num" th:text="${mrc.eventAmt} + '张'"></span>

                                                                    <span class="member-coupes-time" th:text="${memberPrice.days} + '天'"></span>
                                                                </div>
                                                                <div class="member-coupes-bth">
                                                                    <!--                                                                    <span onclick="">编辑</span>-->
                                                                    <span th:onclick="editCoupes(this, [[${mrc}]]);">编辑</span>
                                                                    <span class="delCoupes" onclick="delCoupes(this)">删除</span>
                                                                </div>
                                                            </div>
                                                        </ul>
                                                    </div>
                                                    <div class="member-coupes" onclick="addCoupes(this)">+添加券<br/>*全场券不需要重复添加</div>
                                                    <div class="go-member-item" onclick="addColumn(this)">继续添加</div>
                                                    <div class="go-member-item save_mermber" onclick="saveColumn(this, 1)">保存</div>
                                                    <div class="go-member-item del_mermber" onclick="saveColumn(this, 2)">删除</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <!--会员码-->
<!--                            <div class="tab-pane" id="membercode">-->
<!--                                <form class="form-horizontal" id="form-user-resetPwd">-->

<!--                                </form>-->
<!--                            </div>-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="cover_pop" style="display: none">
        <div class="pop_inner">
            <input type="hidden" class="coverFunNum"/>
            <input type="hidden" class="coverIndex"/>
            <input type="hidden" class="coverCon"/>
            <input type="hidden" class="mermberCon"/>
            <input type="hidden" class="bannerCon"/>
            <div class="wrapper wrapper-content animated fadeInRight ibox-content">
                <div class="file-loading">
                    <input id="fileinput-demo-1" type="file" name="file" data-browse-on-zone-click="true"
                           data-msg-placeholder="Select {files} for upload...">
                    <input hidden id="coverImg" name="coverImg">
                </div>
            </div>
            <div class="pop_btns">
                <div class="confirm_btn" onclick="popBtn(2)">确认</div>
                <div class="confirm_btn confirm_cancel" onclick="popBtn(0)">取消</div>
            </div>
        </div>
    </div>

    <div class="coupe_pop" style="display: none">
        <div class="pop_inner">
            <input type="hidden" class="parentsIndex"/>
            <input type="hidden" class="childIndex"/>
            <div class="col-sm-10">
                <input type="text" id="coupeAdd_title" name="coupeAdd_title" placeholder="券标题"/>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">类别：</label>
                <div class="col-sm-10">
                    <div class="radio-box">
                        <label for="radio1" onclick="radioType(this)">
                            <input type="radio" id="coupeAdd1" class="coupeAddVal" name="coupeAdd_type" value="0"/> 全场
                        </label>
                    </div>
                    <div class="radio-box">
                        <label for="radio2" onclick="radioType(this)">
                            <input type="radio" id="coupeAdd2" class="coupeAddVal" name="coupeAdd_type" value="1"/>演出
                        </label>
                    </div>
                    <div class="radio-box">
                        <label for="radio2" onclick="radioType(this)">
                            <input type="radio" id="coupeAdd3" class="coupeAddVal" name="coupeAdd_type" value="2"/>商品
                        </label>
                    </div>
                    <div class="radio-box">
                        <label for="radio2" onclick="radioType(this)">
                            <input type="radio" id="coupeAdd4" class="coupeAddVal" name="coupeAdd_type" value="3"/>优先购买
                        </label>
                    </div>
                </div>
            </div>
            <div class="form-group alltrack">
                <label class="col-sm-2 control-label">类型：</label>
                <div class="col-sm-10">
                    <div class="radio-box">
                        <label for="radio1" onclick="coupetType(this)">
                            <input type="radio" id="coupetypr2" class="coupeAddVal" name="coupe_type" value="2"/>满减券
                        </label>
                    </div>
                    <div class="radio-box">
                        <label for="radio2" onclick="coupetType(this)">
                            <input type="radio" id="coupetypr1" class="coupeAddVal" name="coupe_type" value="1"/>代金券
                        </label>
                    </div>
                </div>
                <div class="col-sm-10 discount">
                    <div class="coupetypr_discount">满 ￥ <input type="text" id="valOver"/> 减 ￥ <input type="text" id="valMinus"/></div>
                    <div class="coupetypr_price" style="display: none;">金额 ￥ <input type="text" id="valFace"/></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">数量：</label>
                <div class="col-sm-10">
                    <input type="text" id="eventAmt" value="1"/> 张
                </div>
            </div>
<!--            <div class="form-group alltrack_limit">-->
<!--                <label class="col-sm-2 control-label">使用限制：</label>-->
<!--                <div class="col-sm-10">-->
<!--                    <div class="radio-box">-->
<!--                        <label for="radio1" onclick="limitType(this)">-->
<!--                            <input type="radio" id="limittypr1" name="limit_type" value="0"/> 叠加-->
<!--                        </label>-->
<!--                    </div>-->
<!--                    <div class="radio-box">-->
<!--                        <label for="radio2" onclick="limitType(this)">-->
<!--                            <input type="radio" id="limittypr2" name="limit_type" value="1"/> 限制-->
<!--                        </label>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="pop_btns">
                <div class="confirm_btn" onclick="popBtn(1)">确认</div>
                <div class="confirm_btn confirm_cancel" onclick="popBtn(0)">取消</div>
            </div>
        </div>
    </div>
</section>

<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>


<script th:inline="javascript">
    var member = [[${member}]];
    console.log(member);
    var memberRightsList = [[${memberRightsList}]];
    console.log(memberRightsList);
    var couponMemberDtoListMap = [[${couponMemberDtoListMap}]];
    console.log(couponMemberDtoListMap);
    var memberPrice = [[${memberPrice}]];
    console.log(member);

    var typeRadio = '';

    var prefix = ctx + "adam/member";
    // 弹窗
    $(function () {
        $("#fileinput-demo-1").fileinput({
            'theme': 'explorer-fas',
            // 'uploadUrl': "/kylin/banners/upload3",
            // 'uploadUrl': "http://127.0.0.1:9003" + "/platform/basicServices/alOss/upload",
            'uploadUrl': "https://devplatform.zhengzai.tv/platform/basicServices/alOss/upload",
            "uploadExtraData": {
                "pathName" : "banner",
                "buckType" : 1
            },
            // overwriteInitial: false,
            // initialPreviewAsData: true,
            autoReplace: true,
            dropZoneTitle: "请上传文件",
            maxFileCount: 1
        });
        $("#fileinput-demo-1").on("fileuploaded", function (event, data, previewId, index) {
            $('.coverCon').val('https://img.zhengzai.tv/' + data.response.data.ossPath);
        });

        var tabActive = window.localStorage.getItem('tabActive');
        if (tabActive == 1) {
            $('.tabs_inner').removeClass('active');
            $('.tab-pane').removeClass('active');
            $('.tabs_inner').eq(Number(tabActive)).addClass('active');
            $('.tab-pane').eq(Number(tabActive)).addClass('active');
        }
    });

    function tabChange (num) {
        window.localStorage.setItem('tabActive', num);
    }

    // 弹窗确认取消按钮
    function popBtn (num) {
        if (num == 0) {
            $('.cover_pop').hide();
            $('.coupe_pop').hide();
        } else if (num == 2) {
            if ($('.coverFunNum').val() == 1) {
                var bannerCon = $('.coverCon').val();
                $('.memberBanner').attr('src', bannerCon);
            } else if ($('.coverFunNum').val() == 2) {
                var mermberCon =  $('.coverCon').val();
                $('.memberLast').attr('src', mermberCon);
            } else {
                var coverIndex = $('.coverIndex').val();
                var coverCon = $('.coverCon').val();
                $('.vip_icon').find('img').eq(coverIndex).attr('src', coverCon);
            }
            $('.cover_pop').hide();
        } else {
            var coupeTitle = $('#coupeAdd_title').val();
            var busiType = this.typeRadio;
            if (this.typeRadio == 0) {
                var couponRuleList = [{
                    useScope: 100,
                    busiName: '全场'
                }]
            } else if ( this.typeRadio == 1) {
                var couponRuleList = [{
                    useScope: 90,
                    busiName: '演出'
                }]
            } else if ( this.typeRadio == 2) {
                var couponRuleList = [{
                    useScope: 80,
                    busiName: '商品'
                }]
            } else {
                var couponRuleList =  [{
                    useScope: 90,
                    busiName: '优先购'
                }]
            }


            if (this.typeRadio == 3) {
                var eventAmt = $('#eventAmt').val();
                var overlay = this.overlay;
            } else {
                var couType = this.typeCoupe;
                var valOver = $('#valOver').val();
                var valMinus = $('#valMinus').val();
                if (couType == 1) {
                    var valFace = $('#valFace').val();
                }
            }
            var itemIndex = $('.parentsIndex').val();
            var mrightsId = this.mrightsId;
            var couponId = this.couponId;

            var MembercoupenData = {
                busiType: Number(busiType),
                couType:  Number(busiType) == 3 ? 101 : Number(couType),
                couponId: couponId? couponId : '',
                couponRuleList: couponRuleList,
                eventAmt: $('#eventAmt').val(),
                label: "标注",
                memberId: member.memberId,
                mrightsId: mrightsId ? mrightsId : memberRightsList[itemIndex].mrightsId ? memberRightsList[itemIndex].mrightsId : 'string',
                // overlay: overlay ? overlay : 0,
                overlay: 1,
                title: coupeTitle,
                valFace: valFace ? valFace : 1,
                valOver: valOver ? valOver : 1,
                valMinus: valMinus ? valMinus : 1,
                state: 1
            };
            $.operate.saveModalBody(prefix + "/edit_coupon", JSON.stringify(MembercoupenData), function () {
                $('.coupe_pop').hide();
                $('.cover_pop').hide();
                window.location.reload();
            });
        }
    }

    function limitType (obj) {
        this.overlay = $(obj).find('input').val();
    }

    // 类别
    function radioType (obj) {
        console.log(obj)
        var typeRadio = $(obj).find('input').val();
        $(obj).parent().parent().find('input').removeAttr('checked');
        $(obj).find('input').attr('checked', true);

        this.typeRadio = typeRadio;
        if (typeRadio == 3) {
            $('.alltrack').hide();
            $('.alltrack_limit').show();
        } else {
            $('.alltrack').show();
            $('.alltrack_limit').hide();
        }
    }

    // 类型
    function coupetType (obj) {
        var typeCoupe = $(obj).find('input').val();
        this.typeCoupe = typeCoupe;
        if (typeCoupe == 1) {
            $('.coupetypr_price').show();
            $('.coupetypr_discount').hide();
        } else {
            $('.coupetypr_price').hide();
            $('.coupetypr_discount').show();
        }
    }

    // 权益图片上传
    function icon (obj, num) {
        $('.coverFunNum').val(num);
        var addIconIndex = $('.vip_icon').index($(obj));
        $('.coverIndex').val(addIconIndex);
        $('.cover_pop').show();
    }

    // 删除券
    function delCoupes (obj) {
        var thisVal = $(obj).parents('ul');
        var busiType = Number(thisVal.find('#mrcbusiType').val());
        var couType = Number(thisVal.find('#mrccouType').val());
        var couponId = thisVal.find('#mrccouponId').val();
        var mrightsId = thisVal.find('#mrcmcouponId').val();
        var eventAmt = thisVal.find('#mrceventAmt').val();
        var memberId = member.memberId;
        // var overlay = thisVal.find('#mrcoverlay').val();
        var titleDel = thisVal.find('#mrctitle').val();
        var valFace = thisVal.find('#mrvalFace').val();
        var valOver = thisVal.find('#mrcvalOver').val();
        var valMinus = thisVal.find('#mrcvalMinus').val();
        // var mrightsId =

        if (busiType == 0) {
            var couponRuleList = [{
                useScope: 100,
                busiName: '全场'
            }]
        } else if ( busiType == 1) {
            var couponRuleList = [{
                useScope: 90,
                busiName: '演出'
            }]
        } else if ( busiType == 3 ) {
            var couponRuleList = [{
                useScope: 80,
                busiName: '商品'
            }]
        } else {
            var couponRuleList =  [{
                useScope: 90,
                busiName: '优先购'
            }]
        }

        var MembercoupenData = {
            busiType: busiType,
            couType:  couType == 3 ? 101 : couType,
            couponId: couponId,
            couponRuleList: couponRuleList,
            eventAmt: eventAmt,
            label: "标注",
            memberId: memberId,
            mrightsId: mrightsId,
            // overlay: overlay ? overlay : 0,
            overlay: 1,
            title: titleDel,
            valFace: valFace ? valFace : 1,
            valOver: valOver ? valOver : 1,
            valMinus: valMinus ? valMinus : 1,
            state: 2
        };
        $.operate.saveModalBody(prefix + "/edit_coupon", JSON.stringify(MembercoupenData));
        thisVal.remove();
    }

    // 添加券
    function addCoupes (obj) {
        var addItemIndex = $('.member-coupes').index($(obj));
        $('.parentsIndex').val(addItemIndex);
        $('.coupe_pop').show();
    }

    // 编辑券
    function editCoupes (obj, dataObj) {
        var coupenObj = dataObj;
        this.typeRadio = coupenObj.busiType;
        this.typeCoupe = coupenObj.couType;
        $('.coupeAddVal').parent().removeClass('checked');
        $('.coupeAddVal').attr('checked', false);
        $('#coupeAdd_title').val(coupenObj.title);
        $('#coupeAdd' + (coupenObj.busiType + 1)).attr('checked', true);
        $('#coupeAdd' + (coupenObj.busiType + 1)).parent().addClass('checked');

        $('#coupetypr' + coupenObj.couType).attr('checked', true);
        $('#coupetypr' + coupenObj.couType).parent().addClass('checked');

        var parentObj = $(obj).parent().parent().parent();
        var couponId = parentObj.find('#mrccouponId').val();
        var eventAmt = parentObj.find('#mrceventAmt').val();
        var memberId = member.memberId;
        var mrightsId = parentObj.find('#mrcmcouponId').val();
        var valFace = parentObj.find('#mrvalFace').val();
        var valOver = parentObj.find('#mrcvalOver').val();
        var valMinus = parentObj.find('#mrcvalMinus').val();

        this.mrightsId = mrightsId;
        this.couponId = couponId;

        $('#eventAmt').val(eventAmt);
        $('#valOver').val(valOver);
        $('#valMinus').val(valMinus);
        $('#valFace').val(valFace);

        if (this.typeRadio == 3) {
            $('.alltrack').hide();
            $('.alltrack_limit').show();
        } else {
            $('.alltrack').show();
            $('.alltrack_limit').hide();
        }

        if (this.typeCoupe == 1) {
            $('.coupetypr_price').show();
            $('.coupetypr_discount').hide();
        } else {
            $('.coupetypr_price').hide();
            $('.coupetypr_discount').show();
        }

        if (this.typeRadio == 0) {
            var couponRuleList = [{
                useScope: 100,
                busiName: '全场'
            }]
        } else if ( this.typeRadio == 1) {
            var couponRuleList = [{
                useScope: 90,
                busiName: '演出'
            }]
        } else if ( this.typeRadio == 2) {
            var couponRuleList = [{
                useScope: 80,
                busiName: '商品'
            }]
        } else {
            var couponRuleList =  [{
                useScope: 90,
                busiName: '优先购'
            }]
        }

        $('.coupe_pop').show();
    }

    // 添加权益
    function addColumn (obj) {
        let appendDom = $(obj).parents('.interests_column:last');
        appendDom.append(appendDom.find('.interests_item').prop('outerHTML'));
        let newDom = $('.interests_item:last');
        newDom.find('.interestsIcon').attr('src', '');
        newDom.find('#interestsTitle').val('');
        newDom.find('#interestsSubTitle').val('');
        newDom.find('#interestsDesc').val('');
        newDom.find('.member-coupes-item').html('');
        // $.operate.save(prefix + "/create", data);
    }

    // 保存权益/删除权益
    function saveColumn(obj, num) {
        var objDom = $(obj).parent().parent();
        var domIndex = $('.interests_item').index(objDom);
        var postData = [];
        postData.push({
            "name": "cover",
            "value": objDom.find('#interestsIcon').attr('src')
        }, {
            "name": "detail",
            "value": objDom.find('#interestsDesc').val()
        }, {
            "name": "memberId",
            "value": member.memberId
        }, {
            "name": "seqNo",
            "value": domIndex
        }, {
            "name": "state",
            "value": num
        }, {
            "name": "subTitle",
            "value": objDom.find('#interestsSubTitle').val()
        }, {
            "name": "title",
            "value": objDom.find('#interestsTitle').val()
        });

        if (num == 2) {
            if (objDom.parent().prop("className").indexOf('interests_inner') != -1) {
                postData.push({"name": "mrightsId", "value" : memberRightsList[domIndex].mrightsId});
                objDom.remove();
                $.operate.saveModal(prefix + "/edit_rights", postData, function () {
                    window.location.reload();
                });
            } else {
                objDom.remove();
            }
        } else {
            if (memberRightsList[domIndex]) {
                postData.push({"name": "mrightsId", "value" : memberRightsList[domIndex].mrightsId});
            }
            $.operate.saveModal(prefix + "/edit_rights", postData, function () {
                window.location.reload();
            });
        }
    }

    /*基础信息-修改*/
    $("#form-member-edit").validate({
        onkeyup: false,
        rules:{
            title:{
                required:true,
            },
            subTitle:{
                required:true,
            },
            limitation:{
                required:true,
            },
            interestsDetail:{
                required:true,
            },
            notes:{
                required:true,
            },
            onsale:{
                required:true,
            },
        },
        messages: {
            "title": {
                required: "请输入标题",
            },
            "subTitle": {
                required: "请输入会员说明",
            },
            "limitation": {
                required: "请选择是否限购",
            },
            "interestsDetail": {
                required: "请选择注意事项",
            },
            "notes": {
                required: "请选择是否限购",
            },
            "onsale": {
                required: "请选择是否开售",
            },
        },
        focusCleanup: true
    });

    // 保存基础信息
    function submitMemberInfo() {
        if ($.validate.form()) {
            var formData = $('#form-member-edit').serializeArray();
            formData.push({"name": "avatar", "value": $(".memberBanner").attr('src')});
            formData.push({"name": "icon", "value": $(".memberLast").attr('src')});
            formData.push({"name": "name", "value": member.name});
            $.operate.save(prefix + "/edit_basic", formData);
        }
    }

    // 保存价格
    function submitMemberShip () {
        var MemberShipData = $('#form-membership-edit').serializeArray();
        MemberShipData.push({"name": "memberId", "value": member.memberId});
        // console.log(MemberShipData);
        $.operate.saveModal(prefix + "/edit_price", MemberShipData);
    }


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