zjxpcyc 6 年之前
父節點
當前提交
c67de01336
共有 3 個檔案被更改,包括 36 行新增10 行删除
  1. 4
    0
      config/api.js
  2. 30
    8
      pages/MyCollectEstateList/index.js
  3. 2
    2
      pages/MyCollectEstateList/index.wxml

+ 4
- 0
config/api.js 查看文件

@@ -29,6 +29,10 @@ const $api = {
29 29
     building: {
30 30
       method: 'GET',
31 31
       url: `${BaseAPIURl}wx/collection/:openid`
32
+    },
33
+    delBuilding: {
34
+      method: 'DELETE',
35
+      url: `${BaseAPIURl}wx/collection/:openid`
32 36
     }
33 37
   },
34 38
   dict: {

+ 30
- 8
pages/MyCollectEstateList/index.js 查看文件

@@ -29,14 +29,36 @@ create(store, {
29 29
   },
30 30
   data: {
31 31
     list: [],
32
-    DeleteIndex: null,
33
-    DeleteOff: true
34 32
   },
35
-  DeleteItem() { // 确认删除逻辑
36
-    if (this.data.DeleteOff) {
37
-      this.setData({
38
-        DeleteOff: false
39
-      })
40
-    }
33
+  DeleteItem(e) { // 确认删除逻辑
34
+    const buildingId = e.target.dataset.index
35
+    const userInfo = app.globalData.UserInfo
36
+    const _self = this
37
+
38
+    wx.showModal({
39
+      title: '确认',
40
+      content: '确认要删除当前记录?',
41
+      success(res) {
42
+        if (res.confirm) {
43
+          
44
+          fetch({
45
+            ...getApi('user.delBuilding', { openid: userInfo.openid }),
46
+            query: { buildingId },
47
+          }).then(() => {
48
+            const list = _self.data.list.filter(x => x.buildingId !== buildingId)
49
+
50
+            _self.setData({ list })
51
+          }).catch((err) => {
52
+            wx.showToast({
53
+              title: '删除失败',
54
+              icon: 'error',
55
+            })
56
+          })
57
+
58
+        } else if (res.cancel) {
59
+          console.log('用户点击取消')
60
+        }
61
+      }
62
+    })
41 63
   }
42 64
 })

+ 2
- 2
pages/MyCollectEstateList/index.wxml 查看文件

@@ -5,14 +5,14 @@
5 5
 
6 6
       <!-- 左侧图片 -->
7 7
       <view class="img">
8
-        <image mode="aspectFill" src="{{item.buildingImg}}" class="centerLabel cover" bindtap="DeleteItem"></image>
8
+        <image mode="aspectFill" src="{{item.buildingImg}}" class="centerLabel cover"></image>
9 9
       </view>
10 10
 
11 11
       <!-- 右侧内容 -->
12 12
       <view class="flex-item">
13 13
         <view>
14 14
           <view class="delete">
15
-            <image mode="widthFix" src="/assets/images/icon28.png"></image>
15
+            <image mode="widthFix" src="/assets/images/icon28.png" bindtap="DeleteItem" data-index="{{item.buildingId}}"></image>
16 16
           </view>
17 17
           <text>{{item.name}}</text>
18 18
           <text>{{item.address}}</text>