Browse Source

始宁农业小程序:代码优化

panyong 2 years ago
parent
commit
9c5a8c2de4

+ 1 - 1
htmldev/shiningWxMini/pages/news/api/index.js

@@ -9,7 +9,7 @@ export const postFollowUser = (id) => request({
   url: '/api/user/follow/user',
   method: 'POST',
   data: {
-    user_id: id // todo 这里应该是商户ID,不是店铺ID
+    shop_id: id // todo 这里应该是商户ID,不是店铺ID
   },
   showLoading: true
 })

+ 2 - 2
htmldev/shiningWxMini/pages/news/news.js

@@ -109,14 +109,14 @@ Page({
       booLock: true
     })
     try {
-      const { status, msg } = await postFollowUser(item.user_id)
+      const { status, msg } = await postFollowUser(item.shop_id)
       if (status) {
         wx.showToast({
           title: '已关注',
           icon: 'none'
         })
         this.setData({
-          [listData[index].follow_status]: 1
+          ['listData[' + index + '].follow_status']: 1
         })
       } else {
         wx.showToast({

+ 6 - 1
htmldev/shiningWxMini/pages/news/news.scss

@@ -175,7 +175,12 @@
   }
 
   .favorite {
-    margin-left: 30rpx;
+    display: flex;
+    align-items: center;
+  }
+
+  .good-count {
+    margin-left: 10rpx;
   }
 }
 

+ 3 - 7
htmldev/shiningWxMini/pages/news/news.wxml

@@ -35,11 +35,10 @@
         </view>
         <button
           class="follow"
-          disabled="{{booLock}}"
-          wx:if="{{item.follow_status === 0}}"
+          disabled="{{booLock || item.follow_status === 1}}"
           data-item="{{item}}"
           data-index="{{index}}"
-          bind:tap="followUser">关注
+          bind:tap="followUser">{{item.follow_status === 1 ? '已' : ''}}关注
         </button>
       </view>
       <view class="news">
@@ -60,13 +59,10 @@
           <image src="../../image/news/Chat.png"></image>
         </view>
         <view class="collection-favorite">
-          <view>
-            <image src="../../image/news/collection_0.png" wx:if="{{true}}"></image>
-            <image src="../../image/news/collection_1.png" wx:if="{{false}}"></image>
-          </view>
           <view class="favorite">
             <image src="../../image/news/like_0.png" wx:if="{{true}}"></image>
             <image src="../../image/news/like_1.png" wx:if="{{false}}"></image>
+            <text class="good-count">{{item.good_count}}</text>
           </view>
         </view>
       </view>