shop--10.店鋪詳情(後臺+前端相似於shoplist)

1.獲取店鋪的詳細信息和商品類別列表javascript

/**
     * 獲取店鋪信息和該店鋪下的商品類別列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/getshopdetailpageinfo", method= RequestMethod.GET)
    @ResponseBody
    private Map<String, Object> getShopDetailPageInfo(HttpServletRequest request){
        Map<String, Object> modelMap = new HashMap<>();
        Long shopId = HttpServletRequestUtil.getLong( request, "shopId" );
        Shop shop = null;
        List<ProductCategory> productCategoryList = null;
        //獲取店鋪id爲shopId的商品信息
        if(shopId != -1){
            //獲取shopId的店鋪信息
            shop = shopService.getShopByShopId( shopId );
            //獲取該店鋪下的商品列表
            productCategoryList = productCategoryService.getProductCategoryList( shopId );

            modelMap.put( "success", true );
            modelMap.put( "shop", shop );
            modelMap.put( "productCategoryList", productCategoryList );
        } else{
            modelMap.put( "success", false );
            modelMap.put( "errMsg", "empty shopId" );
        }
        return modelMap;
    }

  

2.根據查詢條件,返回該店鋪下的商品詳細信息css

/**
     * 根據查詢條件,分頁列出該店鋪下的商品信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/prouctlistbyshop", method = RequestMethod.GET)
    @ResponseBody
    private Map<String, Object> productListByShop(HttpServletRequest request){
        Map<String, Object> modelMap = new HashMap<>(  );
        //獲取頁碼
        int pageIndex = HttpServletRequestUtil.getInt( request, "pageIndex" );
        //獲取每頁的信息數量
        int pageSize = HttpServletRequestUtil.getInt( request, "pageSize" );
        //獲取shopId
        Long shopId = HttpServletRequestUtil.getLong( request, "shopId");

        //空值判斷
        if(pageIndex > -1 && pageSize > -1 && shopId > -1){
            //獲取productCategoryId
            Long productCategoryId  = HttpServletRequestUtil.getLong( request, "productCategoryId" );
            //獲取productName  進行模糊查詢
            String productName = HttpServletRequestUtil.getString( request, "productName" );
            Product productCondition = compactProuctCondition4Search(shopId, productCategoryId, productName);
            ProductExecution productExecution = productService.getProductList( productCondition, pageIndex, pageSize);
            modelMap.put( "success", true );
            modelMap.put( "productList", productExecution.getProductList() );
            modelMap.put( "count", productExecution.getCount() );
        } else{
            modelMap.put( "success", false );
            modelMap.put( "errMsg", "empty pageSize or pageIndex or shopId" );
        }
        return modelMap;
    }

    /**
     * 組合查詢條件到productCondition,進行進一步的店鋪下的相關商品信息查詢
     * @param shopId
     * @param productCategoryId
     * @param productName
     * @return
     */
    private Product compactProuctCondition4Search(Long shopId, Long productCategoryId, String productName) {
        Product productCondition = new Product();

        Shop shop = new Shop();
        shop.setShopId( shopId );

        productCondition.setShop( shop );

        //查詢某個商品類別下的商品列表
        if(productCategoryId != -1){
            ProductCategory productCategory = new ProductCategory();
            productCategory.setProductCategoryId( productCategoryId );
            productCondition.setProductCategory( productCategory );
        }

        //進行productName的模糊查詢
        if(productName != null){
            productCondition.setProductName(productName);
        }

        //只查詢商品中status=1的上架的商品
        productCondition.setStatus( 1 );
        return productCondition;
    }

  

 

前端html

shopdetail.html  相似於shoplist.html前端

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商店詳情</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
    <link rel="stylesheet" href="../resources/css/frontend/shoplist.css">
