Authored by zhangxiaoru

favorite

@@ -67,10 +67,10 @@ app.use(session({ @@ -67,10 +67,10 @@ app.use(session({
67 domain: 'yohobuy.com', 67 domain: 'yohobuy.com',
68 httpOnly: false 68 httpOnly: false
69 }, 69 },
70 - store: new MemcachedStore({  
71 - hosts: config.memcache.session,  
72 - prefix: 'yohobuy_session:'  
73 - }) 70 + // store: new MemcachedStore({
  71 + // hosts: config.memcache.session,
  72 + // prefix: 'yohobuy_session:'
  73 + // })
74 })); 74 }));
75 75
76 app.use((req, res, next) => { 76 app.use((req, res, next) => {
  1 +/**
  2 +* 个人中心我的收藏
  3 +* @author: zxr<xiaoru.zhang@yoho.cn>
  4 +* @date: 2016/08/16
  5 +*/
  6 +
  7 +'use strict';
  8 +
  9 +const favoriteModel = require('../models/favorite');
  10 +
  11 +const favorite = (req, res, next) => {
  12 +
  13 + // favoriteModel.getfavoriteData(uid, page, limit).then((result) => {
  14 +
  15 + // }).catch(next);
  16 + res.render('favorite', {
  17 + module: 'home',
  18 + page: 'favorite',
  19 + favorite: {
  20 + productUrl: 'm.yohobuy.com',
  21 + brandUrl: 'm.yohobuy.com'
  22 + }
  23 + })
  24 +};
  25 +
  26 +let favProduct = (req, res, next) => {
  27 + let uid = req.user.uid;
  28 + let page = req.query.page || 1;
  29 + let limit = 10;
  30 +
  31 + favoriteModel.favProduct(uid, page, limit).then((result) => {
  32 + res.render('favorite/favorite-product', {
  33 + layout: false,
  34 + hasFavProduct: result
  35 + })
  36 + }).catch(next);
  37 +};
  38 +
  39 +let favfavBrand = (req, res, next) => {
  40 + let uid = req.user.uid;
  41 + let page = req.query.page || 1;
  42 + let limit = 10;
  43 +
  44 + favoriteModel.favfavBrand(uid, page, limit).then((result) => {
  45 + res.render('favorite/favorite-brand', {
  46 + layout: false,
  47 + hasFavBrand: result
  48 + })
  49 + }).catch(next);
  50 +};
  51 +
  52 +let favoriteDelete = (req, res, next) => {
  53 + let uid = req.user.uid;
  54 + let type = 'product';
  55 + let favId = req.body.id;
  56 +
  57 + favoriteModel.favoriteDelete(uid, type, favId).then((result) => {
  58 + res.json(result);
  59 + }).catch(next);
  60 +};
  61 +
  62 +module.exports = {
  63 + favorite,
  64 + favProduct,
  65 + favfavBrand,
  66 + favoriteDelete
  67 +}
  1 +/**
  2 +* 个人中心我的收藏
  3 +* @author: zxr<xiaoru.zhang@yoho.cn>
  4 +* @date: 2016/08/16
  5 +*/
  6 +
  7 +'use strict';
  8 +
  9 +const logger = global.yoho.logger;
  10 +const api = global.yoho.API;
  11 +const serviceAPI = global.yoho.ServiceAPI;
  12 +const camelCase = global.yoho.camelCase;
  13 +const _ = require('lodash');
  14 +const config = global.yoho.config;
  15 +const helpers = global.yoho.helpers;
  16 +
  17 +const favProduct = (uid, page, limit) => {
  18 +
  19 + return api.get('', {
  20 + method: 'app.favorite.product',
  21 + uid: uid,
  22 + page: page,
  23 + limit: limit
  24 + }).then((result) => {
  25 + // console.log(result)
  26 + let resu = {
  27 + hasFavProduct: []
  28 + };
  29 +
  30 + if (result && result.code === 200) {
  31 +
  32 + let list = camelCase(result);
  33 +
  34 + if (page > 1 && list === []) {
  35 + resu.end = true;
  36 + return;
  37 + }
  38 +
  39 + if (page <= list.data.pageTotal) {
  40 + let hasFavProduct = [];
  41 +
  42 + _.forEach(list.data.productList, function(val) {
  43 + let obj = {};
  44 + // if (empty(val.productSkn)) {
  45 + // continue;
  46 + // }
  47 +
  48 + if (val.goodsId && val.cnAlphabet) {
  49 + obj =_.assign (obj, {
  50 + link: config.siteUrl + '/product/list/pro_' +
  51 + val.productId + '_' + val.goodsId + '/' +
  52 + val.cnAlphabet + '.html'
  53 + });
  54 + } else {
  55 + obj =_.assign (obj, {
  56 + link: ''
  57 + });
  58 + }
  59 +
  60 + if (val.image) {
  61 + obj = _.assign(obj, {
  62 + imgUrl: val.image
  63 + });
  64 + } else {
  65 + obj = _.assign(obj, {
  66 + imgUrl: ''
  67 + });
  68 + }
  69 +
  70 + if (val.marketPrice - val.salesPrice > 0) {
  71 + obj = _.assign(obj, {
  72 + discountPrice: val.salesPrice
  73 + });
  74 + }
  75 +
  76 + if (val.priceDown > 0) {
  77 + obj = _.assign(obj, {
  78 + savePrice: '¥' + val.priceDown
  79 + });
  80 + } else {
  81 + obj = _.assign(obj, {
  82 + savePrice: false
  83 + });
  84 + }
  85 +
  86 + if (val.storage <= 0) {
  87 + obj = _.assign(obj, {
  88 + sellOut: true
  89 + });
  90 + }
  91 +
  92 + obj = _.assign(obj, {
  93 + favId: val.productId,
  94 + title: val.productName,
  95 + price: '¥' + val.marketPrice,
  96 + invalidGoods: val.status === 0
  97 + });
  98 +
  99 + resu.hasFavProduct.push(obj);
  100 + });
  101 +
  102 + } else {
  103 + resu.push({
  104 + end: true
  105 + });
  106 + }
  107 +
  108 + return resu.hasFavProduct;
  109 + } else {
  110 + logger.error('收藏商品 cood 不是 200');
  111 + }
  112 + });
  113 +};
  114 +
  115 +const favfavBrand = (uid, page, limit) => {
  116 +
  117 + return api.get('', {
  118 + method: 'app.favorite.brand',
  119 + uid: uid,
  120 + page: page,
  121 + limit: limit
  122 + }).then((result) => {
  123 + let hasFavBrand = [];
  124 +
  125 + if (result && result.code === 200) {
  126 + let list = camelCase(result);
  127 +
  128 + if (page > 1 && list === []) {
  129 + resu.end = true;
  130 + return;
  131 + }
  132 +
  133 + if (page <= list.data.pageTotal) {
  134 + let brand = [];
  135 +
  136 + _.forEach(list.data.brandList, function(val) {
  137 + let obj = {
  138 + productList: []
  139 + };
  140 + let brandPro = [];
  141 + // if (empty(val.productSkn)) {
  142 + // continue;
  143 + // }
  144 + if (val.brandOrShopType === 'brandOrShopType') {
  145 + obj = _.assign(obj, {
  146 + link: helpers.urlFormat('/product/index/brand', {
  147 + shop_id: val.shopId
  148 + })
  149 + })
  150 + } else {
  151 + obj = _.assign(obj, {
  152 + link: helpers.urlFormat('', {}, val.brandDomain)
  153 +
  154 + })
  155 + }
  156 +
  157 + obj = _.assign(obj, {
  158 + id: val.brandId,
  159 + brandName: val.brandName,
  160 + updata: val.newProductNum,
  161 + discount: val.productDiscountNum,
  162 + brandImg: val.brandIco
  163 + });
  164 +
  165 + _.forEach(val.newProduct, function(data) {
  166 + obj.productList.push({
  167 + link: '/product/pro_' + data.productId + '_' + data.goods[0].id + '/' + data.cnAlphabet + '.html',
  168 + imgUrl: data.defaultImages,
  169 + price: '¥' + data.marketPrice
  170 + })
  171 +
  172 + if (data.marketPrice > data.salesPrice) {
  173 + obj.productList.push({
  174 + discount: '¥' + data.salesPrice
  175 + })
  176 + }
  177 + })
  178 +
  179 + hasFavBrand.push(obj);
  180 + });
  181 +
  182 + console.log(hasFavBrand)
  183 + return hasFavBrand;
  184 + } else {
  185 + hasFavBrand.push({
  186 + end: true
  187 + });
  188 + }
  189 +
  190 + } else {
  191 + logger.error('收藏品牌 cood 不是 200');
  192 + }
  193 + });
  194 +}
  195 +
  196 +const favoriteDelete = (uid, type, favId) => {
  197 +
  198 + return api.get('', {
  199 + method: 'app.favorite.cancel',
  200 + uid: uid,
  201 + type: type,
  202 + fav_id: favId
  203 + })
  204 +}
  205 +
  206 +module.exports = {
  207 + favProduct,
  208 + favfavBrand,
  209 + favoriteDelete
  210 +};
@@ -10,8 +10,21 @@ const router = express.Router(); // eslint-disable-line @@ -10,8 +10,21 @@ const router = express.Router(); // eslint-disable-line
10 const cRoot = './controllers'; 10 const cRoot = './controllers';
11 11
12 const personalController = require(`${cRoot}/qrcode`); 12 const personalController = require(`${cRoot}/qrcode`);
  13 +const favorite = require(`${cRoot}/favorite`);
13 14
14 // 查看二维码 15 // 查看二维码
15 router.get('/QRcode/:id', personalController.QRcode); 16 router.get('/QRcode/:id', personalController.QRcode);
16 17
  18 +//我的收藏
  19 +router.get('/favorite', favorite.favorite);
  20 +
  21 +//收藏的商品
  22 +router.get('/favProduct', favorite.favProduct);
  23 +
  24 +//收藏的品牌
  25 +router.get('/favBrand', favorite.favfavBrand);
  26 +
  27 +//取消收藏
  28 +router.post('/favoriteDel', favorite.favoriteDelete);
  29 +
17 module.exports = router; 30 module.exports = router;
  1 +<div class="yoho-favorite-page yoho-page">
  2 + {{# favorite}}
  3 + <ul id="fav-tab" class="fav-tab {{# brandTab}}brand-tab{{/ brandTab}}">
  4 + <li>收藏的商品</li>
  5 + <li>收藏的品牌</li>
  6 + </ul>
  7 + <div class="fav-content" id="fav-content">
  8 + <div class="fav-type">
  9 + <ul class="fav-product-list"></ul>
  10 + <div class="fav-content-loading"></div>
  11 +
  12 + <div class="fav-null-box hide">
  13 + <span class="fav-null">您暂无收藏任何商品</span>
  14 + <a class="go-shopping" href="{{productUrl}}">随便逛逛</a>
  15 + </div>
  16 + <div class="fav-load-more fav-load-background hide"></div>
  17 + </div>
  18 + <div class="fav-type">
  19 + <div class="fav-brand-swiper-wrapper"></div>
  20 + <div class="fav-content-loading"></div>
  21 +
  22 + <div class="fav-null-box hide">
  23 + <span class="fav-null">您暂无收藏任何品牌</span>
  24 + <a class="go-shopping" href="{{brandUrl}}">随便逛逛</a>
  25 + </div>
  26 + <div class="fav-brand-load-more fav-load-background hide"></div>
  27 + </div>
  28 + </div>
  29 + {{/ favorite}}
  30 +</div>
  1 +{{# hasFavBrand}}
  2 +<div class="fav-brand-swiper">
  3 + <a class="swiper-header" href="{{link}}">
  4 + <div class="swiper-logo">
  5 + <img src="{{image brandImg 30 30}}" alt=""/>
  6 + </div>
  7 + <div class="brand-info">
  8 + <span class="brand-name">{{brandName}}</span>
  9 + <div class="brand-update">
  10 + {{# update}}
  11 + <span class="brand-new">上新<b>{{.}}</b></span>
  12 + {{/ update}}
  13 + {{# discount}}
  14 + <span class="brand-discount">折扣<b>{{.}}</b></span>
  15 + {{/ discount}}
  16 + </div>
  17 + </div>
  18 + <span class="fav-more"></span>
  19 + </a>
  20 + {{#if productList}}
  21 + <div id="swiper-container-{{id}}" class="swiper-container" data-id="{{id}}">
  22 + <ul class="swiper-wrapper swiper-wrapper-{{id}}">
  23 + {{# productList}}
  24 + <li class="swiper-slide">
  25 + <a href="{{link}}">
  26 + <img class="swiper-lazy" data-src="{{image imgUrl 97 150}}" alt=""/>
  27 + </a>
  28 + <div class="brand-product">
  29 + <div class="{{# discount}}price-discount{{/ discount}}">
  30 + {{# discount}}<span>{{.}}<span>{{/ discount}}
  31 + <b>{{price}}</b>
  32 + </div>
  33 + </div>
  34 + <div class="swiper-lazy-preloader"></div>
  35 + </li>
  36 + {{/ productList}}
  37 + </ul>
  38 + </div>
  39 + {{/if}}
  40 +</div>
  41 +{{/ hasFavBrand}}
  1 +{{# hasFavProduct}}
  2 +<li data-id="{{favId}}" class="{{#if invalidGoods}}invalidGoods{{/if}}">
  3 + <a href="{{link}}">
  4 + <div class="fav-img-box">
  5 + <img src="{{imgUrl}}" alt=""/>
  6 + </div>
  7 + <div class="fav-info-list">
  8 + <h2>{{title}}</h2>
  9 + <div class="fav-price">
  10 + {{# discountPrice}}
  11 + <span class="new-price">{{.}}</span>
  12 + {{/ discountPrice}}
  13 + <span class="fav-price {{# discountPrice}}price-underline{{/ discountPrice}}">{{price}}</span>
  14 + </div>
  15 + {{# savePrice}}
  16 + <div class="save-price save-price-number">
  17 + 比收藏时降价了<span>{{.}}</span>
  18 + <span class="del-fav iconfont">&#xe621;</span>
  19 + </div>
  20 + {{/ savePrice}}
  21 +
  22 + {{^ savePrice}}
  23 + <div class="save-price">
  24 + {{# sellOut}}
  25 + <span class="sell-out">已售罄</span>
  26 + {{/ sellOut}}
  27 + <span class="del-fav iconfont">&#xe621;</span>
  28 + </div>
  29 + {{/ savePrice}}
  30 + </div>
  31 + </a>
  32 +</li>
  33 +{{/ hasFavProduct}}
  1 +/**
  2 + * search model
  3 + * @author: wsl<shuiling.wang@yoho.cn>
  4 + * @date: 2016/07/21
  5 + */
  6 +'use strict';
  7 +const utils = '../../../utils';
  8 +const productProcess = require(`${utils}/product-process`);
  9 +const searchProcess = require(`${utils}/search-process`);
  10 +const _ = require('lodash');
  11 +const logger = global.yoho.logger;
  12 +const api = global.yoho.API;
  13 +const camelCase = global.yoho.camelCase;
  14 +
  15 +/**
  16 + * 品牌名称处理
  17 + * @param {[object]} list
  18 + * @return {[object]}
  19 + */
  20 +const _processBrandNames = (list) => {
  21 + const formatData = [];
  22 +
  23 + list = list || [];
  24 + list = camelCase(list);
  25 +
  26 + _.forEach(list, (item) => {
  27 + _.forEach(item, (obj) => {
  28 + formatData.push({
  29 + brandDomain: obj.brandDomain,
  30 + brandName: obj.brandName
  31 + });
  32 + });
  33 + });
  34 +
  35 + return formatData;
  36 +};
  37 +
  38 +/**
  39 + * 品牌名称处理
  40 + * @param {[object]} list
  41 + * @return {[object]}
  42 + */
  43 +const _processClassNames = (list) => {
  44 + const formatData = {
  45 + first: {},
  46 + second: {}
  47 + };
  48 +
  49 + list = list || [];
  50 + list = camelCase(list);
  51 +
  52 + _.forEach(list, (item) => {
  53 + _.forEach(item, (obj) => {
  54 + formatData.first[obj.categoryId] = obj.categoryName;
  55 +
  56 + if (obj.sub) {
  57 + _.forEach(obj.sub, (sub) => {
  58 + formatData.second[sub.categoryId] = sub.categoryName;
  59 + });
  60 + }
  61 +
  62 + });
  63 + });
  64 +
  65 + return formatData;
  66 +};
  67 +
  68 +/**
  69 + * 商品搜索接口请求
  70 + * @param {[object]} params
  71 + * @return {[array]}
  72 + */
  73 +const _searchGoods = (params) => {
  74 + let method = 'app.search.li';
  75 +
  76 + // 排除基本筛选项默认值为0的对象
  77 + for (let str in params) {
  78 + if (str !== 'order' && params[str] === '0' || params[str] === null) {
  79 + delete params[str];
  80 + }
  81 + }
  82 +
  83 + if (params.channel) {
  84 + params.yh_channel = searchProcess.getChannelType(params.channel);
  85 + delete params.channel;
  86 + }
  87 +
  88 + params = _.assign({
  89 + limit: '60',
  90 + status: 1,
  91 + sales: 'Y',
  92 + stocknumber: 1,
  93 + attribute_not: 2
  94 + }, params);
  95 +
  96 + if (params.order) {
  97 + params.order = searchProcess.getTypeCont(params.type || '', params.order);
  98 + }
  99 +
  100 + return api.get('', _.assign({
  101 + method: method
  102 + }, params), {
  103 + cache: true
  104 + });
  105 +};
  106 +
  107 +/**
  108 + * 获取商品数据
  109 + */
  110 +const getSearchData = (params) => {
  111 + return _searchGoods(params).then((result) => {
  112 + if (result && result.code === 200) {
  113 + return productProcess.processProductList(result.data.product_list || []);
  114 + } else {
  115 + logger.error('get product search api return code is not 200');
  116 + return [];
  117 + }
  118 + });
  119 +};
  120 +
  121 +/**
  122 + * 获取筛选数据
  123 + * @param {[object]} params
  124 + * @return {[array]}
  125 + */
  126 +const getFilterData = (params) => {
  127 + return _searchGoods(params).then((result) => {
  128 + if (result && result.code === 200) {
  129 + return productProcess.processFilter(result.data.filter || []);
  130 + } else {
  131 + logger.error('get filter data api return code is not 200');
  132 + return [];
  133 + }
  134 + });
  135 +};
  136 +
  137 +/**
  138 + * 获取所有的品类名称
  139 + **/
  140 +const getClassNames = () => {
  141 + return api.get('', {
  142 + method: 'app.sort.get'
  143 + }, {
  144 + cache: true
  145 + }).then((result) => {
  146 + if (result && result.code === 200) {
  147 + return _processClassNames(result.data);
  148 + } else {
  149 + logger.error('get category name api return code is not 200');
  150 + return {};
  151 + }
  152 + });
  153 +};
  154 +
  155 +/**
  156 + * 获取所有的品牌名称
  157 + **/
  158 +const getAllBrandNames = () => {
  159 + return api.get('', {
  160 + method: 'app.brand.brandlist'
  161 + }, {
  162 + cache: true
  163 + }).then((result) => {
  164 + if (result && result.code === 200) {
  165 + return _processBrandNames(result.data.brands);
  166 + } else {
  167 + logger.error('get brand all name data api return code is not 200');
  168 + return {};
  169 + }
  170 + });
  171 +};
  172 +
  173 +/**
  174 + * 获取热门搜索
  175 + **/
  176 +const getSearchIndex = () => {
  177 + return api.get('', {
  178 + method: 'app.search.getTerms'
  179 + }).then((result) => {
  180 + if (result && result.code === 200) {
  181 + return result.data.hotTerms;
  182 + } else {
  183 + logger.error('Hot Search return code is not 200');
  184 + return {};
  185 + }
  186 + });
  187 +};
  188 +
  189 +const getFuzzyDatas = (params) => {
  190 + return api.get('', {
  191 + method: 'app.search.fuzzy',
  192 + keyword: params
  193 + }).then((result) => {
  194 + if (result && result.code === 200) {
  195 + return result.data;
  196 + } else {
  197 + logger.error('FuzzyDatas return code is not 200');
  198 + return {};
  199 + }
  200 + });
  201 +};
  202 +
  203 +module.exports = {
  204 + getSearchData,
  205 + getFilterData,
  206 + getAllBrandNames,
  207 + getClassNames,
  208 + getSearchIndex,
  209 + getFuzzyDatas
  210 +};
@@ -17,8 +17,8 @@ module.exports = { @@ -17,8 +17,8 @@ module.exports = {
17 // api: 'http://devapi.yoho.cn:58078/', 17 // api: 'http://devapi.yoho.cn:58078/',
18 // service: 'http://devservice.yoho.cn:58077/' 18 // service: 'http://devservice.yoho.cn:58077/'
19 19
20 - api: 'http://testapi.yoho.cn:28078/',  
21 - service: 'http://testservice.yoho.cn:28077/' 20 + api: 'http://api.yoho.cn/',
  21 + service: 'http://service.yoho.cn/'
22 }, 22 },
23 subDomains: { 23 subDomains: {
24 host: '.m.yohobuy.com', 24 host: '.m.yohobuy.com',
@@ -33,9 +33,9 @@ module.exports = { @@ -33,9 +33,9 @@ module.exports = {
33 useOneapm: false, 33 useOneapm: false,
34 useCache: false, 34 useCache: false,
35 memcache: { 35 memcache: {
36 - master: ['192.168.102.222:12111'],  
37 - slave: ['192.168.102.222:12111'],  
38 - session: ['192.168.102.222:12111'], 36 + master: ['192.168.102.205:12111'],
  37 + slave: ['192.168.102.205:12111'],
  38 + session: ['192.168.102.205:12111'],
39 timeout: 1000, 39 timeout: 1000,
40 retries: 0 40 retries: 0
41 }, 41 },

2.5 KB | W: | H:

3.6 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
  1 +/**
  2 + * 个人中心--收藏
  3 + * @author: zxr
  4 + * @date: 2016/8/16
  5 + */
  6 +var $ = require('yoho-jquery'),
  7 + Hammer = require('yoho-hammer'),
  8 + Swiper = require('yoho-swiper');
  9 +
  10 +var diaLog = require('../plugin/dialog');
  11 +
  12 +var tip = require('../plugin/tip');
  13 +
  14 +var $navLi = $('#fav-tab > li'),
  15 + $favContainer = $('.fav-content > .fav-type'),
  16 + swiperObj = {},
  17 + favTabHammer,
  18 + favContentHammer,
  19 + $loadMore = $('.fav-load-more'),
  20 + $brandLoadMore = $('.fav-brand-load-more'),
  21 + winH = $(window).height(),
  22 + footerH = $('#yoho-footer').height(),
  23 + $favProductList = $('.fav-product-list'),
  24 + $favBrandList = $('.fav-brand-swiper-wrapper'),
  25 + pageId = 1,
  26 + brandPageId = 1, //收藏品牌的当前页数
  27 + lockId = true,
  28 + brandLockId = true, //收藏品牌是否可下拉加载更多
  29 + brandTab = false; //当前是否停留在收藏品牌页
  30 +
  31 +require('../common');
  32 +
  33 +function showFavTab(index) {
  34 + $navLi.filter('.active').removeClass('active');
  35 + $navLi.eq(index).addClass('active');
  36 +
  37 + $favContainer.filter('.show').removeClass('show');
  38 + $favContainer.eq(index).addClass('show');
  39 +}
  40 +
  41 +//初始化swiper
  42 +function initSwiper(data) {
  43 + var i,
  44 + idStrReg = /container-(\d+)['"]{1}/gi,
  45 + idReg = /\d+/,
  46 + idArr = data.match(idStrReg),
  47 + idArrLen = idArr.length,
  48 + containerId;
  49 +
  50 + //$swiperList = $('.swiper-container');
  51 + for (i = 0; i < idArrLen; i++) {
  52 +
  53 + /*id = $swiperList.eq(i).attr('data-id');
  54 +
  55 + if (!!swiperObj[id]) {
  56 + swiperObj[id].destroy(true, true);
  57 + }*/
  58 +
  59 + containerId = idArr[i].match(idReg)[0];
  60 +
  61 + swiperObj[containerId] = new Swiper('#swiper-container-' + containerId, {
  62 + slidesPerView: 'auto',
  63 + grabCursor: true,
  64 + slideElement: 'li',
  65 + wrapperClass: 'swiper-wrapper-' + containerId,
  66 + lazyLoading: true,
  67 + watchSlidesVisibility: true
  68 + });
  69 + }
  70 +}
  71 +
  72 +// 上拉加载更多
  73 +function loadData($parent, url, page) {
  74 + if (url === 'favBrand') {
  75 + brandLockId = true;
  76 + } else {
  77 + lockId = true;
  78 + }
  79 + $.ajax({
  80 + method: 'get',
  81 + url: '/home/' + url,
  82 + data: {
  83 + page: page
  84 + },
  85 + success: function(data) {
  86 + var $loadingMask = $parent.closest('.fav-type').find('.fav-content-loading');
  87 +
  88 + if (url === 'favBrand') {
  89 + $brandLoadMore.addClass('hide');
  90 + } else {
  91 + $loadMore.addClass('hide');
  92 + }
  93 +
  94 + if (data === ' ') {
  95 + $loadingMask.addClass('hide');
  96 + $parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
  97 + window.rePosFooter();
  98 + } else if (data === 'end') {
  99 +
  100 + //处理data等于end时如果loadingMask存在且没有hide样式的情况
  101 + if ($loadingMask && !$loadingMask.hasClass('hide')) {
  102 + $loadingMask.addClass('hide');
  103 +
  104 + //$parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
  105 + }
  106 +
  107 + $parent.closest('.fav-type').find('.fav-load-background')
  108 + .removeClass('fav-load-background').html('没有更多了');
  109 +
  110 + // hf: fixes bug to 修改没有数据还调接口,加载错误页面问题
  111 + brandLockId = true;
  112 + lockId = true;
  113 + } else if (data.length > 10) {
  114 + $parent.append(data);
  115 +
  116 + //如果有数据loadingMask会被remove掉
  117 + $loadingMask.remove();
  118 + if (url === 'favBrand') {
  119 + initSwiper(data);//如果是收藏品牌需要初始化swiper
  120 +
  121 + brandLockId = false;//请求成功后解锁品牌收藏page++
  122 + } else {
  123 + lockId = false;//请求成功后解锁商品收藏page++
  124 + }
  125 + }
  126 + window.rePosFooter();
  127 + }
  128 + });
  129 +}
  130 +
  131 +// 如果从品牌收藏入口进入
  132 +if ($('#fav-tab').hasClass('brand-tab')) {
  133 + showFavTab(1);
  134 + loadData($favBrandList, 'favBrand', 1);
  135 + brandTab = true;
  136 + window.rePosFooter();
  137 +} else {
  138 + showFavTab(0);
  139 + loadData($favProductList, 'favProduct', 1);
  140 + brandTab = false;
  141 + window.rePosFooter();
  142 +}
  143 +
  144 +favTabHammer = new Hammer(document.getElementById('fav-tab'));
  145 +favTabHammer.on('tap', function(e) {
  146 + var $cur = $(e.target).closest('li'),
  147 + index;
  148 +
  149 + if ($cur.length === 0 || $cur.hasClass('active')) {
  150 + return;
  151 + }
  152 +
  153 + index = $cur.index();
  154 +
  155 + if (index === 0) {
  156 + brandTab = false;
  157 + if ($favProductList.find('li').length === 0 &&
  158 + $favProductList.closest('.fav-type').find('.fav-null-box').hasClass('hide')) {
  159 + loadData($favProductList, 'favProduct', 1);
  160 + }
  161 + } else {
  162 + brandTab = true;
  163 + if ($favBrandList.find('div').length === 0 &&
  164 + $favBrandList.closest('.fav-type').find('.fav-null-box').hasClass('hide')) {
  165 + loadData($favBrandList, 'favBrand', 1);
  166 + }
  167 + }
  168 + showFavTab(index);
  169 + window.rePosFooter();
  170 +
  171 +});
  172 +
  173 +//删除收藏的商品
  174 +favContentHammer = new Hammer(document.getElementById('fav-content'));
  175 +
  176 +favContentHammer.on('tap', function(e) {
  177 + var id = '';
  178 +
  179 + if (!$(e.target).hasClass('del-fav')) {
  180 + return;
  181 + }
  182 +
  183 + diaLog.showDialog({
  184 + dialogText: '您确定要取消收藏吗?',
  185 + hasFooter: {
  186 + leftBtnText: '取消',
  187 + rightBtnText: '确定'
  188 + }
  189 + }, function() {
  190 + id = $(e.target).closest('li').data('id');
  191 + $.ajax({
  192 + method: 'post',
  193 + url: '/home/favoriteDel',
  194 + data: {
  195 + id: id
  196 + }
  197 + }).then(function(data) {
  198 +
  199 + if (data.code === 200) {
  200 + diaLog.showDialog({
  201 + autoHide: true,
  202 + fast: true,
  203 + dialogText: '已经取消收藏'
  204 + });
  205 + $(e.target).closest('li').remove();
  206 + } else if (data.code === 400) {
  207 + diaLog.showDialog({
  208 + autoHide: true,
  209 + fast: true,
  210 + dialogText: data.message
  211 + });
  212 + } else {
  213 + diaLog.showDialog({
  214 + autoHide: true,
  215 + fast: true,
  216 + dialogText: '取消收藏失败'
  217 + });
  218 + }
  219 + }).fail(function() {
  220 +
  221 + //TODO
  222 +
  223 + diaLog.showDialog({
  224 + autoHide: true,
  225 + dialogText: '网络错误~'
  226 + });
  227 + });
  228 + });
  229 +});
  230 +
  231 +function scrollHandler() {
  232 +
  233 + //距离底部未1/4列表高度+底部高度的时候加载更多
  234 + if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $favBrandList.height() - footerH) {
  235 + if (brandTab) {
  236 + $brandLoadMore.filter('.hide').removeClass('hide');
  237 +
  238 + if (!brandLockId) {
  239 + brandPageId++;
  240 + loadData($favBrandList, 'favBrand', brandPageId);
  241 + }
  242 +
  243 + } else {
  244 +
  245 + $loadMore.filter('.hide').removeClass('hide');
  246 +
  247 + if (!lockId) {
  248 + pageId++;
  249 + loadData($favProductList, 'favProduct', pageId);
  250 + }
  251 + }
  252 + }
  253 +}
  254 +
  255 +//srcoll to load more
  256 +$(window).scroll(scrollHandler);
  257 +
  258 +$(document).on('touchend', '.swiper-header', function() {
  259 + var url = $(this).find('.fav-more').attr('href');
  260 +
  261 + if (url) {
  262 + window.location.href = url;
  263 + }
  264 +});
  265 +
  266 +$('.invalidGoods').on('touchstart touchend', function(e) {
  267 + var $this = $(e.target).closest('span');
  268 +
  269 + if ($this.hasClass('del-fav')) {
  270 + return;
  271 + }
  272 + tip.show('商品已下架');
  273 + return false;
  274 +});
  1 +.yoho-favorite-page {
  2 + width: 100%;
  3 + height: auto;
  4 +
  5 + .fav-tab {
  6 + width: 100%;
  7 + height: 88px;
  8 + line-height: 88px;
  9 + border-bottom: 1px solid #e0e0e0;
  10 + color: #b0b0b0;
  11 + font-size: 26px;
  12 +
  13 + li {
  14 + width: 50%;
  15 + height: 100%;
  16 + float: left;
  17 + text-align: center;
  18 +
  19 + &.active {
  20 + color: #444;
  21 + }
  22 +
  23 + &:nth-last-of-type(1) {
  24 + float: right;
  25 + position: relative;
  26 +
  27 + &:after {
  28 + content: '';
  29 + display: block;
  30 + width: 1px;
  31 + height: 44px;
  32 + position: absolute;
  33 + left: 0;
  34 + top: 22px;
  35 + background: #b0b0b0;
  36 + }
  37 + }
  38 + }
  39 + }
  40 +
  41 + .fav-content {
  42 +
  43 + .fav-type {
  44 + display: none;
  45 + }
  46 + .show {
  47 + display: block;
  48 + }
  49 +
  50 + .fav-null {
  51 + font-size: 22px;
  52 + color: #444;
  53 + display: block;
  54 + margin-top: 100px;
  55 + text-align: center;
  56 +
  57 + &:before {
  58 + content: '';
  59 + display: block;
  60 + width: 188px;
  61 + height: 171px;
  62 + /*background: resolve("me/fav/fav-null.png");*/
  63 + background-size: 100% 100%;
  64 + margin: 0 auto 45px auto;
  65 + }
  66 + }
  67 +
  68 + .go-shopping {
  69 + width: 472px;
  70 + height: 88px;
  71 + line-height: 88px;
  72 + margin: 80px auto 0 auto;
  73 + background: #444;
  74 + text-align: center;
  75 + color: #fff;
  76 + display: block;
  77 + font-size: 26px;
  78 + border-radius:.2rem;
  79 + }
  80 +
  81 + .fav-product-list {
  82 + list-style: none;
  83 + margin-left: 30px;
  84 +
  85 + li {
  86 + height: auto;
  87 + overflow: hidden;
  88 + margin-top: 20px;
  89 + }
  90 +
  91 + .fav-img-box {
  92 + width: 90px;
  93 + height: 120px;
  94 + float: left;
  95 + margin-right: 24px;
  96 +
  97 + img {
  98 + display: block;
  99 + overflow: hidden;
  100 + width: 100%;
  101 + height: 100%;
  102 + }
  103 + }
  104 +
  105 + .fav-info-list {
  106 + color: #444;
  107 + font-size: 24px;
  108 + border-bottom: 1px solid #e0e0e0;
  109 + padding-bottom: 20px;
  110 + height: 120px;
  111 + overflow: hidden;
  112 + position: relative;
  113 +
  114 + h2 {
  115 + width: 430px;
  116 + /*white-space: nowrap;
  117 + overflow: hidden;*/
  118 + text-overflow: ellipsis;
  119 + }
  120 +
  121 + .fav-price {
  122 +
  123 + .new-price {
  124 + color: #d1021c;
  125 + }
  126 +
  127 + .price-underline {
  128 + text-decoration: line-through;
  129 + margin-left: 15px;
  130 + color: #b0b0b0;
  131 + }
  132 + }
  133 +
  134 + .save-price {
  135 +
  136 + position: absolute;
  137 + bottom: 20px;
  138 + left: 0;
  139 + width: 100%;
  140 + min-height: 24px;
  141 +
  142 + &.save-price-number {
  143 + text-indent: 42px;
  144 + color: #b0b0b0;
  145 + padding-top: 3px;
  146 +
  147 + &:before {
  148 + content: '';
  149 + display: block;
  150 + /*background: url("/me/fav/save-price.png");*/
  151 + width: 32px;
  152 + height: 32px;
  153 +
  154 + position: absolute;
  155 + top: 50%;
  156 + left: 0;
  157 + margin-top: -16px;
  158 +
  159 + }
  160 + span {
  161 + margin-left: 15px;
  162 + }
  163 + .del-fav {
  164 + text-indent: 0;
  165 + margin-left: 0;
  166 + }
  167 + }
  168 +
  169 + span {
  170 + color: #d1021c;
  171 +
  172 + &.sell-out {
  173 + padding: 5px 18px;
  174 + color: #fffefe;
  175 + border-radius: 20px;
  176 + background: #7f7f7f;
  177 + font-size: 22px;
  178 + }
  179 +
  180 + &.del-fav {
  181 + width: 2rem;
  182 + height: 1.5rem;
  183 + line-height: 1.5rem;
  184 + position: absolute;
  185 + top: 50%;
  186 + margin-top: -0.75rem;
  187 + right: 0;
  188 + color: #999;
  189 +
  190 + padding-right: 0.75rem;
  191 + text-align: right;
  192 +
  193 + }
  194 + }
  195 + }
  196 + }
  197 + }
  198 + /*品牌收藏*/
  199 + .fav-brand-swiper {
  200 + border-top: 1px solid #e0e0e0;
  201 + border-bottom: 28px solid #f0f0f0;
  202 + position: relative;
  203 +
  204 + &:nth-of-type(1) {
  205 + border-top: 0;
  206 + }
  207 +
  208 + &:after {
  209 + content: '';
  210 + position: absolute;
  211 + left: 0;
  212 + bottom: -2px;
  213 + border-top: 1px solid #e0e0e0;
  214 + display: block;
  215 + width: 100%;
  216 + height: 1px;
  217 + }
  218 +
  219 + .swiper-header {
  220 + height: 100px;
  221 + padding: 20px 30px;
  222 + display: inline-block;
  223 + position: relative;
  224 + width: 100%;
  225 + box-sizing: border-box;
  226 +
  227 + .swiper-logo {
  228 + height: 100%;
  229 + display: inline-block;
  230 + float: left;
  231 + margin-right: 45px;
  232 +
  233 + > img {
  234 + max-height: 100%;
  235 + vertical-align: middle;
  236 + }
  237 + }
  238 +
  239 + .brand-info {
  240 + float: left;
  241 +
  242 + .brand-name {
  243 + font-size: 28px;
  244 +
  245 + b {
  246 + color: #b0b0b0;
  247 + font-weight: normal;
  248 + }
  249 + }
  250 +
  251 + .brand-update {
  252 + font-size: 22px;
  253 +
  254 + b {
  255 + color: #b0b0b0;
  256 + font-weight: normal;
  257 + }
  258 +
  259 + .brand-new {
  260 + color: #86bf4a;
  261 + margin-right: 24px;
  262 + }
  263 + .brand-discount {
  264 + color: #d1021c;
  265 + }
  266 + }
  267 + }
  268 + .fav-more {
  269 + width: 2.5rem;
  270 + height: 2.5rem;
  271 + position: absolute;
  272 + top: 0;
  273 + right: 0;
  274 +
  275 + &:after {
  276 + width: 18px;
  277 + height: 29px;
  278 + background: url("/me/fav/fav-more.png");
  279 + position: absolute;
  280 + top: 50%;
  281 + right: 30px;
  282 + margin-top: -15px;
  283 + content: '';
  284 + }
  285 + }
  286 + }
  287 + .swiper-container {
  288 + height: 365px;
  289 + margin: 0 30px;
  290 +
  291 + .swiper-slide {
  292 + width: 225px;
  293 + height: 100%;
  294 + float: left;
  295 + padding-right: 30px;
  296 +
  297 + &:nth-last-of-type(1) {
  298 + padding-right: 0;
  299 + }
  300 +
  301 + img {
  302 + display: block;
  303 + width: 100%;
  304 + height: 300px;
  305 + overflow: hidden;
  306 + }
  307 + .brand-product {
  308 + height: 65px;
  309 + line-height: 65px;
  310 + text-align: center;
  311 + font-size: 22px;
  312 +
  313 + .price-discount {
  314 + span {
  315 + color: #d1021c
  316 + }
  317 + b {
  318 + color: #b0b0b0;
  319 + text-decoration: line-through;
  320 + font-weight: normal;
  321 + margin-left: 13px;
  322 + }
  323 + }
  324 + }
  325 + }
  326 + }
  327 + }
  328 + }
  329 +
  330 + .fav-load-more,.fav-brand-load-more {
  331 + width: 100%;
  332 + height: 2rem;
  333 + line-height: 2rem;
  334 + text-align: center;
  335 + color: #444;
  336 +
  337 + &.load-background {
  338 + /*background: resolve('loading.gif') center center no-repeat;*/
  339 + background-size: auto 40%;
  340 + }
  341 + }
  342 + .fav-content-loading {
  343 + width: 100%;
  344 + height: 2rem;
  345 + /*background: resolve('loading.gif') center center no-repeat;*/
  346 + background-size: auto 40%;
  347 +
  348 + position: absolute;
  349 + top: 50%;
  350 + left: 0;
  351 + margin-top: -1rem;
  352 + }
  353 +}
1 @import "qrcode"; 1 @import "qrcode";
  2 +@import "favorite";