<?php /*a:3:{s:99:"/home/u833649990/domains/beyondtravel.tours/public_html/app/app/admin/view/member/order_config.html";i:1763702585;s:93:"/home/u833649990/domains/beyondtravel.tours/public_html/app/app/admin/view/public/header.html";i:1763702586;s:93:"/home/u833649990/domains/beyondtravel.tours/public_html/app/app/admin/view/public/footer.html";i:1763702586;}*/ ?>
<!doctype html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>后台登录-<?php echo htmlentities($system_name); ?></title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/xadmin.css">
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="/static/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/admin/js/xadmin.js?date=<?php echo date('Ymd'); ?>"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="/static/admin/js/html5.min.js"></script>
    <script src="/static/admin/js/respond.min.js"></script>
    <![endif]-->
</head>

<style>
    .layui-form-selected dl {
        z-index: 1000;
    }

    .input-hide {
        display: none;
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" name="id" value="<?php echo htmlentities((isset($info['id']) && ($info['id'] !== '')?$info['id']:'0')); ?>">
            <input type="hidden" name="uid" value="<?php echo htmlentities($uid); ?>">
            <div class="layui-form-item">
                <label class="layui-form-label" style="font-weight: bold; color: #FF5722;">
                    总订单控制
                </label>
                <div class="layui-input-inline" style="padding-top: 7px;">
                    <input type="checkbox" name="total_order_stop" lay-filter="totalOrderStop" 
                           lay-skin="switch" lay-text="ON|STOP" value="1"
                           <?php if($total_order_stop == '1'): ?>checked<?php endif; ?>>
                    <input type="hidden" name="total_order_stop_value" id="total_order_stop_value" value="<?php echo htmlentities((isset($total_order_stop) && ($total_order_stop !== '')?$total_order_stop:'1')); ?>">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    STOP: 用户无法创建任何订单（无提示）
                </div>
            </div>
            <div class="layui-form-item" id="orderConfigForm" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label class="layui-form-label">用户昵称</label>
                <div class="layui-input-inline">
                    <input type="text" readonly class="layui-input" value="<?php echo htmlentities($nickname); ?>-<?php echo htmlentities($uid); ?>">
                </div>
            </div>
            <div class="layui-form-item" id="orderConfigForm2" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label class="layui-form-label">任务情况</label>
                <div class="layui-input-inline">
                    <input type="text" readonly class="layui-input" value="<?php echo htmlentities($order_total); ?>-<?php echo htmlentities($order_num); ?>">
                </div>
            </div>
            <div class="layui-form-item" id="orderConfigForm3" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline" style="padding-top: 7px;">
                    <input type="checkbox" name="type" lay-filter="switchType" lay-skin="switch" lay-text="连单|卡单" value="2"
                           <?php if($info['type'] == '2'): ?>checked<?php endif; ?>>
                </div>
            </div>
            <div class="layui-form-item <?php if($info['type'] == '1'): ?>input-hide<?php endif; ?>" id="start_num" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label class="layui-form-label">开始连单单数</label>
                <div class="layui-input-inline">
                    <input type="number" name="start_num" lay-verify="required" autocomplete="off" class="layui-input"
                           value="<?php echo htmlentities((isset($info['start_num']) && ($info['start_num'] !== '')?$info['start_num']:'1')); ?>" placeholder="几单后开始连单">
                </div>
            </div>
            <div class="layui-form-item" id="orderConfigForm4" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label class="layui-form-label">当前设置</label>
                <div class="layui-input-inline">
                    <input type="text" readonly class="layui-input" value="<?php echo htmlentities((isset($info['current_config']) && ($info['current_config'] !== '')?$info['current_config']:'')); ?>">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>文字描述为：<?php echo htmlentities((isset($info['current_txt']) && ($info['current_txt'] !== '')?$info['current_txt']:"")); ?>
                </div>
            </div>
            <div class="layui-form-item" id="orderConfigForm5" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label for="config" class="layui-form-label">新的设置</label>
                <div class="layui-input-inline">
                    <input type="text" id="config" name="config" readonly class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item" id="orderConfigForm6" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline" style="padding-top: 7px;">
                    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" value="1"
                           <?php if($info['status'] == '1'): ?>checked<?php endif; ?>>
                </div>
            </div>
            <div class="layui-form-item" id="orderConfigForm7" <?php if($total_order_stop == '2'): ?>style="display:none"<?php endif; ?>>
                <label class="layui-form-label">
                </label>
                <button class="layui-btn" lay-filter="add" lay-submit="">保存设置</button>
            </div>
        </form>
    </div>
    <div class="layui-card-body ">
        <div class="layui-form-item">
            <div class="layui-inline layui-show-xs-block">
                <label class="layui-form-label" style="width: 65px">价格范围</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" id="price_min" placeholder="￥" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" id="price_max" placeholder="￥" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline layui-show-xs-block">
                    <a class="layui-btn" href="javascript:;" onclick="searchGoods(true)">
                        <i class="layui-icon">&#xe615;</i>
                    </a>
                </div>
            </div>
        </div>
        <table class="layui-table layui-form" style="table-layout: fixed;">
            <thead>
            <tr>
                <th>产品ID</th>
                <th>商品名称</th>
                <th>商品价格</th>
                <th>第几单</th>
                <th>状态</th>
            </tr>
            </thead>
            <tbody id="goods"></tbody>
        </table>
        <div class="layui-form-mid layui-word-aux" id="more" onclick="searchGoods(false)"
             style="font-size: 20px;text-align: center;width: 100%;display: none;cursor: pointer">
            点击加载更多
        </div>
    </div>
</div>
<script type="text/javascript">
    var order_type = '<?php echo htmlentities($info['type']); ?>';
    var level_order_rate = parseFloat('<?php echo htmlentities((isset($level_order_rate) && ($level_order_rate !== '')?$level_order_rate:"0")); ?>') || 0;
    var price_min, price_max, page, is_finish,select_goods;
    if (order_type == 1)
        select_goods = {};
    else
        select_goods = [];
    layui.use(['form'], function () {
        var form = layui.form;

        // Initialize hidden field value based on checkbox state on page load
        var checkbox = $('input[name="total_order_stop"]');
        if (checkbox.length && checkbox[0].checked) {
            $('#total_order_stop_value').val('1');
        } else {
            $('#total_order_stop_value').val('2');
        }

        form.on('switch(totalOrderStop)', function (data) {
            var total_order_stop_value = this.checked ? '1' : '2';
            $('#total_order_stop_value').val(total_order_stop_value);
            
            if (this.checked) {
                // ON - Show all form fields
                $('#orderConfigForm, #orderConfigForm2, #orderConfigForm3, #orderConfigForm4, #orderConfigForm5, #orderConfigForm6, #orderConfigForm7').show();
                // Respect type toggle for start_num visibility
                if (order_type == 2) {
                    $('#start_num').show();
                }
            } else {
                // STOP - Hide all form fields
                $('#orderConfigForm, #orderConfigForm2, #orderConfigForm3, #orderConfigForm4, #orderConfigForm5, #orderConfigForm6, #orderConfigForm7').hide();
                $('#start_num').hide();
            }
            
            // Auto-save the toggle state immediately
            var formData = {
                uid: '<?php echo htmlentities($uid); ?>',
                total_order_stop_value: total_order_stop_value,
                id: '<?php echo htmlentities((isset($info['id']) && ($info['id'] !== '')?$info['id']:"0")); ?>'
            };
            
            $.ajax({
                url: '<?php echo url("admin/Member/orderConfig"); ?>',
                type: 'post',
                data: formData,
                dataType: 'json',
                success: function (res) {
                    if (res.status == '200') {
                        tipAction(1, res.msg);
                    } else {
                        tipAction(2, res.msg);
                    }
                },
                error: function () {
                    tipAction(2, '保存失败，请重试');
                }
            });
        });

        form.on('switch(switchType)', function (data) {
            if (this.checked) {
                $('#start_num').show();
                order_type = 2;
                select_goods = [];
            } else {
                $('#start_num').hide();
                order_type = 1;
                select_goods = {};
            }
            $('#config').val('');
            $('.checkTd').children().attr('data-type',0).html('&#xe67b;');
        });

        //监听提交
        form.on('submit(add)', function (data) {
            // Ensure hidden field value is included
            var formData = data.field;
            formData['total_order_stop_value'] = $('#total_order_stop_value').val();
            
            //发异步，把数据提交给php
            $.ajax({
                url: '<?php echo url("admin/Member/orderConfig"); ?>',
                type: 'post',
                data: formData,
                dataType: 'json',
                success: function (res) {
                    if (res.status == '200') {
                        tipAction(1, res.msg);
                        setTimeout(function () {
                            parent.layer.closeAll();
                        }, 1000);
                    } else {
                        tipAction(2, res.msg);
                    }
                },
                error: function () {
                    tipAction(2, '系统繁忙');
                }
            });
            return false;
        });
    });

    function searchGoods(is_new) {
        price_min = $('#price_min').val();
        price_max = $('#price_max').val();
        if (is_new) {
            page = 1;
            is_finish = false;
        } else
            page++;
        $.ajax({
            url: "<?php echo url('admin/Product/list'); ?>",
            type: 'post',
            data: {price_max, price_min, page},
            dataType: 'json',
            success: function (res) {
                if (res.status < 202) {
                    var html = '';
                    res.data.forEach(function (item) {
                        html += '<tr><td>' + item['id'] + '</td><td>' + item['name'] + '</td><td>' + item['price'] + '</td>' +
                            '<td><input type="text" autocomplete="off" class="layui-input" value="1"></td>' +
                            '<td><input type="number" step="0.01" class="layui-input order_rate" value="' + level_order_rate.toFixed(2) + '"></td>' +
                            '<td class="checkTd"><i class="layui-icon" data-id="' + item['id'] + '" data-type="0" style="font-size: 20px" onclick="selectGoods(this)">&#xe67b;</i></td></tr>';
                    });
                    if (is_new)
                        $('#goods').html(html);
                    else
                        $('#goods').append(html);
                    if (res.status == '200') {
                        $('#more').show();
                    } else {
                        $('#more').hide();
                    }
                } else {
                    $('#more').hide();
                    tipAction(2, '没数据了')
                }
            }
        });
    }

    function selectGoods(obj) {
        var id = $(obj).data('id');
        var type = $(obj).attr('data-type');
        var order_no = $(obj).parent().prev().prev().children().val(); // Modified
        var order_rate = $(obj).parent().prev().children('.order_rate').val(); // ADDED
        if (type == 0) {
            if (order_type == 1 && select_goods[order_no] != undefined) {
                tipAction(2, '请填写别的单号');
                return false;
            }
            $(obj).attr('data-type', 1).html('&#xe67a;');
            if (order_type == 1) {
                select_goods[order_no] = {gid: id, order_rate: order_rate}; // Modified
            } else {
                select_goods.push({gid: id, order_rate: order_rate}); // Modified
            }
        } else {
            $(obj).attr('data-type', 0).html('&#xe67b;');
            if (order_type == 1)
                delete select_goods[order_no];
            else {
                var index = -1;
                for (var i = 0; i < select_goods.length; i++) {
                    if (select_goods[i].gid == id) {
                        index = i;
                        break;
                    }
                }
                if (index > -1) {
                    select_goods.splice(index, 1);
                }
            }
        }
        var list = [];
        if (order_type == 1) {
            list = $.map(select_goods, function (val) {
                return val;
            });
        } else {
            list = select_goods;
        }
        $('#config').val(JSON.stringify(list)); // Modified
    }
</script>
</body>
</html>
<script type="application/javascript">
    /**
     * 统一接口返回提示弹窗
     * type 1-成功 2-失败
     * info 提示信息
     * */
    function tipAction(type, info) {
        layer.msg(info, {icon: type, time: 1500})
    }

    //图片放大
    function showBig(obj) {
        let img_src = $(obj).attr('src');
        layer.open({
            type: 1,
            area: ['70%', 'auto'],
            shadeClose: true,
            title: false,
            closeBtn: false,
            content: `<div style=""><img src="${img_src}" alt="" width="100%"></div>`
        });
    }
</script>

