42 lines
995 B
JavaScript
42 lines
995 B
JavaScript
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
item: null
|
|
},
|
|
|
|
onLoad: function(options) {
|
|
const id = options.id
|
|
const item = app.globalData.items.find(item => item.id === id)
|
|
if (item) {
|
|
this.setData({ item })
|
|
}
|
|
},
|
|
|
|
deleteItem: function() {
|
|
wx.showModal({
|
|
title: '确认删除',
|
|
content: '确定要删除这个物品吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
const index = app.globalData.items.findIndex(item => item.id === this.data.item.id)
|
|
if (index !== -1) {
|
|
app.globalData.items.splice(index, 1)
|
|
wx.setStorageSync('items', app.globalData.items)
|
|
|
|
wx.showToast({
|
|
title: '删除成功',
|
|
icon: 'success',
|
|
duration: 2000,
|
|
success: () => {
|
|
setTimeout(() => {
|
|
wx.navigateBack()
|
|
}, 2000)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|