Initial Commit
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
// person-detail.js
|
||||
const storage = require('../../utils/storage')
|
||||
const dateUtils = require('../../utils/date')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
personId: null,
|
||||
person: {},
|
||||
anniversaries: []
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
if (!options.id) {
|
||||
wx.showToast({ title: '参数错误', icon: 'none' })
|
||||
wx.navigateBack()
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({ personId: options.id })
|
||||
this.loadPerson()
|
||||
this.loadAnniversaries()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// 重新加载数据
|
||||
this.loadPerson()
|
||||
this.loadAnniversaries()
|
||||
},
|
||||
|
||||
/**
|
||||
* 加载人员信息
|
||||
*/
|
||||
loadPerson() {
|
||||
const person = storage.getPersonById(this.data.personId)
|
||||
if (person) {
|
||||
this.setData({ person })
|
||||
wx.setNavigationBarTitle({ title: person.name })
|
||||
} else {
|
||||
wx.showToast({ title: '人员不存在', icon: 'none' })
|
||||
wx.navigateBack()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 加载纪念日
|
||||
*/
|
||||
loadAnniversaries() {
|
||||
const anniversaries = storage.getAnniversariesByPersonId(this.data.personId)
|
||||
|
||||
// 格式化纪念日数据
|
||||
const formatted = anniversaries.map(a => {
|
||||
const date = new Date(a.solarYear, a.solarMonth - 1, a.solarDay)
|
||||
const daysUntil = dateUtils.getDaysUntil(date)
|
||||
|
||||
return {
|
||||
...a,
|
||||
date,
|
||||
dateText: dateUtils.formatDate(date, 'YYYY年MM月DD日'),
|
||||
daysUntil,
|
||||
typeIcon: this.getTypeIcon(a.type),
|
||||
typeName: a.customTypeName || this.getTypeName(a.type),
|
||||
importanceText: this.getImportanceText(a.importance)
|
||||
}
|
||||
})
|
||||
|
||||
// 按日期排序
|
||||
formatted.sort((a, b) => a.daysUntil - b.daysUntil)
|
||||
|
||||
this.setData({ anniversaries: formatted })
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取类型图标
|
||||
*/
|
||||
getTypeIcon(type) {
|
||||
const icons = {
|
||||
birthday: '🎂',
|
||||
lunar_birthday: '🌙',
|
||||
wedding: '💍',
|
||||
engagement: '💕',
|
||||
other: '📅'
|
||||
}
|
||||
return icons[type] || '📅'
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取类型名称
|
||||
*/
|
||||
getTypeName(type) {
|
||||
const names = {
|
||||
birthday: '公历生日',
|
||||
lunar_birthday: '农历生日',
|
||||
wedding: '结婚纪念日',
|
||||
engagement: '订婚纪念日',
|
||||
other: '其他纪念日'
|
||||
}
|
||||
return names[type] || '其他'
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取重要程度文本
|
||||
*/
|
||||
getImportanceText(importance) {
|
||||
const texts = {
|
||||
high: '非常重要',
|
||||
medium: '重要',
|
||||
low: '一般'
|
||||
}
|
||||
return texts[importance] || '一般'
|
||||
},
|
||||
|
||||
/**
|
||||
* 编辑人员
|
||||
*/
|
||||
onEditPerson() {
|
||||
wx.navigateTo({
|
||||
url: `/pages/add-person/add-person?id=${this.data.personId}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除人员
|
||||
*/
|
||||
onDeletePerson() {
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: `确定要删除"${this.data.person.name}"吗?相关纪念日也将被删除。`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 先删除相关纪念日
|
||||
const anniversaries = storage.getAnniversariesByPersonId(this.data.personId)
|
||||
anniversaries.forEach(a => storage.deleteAnniversary(a.id))
|
||||
|
||||
// 再删除人员
|
||||
const success = storage.deletePerson(this.data.personId)
|
||||
if (success) {
|
||||
wx.showToast({ title: '删除成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
wx.navigateBack()
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 添加纪念日
|
||||
*/
|
||||
onAddAnniversary() {
|
||||
wx.navigateTo({
|
||||
url: `/pages/add-anniversary/add-anniversary?personId=${this.data.personId}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 编辑纪念日
|
||||
*/
|
||||
onEditAnniversary(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
wx.navigateTo({
|
||||
url: `/pages/add-anniversary/add-anniversary?personId=${this.data.personId}&id=${id}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除纪念日
|
||||
*/
|
||||
onDeleteAnniversary(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
const anniversary = this.data.anniversaries.find(a => a.id === id)
|
||||
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除这条纪念日吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const success = storage.deleteAnniversary(id)
|
||||
if (success) {
|
||||
wx.showToast({ title: '删除成功', icon: 'success' })
|
||||
this.loadAnniversaries()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user