index.html 7.6 KB
<!DOCTYPE html>
<html lang="en">

{include file="public/head"/}
<link rel="stylesheet" href="__CDN__/assets/advertising/css/index.css">
<link rel="stylesheet" href="__CDN__/assets/advertising/css/swiper.min.css">
<style>
    .swiper-slide{
        height: 180px;
    }
    .swiper-slide img{
        width: 100%;
        height: 100%;
    }
    .refresh_box {
        display: none;
        text-align: center;
        height: 1rem;
        line-height: 0.7rem;
        font-size: 0.28rem;
        background-color: #FB7A17;
    }
</style>
<body>
<div class="outerScroller">
    <div class="refresh_box">松手后刷新</div>
    <div class="index clearfix">
        <div class="banner">
            <div class="swiper-container swiper-container-horizontal banner_img">
                <div class="swiper-wrapper">
                    {foreach name="$slide" item="s"}
                    <div class="swiper-slide">
                        <img src="{$s.image}" alt="">
                    </div>
                    {/foreach}
                </div>
                <div class="swiper-pagination swiper-pagination-white swiper-pagination-clickable swiper-pagination-bullets"></div>
            </div>
        </div>
        <!-- 列表 -->
        <div class="content_list">
            <div id="dom">
                {foreach name="$data" item="vo"}
                <div class="content_single" onclick="detail('{$vo.id}')">
                    <div class="single_title">{$vo.goods_name}</div>
                    <div class="single_coupon">{$vo.exp}红包券</div>
                    <div class="layout justify flex_row align_center">
                        <div class="single_date">截止日期: {$vo.end_time}</div>
                        <div class="single_btn">可参与</div>
                    </div>
                </div>
                {/foreach}
            </div>
            {empty name="$data"}
            <div class="empty_data">
                暂无数据
            </div>
            {/empty}
            {notempty name="$data"}
            <div class="load_more layout align_center justify_center">
                <div>加载更多</div>
                <div class="layout align_center justify_center">
                    <img src="__CDN__/assets/advertising/img/right.png" alt="">
                </div>
            </div>
            <!--当前页-->
            <input type="hidden" id="page" value="1"/>
            {/notempty}
        </div>

        {include file="public/nav"/}
    </div>
</div>
{include file="public/js" /}
<script src="__CDN__/assets/advertising/js/swiper.min.js"></script>
<script>
    var user_id = "{:get_current_user_id()}";
    //幻灯片
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        loop: true,
        autoplay: true,
        spaceBetween: 0,
        autoplay: 3000,
    });
    //进入详情页
    function detail(goods_id){
        window.location.href = "{:url('home/goods/detail',array('goods_id'=>'GOODS_ID'),false,true)}".replace('GOODS_ID',goods_id);
    }
    // 下拉刷新
    var disY, startY, endY;
    $(".outerScroller").on("touchstart", function(e) {
        startY = e.changedTouches[0].pageY;
        $(".refresh_box").text("松手后刷新")
    });
    $(".outerScroller").on("touchmove", function(e) {
        endY = e.changedTouches[0].pageY;
        disY = endY - startY;
        if (disY > 30) {
            $(".refresh_box").slideDown("slow");
        }
    });
    $(".outerScroller").on("touchend", function(e) {
        $(".refresh_box").text("刷新中");
        $(".refresh_box").slideUp("slow");
        refresh();
    });

    function refresh() {
        $.ajax({
            url:"{:url('home/index/more')}",
            type:"POST",
            data:{'page':1,'user_id':user_id},
            success:function(res){
                if(res.code == 1){
                    if(res.data == ''){
                        $('.justify_center').html("<div>没有更多了~</div>");
                        toast('没有更多了~');
                        return;
                    }
                    var html = "";
                    $(res.data).each(function (key, vo) {
                        html += "<div class=\"content_single\" onclick=\"detail('"+vo.id+"')\">\n" +
                            "                <div class=\"single_title\">"+vo.goods_name+"</div>\n" +
                            "                <div class=\"single_coupon\">"+vo.exp+"红包券</div>\n" +
                            "                <div class=\"layout justify flex_row align_center\">\n" +
                            "                    <div class=\"single_date\">截止日期: "+vo.end_time+"</div>\n" +
                            "                    <div class=\"single_btn\">可参与</div>\n" +
                            "                </div>\n" +
                            "            </div>";
                    });
                    $('#dom').append(html);
                    $('#page').val(page);
                }else{
                    toast('与服务器断开连接');
                }
            },
            error:function(){
                toast('与服务器断开连接');
            }
        })
    };
    //加载更多
    $(".load_more").click(function () {
        var page = $('#page').val();
        page++;
        $.ajax({
            url:"{:url('home/index/more')}",
            type:"POST",
            data:{'page':page,'user_id':user_id},
            success:function(res){
                if(res.code == 1){
                    if(res.data == ''){
                        $('.justify_center').html("<div>没有更多了~</div>");
                        toast('没有更多了~');
                        return;
                    }
                    var html = "";
                    $(res.data).each(function (key, vo) {
                        html += "<div class=\"content_single\" onclick=\"detail('"+vo.id+"')\">\n" +
                            "                <div class=\"single_title\">"+vo.goods_name+"</div>\n" +
                            "                <div class=\"single_coupon\">"+vo.exp+"红包券</div>\n" +
                            "                <div class=\"layout justify flex_row align_center\">\n" +
                            "                    <div class=\"single_date\">截止日期: "+vo.end_time+"</div>\n" +
                            "                    <div class=\"single_btn\">可参与</div>\n" +
                            "                </div>\n" +
                            "            </div>";
                    });
                    $('#dom').append(html);
                    $('#page').val(page);
                }else{
                    toast('与服务器断开连接');
                }
            },
            error:function(){
                toast('与服务器断开连接');
            }
        })
    })

    // 地图定位
    // var geolocation = new qq.maps.Geolocation("LQNBZ-F3L34-EQMUR-DILMD-LBR4Q-GDFOH", "myapp");
    // var positionNum = 0;
    // var options = {
    //     timeout: 5000
    // };

    // function showPosition(position) {
    //     var city = position.city; //城市
    //     var addr = position.addr; //详细地址
    //     var lat = position.lat; //
    //     var lng = position.lng; //经纬度
    // }

    // function showErr() {
    //     Toast.init();
    //     Toast.show('定位失败', 'success', null);
    //     setTimeout(function() {
    //         Toast.hide();
    //     }, 20000);
    // };
    // $(function() { //定位
    //     geolocation.getLocation(showPosition, showErr, options);
    // })
</script>
</body>


</html>