<link rel="stylesheet" href="/plugins/addons/group_buy/template/js/layui/css/layui.css" media="all">
<style>
    .layui-form-item{
        display: flex;
        align-items: stretch;
    }
    .layui-form-label{
        flex: 0 0 auto;
    }
    .layui-input-block{
        flex: 1 1 auto;
        margin-left: 0!important;
    }
</style>
<section class="admin-main">
    <div class="container-fluid">
        <div class="page-container">
            <div class="card">
                <div class="card-body">
                    <!-- class="col-lg-1 col-md-12 col-sm-12" -->
                    <div class="card-title row">
                        <div class="pl-4 pr-4">{$Title}</div>
                        <div class="col-lg-8 col-md-12 col-sm-12">
                            {foreach $PluginsAdminMenu as $v}
                                {if $v['custom']}
                                    <span  class="ml-2"><a  class="h5" href="{$v.url}" target="_blank">{$v.name}</a></span>
                                {else/}
                                    <span  class="ml-2"> <a  class="h5" href="{$v.url}">{$v.name}</a></span>
                                {/if}
                            {/foreach}
                        </div>
                    </div>

                    <div class="tab-content mt-4">

                        <div class="table-body auto-login-content" style="margin-top: 10px;">

                            <form class="layui-form layui-form-pane" action="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">商品分组</label>
                                    <div class="layui-input-block" id="list1">
                                   </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">商品</label>
                                    <div class="layui-input-block" id="productList">
                                   </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">显示名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="product_name"  placeholder="留空默认显示商品名称" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">付款方式</label>
                                    <div class="layui-input-block" id="payType"></div>
                                </div>
                                <div id="set_config"></div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">续费价格</label>
                                    <div class="layui-input-block">
                                        <select name="renew" lay-verify="required">
                                            <option value="1">商品原价续费</option>
                                            <option value="2">拼团价续费</option>

                                        </select>
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">元</div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">2人团价格</label>
                                    <div class="layui-input-block">
                                        <input type="number" name="two"  placeholder="留空不支持此模式" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">元</div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">3人团价格</label>
                                    <div class="layui-input-block">
                                        <input type="number" name="three"  placeholder="留空不支持此模式" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">元</div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">5人团价格</label>
                                    <div class="layui-input-block">
                                        <input type="number" name="five"  placeholder="留空不支持此模式" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">元</div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">超时天数</label>
                                    <div class="layui-input-block">
                                        <input type="number" name="days" placeholder="请输入超时天数" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">天</div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">活动到期时间</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="end_time" id="end_time" placeholder="请输入活动到期时间" autocomplete="off" class="layui-input">
                                    </div>

                                </div>
                                <div class="layui-form-item layui-form-text" style="flex-direction: column;">
                                    <label class="layui-form-label">宣传语(网址请用【网址】代替，价格用【价格】代替)，如低至【价格】，拼团网址：【网址】</label>
                                    <div class="layui-input-block">
                                        <textarea  name="content" id="content" placeholder="请输入宣传语" autocomplete="off" class="layui-textarea"></textarea>
                                    </div>

                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                        <a href="javascript:;" class="layui-btn layui-btn-primary lay-btn-reset">重置</a>
                                        <a href="/plugins/addons/group_buy/" target="_blank">查看拼团专页</a>
                                    </div>
                                </div>
                            </form>
                            <table id="productTable" lay-filter="productTable"></table>
                            <div id="page-id"></div>
                        </div>
                        <div class="table-body">文档说明：<a href="https://html5code.org/type/zjmf.html" target="_blank">https://html5code.org/type/zjmf.html</a> </div>
                        <div class="table-body" id="renewMsg" style="color: #ff0000;"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script src="/plugins/addons/group_buy/template/js/layui/layui.js"></script>
