Commit c13ccea8 authored by linlinjava's avatar linlinjava
Browse files

Merge branch 'dev' of https://github.com/linlinjava/litemall into dev

parents 97338d20 46d2a4e0
...@@ -16,9 +16,9 @@ public class LitemallCollectService { ...@@ -16,9 +16,9 @@ public class LitemallCollectService {
@Resource @Resource
private LitemallCollectMapper collectMapper; private LitemallCollectMapper collectMapper;
public int count(int uid, Integer gid) { public int count(int uid, byte type, Integer gid) {
LitemallCollectExample example = new LitemallCollectExample(); LitemallCollectExample example = new LitemallCollectExample();
example.or().andUserIdEqualTo(uid).andValueIdEqualTo(gid).andDeletedEqualTo(false); example.or().andUserIdEqualTo(uid).andTypeEqualTo(type).andValueIdEqualTo(gid).andDeletedEqualTo(false);
return (int) collectMapper.countByExample(example); return (int) collectMapper.countByExample(example);
} }
......
package org.linlinjava.litemall.wx.web; package org.linlinjava.litemall.wx.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
...@@ -9,18 +16,19 @@ import org.linlinjava.litemall.core.validator.Order; ...@@ -9,18 +16,19 @@ import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort; import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallCollect; import org.linlinjava.litemall.db.domain.LitemallCollect;
import org.linlinjava.litemall.db.domain.LitemallGoods; import org.linlinjava.litemall.db.domain.LitemallGoods;
import org.linlinjava.litemall.db.domain.LitemallTopic;
import org.linlinjava.litemall.db.service.LitemallCollectService; import org.linlinjava.litemall.db.service.LitemallCollectService;
import org.linlinjava.litemall.db.service.LitemallGoodsService; import org.linlinjava.litemall.db.service.LitemallGoodsService;
import org.linlinjava.litemall.db.service.LitemallTopicService;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import javax.validation.constraints.NotNull; import org.springframework.web.bind.annotation.RequestBody;
import java.util.ArrayList; import org.springframework.web.bind.annotation.RequestMapping;
import java.util.HashMap; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/** /**
* 用户收藏服务 * 用户收藏服务
...@@ -35,6 +43,8 @@ public class WxCollectController { ...@@ -35,6 +43,8 @@ public class WxCollectController {
private LitemallCollectService collectService; private LitemallCollectService collectService;
@Autowired @Autowired
private LitemallGoodsService goodsService; private LitemallGoodsService goodsService;
@Autowired
private LitemallTopicService topicService;
/** /**
* 用户收藏列表 * 用户收藏列表
...@@ -64,13 +74,21 @@ public class WxCollectController { ...@@ -64,13 +74,21 @@ public class WxCollectController {
c.put("id", collect.getId()); c.put("id", collect.getId());
c.put("type", collect.getType()); c.put("type", collect.getType());
c.put("valueId", collect.getValueId()); c.put("valueId", collect.getValueId());
if (type == (byte)0){
LitemallGoods goods = goodsService.findById(collect.getValueId()); //查询商品信息
c.put("name", goods.getName()); LitemallGoods goods = goodsService.findById(collect.getValueId());
c.put("brief", goods.getBrief()); c.put("name", goods.getName());
c.put("picUrl", goods.getPicUrl()); c.put("brief", goods.getBrief());
c.put("retailPrice", goods.getRetailPrice()); c.put("picUrl", goods.getPicUrl());
c.put("retailPrice", goods.getRetailPrice());
} else {
//查询专题信息
LitemallTopic topic = topicService.findById(collect.getValueId());
c.put("title", topic.getTitle());
c.put("subtitle", topic.getTitle());
c.put("price", topic.getPrice());
c.put("picUrl", topic.getPicUrl());
}
collects.add(c); collects.add(c);
} }
......
...@@ -147,7 +147,7 @@ public class WxGoodsController { ...@@ -147,7 +147,7 @@ public class WxGoodsController {
// 用户收藏 // 用户收藏
int userHasCollect = 0; int userHasCollect = 0;
if (userId != null) { if (userId != null) {
userHasCollect = collectService.count(userId, id); userHasCollect = collectService.count(userId, (byte)0, id);
} }
// 记录用户的足迹 异步处理 // 记录用户的足迹 异步处理
......
...@@ -7,8 +7,10 @@ import org.linlinjava.litemall.core.validator.Order; ...@@ -7,8 +7,10 @@ import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort; import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallGoods; import org.linlinjava.litemall.db.domain.LitemallGoods;
import org.linlinjava.litemall.db.domain.LitemallTopic; import org.linlinjava.litemall.db.domain.LitemallTopic;
import org.linlinjava.litemall.db.service.LitemallCollectService;
import org.linlinjava.litemall.db.service.LitemallGoodsService; import org.linlinjava.litemall.db.service.LitemallGoodsService;
import org.linlinjava.litemall.db.service.LitemallTopicService; import org.linlinjava.litemall.db.service.LitemallTopicService;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -35,6 +37,8 @@ public class WxTopicController { ...@@ -35,6 +37,8 @@ public class WxTopicController {
private LitemallTopicService topicService; private LitemallTopicService topicService;
@Autowired @Autowired
private LitemallGoodsService goodsService; private LitemallGoodsService goodsService;
@Autowired
private LitemallCollectService collectService;
/** /**
* 专题列表 * 专题列表
...@@ -59,7 +63,7 @@ public class WxTopicController { ...@@ -59,7 +63,7 @@ public class WxTopicController {
* @return 专题详情 * @return 专题详情
*/ */
@GetMapping("detail") @GetMapping("detail")
public Object detail(@NotNull Integer id) { public Object detail(@LoginUser Integer userId, @NotNull Integer id) {
LitemallTopic topic = topicService.findById(id); LitemallTopic topic = topicService.findById(id);
List<LitemallGoods> goods = new ArrayList<>(); List<LitemallGoods> goods = new ArrayList<>();
for (Integer i : topic.getGoods()) { for (Integer i : topic.getGoods()) {
...@@ -67,10 +71,17 @@ public class WxTopicController { ...@@ -67,10 +71,17 @@ public class WxTopicController {
if (null != good) if (null != good)
goods.add(good); goods.add(good);
} }
// 用户收藏
int userHasCollect = 0;
if (userId != null) {
userHasCollect = collectService.count(userId, (byte)1, id);
}
Map<String, Object> entity = new HashMap<String, Object>(); Map<String, Object> entity = new HashMap<String, Object>();
entity.put("topic", topic); entity.put("topic", topic);
entity.put("goods", goods); entity.put("goods", goods);
entity.put("userHasCollect", userHasCollect);
return ResponseUtil.ok(entity); return ResponseUtil.ok(entity);
} }
......
...@@ -10,7 +10,9 @@ Page({ ...@@ -10,7 +10,9 @@ Page({
topicList: [], topicList: [],
commentCount: 0, commentCount: 0,
commentList: [], commentList: [],
topicGoods: [] topicGoods: [],
collect: false,
userHasCollect: 0
}, },
onLoad: function(options) { onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
...@@ -25,7 +27,9 @@ Page({ ...@@ -25,7 +27,9 @@ Page({
if (res.errno === 0) { if (res.errno === 0) {
that.setData({ that.setData({
topic: res.data.topic, topic: res.data.topic,
topicGoods: res.data.goods topicGoods: res.data.goods,
userHasCollect: res.data.userHasCollect,
collect: res.data.userHasCollect == 1
}); });
WxParse.wxParse('topicDetail', 'html', res.data.topic.content, that); WxParse.wxParse('topicDetail', 'html', res.data.topic.content, that);
...@@ -59,6 +63,31 @@ Page({ ...@@ -59,6 +63,31 @@ Page({
} }
}); });
}, },
//添加或是取消收藏
addCollectOrNot: function() {
let that = this;
util.request(api.CollectAddOrDelete, {
type: 1,
valueId: this.data.id
}, "POST")
.then(function(res) {
if (that.data.userHasCollect == 1) {
that.setData({
collect: false,
userHasCollect: 0
});
} else {
that.setData({
collect: true,
userHasCollect: 1
});
}
});
},
postComment() { postComment() {
if (!app.globalData.hasLogin) { if (!app.globalData.hasLogin) {
wx.navigateTo({ wx.navigateTo({
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
<scroll-view class="sv-goods" wx:if="{{topicGoods.length > 0 }}"> <scroll-view class="sv-goods" wx:if="{{topicGoods.length > 0 }}">
<view class="topic-goods"> <view class="topic-goods">
<view class="h"> <view class="h">
<text class="t">专题商品</text> <text class="t">专题商品</text>
<van-icon class="i" bindtap="addCollectOrNot" name="star" wx:if="{{collect}}" color="#ab956d"/>
<van-icon class="i" bindtap="addCollectOrNot" name="star-o" wx:else/>
</view> </view>
<view class="b"> <view class="b">
<view class="item" wx:for="{{topicGoods}}" wx:for-index="index" wx:for-item="item" wx:key="id"> <view class="item" wx:for="{{topicGoods}}" wx:for-index="index" wx:for-item="item" wx:key="id">
......
...@@ -144,6 +144,13 @@ ...@@ -144,6 +144,13 @@
border-bottom: 1px solid #d9d9d9; border-bottom: 1px solid #d9d9d9;
} }
.topic-goods .h .i {
display: block;
float: right;
width: 33rpx;
height: 33rpx;
}
.topic-goods .h .t { .topic-goods .h .t {
display: block; display: block;
float: left; float: left;
......
...@@ -27,9 +27,21 @@ Page({ ...@@ -27,9 +27,21 @@ Page({
totalPages: res.data.pages totalPages: res.data.pages
}); });
} }
}).finally(() => {
wx.hideLoading(); wx.hideLoading();
}); });
}, },
switchTab: function(event) {
let type = event.currentTarget.dataset.index;
this.setData({
collectList: [],
type,
page: 1,
limit: 10,
totalPages: 1
});
this.getCollectList();
},
onLoad: function(options) { onLoad: function(options) {
this.getCollectList(); this.getCollectList();
}, },
...@@ -61,15 +73,13 @@ Page({ ...@@ -61,15 +73,13 @@ Page({
onUnload: function() { onUnload: function() {
// 页面关闭 // 页面关闭
}, },
openGoods(event) { openCollect(event) {
let that = this; let that = this;
let index = event.currentTarget.dataset.index; let index = event.currentTarget.dataset.index;
let goodsId = this.data.collectList[index].valueId; let valueId = this.data.collectList[index].valueId;
//触摸时间距离页面打开的毫秒数 //触摸时间距离页面打开的毫秒数
var touchTime = that.data.touchEnd - that.data.touchStart; var touchTime = that.data.touchEnd - that.data.touchStart;
console.log(touchTime);
//如果按下时间大于350为长按 //如果按下时间大于350为长按
if (touchTime > 350) { if (touchTime > 350) {
wx.showModal({ wx.showModal({
...@@ -80,10 +90,9 @@ Page({ ...@@ -80,10 +90,9 @@ Page({
util.request(api.CollectAddOrDelete, { util.request(api.CollectAddOrDelete, {
type: that.data.type, type: that.data.type,
valueId: goodsId valueId: valueId
}, 'POST').then(function(res) { }, 'POST').then(function(res) {
if (res.errno === 0) { if (res.errno === 0) {
console.log(res.data);
wx.showToast({ wx.showToast({
title: '删除成功', title: '删除成功',
icon: 'success', icon: 'success',
...@@ -99,9 +108,12 @@ Page({ ...@@ -99,9 +108,12 @@ Page({
} }
}) })
} else { } else {
var prefix = '/pages/goods/goods?id='
if(this.data.type == 1){
prefix = "/pages/topicDetail/topicDetail?id="
}
wx.navigateTo({ wx.navigateTo({
url: '/pages/goods/goods?id=' + goodsId, url: prefix + valueId,
}); });
} }
}, },
......
<view class="container"> <view class="container">
<view class="collect-switch">
<view class="item {{ type == 0 ? 'active' : ''}}" bindtap="switchTab" data-index='0'>
<view class="txt">商品收藏</view>
</view>
<view class="item {{ type == 1 ? 'active' : ''}}" bindtap="switchTab" data-index='1'>
<view class="txt">专题收藏</view>
</view>
</view>
<view class="no-collect" wx:if="{{collectList.length <= 0}}"> <view class="no-collect" wx:if="{{collectList.length <= 0}}">
<view class="c"> <view class="c">
<text>还没有收藏</text> <text>还没有收藏</text>
</view> </view>
</view> </view>
<view class="collect-list" wx:else> <view class="{{type==0 ? 'goods-list' : 'topic-list'}}" wx:else>
<view class="item" bindtap="openGoods" bindtouchstart="touchStart" bindtouchend="touchEnd" wx:for="{{collectList}}" wx:key="id" data-index="{{index}}"> <view class="item" bindtap="openCollect" bindtouchstart="touchStart" bindtouchend="touchEnd" wx:for="{{collectList}}" wx:key="id" data-index="{{index}}">
<image class="img" src="{{item.picUrl}}"></image> <image class="img" src="{{item.picUrl}}"></image>
<view class="info"> <view class="info" wx:if="{{type==0}}" >
<view class="name">{{item.name}}</view> <view class="name">{{item.name}}</view>
<view class="subtitle">{{item.brief}}</view> <view class="subtitle">{{item.brief}}</view>
<view class="price">¥{{item.retailPrice}}</view> <view class="price">¥{{item.retailPrice}}</view>
</view> </view>
<view class="info" wx:if="{{type==1}}">
<text class="title">{{item.title}}</text>
<text class="desc">{{item.subtitle}}</text>
<text class="price">{{item.price}}元起</text>
</view>
</view> </view>
</view> </view>
......
...@@ -10,6 +10,34 @@ page { ...@@ -10,6 +10,34 @@ page {
height: auto; height: auto;
overflow: hidden; overflow: hidden;
} }
.collect-switch {
width: 100%;
background: #fff;
height: 84rpx;
}
.collect-switch .item {
display: inline-block;
height: 82rpx;
width: 50%;
padding: 0 15rpx;
text-align: center;
}
.collect-switch .item .txt {
display: inline-block;
height: 82rpx;
padding: 0 20rpx;
line-height: 82rpx;
color: #9a9ba1;
font-size: 30rpx;
width: 170rpx;
}
.collect-switch .item.active .txt {
color: #ab956d;
border-bottom: 4rpx solid #ab956d;
}
.no-collect { .no-collect {
width: 100%; width: 100%;
...@@ -34,7 +62,8 @@ page { ...@@ -34,7 +62,8 @@ page {
color: #999; color: #999;
} }
.collect-list { /*商品收藏列表样式*/
.goods-list {
width: 100%; width: 100%;
height: auto; height: auto;
overflow: hidden; overflow: hidden;
...@@ -43,7 +72,7 @@ page { ...@@ -43,7 +72,7 @@ page {
border-top: 1px solid #e1e1e1; border-top: 1px solid #e1e1e1;
} }
.item { .goods-list .item {
height: 212rpx; height: 212rpx;
width: 720rpx; width: 720rpx;
background: #fff; background: #fff;
...@@ -51,17 +80,17 @@ page { ...@@ -51,17 +80,17 @@ page {
border-bottom: 1px solid #e1e1e1; border-bottom: 1px solid #e1e1e1;
} }
.item:last-child { .goods-list .item:last-child {
border-bottom: 1px solid #fff; border-bottom: 1px solid #fff;
} }
.item .img { .goods-list .item .img {
float: left; float: left;
width: 150rpx; width: 150rpx;
height: 150rpx; height: 150rpx;
} }
.item .info { .goods-list .item .info {
float: right; float: right;
width: 540rpx; width: 540rpx;
height: 150rpx; height: 150rpx;
...@@ -71,22 +100,87 @@ page { ...@@ -71,22 +100,87 @@ page {
padding-left: 20rpx; padding-left: 20rpx;
} }
.item .info .name { .goods-list .item .info .name {
font-size: 28rpx; font-size: 28rpx;
color: #333; color: #333;
line-height: 40rpx; line-height: 40rpx;
} }
.item .info .subtitle { .goods-list .item .info .subtitle {
margin-top: 8rpx; margin-top: 8rpx;
font-size: 24rpx; font-size: 24rpx;
color: #888; color: #888;
line-height: 40rpx; line-height: 40rpx;
} }
.item .info .price { .goods-list .item .info .price {
margin-top: 8rpx; margin-top: 8rpx;
font-size: 28rpx; font-size: 28rpx;
color: #333; color: #333;
line-height: 40rpx; line-height: 40rpx;
} }
/*专题收藏列表样式*/
.topic-list{
width: 750rpx;
height: 100%;
overflow: hidden;
background: #f4f4f4;
}
.topic-list .item{
width: 100%;
height: 625rpx;
overflow: hidden;
background: #fff;
margin-bottom: 20rpx;
}
.topic-list .img{
width: 100%;
height: 415rpx;
}
.topic-list .info{
width: 100%;
height: 210rpx;
overflow: hidden;
}
.topic-list .title{
display: block;
text-align: center;
width: 100%;
height: 33rpx;
line-height: 35rpx;
color: #333;
overflow: hidden;
font-size: 35rpx;
margin-top: 30rpx;
}
.topic-list .desc{
display: block;
text-align: center;
position: relative;
width: auto;
height: 24rpx;
line-height: 24rpx;
overflow: hidden;
color: #999;
font-size: 24rpx;
margin-top: 16rpx;
margin-bottom: 30rpx;
}
.topic-list .price{
display: block;
text-align: center;
width: 100%;
height: 27rpx;
line-height: 27rpx;
overflow: hidden;
color: #b4282d;
font-size: 27rpx;
}
\ No newline at end of file
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
</view> </view>
<view class='user_column_item' bindtap='goCollect'> <view class='user_column_item' bindtap='goCollect'>
<image class='user_column_item_image' src='/static/images/collect.png'></image> <image class='user_column_item_image' src='/static/images/collect.png'></image>
<view class='user_column_item_text'>商品收藏</view> <view class='user_column_item_text'>收藏</view>
</view> </view>
<view class='user_column_item' bindtap='goFootprint'> <view class='user_column_item' bindtap='goFootprint'>
<image class='user_column_item_image' src='/static/images/footprint.png'></image> <image class='user_column_item_image' src='/static/images/footprint.png'></image>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment