Browse Source

小程序:商品收藏、供应商收藏接口对接

panyong 2 years ago
parent
commit
dc744f788b

+ 34 - 4
htmldev/wxMini/pages/businessDetail/businessDetail.js

@@ -1,5 +1,6 @@
 const pages = require('../../mixin/pages')
 const { getShopDetail } = require('../../api/common')
+const { postShopCollect } = require('./api/index')
 
 Page({
 
@@ -12,7 +13,6 @@ Page({
     searchForm: {
       shop_id: ''
     },
-    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
     nav: [
       {
         name: '详情',
@@ -24,7 +24,8 @@ Page({
       }
     ],
     active: '1',
-    objShopDetail: {shop_address: {}}
+    objShopDetail: { shop_address: {} },
+    booLock: false
   },
   ...pages.methods,
   /**
@@ -97,11 +98,13 @@ Page({
     try {
       const { status, data, msg } = await getShopDetail(this.data.searchForm.shop_id)
       if (status) {
+        const { shop_address, collect_status } = data
         this.setData({
           objShopDetail: {
             ...data,
-            shop_address: JSON.parse(data.shop_address)
-          }
+            shop_address: JSON.parse(shop_address)
+          },
+          'searchForm.type': collect_status === 0 ? 1 : 2 // 是否收藏(0否1是)
         })
       } else {
         wx.showToast({
@@ -111,6 +114,33 @@ Page({
       }
     } catch (err) {}
   },
+  async shopCollect() {
+    const { type, shop_id } = this.data.searchForm
+
+    if (this.data.booLock) {
+      return
+    }
+    this.setData({
+      booLock: true
+    })
+    try {
+      const { status, msg } = await postShopCollect(shop_id, type)
+      if (status) {
+        this.setData({
+          'searchForm.type': type === 1 ? 2 : 1
+        })
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
+
+    this.setData({
+      booLock: false
+    })
+  },
   handleNav(e) {
     const { value } = e.detail
 

+ 9 - 2
htmldev/wxMini/pages/businessDetail/businessDetail.wxml

@@ -18,11 +18,18 @@
   </swiper>
 </view>
   <!--TODO 收藏-->
-<view class="business-name">
+<view
+  class="business-name"
+  bind:tap="shopCollect">
   <text
     wx:for="{{objShopDetail.user_name}}"
     wx:key="index">{{item}}</text>
-  <image src="../../image/common/bookmark_1.png"></image>
+  <image
+    src="../../image/common/bookmark_0.png"
+    wx:if="{{searchForm.type === 1}}"></image>
+  <image
+    src="../../image/common/bookmark_1.png"
+    wx:elif="{{searchForm.type === 2}}"></image>
 </view>
 <customer-tab
   nav="{{nav}}"

+ 0 - 1
htmldev/wxMini/pages/goodsDetail/goodsDetail.wxml

@@ -71,7 +71,6 @@
     </scroll-view>
   </block>
 </view>
-  <!-- todo 供应商-->
 <view
   hidden="{{active === '1'}}">
   <business-detail-large