shop-list.page.js
2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require('product/shop/shop.page.css');
const $ = require('yoho-jquery');
const tip = require('plugin/tip');
const ProductListWithFilter = require('product/list/product-list-with-filter');
const $shopIntroBtn = $('#shopIntroBtn');
const $introBox = $('#introBox');
const $closeIntroBtn = $('#closeIntroBtn');
const $collectShopIcon = $('#collectShop');
const shopId = $('#shopId').val();
const productListWithFilterModel =
new ProductListWithFilter({
shop_id: shopId,
page: 2, // 首页服务端已经渲染
isShopList: 'Y' // 传给 filter,表明调用哪个接口获取筛选面板的数据
}, 'product/search/shop/goods');
productListWithFilterModel.getFilter();
/**
* 添加或者取消收藏处理
* @param {*} opt
*/
function collectOrNotShop(opt) {
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/opt/favoriteBrand',
data: {
id: shopId,
opt: opt,
type: 'shop'
},
xhrFields: {
withCredentials: true
},
success: function(data) {
if (data.code === 200) {
$collectShopIcon.toggleClass('coled');
// 提示
if (opt === 'ok') {
tip.show('添加收藏成功');
} else {
tip.show('取消收藏成功');
}
} else if (data.code === 400) {
location.href = data.data;// 未登录跳转登录页
} else {
tip.show(data.message);
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
/**
* 打开店铺介绍
*/
$shopIntroBtn.on('click', () => {
$introBox.removeClass('hide');
});
/**
* 关闭店铺介绍
*/
$closeIntroBtn.on('click', () => {
$introBox.addClass('hide');
});
/**
* 添加或者取消收藏操作
*/
$collectShopIcon.on('click', () => {
if ($collectShopIcon.hasClass('coled')) {
collectOrNotShop();
} else {
collectOrNotShop('ok');
}
});