</head>
<body>
<!-- page集合的容器,裏面放多個平行的.page,其餘.page做爲內聯頁面由路由控制展現 -->
<div class="page-group">
    <!-- 單個page ,第一個.page默認被展現-->
    <div class="page">
        <!-- 標題欄 -->
        <header class="bar bar-nav">
            <a class="button button-link button-nav pull-left" external
               href="index" data-transition="slide-out">
                <span class="icon icon-left"></span>
                返回</a>
            <!--動態綁定店鋪名字-->
            <h1 class="title" id="shop-name">店鋪詳情</h1>
        </header>

        <!-- 工具欄 -->
        <nav class="bar bar-tab">
            <a class="tab-item external active" href="frontend/index" external>
                <span class="icon icon-home"></span>
                <span class="tab-label">首頁</span>
            </a>
            <a class="tab-item external" href="#" id="me">
                <span class="icon icon-me"></span>
                <span class="tab-label">我的</span>
            </a>
        </nav>

        <!--無限滾動-->
        <div class="content infinite-scroll infinite-scroll-bottom" data-distance="100">
            <!--商品列表展現區-->
            <!--商品列表在此添加  卡片-->
            <div class="shop-detail-dev">
                <div class="card">
                    <div valign="bottom" class="card-header color-white no-border no-padding">
                        <img class='card-cover' id="shop-cover-pic" src="" alt="">
                    </div>
                    <div class="card-content">
                        <div class="card-content-inner">
                            <p class="color-gray">
                                <span id="shop-uptate-time"></span>
                            </p>
                            <p id="shop-desc"></p>
                        </div>
                    </div>
                    <div class="card-footer">
                        <span id="shop-addr"></span>
                        <span id="shop-phone"></span>
                    </div>
                </div>
            </div>
            <!--商品類別列表展現區-->
            <div class="shopdetail-button-div" id="shopdetail-button-div">
                <!--<a href="#" class="button">全部貨物</a>
                <a href="#" class="button">吃的</a>
                <a href="#" class="button">喝的</a>-->
            </div>
            <!--商品名字搜索區-->
            <div class="detail-search">
                <div class="searchbar">
                    <a class="searchbar-cancel">取消</a>
                    <div class="search-input">
                        <label class="icon icon-search" for="search"></label>
                        <input type="search" id='search' placeholder='輸入關鍵字...'/>
                    </div>
                </div>
            </div>
            <!--商品列表在此添加  卡片-->
            <div class="list-div">
                <!--<div class="card">
                    <div class="card-header">傳統火鍋店</div>
                    <div class="card-content">
                        <div class="list-block media-list">
                            <ul>
                                <li class="item-content">
                                    <div class="item-media">
                                        <img src="http://gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i3/TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg" width="44">
                                    </div>
                                    <div class="item-inner">
                                        <div class="item-subtitle">標題</div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="card-footer">
                        <span>2015/01/15</span>
                        <span>5 評論</span>
                    </div>
                </div>-->
            </div>
            <!-- 加載提示符 -->
            <div class="infinite-scroll-preloader">
                <div class="preloader"></div>
            </div>
        </div>
    </div>

    <!--側邊欄-->
    <div class="panel-overlay"></div>
    <div class="panel panel-right panel-reveal" id="panel-left-demo">
        <div class="content-block">
            <p>
                <a href="/myo2o/frontend/myrecord" class="close-panel">消費記錄</a>
            </p>
            <p>
                <a href="/myo2o/frontend/mypoint" class="close-panel">個人積分</a>
            </p>
            <p>
                <a href="/myo2o/frontend/pointrecord" class="close-panel">積分兌換記錄</a>
            </p>
            <!-- Click on link with "close-panel" class will close panel -->
        </div>
    </div>
</div>

<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
<script type='text/javascript' src='../resources/js/frontend/shopdetail.js' charset='utf-8'></script>
<script type='text/javascript' src='../resources/js/common/commons.js' charset="utf-8"></script>
</body>
</html>

  

shopdetail.jsjava