<script src="/plugins/addons/group_buy/template/js/xm-select/dist/xm-select.js"></script>
<script>
    let DemoClient="{$DemoClient}";
    let queryToJson=function (hash){
        let str=hash?window.location.hash:window.location.search
        if( !str ) return { };
        if(str) str=str.substr(1);
        if( !str ) return { };
        let arr = str.split('&');
        let data={ };
        $.each( arr, function (k,v) {

            if(v.indexOf("=")>-1){
                let d=v.indexOf("=");
                data[ decodeURIComponent(v.substr(0,d)) ]=decodeURIComponent(v.substr(d+1));

            }

        } );
        return data;
    }
    let jsonToQuery=function (json){
        return  Object.keys(json).map(function (key) {
            return json[key]? (key + "=" + encodeURIComponent(json[key])):"";
        }).join("&");
    }
    let GzhxLoading=function(str){



        return layer.msg(str, {
            time: 0,
            icon:16

            ,shade: 0.3,zIndex: layer.zIndex

            ,success:function (layero) {

                layer.setTop(layero);

            }

        });

    }
    let ajax=function (option){
        let index=GzhxLoading(option.load||"加载中……")
        $.ajax({
                dataType: "json",
                type: option.type||"post",

                headers: {
                    "X-Requested-With": "XMLHttpRequest",

                },
                url: option.url||"",
                data:option.data,
                async:true,
                success: function (t) {

                    layer.close(index);

                    if( t.status==1 ){
                        if(option.success)  option.success(t.info);
                    }else{
                        if(option.error){
                            option.error(t.info);
                        }else{
                            layer.msg(t.info);
                        }
                    }
                },

                error: function (request, status, errorThrown) {
                    layer.close(index);
                    if(option.error){
                        option.error("网络错误，请重试");
                    }else{
                        layer.msg("网络错误，请重试");
                    }
                }
            }
        );
    }
    let getProductAjax=function (option) {
        let AdminApplication="{$AdminApplication}";
        let index=GzhxLoading(option.load||"加载中……")
        $.ajax({
                dataType: "json",
                type: "get",

                headers: {
                    "X-Requested-With": "XMLHttpRequest",

                },
                url: "/"+AdminApplication+"/orders/set_config?pid="+option.id+"&request_time=1644996090764&languagesys=CN",

                async:true,
                success: function (t) {

                    layer.close(index);

                    if( t.status==200 ){
                        if(option.success)  option.success(t);
                    }else{
                        if(option.error){
                            option.error(t.msg);
                        }else{
                            layer.msg(t.msg);
                        }
                    }
                },

                error: function (request, status, errorThrown) {
                    layer.close(index);
                    if(option.error){
                        option.error("网络错误，请重试");
                    }else{
                        layer.msg("网络错误，请重试");
                    }
                }
            }
        );
    }
    layui.use(['layer','form','table','laydate'],function(){
        let productList=[];
        let productSelect=xmSelect.render({
            el: '#productList',
            radio: true,
            filterable: true,
            clickClose:true,
            name:"pid",
            empty:'请先选择商品分组',
            data: [],

            tips:'请选择商品',
            prop:{
                name:"name",
                value:"id"
            },
            on:function (data){
                if(data.arr.length>0){
                    getProductAjax({
                        id:data.arr[0].id,
                        success:function (config) {
                            console.log(config);
                            let html='';
                            let _call={  },_xm={  };
                            if(config.option) {
                                $.each(config.option,function (k,v){
                                    let data='',xmList=[],xmConfig=null;
                                    if(v.option_type==12) {
                                        data +='<select name="option_'+v.id+'" data-intype="select">';
                                        $.each(v.child,function (kk,vv){
                                            data +='<option value="'+vv.area[0].id+'">'+kk+'</option>';
                                        })

                                        data +='</select>';
                                    }
                                   else if(v.option_type==6||v.option_type==8||v.option_type==10||v.option_type==2||v.option_type==13) {
                                        data +='<select name="option_'+v.id+'" data-intype="select">';
                                        $.each(v.child,function (kk,vv){
                                            data +='<option value="'+vv.id+'">'+vv.option_name+'</option>';
                                        })

                                        data +='</select>';
                                    }

                                   else if(v.option_type==5){

                                        $.each(v.child,function (kk,vv){
                                            let children=[];
                                            $.each(vv.child,function (kkk,vvv){
                                                children.push({
                                                    name:vvv.version,
                                                    value:vvv.id
                                                })
                                            })
                                            xmList.push({
                                                name:kk,
                                                value:vv.system,
                                                item:children
                                            })
                                        })
                                            xmConfig={
                                                radio: true,
                                                clickClose: true,
                                                name:"option_"+v.id,
                                                el: '#option_'+v.id,
                                                data:xmList
                                        }
                                        let xmConfigChildren={
                                            radio: true,
                                            clickClose: true,
                                            name:"option_"+v.id+"_children",
                                            el: '#option_'+v.id+"_children",
                                            data:[]
                                        };
                                        _call[ "option_"+v.id ]=function (rdata){
                                            console.log(rdata);
                                            if(rdata.arr.length>0){
                                                //option_'+v.id+'_children
                                                _xm[ 'option_'+v.id+'_children' ].update({
                                                    data:rdata.arr[0].item
                                                })
                                            }else{
                                                _xm[ 'option_'+v.id+'_children' ].update({
                                                    data:[]
                                                })
                                            }
                                        }
                                        data +='<div class="xm-select" id="option_'+v.id+'" data-intype="xm" data-xm=\''+JSON.stringify(xmConfig)+'\' style="width:150px;"></div>' +
                                            '<div class="xm-select" id="option_'+v.id+'_children" data-intype="xm" data-xm=\''+JSON.stringify(xmConfigChildren)+'\' style="flex:1 1 auto;"></div>'
                                    }else{
                                        data +='<input type="text" name="option_'+v.id+'" data-intype="text" autocomplete="off" class="layui-input">';
                                    }

                                    html +=' <div class="layui-form-item">'+
                                        '<label class="layui-form-label">'+v.option_name+'</label>'+
                                        ' <div class="layui-input-block" style="display: flex;justify-content: flex-start;align-items: center;">'+data+'</div>'+
                                        '</div>';
                                })
                            }
                            html +='<div class="layui-form-item">'+
                            ' <label class="layui-form-label">配置价格</label>'+
                            '<div class="layui-input-block" style="width: 100px;flex: 0 0 auto;">'+
                            '    <input type="text" name="original_price"  placeholder="" autocomplete="off" class="layui-input" readonly>'+
                            ' </div>'+
                            '<div class="layui-word-aux"><button class="layui-btn layui-btn-normal" lay-submit lay-filter="formSetMoney">获取</button></div>'+
                            '</div>' +
                                '<div class="layui-form-item layui-form-text" style="flex-direction: column;display: none;">' +
                            '<label class="layui-form-label">配置详情</label>' +
                            '<div class="layui-input-block">' +
                            '    <textarea  name="config_cn" id="config_cn" placeholder="" autocomplete="off" class="layui-textarea" readonly></textarea>' +
                            ' </div>' +
                            '</div>';

                            $("#set_config").html(html);
                            _setMoney();
                            $('#set_config .xm-select').each(function(){
                                let config=$(this).data("xm"),id=$(this).attr("id");
                                console.log(id);
                                if( _call.hasOwnProperty(id) ) {
                                    config.on=function (rdata){
                                        _call[id](rdata);
                                    }
                                }
                               _xm[id]=xmSelect.render(config)
                            })
                            layui.form.render();
                        }
                    })
                }
            }
        });

        let payType = xmSelect.render({
            el: '#payType',
            radio: true,
            clickClose:true,
            name:"pay_type",
            data: [
                {
                    name:"月付",
                    value:"monthly"
                },
                {
                    name:"年付",
                    value:"annually"
                }
            ],
            tips:'请选择付款方式',

            on:function (data){
                if(data.arr.length>0){
                    let Arr=[];
                    let productSelectId=productSelect.getValue("value");
                    $.each(productList,function (k,v){
                        Arr.push({
                            name:v.name+"("+(data.arr[0].value=="monthly"?"月付":"年付")+v[ data.arr[0].value ]+"元)",
                            id:v.id,
                            selected:productSelectId&&productSelectId.length>0&&productSelectId[0]==v.id
                        })
                    })

                    productSelect.update({
                        data:Arr
                    })
                }
            }
        })
        let demo1 = xmSelect.render({
            el: '#list1',
            radio: true,
            filterable: true,
            clickClose:true,
            name:"gid",
            data: [],
            tips:'请选择分组',
            prop:{
                name:"name",
                value:"id"
            },
            on:function (data){
                if(data.arr.length>0){
                    productList=data.arr[0].products;

                    let payTypeId=payType.getValue("value");
                    if(payTypeId&&payTypeId.length>0){
                        let Arr=[];

                        $.each(productList,function (k,v){
                            Arr.push({
                                name:v.name+"("+(payTypeId[0]=="monthly"?"月付":"年付")+v[ payTypeId[0] ]+"元)",
                                id:v.id
                            })
                        })
                        productSelect.update({
                            data:Arr
                        })
                    }else{
                        productSelect.update({
                            data:data.arr[0].products
                        })
                    }

                }else{
                    productSelect.update({
                        data:[]
                    })
                }
            }
        })
        layui.laydate.render({
            elem: '#end_time',

        });

        let productTable= layui.table.render({
            elem: '#productTable'
            ,id:"productTable"
            ,cols: [[
                {field: 'id', title: 'ID', width:80}
                ,{field: 'group_name', title: '分组'}
                ,{field: 'name', title: '产品',templet: function(d){
                    return d.product_name?(d.product_name+"("+d.name+")"):d.name;
                    },minWidth:200}
                ,{field: 'two', title: '2人团价格'}
                ,{field: 'three', title: '3人团价格'}
                ,{field: 'five', title: '5人团价格'}
                ,{field: 'pay_type', title: '支付方式',templet: function(d){
                    return d.pay_type=="monthly"?"月付":"年付";
                    }}
            ,{field: 'renew', title: '续费方式',templet: function(d){
                return d.renew=="1"?"原价续费":"拼团价续费";
                }}
                ,{field: 'days', title: '拼团超时天数'}
                ,{field: 'end_time', title: '活动到期时间'}

                ,{field: 'op', title: '编辑',templet: function(d){
                return '<a href="javascript:;" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
            }

            }
            ]]
            ,data:[]
        });

        let _get=function (callback){
            ajax({
                data:{
                    action:'get',
                    p:''
                },
                success:function (res){
                    demo1.update({
                        data:res
                    });
                    if(callback){
                        callback(res);

                    }
                }
            })
        }
        _get();
        let _setMoney=function (){
            layui.form.on('submit(formSetMoney)', function(data){

                let info=[
                    {
                        name:'pid[0]',
                        value:data.field.pid
                    },
                    {
                        name:'billingcycle[0]',
                        value:data.field.pay_type
                    },
                    {
                        name:'qty[0]',
                        value:1
                    },
                    {
                        name:'uid',
                        value:DemoClient
                    }

                ];
                let option_cn=[ ];
                $.each( data.field,function (k,v){
                    if(k.substr(0,7)=="option_"&&k.indexOf("_children")==-1){
                        let id=k.substr(7);
                        let title=$('[name="option_'+id+'"]').closest('div.layui-form-item').children("label").text();
                        let intype=$('[name="option_'+id+'"]').data("intype");
                        let val="";
                        if(!intype) {
                            intype=$('[name="option_'+id+'"]').closest('[data-intype]').data("intype");
                        }
                        if(intype=="text") {
                            val=$('[name="option_'+id+'"]').val();
                        }else if(intype=="select") {
                            val=$('[name="option_'+id+'"]>option:selected').text();
                        }else if(intype=="xm"){
                            val=$('#option_'+id+' .xm-label>.scroll>.label-content').attr("title");
                        }
                        option_cn.push('<li><strong>'+title+'：</strong>'+val+'</li>');
                        if(!data.field.hasOwnProperty(k+"_children")){
                            info.push({
                                name:'configoption[0]['+id+']',
                                value:v
                            })

                        }else{
                            info.push({
                                name:'configoption[0]['+id+']',
                                value:data.field[ k+"_children" ]
                            })
                        }
                    }
                } )
                console.log(option_cn);
                $('textarea[name="config_cn"]').val('<h5>'+option_cn.join("\n")+'</h5>').closest('.layui-form-text').show();
                let AdminApplication="{$AdminApplication}";
                let index="处理中……"
                $.ajax({
                        dataType: "json",
                        type: "post",
                        data:info,
                        headers: {
                            "X-Requested-With": "XMLHttpRequest",
                            "Content-Type": " application/x-www-form-urlencoded"
                        },
                        url: "/"+AdminApplication+"/get_total?request_time=1645429424348&languagesys=CN",

                        async:true,
                        success: function (t) {
                            console.log(t);
                            layer.close(index);

                            if( t.status==200 ){
                                $('input[name="original_price"]').val(t.subtotal);
                            }else{
                                layer.msg(t.msg);
                            }
                        },

                        error: function (request, status, errorThrown) {
                            layer.close(index);
                            layer.msg("网络错误，请重试");
                        }
                    }
                );






                return false;
            });
        }
    layui.table.on('tool(productTable)', function(obj){

        switch (obj.event) {
            case 'edit':{
                _get(function (groups){
                    demo1.setValue([ obj.data.gid ]);
                    payType.setValue([ obj.data.pay_type ]);
                    console.log(demo1.getValue());
                    let productList=[];
                    $.each(groups,function(k,v){
                        if (v.id==obj.data.gid){
                            productList=v.products;
                            return false;
                        }
                    })


                    let Arr=[];
                    let productSelectId=[obj.data.pid];
                    $.each(productList,function (k,v){
                        Arr.push({
                            name:v.name+"("+(obj.data.pay_type=="monthly"?"月付":"年付")+v[ obj.data.pay_type ]+"元)",
                            id:v.id,
                            selected:productSelectId&&productSelectId.length>0&&productSelectId[0]==v.id
                        })
                    })

                    productSelect.update({
                        data:Arr
                    })
                    $('input[name="two"]').val(obj.data.two);
                    $('input[name="three"]').val(obj.data.three);
                    $('input[name="five"]').val(obj.data.five);
                    $('input[name="end_time"]').val(obj.data.end_time);
                    $('textarea[name="content"]').val(obj.data.content);
                    $('input[name="days"]').val(obj.data.days);
                    $('select[name="renew"]').val(obj.data.renew);
                    $('input[name="product_name"]').val(obj.data.product_name);
                        let optionData=obj.data.option?JSON.parse(obj.data.option):null;
                        /**刷新产品**/
                        getProductAjax({
                            id:obj.data.pid,
                            success:function (config) {

                                let html='';
                                let _call={  },_xm={  },_callDefault=[ ];
                                if(config.option) {
                                    $.each(config.option,function (k,v){
                                        let data='',xmList=[],xmConfig=null;
                                        if(v.option_type==12) {
                                            data +='<select name="option_'+v.id+'" data-intype="select">';
                                            $.each(v.child,function (kk,vv){
                                                data +='<option value="'+vv.area[0].id+'" '+(optionData&&optionData.hasOwnProperty('option_'+v.id)&&optionData[ 'option_'+v.id ]==vv.area[0].id?"selected":"")+'>'+kk+'</option>';
                                            })

                                            data +='</select>';
                                        }
                                        else if(v.option_type==6||v.option_type==8||v.option_type==10||v.option_type==2||v.option_type==13) {
                                            data +='<select name="option_'+v.id+'" data-intype="select">';
                                            $.each(v.child,function (kk,vv){
                                                data +='<option value="'+vv.id+'" '+(optionData&&optionData.hasOwnProperty('option_'+v.id)&&optionData[ 'option_'+v.id ]==vv.id?"selected":"")+'>'+vv.option_name+'</option>';
                                            })

                                            data +='</select>';
                                        }

                                        else if(v.option_type==5){

                                            $.each(v.child,function (kk,vv){
                                                let children=[],_callDefaultItem=null;
                                                $.each(vv.child,function (kkk,vvv){
                                                    children.push({
                                                        name:vvv.version,
                                                        value:vvv.id,
                                                        selected:optionData&&optionData.hasOwnProperty('option_'+v.id+'_children')&&optionData[ 'option_'+v.id+'_children' ]==vvv.id
                                                    })
                                                    /*_callDefaultItem=function (){
                                                        _xm[ 'option_'+v.id+'_children' ].setValue([ optionData&&optionData.hasOwnProperty('option_'+v.id+'_children')&&optionData[ 'option_'+v.id+'_children' ]==vvv.id?vvv.id:"" ])
                                                    };*/

                                                })
                                                xmList.push({
                                                    name:kk,
                                                    value:vv.system,
                                                    item:children,
                                                    selected:optionData&&optionData.hasOwnProperty('option_'+v.id)&&optionData[ 'option_'+v.id ]==vv.system
                                                })
                                                if(optionData&&optionData.hasOwnProperty('option_'+v.id)&&optionData[ 'option_'+v.id ]==vv.system) {
                                                    _callDefault.push( function (){
                                                        _xm[ 'option_'+v.id+'_children' ].update({
                                                            data:children
                                                        })
                                                    } )

                                                }
                                            })


                                            xmConfig={
                                                radio: true,
                                                clickClose: true,
                                                name:"option_"+v.id,
                                                el: '#option_'+v.id,
                                                data:xmList
                                            }
                                            let xmConfigChildren={
                                                radio: true,
                                                clickClose: true,
                                                name:"option_"+v.id+"_children",
                                                el: '#option_'+v.id+"_children",
                                                data:[]
                                            };
                                            _call[ "option_"+v.id ]=function (rdata){
                                                console.log(rdata);
                                                if(rdata.arr.length>0){
                                                    //option_'+v.id+'_children
                                                    _xm[ 'option_'+v.id+'_children' ].update({
                                                        data:rdata.arr[0].item
                                                    })
                                                }else{
                                                    _xm[ 'option_'+v.id+'_children' ].update({
                                                        data:[]
                                                    })
                                                }
                                            }
                                            data +='<div class="xm-select" id="option_'+v.id+'" data-intype="xm" data-xm=\''+JSON.stringify(xmConfig)+'\' style="width:150px;"></div>' +
                                                '<div class="xm-select" id="option_'+v.id+'_children" data-intype="xm" data-xm=\''+JSON.stringify(xmConfigChildren)+'\' style="flex:1 1 auto;"></div>'
                                        }else{
                                            data +='<input type="text" name="option_'+v.id+'" data-intype="text" autocomplete="off" class="layui-input" value="'+(optionData&&optionData.hasOwnProperty('option_'+v.id)?optionData[ 'option_'+v.id ]:"")+'">';
                                        }
                                        html +=' <div class="layui-form-item">'+
                                            '<label class="layui-form-label">'+v.option_name+'</label>'+
                                            ' <div class="layui-input-block" style="display: flex;justify-content: flex-start;align-items: center;">'+data+'</div>'+
                                            '</div>';
                                    })
                                }
                                html +='<div class="layui-form-item">'+
                                    ' <label class="layui-form-label">配置价格</label>'+
                                    '<div class="layui-input-block" style="width: 100px;flex: 0 0 auto;">'+
                                    '    <input type="text" name="original_price"  placeholder="" autocomplete="off" class="layui-input" readonly>'+
                                    ' </div>'+
                                    '<div class="layui-word-aux"><button class="layui-btn layui-btn-normal" lay-submit lay-filter="formSetMoney">获取</button></div>'+
                                    '</div>' +
                                '<div class="layui-form-item layui-form-text" style="flex-direction: column;display: none;">' +
                                '<label class="layui-form-label">配置详情</label>' +
                                '<div class="layui-input-block">' +
                                '    <textarea  name="config_cn" id="config_cn" placeholder="" autocomplete="off" class="layui-textarea" readonly></textarea>' +
                                ' </div>' +
                                '</div>';

                                $("#set_config").html(html);
                                _setMoney();
                                $('#set_config .xm-select').each(function(){
                                    let config=$(this).data("xm"),id=$(this).attr("id");
                                    console.log(id);
                                    if( _call.hasOwnProperty(id) ) {
                                        config.on=function (rdata){
                                            _call[id](rdata);
                                        }
                                    }
                                    _xm[id]=xmSelect.render(config);

                                })
                                $.each(_callDefault,function(k,v){
                                    v();
                                })
                                layui.form.render();
                                $('[lay-filter="formSetMoney"]').trigger("click")
                            }
                        })
                        /**刷新产品**/


                });
                break;
            }


            default:

                break;

        }

    });
        let _getProduct=function (){
            ajax({
                data:{
                    action:'product',
                    p:''
                },
                success:function (res){
                    productTable.reload({
                        data:res.data
                    })
                }
            })
        }
        _getProduct();


        layui.form.on('submit(formDemo)', function(data){
            if(!data.field.two&&!data.field.three&&!data.field.five){
                layer.msg("最少要有一项目人数价格");
                return false;
            }

            ajax({
                data:{
                    action:'set',
                    data:data.field
                },
                success:function (res){
                    $('input[name="two"]').val("");
                    $('input[name="three"]').val("");
                    $('input[name="five"]').val("");
                    $('input[name="end_time"]').val("");
                    $('input[name="days"]').val("");
                    $('textarea[name="content"]').val('');
                    $('input[name="product_name"]').val('');
                    demo1.setValue([]);
                    productSelect.setValue([]);
                    payType.setValue([]);
                    $("#set_config").empty();
                    _getProduct();

                }
            })

            return false;
        });
        $("a.lay-btn-reset").off("click").on("click",function(){
            $('input[name="two"]').val("");
            $('input[name="three"]').val("");
            $('input[name="five"]').val("");
            $('input[name="end_time"]').val("");
            $('input[name="days"]').val("");
            $('textarea[name="content"]').val('');
            demo1.setValue([]);
            productSelect.setValue([]);
            payType.setValue([]);
            $("#set_config").empty();
            _getProduct();

        })
    })
</script>
