{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>旅游导览</title>
    <link rel="stylesheet" href="{% static '/lib/font/fontIcon/iconfont.css' %}">
    <link rel="stylesheet" href="{% static '/lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static '/lib/css/reset.css' %}">
    <link rel="stylesheet" href="{% static '/css/common.css' %}">
    <link rel="stylesheet" href="{% static '/css/module.css' %}">
    <link rel="stylesheet" href="{% static '/css/pickIntro.css' %}">
    <style>
        .address{
            line-height: 22px;
            margin-left: 70px;
            text-indent: -69px;
        }
        .touristDesc{
            padding: 10px 20px;
        }
        .pickDesc .descTitle{
            border-left: 3px solid #41b850;
            padding-left: 10px;
            font-size: 14px;
            margin: 10px 0;
            font-weight: 700;
        }
        .advImg{
            background: url(../static/imgs/scenicAdv.jpg) no-repeat center;
        }
    </style>
</head>

<body>
    <div class="header">
        <div class="headerTxt">
            <div class="wrapper">
                <p class="logoNameCn">休闲农业旅游网</p>
                <p class="logoNameEn">Leisure agricultural tourism network</p>
            </div>

        </div>
        <!-- 广告 -->
        <div class="bjColor advImg"></div>
    </div>
    <!-- 主体部分 -->
    <div class="content">
        <div class="wrapper">
            <div class="">
                <!-- 详情 -->
                <div class="newsDiv gardenItem">
                    <!-- 面包屑导航 -->
                    <div class="breadcrumb">
                        <span class="layui-breadcrumb">
                            <a href="home">首页</a>
                            <a>
                                <cite>采摘详情</cite>
                            </a>
                        </span>
                    </div>
                    <!-- 采摘详情 -->
                    <div class="pickDesc">
                        <h1 class="caption">大连天门山</h1>
                        <div class="sendTime title">2019-11-15</div>
                        <div class="prodectIntro">
                            <div class="prodectImg">
                                <img src="https://www.cnnyly.com/upload/goods/20200509/9806f6bba92a29186a82d7851221ec552.jpg" alt="">
                            </div>
                            <div class="descTxt">
                                <div><span>景点名称：</span>大连天门山</div>
                                <div><span>联系电话：</span>0411-98985555</div>
                                <div><span>门票价格：</span>70元/人</div>
                                <div><span>开放时间：</span>7:00~18:00</div>
                                <div class="address"><span>景点地址：</span>河南省郑州市金水河南省郑州市金水河南省郑州市金水河南省郑州市金水</div>
                            </div>
                        </div>
                        <div class="title">详细介绍</div>
                        <div class="touristDesc">
                            <div class="descTitle">介绍</div>
                            <div>1</div>
                            <div class="descTitle">景区导览图</div>
                            <div>
                                <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597225887915&di=adc05d45d3ab13de6b52ac19f72f6579&imgtype=0&src=http%3A%2F%2Fwww.hengdiantour.com%2Fupload%2Fmhg.jpg" width="100%" alt="">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <!-- 底部版权 -->
    <div class="footer bjColor">
        <div class="wrapper">
            <div class="floatDiv">
                <div class="copyrightTxt">
                    <div>休闲农业旅游网</div>
                    <div>联系人：李四　　联系电话：13811111111</div>
                    <div>地址：河南省郑州市XXXXXXXXXXXXXXXXXXXXXXXXXX</div>
                </div>
                <div class="WeChatCode">
                    <img src="{% static '/imgs/WeChatCode.jpg' %}" alt="">
                    <p>关注公众号</p>
                </div>
            </div>
            <div class="copyright">
                版权所有XXXXXXXXXXXXXXXXXXXXXX
            </div>
        </div>
    </div>

    <script src="{% static '/lib/js/jquery-2.1.4.min.js'%}"></script>
    <script src="{% static '/lib/layui/layui.js'%}"></script>
    <script>
        //注意：导航 依赖 element 模块，否则无法进行功能性操作
        layui.use(['element', 'laypage'], function () {
            var element = layui.element;
        });
        // 请求菜单
        $.ajax({
            url: 'garden_list',
            type: 'post',
            data: { page: 1 },
            dataType: 'json',
            success: function (data) {
                console.log(data);
                createLeftMenu(data)
            },
            error: function (type) {
                console.log(type);
            }
        })
        var menuCurrId; //当前id
        var menuCurrNum = 1; //当前页
        var menuTotalPage;  //总页
        // 农场获取
        function createLeftMenu(data) {
            menuTotalPage = Math.ceil(data.nums / 10);
            if (menuTotalPage > 1) {
                $('.gardenListBtn').show();
            } else {
                $('.gardenListBtn').hide();
            }
            var html = '';
            for (var i = 0; i < data.farms.length; i++) {
                if (i == 0) {
                    html += '<li class="active" data-id=' + data.farms[i].id + '>' + data.farms[i].name + '</li>';
                } else {
                    html += '<li data-id=' + data.farms[i].id + '>' + data.farms[i].name + '</li>';
                }
                if (i == data.farms.length - 1) {
                    $('#gardenListUl').html(html);
                    $('.menuTotalPage').html(menuTotalPage);
                    menuCurrId = data.farms[0].id;
                    getDataList(menuCurrId);
                    // 菜单切换
                    $('#gardenListUl').on('click', 'li', function () {
                        $('#gardenListUl li').removeClass('active');
                        $(this).addClass('active');
                        menuCurrId = $(this).data('id');
                        getDataList(menuCurrId);
                    });
                }
            }
        }
        // 分页切换
        function switchPage(flag) {
            if (flag == 'jia') {
                if (menuCurrNum < menuTotalPage) {
                    menuCurrNum++;
                }
            } else if (flag == 'jian') {
                if (menuCurrNum > 1) {
                    menuCurrNum--;
                }
            } else {
                menuCurrNum = 1;
            }
            $('.menuCurr').html(menuCurrNum);
            $.ajax({
                url: 'garden_list',
                type: 'post',
                data: { page: menuCurrNum },
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    createLeftMenu(data)
                },
                error: function (type) {
                    console.log(type);
                }
            })
        }

        // 请求列表
        function getDataList(id) {
            console.log('id:', id)
            $.ajax({
                url: 'garden_detail',
                type: 'post',
                dataType: 'json',
                data: { id: id, page: 1 },
                success: function (data) {
                    // $('#dataFillDiv').html(data);
                    setHtml(data.pick);
                    if (data.nums) {
                        $('#page').show();
                        //执行一个laypage实例
                        layui.use(['laypage'], function () {
                            var laypage = layui.laypage;
                            laypage.render({
                                elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                                , count: data.nums //数据总数，从服务端得到
                                , limit: 12
                                // , curr: 8
                                , jump: function (obj, first) {
                                    $.ajax({
                                        url: 'garden_detail',
                                        type: 'post',
                                        dataType: 'json',
                                        data: { id: id, page: obj.curr },
                                        success: function (data) {
                                            // $('#dataFillDiv').html(data);
                                            setHtml(data.pick);
                                        },
                                        error: function (type) {
                                            alert('请求失败')
                                        }
                                    })
                                }
                            });
                        });
                    }else{
                        $('#page').hide();
                    }

                },
                error: function (type) {
                    alert('请求失败')
                }
            })


        }

        function setHtml(data) {
            if (data.length) {
                var html = '<ul class="productList">';
                for (var i = 0; i < data.length; i++) {
                    html += '<li class="productItem"><div class="productImg">' +
                        '<img src="' + data[i].img + '" alt=""></div>' +
                        '<div>' + data[i].farm + '</div><div>' + data[i].time + '采摘</div><div>' + data[i].company + '</div></li>';
                    if (i == data.length - 1) {
                        html += '</ul>';
                        $('#dataFillDiv').html(html);
                    }
                }
            } else {
                $('#dataFillDiv').html('<div style="text-align:center;line-height:200px;font-size:18px">暂无数据</div>');
            }
        }
        // ceshi 

    </script>
</body>

</html>