Browse Source

fix 专题商品显示代码
Merge pull request !8 from youc3576/master

youc3576 7 years ago
parent
commit
a50998e68f

+ 40 - 26
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxTopicController.java

@@ -1,6 +1,8 @@
 package org.linlinjava.litemall.wx.web;
 
+import org.linlinjava.litemall.db.domain.LitemallGoods;
 import org.linlinjava.litemall.db.domain.LitemallTopic;
+import org.linlinjava.litemall.db.service.LitemallGoodsService;
 import org.linlinjava.litemall.db.service.LitemallTopicService;
 import org.linlinjava.litemall.core.util.ResponseUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.constraints.NotNull;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -21,6 +24,8 @@ import java.util.Map;
 public class WxTopicController {
     @Autowired
     private LitemallTopicService topicService;
+    @Autowired
+    private LitemallGoodsService goodsService;
 
     /**
      * 专题列表
@@ -28,17 +33,17 @@ public class WxTopicController {
      * @param page 分页页数
      * @param size 分页大小
      * @return 专题列表
-     *   成功则
-     *  {
-     *      errno: 0,
-     *      errmsg: '成功',
-     *      data:
-     *          {
-     *              data: xxx,
-     *              count: xxx
-     *          }
-     *  }
-     *   失败则 { errno: XXX, errmsg: XXX }
+     * 成功则
+     * {
+     * errno: 0,
+     * errmsg: '成功',
+     * data:
+     * {
+     * data: xxx,
+     * count: xxx
+     * }
+     * }
+     * 失败则 { errno: XXX, errmsg: XXX }
      */
     @GetMapping("list")
     public Object list(@RequestParam(defaultValue = "1") Integer page,
@@ -56,18 +61,27 @@ public class WxTopicController {
      *
      * @param id 专题ID
      * @return 专题详情
-     *   成功则
-     *  {
-     *      errno: 0,
-     *      errmsg: '成功',
-     *      data: xxx
-     *  }
-     *   失败则 { errno: XXX, errmsg: XXX }
+     * 成功则
+     * {
+     * errno: 0,
+     * errmsg: '成功',
+     * data: xxx
+     * }
+     * 失败则 { errno: XXX, errmsg: XXX }
      */
     @GetMapping("detail")
     public Object detail(@NotNull Integer id) {
+        Map<String, Object> data = new HashMap<>();
         LitemallTopic topic = topicService.findById(id);
-        return ResponseUtil.ok(topic);
+        data.put("topic", topic);
+        List<LitemallGoods> goods = new ArrayList<>();
+        for (Integer i : topic.getGoods()) {
+            LitemallGoods good = goodsService.findByIdVO(i);
+            if (null != good)
+                goods.add(good);
+        }
+        data.put("goods", goods);
+        return ResponseUtil.ok(data);
     }
 
     /**
@@ -75,13 +89,13 @@ public class WxTopicController {
      *
      * @param id 专题ID
      * @return 相关专题
-     *   成功则
-     *  {
-     *      errno: 0,
-     *      errmsg: '成功',
-     *      data: xxx
-     *  }
-     *   失败则 { errno: XXX, errmsg: XXX }
+     * 成功则
+     * {
+     * errno: 0,
+     * errmsg: '成功',
+     * data: xxx
+     * }
+     * 失败则 { errno: XXX, errmsg: XXX }
      */
     @GetMapping("related")
     public Object related(@NotNull Integer id) {

+ 5 - 5
litemall-wx/pages/topicDetail/topicDetail.js

@@ -9,7 +9,8 @@ Page({
     topic: {},
     topicList: [],
     commentCount: 0,
-    commentList: []
+    commentList: [],
+    topicGoods: []
   },
   onLoad: function (options) {
     // 页面初始化 options为页面跳转所带来的参数
@@ -20,12 +21,12 @@ Page({
 
     util.request(api.TopicDetail, { id: that.data.id }).then(function (res) {
       if (res.errno === 0) {
-
         that.setData({
-          topic: res.data,
+          topic: res.data.topic,
+          topicGoods: res.data.goods
         });
 
-        WxParse.wxParse('topicDetail', 'html', res.data.content, that);
+        WxParse.wxParse('topicDetail', 'html', res.data.topic.content, that);
       }
     });
 
@@ -41,7 +42,6 @@ Page({
     let that = this;
     util.request(api.CommentList, { valueId: that.data.id, type: 1, showType: 0, page: 1, size: 5 }).then(function (res) {
       if (res.errno === 0) {
-
         that.setData({
           commentList: res.data.data,
           commentCount: res.data.count

+ 20 - 0
litemall-wx/pages/topicDetail/topicDetail.wxml

@@ -3,8 +3,28 @@
     <import src="../../lib/wxParse/wxParse.wxml"/> 
     <template is="wxParse" data="{{wxParseData:topicDetail.nodes}}"/>
   </scroll-view>
+  <scroll-view class="sv-goods">
   <view class="topic-goods">
+   <view class="h">
+      <text class="t">专题商品</text>
+      <image bindtap="postComment" class="i" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/comment-add-2aca147c3f.png"></image>
+    </view>
+     <view class="b">
+   <view class="item" wx:for="{{topicGoods}}" wx:for-index="index" wx:for-item="item" wx:key="id">
+    <navigator url="/pages/goods/goods?id={{item.id}}">
+     <image class="img" src="{{item.picUrl}}" background-size="cover"></image>
+     <view class="right">
+      <view class="text">
+       <text class="name">{{item.name}}</text>
+       <text class="desc">{{item.brief}}</text>
+       <text class="price">¥{{item.retailPrice}}</text>
+      </view>
+     </view>
+    </navigator>
+   </view>
   </view>
+  </view>
+  </scroll-view>
   <scroll-view class="comments">
     <view class="h">
       <text class="t">精选留言</text>

+ 59 - 3
litemall-wx/pages/topicDetail/topicDetail.wxss

@@ -1,6 +1,3 @@
-
-
-
 .content{
     width: 100%;
     height: auto;
@@ -138,6 +135,65 @@
     width: 115rpx;
 }
 
+.sv-goods{
+    width: 100%;
+    height: auto;
+    padding-left:30rpx;
+    background: #fff;
+    margin-top: 20rpx;
+}
+
+.topic-goods .b .item {
+ border-top: 1px solid #d9d9d9;
+ margin: 0 20rpx;
+ height: 244rpx;
+ width: 710rpx;
+}
+.topic-goods .b .img {
+ margin-top: 12rpx;
+ margin-right: 12rpx;
+ float: left;
+ width: 220rpx;
+ height: 220rpx;
+}
+.topic-goods .b .right {
+ float: left;
+ height: 244rpx;
+ width: 476rpx;
+ display: flex;
+ flex-flow: row nowrap;
+}
+.topic-goods .b .text {
+ display: flex;
+ flex-wrap: nowrap;
+ flex-direction: column;
+ justify-content: center;
+ overflow: hidden;
+ height: 244rpx;
+ width: 476rpx;
+}
+.topic-goods .b .name {
+ float: left;
+ width: 330rpx;
+ display: block;
+ color: #333;
+ line-height: 50rpx;
+ font-size: 30rpx;
+}
+.topic-goods .b .desc {
+ width: 476rpx;
+ display: block;
+ color: #999;
+ line-height: 50rpx;
+ font-size: 25rpx;
+}
+.topic-goods .b .price {
+ width: 476rpx;
+ display: flex;
+ color: #b4282d;
+ line-height: 50rpx;
+ font-size: 33rpx;
+}
 
 .rec-box{
     width: 690rpx;