Skip to content

Commit

Permalink
修复 删除操作的一些bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Chadwuo committed Jan 21, 2022
1 parent ea37c12 commit ee0bbb6
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 57 deletions.
55 changes: 21 additions & 34 deletions miniprogram/pages/bookEdit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '删除成功',
// })
// }
// })
// })
}
}
})
Expand Down
32 changes: 23 additions & 9 deletions miniprogram/pages/books/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '删除成功',
})
}
})
})
}
}
Expand Down Expand Up @@ -138,7 +152,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

},

/**
Expand Down
32 changes: 24 additions & 8 deletions miniprogram/pages/friendEdit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '删除成功',
})
}
})
})
}
}
Expand Down
34 changes: 29 additions & 5 deletions miniprogram/pages/friends/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '删除成功',
})
}
})
})
}
}
})
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion miniprogram/pages/friends/friends.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<van-cell-group inset>
<van-swipe-cell right-width="{{ 65 }}" wx:for="{{item.subItems}}" wx:for-item="data" wx:key="dataindex">
<van-cell title="{{data.name}}" size="large" bind:click="onFriendClick" data-friend='{{data}}'/>
<van-button slot="right" type="danger" bind:click="onDelete">删除</van-button>
<van-button slot="right" type="danger" bind:click="onDelete" data-friendid="{{data._id}}">删除</van-button>
</van-swipe-cell>
</van-cell-group>
</view>
Expand Down

0 comments on commit ee0bbb6

Please sign in to comment.