$(function() {
    //無限滾動事件
    // 加載flag
    var loading = false;
    // 最多可加載的條目,超過此數目,禁止訪問後臺
    var maxItems = 20;
    // 每次加載添加多少條目
    var pageSize = 3;
    //獲取商品列表的URL
    var listUrl = '/frontend/prouctlistbyshop';
    //頁碼
    var pageNum = 1;
    //從地址欄URL裏嘗試獲取shopId
    var shopId = getQueryString('shopId');
    var productCategoryId = '';
    var productName = '';
    //獲取本店鋪詳細信息及商品類別信息列表的URL
    var searchDivUrl = '/frontend/getshopdetailpageinfo?shopId=' + shopId;
    //渲染出店鋪基本信息及商品類別列表以供搜索
    getSearchDivData();
    //預先加載10條店鋪信息
    addItems(pageSize, pageNum);

    /**
     * 獲取店鋪詳細信息以及商品類別信息列表
     */
    function getSearchDivData(){
        //若是傳入了parentId,則將parentId傳入後臺,用來獲取parentId下的二級店鋪列表
        var url = searchDivUrl;
        $.getJSON(url, function(data) {
            if (data.success) {
                //獲取後臺返回的店鋪類別列表
                var shop = data.shop;
                $('#shop-cover-pic').attr('src', shop.shopImg);
                $('#shop-uptate-time').html(
                    new Date(shop.lastEditTime).Format("yyyy-MM-dd"));
                $('#shop-name').html(shop.shopName);
                $('#shop-desc').html(shop.shopDesc);
                $('#shop-addr').html(shop.shopAddr);
                $('#shop-phone').html(shop.phone);

                html += '<a href="#" class="button" data-category-id=""> 所有類別  </a>';
                //獲取後臺返回的店鋪的商品類別列表
                var productCategoryList = data.productCategoryList;
                var html = '';
                //遍歷商品類別列表,生成能夠點擊搜索相應商品類別下的商品的a標籤
                productCategoryList.map(function(item, index) {
                    html += '<a href="#" class="button" data-product-search-id='
                        + item.productCategoryId
                        + '>'
                        + item.productCategoryName
                        + '</a>';
                });
                //將拼接好的商品類別a標籤綁定到相應的的html組件裏
                $('#shopdetail-button-div').html(html);
            }
        });
    }


    /**
     * 獲取分頁展現的商品列表信息
     * @param pageSize
     * @param pageIndex
     */
    function addItems(pageSize, pageIndex) {
        //拼接出查詢的URL,爲空就默認去掉這個條件的限制,有值就表明按這個條件去查詢
        var url = listUrl + '?' + 'pageIndex=' + pageIndex + '&pageSize='
            + pageSize + '&productCategoryId=' + productCategoryId
            + '&productName=' + productName + '&shopId=' + shopId;
        //設定加載符,若還在後臺取數據則不能再次訪問後臺,避免屢次重複加載
        loading = true;
        //訪問後臺獲取相應查詢條件下的店鋪列表
        $.getJSON(url, function(data) {
            if (data.success) {
                //獲取當前查詢條件下的商品總數
                maxItems = data.count;
                var html = '';
                //遍歷商品列表,拼接處卡片集合
                data.productList.map(function(item, index) {
                    html += '' + '<div class="card" data-product-id='
                        + item.productId + '>'
                        + '<div class="card-header">' + item.productName
                        + '</div>' + '<div class="card-content">'
                        + '<div class="list-block media-list">' + '<ul>'
                        + '<li class="item-content">'
                        + '<div class="item-media">' + '<img src="'
                        + item.imgAddr + '" width="44">' + '</div>'
                        + '<div class="item-inner">'
                        + '<div class="item-subtitle">' + item.productDesc
                        + '</div>' + '</div>' + '</li>' + '</ul>'
                        + '</div>' + '</div>' + '<div class="card-footer">'
                        + '<p class="color-gray">'
                        + new Date(item.lastEditTime).Format("yyyy-MM-dd")
                        + '更新</p>' + '<span>點擊查看</span>' + '</div>'
                        + '</div>';
                });
                //將卡片集合添加到目錄html組件裏
                $('.list-div').append(html);
                //獲取目前爲止已顯示的卡片總數,包含以前已經加載的
                var total = $('.list-div .card').length;
                //若總數達到按照此查詢條件列出來的總數一致時,則中止後臺的加載
                if (total >= maxItems) {
                   /* // 加載完畢,則註銷無限加載事件,以防沒必要要的加載
                    $.detachInfiniteScroll($('.infinite-scroll'));*/
                    // 隱藏加載提示符
                    $('.infinite-scroll-preloader').hide();
                } else{
                    // 顯示加載提示符
                    $('.infinite-scroll-preloader').show();
                }
                //不然頁碼+1,繼續load新的店鋪
                pageNum += 1;
                //加載結束,能夠再次加載
                loading = false;
                //刷新頁面,顯示新加載的店鋪
                $.refreshScroller();
            }
        });
    }

    //下滑屏幕自動進行分頁搜索
    $(document).on('infinite', '.infinite-scroll-bottom', function() {
        if (loading)
            return;
        addItems(pageSize, pageNum);
    });

    //選擇新的商品類別以後,重置頁碼,清空原先的商品列表,按照新的類別去查詢
    $('#shopdetail-button-div').on(
        'click',
        '.button',
        function(e) {
            //若是傳遞過來的是一個父類下的子類
            productCategoryId = e.target.dataset.productSearchId;
            if (productCategoryId) {
                if ($(e.target).hasClass('button-fill')) {
                    $(e.target).removeClass('button-fill');
                    productCategoryId = '';
                } else {
                    $(e.target).addClass('button-fill').siblings()
                        .removeClass('button-fill');
                }
                $('.list-div').empty();
                pageNum = 1;
                addItems(pageSize, pageNum);
            }
        });

    //點擊商品的卡片進入該店鋪的詳情頁
    $('.list-div').on('click', '.card', function(e) {
        var producyId = e.currentTarget.dataset.productId;
        window.location.href = '/frontend/productdetail?productId=' + productId;
    });

    //須要查詢的店鋪名字發生變化後,重置頁碼,清空原先的店鋪列表,按照新的名字進行查詢
    $('#search').on('change', function(e) {
        productName = e.target.value;
        $('.list-div').empty();
        pageNum = 1;
        addItems(pageSize, pageNum);
    });


    //點擊後打開右側欄
    $('#me').click(function() {
        $.openPanel('#panel-left-demo');
    });

    //初始化頁面
    $.init();
});
相關文章
相關標籤/搜索