|
@@ -1,212 +1,211 @@
|
|
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) {
|
|
|
|
- event.preventDefault();
|
|
|
|
- $(document).trigger('spa:navigate', {
|
|
|
|
- hash: 'placeOrder'
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function renderReviewTemplate(reviews, hasMore) {
|
|
|
|
- var tpl = template('product/reviewList', {
|
|
|
|
- reviews: reviews,
|
|
|
|
- imgW: parseInt((document.body.clientWidth - 30) / 3) - 5
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- $('#productReviewScroll .list-content').append(tpl);
|
|
|
|
-
|
|
|
|
- if (hasMore) {
|
|
|
|
- $('#productReviewScroll .btn-more-container').removeClass('hide');
|
|
|
|
- } else {
|
|
|
|
- $('#productReviewScroll .btn-more-container').addClass('hide');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var cachePageData = {}; //page内部的数据传递
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- title: '壹管家上门服务',
|
|
|
|
- body: '',
|
|
|
|
- init: function (pageData, dtd) {
|
|
|
|
- var $view = this;
|
|
|
|
- var $doc = $(document);
|
|
|
|
-
|
|
|
|
- /* 三个返回操作 */
|
|
|
|
- $.newTouch('.back-button', function (event) {
|
|
|
|
- back.call(this, event);
|
|
|
|
- }, $view);
|
|
|
|
- $view.on('tapBackButton', function (event) {
|
|
|
|
- back.call(this, event);
|
|
|
|
- });
|
|
|
|
- $view.on('swipeRight', function (event) {
|
|
|
|
- back.call(this, event);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 提示信息
|
|
|
|
- $.newTouch('.btn-product-info', function (event) {
|
|
|
|
- $doc.trigger('spa:navigate', {
|
|
|
|
- hash: 'product-info/' + cachePageData.product.type,
|
|
|
|
- pushData: {
|
|
|
|
- needReload: cachePageData.needReload,
|
|
|
|
- fromHome: cachePageData.fromHome
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }, $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);
|
|
|
|
-
|
|
|
|
- // 点击用户头像 打开用户个人中心
|
|
|
|
- $.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);
|
|
|
|
-
|
|
|
|
- //tab切换
|
|
|
|
- $.newTouch('.type-control .control-item', function (event) {
|
|
|
|
- if (isShowVideo()) {
|
|
|
|
- $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var type = $(this).data('type');
|
|
|
|
- $('.type-container', $view).hide();
|
|
|
|
- switch (type) {
|
|
|
|
- case 1:
|
|
|
|
- $('#descContainer').show();
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- $('#reviewContainer').show();
|
|
|
|
- if (cachePageData.needReloadReview) {
|
|
|
|
- cachePageData.needReloadReview = false;
|
|
|
|
- $doc.trigger('spa:openloader');
|
|
|
|
- review.getList(cachePageData.product.type, 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('.img-preview', function (event) {
|
|
|
|
- var current = $(this).attr('data-src');
|
|
|
|
- var i = $(this).parents('.table-view-cell').index();
|
|
|
|
- var imgList = review['reviewDatas'][cachePageData.product.type]['list'][i]['pics'];
|
|
|
|
- var imgLists = [];
|
|
|
|
- imgList.forEach(function (item, index) {
|
|
|
|
- imgLists.push(item.url)
|
|
|
|
- });
|
|
|
|
- native.previewImage(imgLists, current);
|
|
|
|
- }, $view);
|
|
|
|
-
|
|
|
|
- //加载更多
|
|
|
|
- $.newTouch('.btn-more-review', function (event) {
|
|
|
|
- $doc.trigger('spa:openloader');
|
|
|
|
- review.getList(cachePageData.product.type, 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);
|
|
|
|
-
|
|
|
|
- dtd.resolve();
|
|
|
|
- },
|
|
|
|
- beforeopen: function (pageData, dtd) {
|
|
|
|
- var $view = this;
|
|
|
|
- var $doc = $(document);
|
|
|
|
- var pushData = pageData.pushData;
|
|
|
|
-
|
|
|
|
- //渲染空页面
|
|
|
|
- cachePageData.product = pushData.produc;
|
|
|
|
- cachePageData.needReload = pushData.needReload;
|
|
|
|
- if (cachePageData.needReload) {
|
|
|
|
- cachePageData.needReloadReview = true;
|
|
|
|
- var commentCounts = 0;
|
|
|
|
- var productType = cachePageData.product.type;
|
|
|
|
- $doc.trigger('spa:openloader');
|
|
|
|
- review.getList(productType, function (res) {
|
|
|
|
- if (res.success) {
|
|
|
|
- commentCounts = res.sum_count;
|
|
|
|
- var tpl = template('product/index', {
|
|
|
|
- type: productType,
|
|
|
|
- title: cachePageData.product.name,
|
|
|
|
- // tips: product.getGroupDesc(productType),
|
|
|
|
- picLists: cachePageData.product.pics,
|
|
|
|
- commentCounts: commentCounts,
|
|
|
|
- showNavBar: !config.isWX && !config.isChubao,
|
|
|
|
- // isShowVideo: isShowVideo()
|
|
|
|
- });
|
|
|
|
- $('.spa-page-body', $view).html(tpl);
|
|
|
|
-
|
|
|
|
- var iframeW = document.body.clientWidth - 30;
|
|
|
|
- $('#iframe-service-introduce', $view).height(Math.ceil(iframeW * 360 / 640));
|
|
|
|
-
|
|
|
|
- setTimeout(function () {
|
|
|
|
- cachePageData.scroll = new IScroll('#productDescScroll');
|
|
|
|
- }, 1000);
|
|
|
|
-
|
|
|
|
- $doc.trigger('spa:closeloader');
|
|
|
|
- }
|
|
|
|
- }, false);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dtd.resolve();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ /* 返回上一级 */
|
|
|
|
+ function back(event) {
|
|
|
|
+ event.preventDefault();
|
|
|
|
+ $(document).trigger('spa:navigate', {
|
|
|
|
+ hash: 'placeOrder'
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function renderReviewTemplate(reviews, hasMore) {
|
|
|
|
+ var tpl = template('product/reviewList', {
|
|
|
|
+ reviews: reviews,
|
|
|
|
+ imgW: parseInt((document.body.clientWidth - 30) / 3) - 5
|
|
|
|
+ });
|
|
|
|
+ $('#productReviewScroll .list-content').append(tpl);
|
|
|
|
+
|
|
|
|
+ if (hasMore) {
|
|
|
|
+ $('#productReviewScroll .btn-more-container').removeClass('hide');
|
|
|
|
+ } else {
|
|
|
|
+ $('#productReviewScroll .btn-more-container').addClass('hide');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var cachePageData = {}; //page内部的数据传递
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ title: '壹管家上门服务',
|
|
|
|
+ body: '',
|
|
|
|
+ init: function (pageData, dtd) {
|
|
|
|
+ var $view = this;
|
|
|
|
+ var $doc = $(document);
|
|
|
|
+
|
|
|
|
+ /* 三个返回操作 */
|
|
|
|
+ $.newTouch('.back-button', function (event) {
|
|
|
|
+ back.call(this, event);
|
|
|
|
+ }, $view);
|
|
|
|
+ $view.on('tapBackButton', function (event) {
|
|
|
|
+ back.call(this, event);
|
|
|
|
+ });
|
|
|
|
+ $view.on('swipeRight', function (event) {
|
|
|
|
+ back.call(this, event);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 提示信息
|
|
|
|
+ $.newTouch('.btn-product-info', function (event) {
|
|
|
|
+ $doc.trigger('spa:navigate', {
|
|
|
|
+ hash: 'product-info/' + cachePageData.product.type,
|
|
|
|
+ pushData: {
|
|
|
|
+ needReload: cachePageData.needReload,
|
|
|
|
+ fromHome: cachePageData.fromHome
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }, $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);
|
|
|
|
+
|
|
|
|
+ // 点击用户头像 打开用户个人中心
|
|
|
|
+ $.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);
|
|
|
|
+
|
|
|
|
+ //tab切换
|
|
|
|
+ $.newTouch('.type-control .control-item', function (event) {
|
|
|
|
+ if (isShowVideo()) {
|
|
|
|
+ $('#iframe-service-introduce', $view).contents().find('video')[0].pause();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var type = $(this).data('type');
|
|
|
|
+ $('.type-container', $view).hide();
|
|
|
|
+ switch (type) {
|
|
|
|
+ case 1:
|
|
|
|
+ $('#descContainer').show();
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ $('#reviewContainer').show();
|
|
|
|
+ if (cachePageData.needReloadReview) {
|
|
|
|
+ cachePageData.needReloadReview = false;
|
|
|
|
+ $doc.trigger('spa:openloader');
|
|
|
|
+ review.getList(cachePageData.product.type, 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('.img-preview', function (event) {
|
|
|
|
+ var current = $(this).attr('data-src');
|
|
|
|
+ var i = $(this).parents('.table-view-cell').index();
|
|
|
|
+ var imgList = review['reviewDatas'][cachePageData.product.type]['list'][i]['pics'];
|
|
|
|
+ var imgLists = [];
|
|
|
|
+ imgList.forEach(function (item, index) {
|
|
|
|
+ imgLists.push(item.url)
|
|
|
|
+ });
|
|
|
|
+ native.previewImage(imgLists, current);
|
|
|
|
+ }, $view);
|
|
|
|
+
|
|
|
|
+ //加载更多
|
|
|
|
+ $.newTouch('.btn-more-review', function (event) {
|
|
|
|
+ $doc.trigger('spa:openloader');
|
|
|
|
+ review.getList(cachePageData.product.type, 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);
|
|
|
|
+
|
|
|
|
+ dtd.resolve();
|
|
|
|
+ },
|
|
|
|
+ beforeopen: function (pageData, dtd) {
|
|
|
|
+ var $view = this;
|
|
|
|
+ var $doc = $(document);
|
|
|
|
+ var pushData = pageData.pushData;
|
|
|
|
+
|
|
|
|
+ //渲染空页面
|
|
|
|
+ cachePageData.product = pushData.produc;
|
|
|
|
+ cachePageData.needReload = pushData.needReload;
|
|
|
|
+ if (cachePageData.needReload) {
|
|
|
|
+ cachePageData.needReloadReview = true;
|
|
|
|
+ var commentCounts = 0;
|
|
|
|
+ var productType = cachePageData.product.type;
|
|
|
|
+ $doc.trigger('spa:openloader');
|
|
|
|
+ review.getList(productType, function (res) {
|
|
|
|
+ if (res.success) {
|
|
|
|
+ commentCounts = res.sum_count;
|
|
|
|
+ var tpl = template('product/index', {
|
|
|
|
+ type: productType,
|
|
|
|
+ title: cachePageData.product.name,
|
|
|
|
+ // tips: product.getGroupDesc(productType),
|
|
|
|
+ picLists: cachePageData.product.pics,
|
|
|
|
+ commentCounts: commentCounts,
|
|
|
|
+ showNavBar: !config.isWX && !config.isChubao,
|
|
|
|
+ // isShowVideo: isShowVideo()
|
|
|
|
+ });
|
|
|
|
+ $('.spa-page-body', $view).html(tpl);
|
|
|
|
+
|
|
|
|
+ var iframeW = document.body.clientWidth - 30;
|
|
|
|
+ $('#iframe-service-introduce', $view).height(Math.ceil(iframeW * 360 / 640));
|
|
|
|
+
|
|
|
|
+ setTimeout(function () {
|
|
|
|
+ cachePageData.scroll = new IScroll('#productDescScroll');
|
|
|
|
+ }, 1000);
|
|
|
|
+
|
|
|
|
+ $doc.trigger('spa:closeloader');
|
|
|
|
+ }
|
|
|
|
+ }, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dtd.resolve();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
});
|
|
});
|