jmx преди 9 години
родител
ревизия
8852af5cef
променени са 2 файла, в които са добавени 264 реда и са изтрити 270 реда
  1. 1 0
      www/webapp/o2o/js/page/placeOrder.js
  2. 263 270
      www/webapp/o2o/js/page/product.js

+ 1 - 0
www/webapp/o2o/js/page/placeOrder.js

@@ -251,6 +251,7 @@ define(['$', 'template', 'order', 'native', 'helper', 'user', 'api', 'config', '
                 $doc.trigger('spa:navigate', {
                 $doc.trigger('spa:navigate', {
                     hash: 'product',
                     hash: 'product',
                     pushData: {
                     pushData: {
+                        produc: product,
                         needReload: true
                         needReload: true
                     }
                     }
                 });
                 });

+ 263 - 270
www/webapp/o2o/js/page/product.js

@@ -1,303 +1,296 @@
 define(['$', 'template', 'product', 'cart', 'api', 'order', 'user', 'config', 'review', 'native'], function ($, template, product, cart, api, order, user, config, review, native) {
 define(['$', 'template', 'product', 'cart', 'api', 'order', 'user', 'config', 'review', 'native'], function ($, template, product, cart, api, order, user, config, review, native) {
-  function back(event, type){
-    event.preventDefault();
-    var hash = 'placeOrder';
-    if (cachePageData.fromHome) {
-      hash = ''
-    };
-    $(document).trigger('spa:navigate', {
-      hash: hash,
-      pushData: {
-        productType: type,
-        needReset: true
-      }
-    });
-  }
-
-  function renderTemplate(productType) {
-    var $view = this;
-    var tpl = template('product/price', {
-      // productDic: product.productDic,
-      petTypes: product.productGroup[productType]
-    });
-
-    $('.price-table', $view).html(tpl);
-  }
-
-  function renderReviewTemplate(reviews, hasMore) {
-    var tpl = template('product/reviewList', {
-      reviews: reviews,
-      imgW: parseInt((document.body.clientWidth - 30) / 3) - 5
-    });
+    function back(event, type) {
+        event.preventDefault();
+        var hash = 'placeOrder';
+        if (cachePageData.fromHome) {
+            hash = ''
+        }
+        $(document).trigger('spa:navigate', {
+            hash: hash
+        });
+    }
 
 
-    $('#productReviewScroll .list-content').append(tpl);
+    function renderTemplate(productType) {
+        var $view = this;
+        var tpl = template('product/price', {
+            // productDic: product.productDic,
+            petTypes: product.productGroup[productType]
+        });
 
 
-    if (hasMore) {
-      $('#productReviewScroll .btn-more-container').removeClass('hide');
-    } else {
-      $('#productReviewScroll .btn-more-container').addClass('hide');
+        $('.price-table', $view).html(tpl);
     }
     }
-  }
 
 
-  var isShowVideo = function() {
-    var show = true;
-    // 判断安卓版本
-    var UA = navigator.userAgent;
-    var index = UA.indexOf("Android");
-    if(index >= 0){
-      var androidVersion = parseFloat(UA.slice(index+8));
-      if(androidVersion < 4.4){
-        show = false;
-      }
-    }
-    return false;
-  }
+    function renderReviewTemplate(reviews, hasMore) {
+        var tpl = template('product/reviewList', {
+            reviews: reviews,
+            imgW: parseInt((document.body.clientWidth - 30) / 3) - 5
+        });
 
 
-  var cachePageData = {}; //page内部的数据传递
+        $('#productReviewScroll .list-content').append(tpl);
 
 
-  return {
-    title: '预约上门服务',
-    body: '',
-    init: function (pageData, dtd) {
-      var $view = this;
-      var $doc = $(document);
-      //取消
-      $.newTouch('.back-button', function (event) {
-        if (isShowVideo()) {
-          $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
+        if (hasMore) {
+            $('#productReviewScroll .btn-more-container').removeClass('hide');
+        } else {
+            $('#productReviewScroll .btn-more-container').addClass('hide');
         }
         }
-        back.call(this, event, cachePageData.productType);
-      }, $view);
+    }
 
 
-      $view.on('tapBackButton', function(event) {
-        if (isShowVideo()) {
-          $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
+    var isShowVideo = function () {
+        var show = true;
+        // 判断安卓版本
+        var UA = navigator.userAgent;
+        var index = UA.indexOf("Android");
+        if (index >= 0) {
+            var androidVersion = parseFloat(UA.slice(index + 8));
+            if (androidVersion < 4.4) {
+                show = false;
+            }
         }
         }
-        back.call(this, event, cachePageData.productType);
-      });
+        return false;
+    }
 
 
-      //返回
-			$view.on('swipeRight', function (event) {
-        if (isShowVideo()) {
-          $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
-        }
-				back.call(this, event, cachePageData.productType);
-			});
+    var cachePageData = {}; //page内部的数据传递
 
 
-      // 提示信息
-      $.newTouch('.btn-product-info', function(event){
-        $doc.trigger('spa:navigate', {
-          hash: 'product-info/' + cachePageData.productType,
-          pushData: {
-            needReload:cachePageData.needReload,
-            fromHome: cachePageData.fromHome
-          }
-        });
-      }, $view);
+    return {
+        title: '预约上门服务',
+        body: '',
+        init: function (pageData, dtd) {
+            var $view = this;
+            var $doc = $(document);
+            //取消
+            $.newTouch('.back-button', function (event) {
+                if (isShowVideo()) {
+                    $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
+                }
+                back.call(this, event, cachePageData.productType);
+            }, $view);
 
 
-      // 提示信息
-      $.newTouch('.group-title-container', function(event){
-        if ($(this).find('.group-title').hasClass('active')) {
-          $(this).find('.group-title').removeClass('active');
-          $(this).next('.group-detail').addClass('hide');
-        } else {
-          $(this).find('.group-title').addClass('active');
-          $(this).next('.group-detail').removeClass('hide');
-        }
-        cachePageData.scroll.refresh();
-      }, $view);
+            $view.on('tapBackButton', function (event) {
+                if (isShowVideo()) {
+                    $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
+                }
+                back.call(this, event, cachePageData.productType);
+            });
 
 
-      // 点击用户头像 打开用户个人中心
-      $.newTouch('.user-info-btn', function(event){
-        var url = 'http://www.yiguanjia.me'
-        if (config.test) {
-          url = 'http://wwwtest.yiguanjia.me';
-        }
-        var id = $(this).attr('data-id');
-        var param = {
-  				url: url + '/user/' + id
-  			};
-        native.openURL(param);
-      }, $view);
+            //返回
+            $view.on('swipeRight', function (event) {
+                if (isShowVideo()) {
+                    $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
+                }
+                back.call(this, event, cachePageData.productType);
+            });
 
 
-      //tab切换
-      $.newTouch('.type-control .control-item', function(event) {
-        if (isShowVideo()) {
-          $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
-        }
+            // 提示信息
+            $.newTouch('.btn-product-info', function (event) {
+                $doc.trigger('spa:navigate', {
+                    hash: 'product-info/' + cachePageData.productType,
+                    pushData: {
+                        needReload: cachePageData.needReload,
+                        fromHome: cachePageData.fromHome
+                    }
+                });
+            }, $view);
 
 
-        var type = $(this).data('type');
-        $('.type-container', $view).hide();
-        switch(type) {
-          case 1:
-            $('#descContainer').show();
-            break;
-          case 2:
-            $('#reviewContainer').show();
-            if (cachePageData.needReloadReview) {
-              var productType = cachePageData.productType;
-              cachePageData.needReloadReview = false;
-              $doc.trigger('spa:openloader');
-              review.getList(productType, function(res){
-                $doc.trigger('spa:closeloader');
-                var hasMore = true;
-                if (res.current_page >= res.sum_page) {
-                  hasMore = false;
+            // 提示信息
+            $.newTouch('.group-title-container', function (event) {
+                if ($(this).find('.group-title').hasClass('active')) {
+                    $(this).find('.group-title').removeClass('active');
+                    $(this).next('.group-detail').addClass('hide');
+                } else {
+                    $(this).find('.group-title').addClass('active');
+                    $(this).next('.group-detail').removeClass('hide');
                 }
                 }
-                if (res.success) {
-                  renderReviewTemplate(res.data.comments, hasMore);
+                cachePageData.scroll.refresh();
+            }, $view);
+
+            // 点击用户头像 打开用户个人中心
+            $.newTouch('.user-info-btn', function (event) {
+                var url = 'http://www.yiguanjia.me'
+                if (config.test) {
+                    url = 'http://wwwtest.yiguanjia.me';
                 }
                 }
-                if (cachePageData.reviewScroll) {
-                  cachePageData.reviewScroll.destroy();
-                  cachePageData.reviewScroll = null;
+                var id = $(this).attr('data-id');
+                var param = {
+                    url: url + '/user/' + id
+                };
+                native.openURL(param);
+            }, $view);
+
+            //tab切换
+            $.newTouch('.type-control .control-item', function (event) {
+                if (isShowVideo()) {
+                    $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
                 }
                 }
-                setTimeout(function() {
-                  cachePageData.reviewScroll = new IScroll('#productReviewScroll');
-                }, 10);
-              }, true);
-            }
-            break;
-          case 3:
-            $('#consultationContainer').show();
-            break;
-          default:
-            break;
-        }
-      }, $view);
 
 
-      // 图片预览
-      $.newTouch('.img-preview', function(event){
-        var current = $(this).attr('data-src');
-        var i = $(this).parents('.table-view-cell').index();
-        var imgList = review['reviewDatas'][cachePageData.productType]['list'][i]['pics'];
-        var imgLists = [];
-        imgList.forEach(function(item, index){
-          imgLists.push(item.url)
-        });
-        native.previewImage(imgLists, current);
-      }, $view);
+                var type = $(this).data('type');
+                $('.type-container', $view).hide();
+                switch (type) {
+                    case 1:
+                        $('#descContainer').show();
+                        break;
+                    case 2:
+                        $('#reviewContainer').show();
+                        if (cachePageData.needReloadReview) {
+                            var productType = cachePageData.productType;
+                            cachePageData.needReloadReview = false;
+                            $doc.trigger('spa:openloader');
+                            review.getList(productType, function (res) {
+                                $doc.trigger('spa:closeloader');
+                                var hasMore = true;
+                                if (res.current_page >= res.sum_page) {
+                                    hasMore = false;
+                                }
+                                if (res.success) {
+                                    renderReviewTemplate(res.data.comments, hasMore);
+                                }
+                                if (cachePageData.reviewScroll) {
+                                    cachePageData.reviewScroll.destroy();
+                                    cachePageData.reviewScroll = null;
+                                }
+                                setTimeout(function () {
+                                    cachePageData.reviewScroll = new IScroll('#productReviewScroll');
+                                }, 10);
+                            }, true);
+                        }
+                        break;
+                    case 3:
+                        $('#consultationContainer').show();
+                        break;
+                    default:
+                        break;
+                }
+            }, $view);
 
 
-      //加载更多
-      $.newTouch('.btn-more-review', function(event) {
-        $doc.trigger('spa:openloader');
-        review.getList(cachePageData.productType, function(res){
-          $doc.trigger('spa:closeloader');
-          if (res.success) {
-            var hasMore = true;
-            if (res.current_page >= res.sum_page) {
-              hasMore = false;
-            }
-            renderReviewTemplate(res.data.comments, hasMore);
-            cachePageData.reviewScroll.refresh();
-          }
-        }, false);
-      }, $view);
+            // 图片预览
+            $.newTouch('.img-preview', function (event) {
+                var current = $(this).attr('data-src');
+                var i = $(this).parents('.table-view-cell').index();
+                var imgList = review['reviewDatas'][cachePageData.productType]['list'][i]['pics'];
+                var imgLists = [];
+                imgList.forEach(function (item, index) {
+                    imgLists.push(item.url)
+                });
+                native.previewImage(imgLists, current);
+            }, $view);
 
 
-      //立即下单
-      $.newTouch('.btn-next', function (event) {
-        if (isShowVideo()) {
-          $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
-        }
-        event.preventDefault();
-        var productType = cachePageData.productType;
-        $doc.trigger('spa:navigate', {
-          hash: 'placeOrder',
-          pushData: {
-            productType: productType,
-            serviceType: productType,
-            needReset: true
-          }
-        });
-      }, $view);
+            //加载更多
+            $.newTouch('.btn-more-review', function (event) {
+                $doc.trigger('spa:openloader');
+                review.getList(cachePageData.productType, function (res) {
+                    $doc.trigger('spa:closeloader');
+                    if (res.success) {
+                        var hasMore = true;
+                        if (res.current_page >= res.sum_page) {
+                            hasMore = false;
+                        }
+                        renderReviewTemplate(res.data.comments, hasMore);
+                        cachePageData.reviewScroll.refresh();
+                    }
+                }, false);
+            }, $view);
 
 
-      $.newTouch('.video', function(event) {
-        if ($('#iframe-service-introduce', $view).contents().find('video')[0].attr('controls')) {
-          $('#iframe-service-introduce', $view).contents().find('video')[0].removeAttr('controls');
-        } else {
-          $('#iframe-service-introduce', $view).contents().find('video')[0].attr('controls', 'controls');
-        }
-      }, $view);
+            //立即下单
+            $.newTouch('.btn-next', function (event) {
+                if (isShowVideo()) {
+                    $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
+                }
+                event.preventDefault();
+                var productType = cachePageData.productType;
+                $doc.trigger('spa:navigate', {
+                    hash: 'placeOrder',
+                    pushData: {
+                        productType: productType,
+                        serviceType: productType,
+                        needReset: true
+                    }
+                });
+            }, $view);
 
 
-      dtd.resolve();
-    },
-    beforeopen: function (pageData, dtd) {
-      var $view = this;
-      var $doc = $(document);
-      var pushData = pageData.pushData;
-      var productType = pushData.type;
+            $.newTouch('.video', function (event) {
+                if ($('#iframe-service-introduce', $view).contents().find('video')[0].attr('controls')) {
+                    $('#iframe-service-introduce', $view).contents().find('video')[0].removeAttr('controls');
+                } else {
+                    $('#iframe-service-introduce', $view).contents().find('video')[0].attr('controls', 'controls');
+                }
+            }, $view);
 
 
-      //渲染空页面
-      if (productType) {
-        cachePageData.productType = productType;
-        cachePageData.needReload = pushData.needReload;
-        cachePageData.fromHome = pushData.fromHome;
-        if (cachePageData.needReload) {
-          cachePageData.needReloadReview = true;
-          var commentCounts = 0;
-          var productType = cachePageData.productType;
-          var fromHome = cachePageData.fromHome;
-          $doc.trigger('spa:openloader');
-          review.getList(productType, function(res){
-            $doc.trigger('spa:closeloader');
+            dtd.resolve();
+        },
+        beforeopen: function (pageData, dtd) {
+            var $view = this;
+            var $doc = $(document);
+            var pushData = pageData.pushData;
 
 
-            if (res.success) {
-              commentCounts = res.sum_count;
-              var d = new Image();
-              var url= product.getGroupPics(productType).imglists[0];
-              d.src = product.getGroupPics(productType).url + '/' + url;
-              d.onload = function() {
-                var tpl = template('product/index', {
-                  type: productType,
-                  title: product.getGroupName(productType),
-                  fullName: product.getGroupFullName(productType),
-                  productClassName: product.getProductTitle(productType),
-                  tips: product.getGroupDesc(productType),
-                  picLists: product.getGroupPics(productType),
-                  clientW: document.body.clientWidth * 2,
-                  commentCounts: commentCounts,
-                  fromHome: fromHome,
-                  showNavBar: !config.isWX && !config.isChubao,
-                  isShowVideo: isShowVideo()
-                });
-                $('.spa-page-body', $view).html(tpl);
-                if (cachePageData.scroll) {
-                  cachePageData.scroll.destroy();
-                  cachePageData.scroll = null;
-                }
+            //渲染空页面
+            cachePageData.productType = pushData.produc.type;
+            cachePageData.needReload = pushData.needReload;
+            cachePageData.fromHome = pushData.fromHome;
+            if (cachePageData.needReload) {
+                cachePageData.needReloadReview = true;
+                var commentCounts = 0;
+                var productType = cachePageData.productType;
+                var fromHome = cachePageData.fromHome;
+                $doc.trigger('spa:openloader');
+                review.getList(productType, function (res) {
+                    $doc.trigger('spa:closeloader');
 
 
-                var iframeW = document.body.clientWidth - 30;
-                $('#iframe-service-introduce', $view).height(Math.ceil(iframeW * 360/640));
+                    if (res.success) {
+                        commentCounts = res.sum_count;
+                        var d = new Image();
+                        var url = product.getGroupPics(productType).imglists[0];
+                        d.src = product.getGroupPics(productType).url + '/' + url;
+                        d.onload = function () {
+                            var tpl = template('product/index', {
+                                type: productType,
+                                title: product.getGroupName(productType),
+                                fullName: product.getGroupFullName(productType),
+                                productClassName: product.getProductTitle(productType),
+                                tips: product.getGroupDesc(productType),
+                                picLists: product.getGroupPics(productType),
+                                clientW: document.body.clientWidth * 2,
+                                commentCounts: commentCounts,
+                                fromHome: fromHome,
+                                showNavBar: !config.isWX && !config.isChubao,
+                                isShowVideo: isShowVideo()
+                            });
+                            $('.spa-page-body', $view).html(tpl);
+                            if (cachePageData.scroll) {
+                                cachePageData.scroll.destroy();
+                                cachePageData.scroll = null;
+                            }
 
 
-                setTimeout(function() {
-                  cachePageData.scroll = new IScroll('#productDescScroll');
-                }, 10);
-              }
+                            var iframeW = document.body.clientWidth - 30;
+                            $('#iframe-service-introduce', $view).height(Math.ceil(iframeW * 360 / 640));
 
 
+                            setTimeout(function () {
+                                cachePageData.scroll = new IScroll('#productDescScroll');
+                            }, 10);
+                        }
+
+                    }
+                }, false);
             }
             }
-          }, false);
-        }
-      }
 
 
-      dtd.resolve();
-    },
-    afteropen: function (pageData, dtd) {
-      dtd.resolve();
-      var type = pageData.pushData.type;
-      if (config.isWX) {
-        wx.ready(function(){
-          wx.onMenuShareTimeline({
-            title: '家政服务' + product.getWXShare(type).name + ',首选壹管家',
-            link: 'http://www.yiguanjia.me/o2o/web/index',
-            imgUrl: product.getWXShare(type).className
-          });
-          wx.onMenuShareAppMessage({
-            title: '家政服务' + product.getWXShare(type).name + ',首选壹管家',
-            desc: '全程管家,精心没一个细节',
-            link: 'http://www.yiguanjia.me/o2o/web/index',
-            imgUrl: product.getWXShare(type).className
-          });
-        });
-      }
+            dtd.resolve();
+        },
+        afteropen: function (pageData, dtd) {
+            dtd.resolve();
+            var type = pageData.pushData.type;
+            if (config.isWX) {
+                wx.ready(function () {
+                    wx.onMenuShareTimeline({
+                        title: '家政服务' + product.getWXShare(type).name + ',首选壹管家',
+                        link: 'http://www.yiguanjia.me/o2o/web/index',
+                        imgUrl: product.getWXShare(type).className
+                    });
+                    wx.onMenuShareAppMessage({
+                        title: '家政服务' + product.getWXShare(type).name + ',首选壹管家',
+                        desc: '全程管家,精心没一个细节',
+                        link: 'http://www.yiguanjia.me/o2o/web/index',
+                        imgUrl: product.getWXShare(type).className
+                    });
+                });
+            }
+        }
     }
     }
-  }
 })
 })