Merge branch 'dev' of https://github.com/linlinjava/litemall into dev
This commit is contained in:
@@ -16,9 +16,9 @@ public class LitemallCollectService {
|
||||
@Resource
|
||||
private LitemallCollectMapper collectMapper;
|
||||
|
||||
public int count(int uid, Integer gid) {
|
||||
public int count(int uid, byte type, Integer gid) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
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.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -9,18 +16,19 @@ import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCollect;
|
||||
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.LitemallGoodsService;
|
||||
import org.linlinjava.litemall.db.service.LitemallTopicService;
|
||||
import org.linlinjava.litemall.wx.annotation.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 用户收藏服务
|
||||
@@ -35,6 +43,8 @@ public class WxCollectController {
|
||||
private LitemallCollectService collectService;
|
||||
@Autowired
|
||||
private LitemallGoodsService goodsService;
|
||||
@Autowired
|
||||
private LitemallTopicService topicService;
|
||||
|
||||
/**
|
||||
* 用户收藏列表
|
||||
@@ -64,13 +74,21 @@ public class WxCollectController {
|
||||
c.put("id", collect.getId());
|
||||
c.put("type", collect.getType());
|
||||
c.put("valueId", collect.getValueId());
|
||||
|
||||
LitemallGoods goods = goodsService.findById(collect.getValueId());
|
||||
c.put("name", goods.getName());
|
||||
c.put("brief", goods.getBrief());
|
||||
c.put("picUrl", goods.getPicUrl());
|
||||
c.put("retailPrice", goods.getRetailPrice());
|
||||
|
||||
if (type == (byte)0){
|
||||
//查询商品信息
|
||||
LitemallGoods goods = goodsService.findById(collect.getValueId());
|
||||
c.put("name", goods.getName());
|
||||
c.put("brief", goods.getBrief());
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class WxGoodsController {
|
||||
// 用户收藏
|
||||
int userHasCollect = 0;
|
||||
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;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
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.LitemallGoodsService;
|
||||
import org.linlinjava.litemall.db.service.LitemallTopicService;
|
||||
import org.linlinjava.litemall.wx.annotation.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -35,6 +37,8 @@ public class WxTopicController {
|
||||
private LitemallTopicService topicService;
|
||||
@Autowired
|
||||
private LitemallGoodsService goodsService;
|
||||
@Autowired
|
||||
private LitemallCollectService collectService;
|
||||
|
||||
/**
|
||||
* 专题列表
|
||||
@@ -59,7 +63,7 @@ public class WxTopicController {
|
||||
* @return 专题详情
|
||||
*/
|
||||
@GetMapping("detail")
|
||||
public Object detail(@NotNull Integer id) {
|
||||
public Object detail(@LoginUser Integer userId, @NotNull Integer id) {
|
||||
LitemallTopic topic = topicService.findById(id);
|
||||
List<LitemallGoods> goods = new ArrayList<>();
|
||||
for (Integer i : topic.getGoods()) {
|
||||
@@ -67,10 +71,17 @@ public class WxTopicController {
|
||||
if (null != 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>();
|
||||
entity.put("topic", topic);
|
||||
entity.put("goods", goods);
|
||||
entity.put("userHasCollect", userHasCollect);
|
||||
return ResponseUtil.ok(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ Page({
|
||||
topicList: [],
|
||||
commentCount: 0,
|
||||
commentList: [],
|
||||
topicGoods: []
|
||||
topicGoods: [],
|
||||
collect: false,
|
||||
userHasCollect: 0
|
||||
},
|
||||
onLoad: function(options) {
|
||||
// 页面初始化 options为页面跳转所带来的参数
|
||||
@@ -25,7 +27,9 @@ Page({
|
||||
if (res.errno === 0) {
|
||||
that.setData({
|
||||
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);
|
||||
@@ -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() {
|
||||
if (!app.globalData.hasLogin) {
|
||||
wx.navigateTo({
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
<scroll-view class="sv-goods" wx:if="{{topicGoods.length > 0 }}">
|
||||
<view class="topic-goods">
|
||||
<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 class="b">
|
||||
<view class="item" wx:for="{{topicGoods}}" wx:for-index="index" wx:for-item="item" wx:key="id">
|
||||
|
||||
@@ -144,6 +144,13 @@
|
||||
border-bottom: 1px solid #d9d9d9;
|
||||
}
|
||||
|
||||
.topic-goods .h .i {
|
||||
display: block;
|
||||
float: right;
|
||||
width: 33rpx;
|
||||
height: 33rpx;
|
||||
}
|
||||
|
||||
.topic-goods .h .t {
|
||||
display: block;
|
||||
float: left;
|
||||
|
||||
@@ -27,9 +27,21 @@ Page({
|
||||
totalPages: res.data.pages
|
||||
});
|
||||
}
|
||||
}).finally(() => {
|
||||
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) {
|
||||
this.getCollectList();
|
||||
},
|
||||
@@ -61,15 +73,13 @@ Page({
|
||||
onUnload: function() {
|
||||
// 页面关闭
|
||||
},
|
||||
openGoods(event) {
|
||||
|
||||
openCollect(event) {
|
||||
let that = this;
|
||||
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;
|
||||
console.log(touchTime);
|
||||
//如果按下时间大于350为长按
|
||||
if (touchTime > 350) {
|
||||
wx.showModal({
|
||||
@@ -80,10 +90,9 @@ Page({
|
||||
|
||||
util.request(api.CollectAddOrDelete, {
|
||||
type: that.data.type,
|
||||
valueId: goodsId
|
||||
valueId: valueId
|
||||
}, 'POST').then(function(res) {
|
||||
if (res.errno === 0) {
|
||||
console.log(res.data);
|
||||
wx.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'success',
|
||||
@@ -99,9 +108,12 @@ Page({
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
||||
var prefix = '/pages/goods/goods?id='
|
||||
if(this.data.type == 1){
|
||||
prefix = "/pages/topicDetail/topicDetail?id="
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: '/pages/goods/goods?id=' + goodsId,
|
||||
url: prefix + valueId,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
<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="c">
|
||||
<text>还没有收藏</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="collect-list" wx:else>
|
||||
<view class="item" bindtap="openGoods" bindtouchstart="touchStart" bindtouchend="touchEnd" wx:for="{{collectList}}" wx:key="id" data-index="{{index}}">
|
||||
<view class="{{type==0 ? 'goods-list' : 'topic-list'}}" wx:else>
|
||||
<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>
|
||||
<view class="info">
|
||||
<view class="info" wx:if="{{type==0}}" >
|
||||
<view class="name">{{item.name}}</view>
|
||||
<view class="subtitle">{{item.brief}}</view>
|
||||
<view class="price">¥{{item.retailPrice}}</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>
|
||||
|
||||
|
||||
@@ -10,6 +10,34 @@ page {
|
||||
height: auto;
|
||||
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 {
|
||||
width: 100%;
|
||||
@@ -34,7 +62,8 @@ page {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.collect-list {
|
||||
/*商品收藏列表样式*/
|
||||
.goods-list {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
overflow: hidden;
|
||||
@@ -43,7 +72,7 @@ page {
|
||||
border-top: 1px solid #e1e1e1;
|
||||
}
|
||||
|
||||
.item {
|
||||
.goods-list .item {
|
||||
height: 212rpx;
|
||||
width: 720rpx;
|
||||
background: #fff;
|
||||
@@ -51,17 +80,17 @@ page {
|
||||
border-bottom: 1px solid #e1e1e1;
|
||||
}
|
||||
|
||||
.item:last-child {
|
||||
.goods-list .item:last-child {
|
||||
border-bottom: 1px solid #fff;
|
||||
}
|
||||
|
||||
.item .img {
|
||||
.goods-list .item .img {
|
||||
float: left;
|
||||
width: 150rpx;
|
||||
height: 150rpx;
|
||||
}
|
||||
|
||||
.item .info {
|
||||
.goods-list .item .info {
|
||||
float: right;
|
||||
width: 540rpx;
|
||||
height: 150rpx;
|
||||
@@ -71,22 +100,87 @@ page {
|
||||
padding-left: 20rpx;
|
||||
}
|
||||
|
||||
.item .info .name {
|
||||
.goods-list .item .info .name {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
line-height: 40rpx;
|
||||
}
|
||||
|
||||
.item .info .subtitle {
|
||||
.goods-list .item .info .subtitle {
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: #888;
|
||||
line-height: 40rpx;
|
||||
}
|
||||
|
||||
.item .info .price {
|
||||
.goods-list .item .info .price {
|
||||
margin-top: 8rpx;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
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;
|
||||
}
|
||||
@@ -55,7 +55,7 @@
|
||||
</view>
|
||||
<view class='user_column_item' bindtap='goCollect'>
|
||||
<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 class='user_column_item' bindtap='goFootprint'>
|
||||
<image class='user_column_item_image' src='/static/images/footprint.png'></image>
|
||||
|
||||
Reference in New Issue
Block a user