From ee0bbb60c88395e1971381df99583c4985378328 Mon Sep 17 00:00:00 2001 From: micahh28 <1067051515@qq.com> Date: Fri, 21 Jan 2022 08:35:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E4=B8=80=E4=BA=9Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/pages/bookEdit/index.js | 55 ++++++++++---------------- miniprogram/pages/books/books.js | 32 ++++++++++----- miniprogram/pages/friendEdit/index.js | 32 +++++++++++---- miniprogram/pages/friends/friends.js | 34 +++++++++++++--- miniprogram/pages/friends/friends.wxml | 2 +- 5 files changed, 98 insertions(+), 57 deletions(-) diff --git a/miniprogram/pages/bookEdit/index.js b/miniprogram/pages/bookEdit/index.js index 958fdf2f..0e053752 100644 --- a/miniprogram/pages/bookEdit/index.js +++ b/miniprogram/pages/bookEdit/index.js @@ -67,44 +67,31 @@ Page({ var that = this wx.showModal({ title: '删除礼簿?', - // content: '该礼簿所有来往记录都将被删除,确定删除?', - content: '该礼簿所有来往记录不受影响,确定删除?', + content: '该礼簿所有来往记录都将被删除,确定删除?', success(res) { if (res.confirm) { - // 删除礼簿 - db.collection('book').doc(that.data.id).remove({ - success: function (res) { - wx.navigateBack() - wx.showToast({ - title: '删除成功', - }) + // 删除礼簿下所有记录 + wx.cloud.callFunction({ + name: 'lijiFunctions', + data: { + type: 'deleteAllData', + table: 'gift', + where: { + userId: app.globalData.user._id, + bookId: that.data.id, + } } + }).then(res => { + // 删除礼簿 + db.collection('book').doc(that.data.id).remove({ + success: function (res) { + wx.navigateBack() + wx.showToast({ + title: '删除成功', + }) + } + }) }) - // // 删除礼簿下所有记录 - // wx.cloud.callFunction({ - // name: 'lijiFunctions', - // data: { - // type: 'deleteAllData', - // table: 'gift', - // where: { - // userId: app.globalData.user._id, - // bookId: that.data.id, - // } - // } - // }).then(res => { - // // todo删除记录成功 条件判断 - // console.log(res) - - // // 删除礼簿 - // db.collection('book').doc(that.data.id).remove({ - // success: function (res) { - // wx.navigateBack() - // wx.showToast({ - // title: '删除成功', - // }) - // } - // }) - // }) } } }) diff --git a/miniprogram/pages/books/books.js b/miniprogram/pages/books/books.js index 1f1e9a56..e78903ad 100644 --- a/miniprogram/pages/books/books.js +++ b/miniprogram/pages/books/books.js @@ -58,15 +58,29 @@ Page({ content: '该礼簿所有来往记录都将被删除,确定删除?', success(res) { if (res.confirm) { - db.collection('book').doc(that.data.actionId).remove({ - success: function (res) { - that.setData({ - giftBooks: that.data.giftBooks.filter(item => item._id != that.data.actionId) - }) - wx.showToast({ - title: '删除成功', - }) + // 删除礼簿下所有记录 + wx.cloud.callFunction({ + name: 'lijiFunctions', + data: { + type: 'deleteAllData', + table: 'gift', + where: { + userId: app.globalData.user._id, + bookId: that.data.actionId, + } } + }).then(res => { + // 删除礼簿 + db.collection('book').doc(that.data.actionId).remove({ + success: function (res) { + that.setData({ + giftBooks: that.data.giftBooks.filter(item => item._id != that.data.actionId) + }) + wx.showToast({ + title: '删除成功', + }) + } + }) }) } } @@ -138,7 +152,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - + }, /** diff --git a/miniprogram/pages/friendEdit/index.js b/miniprogram/pages/friendEdit/index.js index 5d87a2b2..4716c1ca 100644 --- a/miniprogram/pages/friendEdit/index.js +++ b/miniprogram/pages/friendEdit/index.js @@ -48,22 +48,38 @@ Page({ } }, delFriend() { + app.globalData.refreshRequired.home = true + app.globalData.refreshRequired.book = true app.globalData.refreshRequired.friend = true + app.globalData.refreshRequired.profile = true let that = this wx.showModal({ title: '删除联系人?', content: '该联系人所有来往记录都将被删除,确定删除?', success(res) { if (res.confirm) { - db.collection('friend').doc(that.data.id).remove({ - success: function (res) { - wx.navigateBack({ - delta: 2 - }) - wx.showToast({ - title: '删除成功', - }) + // 删除亲友下所有记录 + wx.cloud.callFunction({ + name: 'lijiFunctions', + data: { + type: 'deleteAllData', + table: 'gift', + where: { + userId: app.globalData.user._id, + friendId: that.data.id, + } } + }).then(res => { + db.collection('friend').doc(that.data.id).remove({ + success: function (res) { + wx.navigateBack({ + delta: 2 + }) + wx.showToast({ + title: '删除成功', + }) + } + }) }) } } diff --git a/miniprogram/pages/friends/friends.js b/miniprogram/pages/friends/friends.js index 47e8b760..a4b5c19e 100644 --- a/miniprogram/pages/friends/friends.js +++ b/miniprogram/pages/friends/friends.js @@ -25,16 +25,41 @@ Page({ url: `/pages/friendEdit/index`, }); }, - onDelete() { + onDelete(e) { + app.globalData.refreshRequired.home = true + app.globalData.refreshRequired.book = true + app.globalData.refreshRequired.friend = true + app.globalData.refreshRequired.profile = true + + let that = this + const friendId = e.currentTarget.dataset.friendid wx.showModal({ title: '提示', content: '该联系人得所有人情往来记录都将被删除,确定删除?', confirmColor: '#F76664', success(res) { if (res.confirm) { - console.log('用户点击确定') - } else if (res.cancel) { - console.log('用户点击取消') + // 删除亲友下所有记录 + wx.cloud.callFunction({ + name: 'lijiFunctions', + data: { + type: 'deleteAllData', + table: 'gift', + where: { + userId: app.globalData.user._id, + friendId: friendId, + } + } + }).then(res => { + db.collection('friend').doc(friendId).remove({ + success: function (res) { + that.loadData() + wx.showToast({ + title: '删除成功', + }) + } + }) + }) } } }) @@ -58,7 +83,6 @@ Page({ table: 'friend', } }).then(res => { - console.log(res) for (const item of res.result.data) { const firstLetter = item.firstLetter if (!isNaN(firstLetter)) { diff --git a/miniprogram/pages/friends/friends.wxml b/miniprogram/pages/friends/friends.wxml index 6cf066f1..938fffa4 100644 --- a/miniprogram/pages/friends/friends.wxml +++ b/miniprogram/pages/friends/friends.wxml @@ -13,7 +13,7 @@ - 删除 + 删除