Commit ede6f3ad authored by spc's avatar spc

del

parent 0bf6541a
...@@ -69,6 +69,13 @@ export const feedingRecordsByDate = (data) => api.get('/c/feeding/records', { ...@@ -69,6 +69,13 @@ export const feedingRecordsByDate = (data) => api.get('/c/feeding/records', {
date:data.date date:data.date
}); });
//删除喂养记录
export const feedingRecordsDelete = (data) => api.post('/c/feeding/records/del', {
recordId:data.recordId,
});
// 获取喂养记录的日历状态 // 获取喂养记录的日历状态
export const feedingRecordsCalendarStatus = (data) => api.get('/c/feeding/records/calendar-status', { export const feedingRecordsCalendarStatus = (data) => api.get('/c/feeding/records/calendar-status', {
babyId:data.babyId, babyId:data.babyId,
......
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
<view class="record-header"> <view class="record-header">
<image :src="getRecordIcon(record.type)" :class="getRecordIconClass(record.type)" /> <image :src="getRecordIcon(record.type)" :class="getRecordIconClass(record.type)" />
<text class="record-type">{{ record.type }}</text> <text class="record-type">{{ record.type }}</text>
<text class="delete-btn" @click="deleteRecord(record)">删除</text>
<text class="edit-btn" @click="editRecord(index)">修改</text> <text class="edit-btn" @click="editRecord(index)">修改</text>
</view> </view>
<view class="record-details"> <view class="record-details">
...@@ -141,6 +142,18 @@ ...@@ -141,6 +142,18 @@
</scroll-view> </scroll-view>
</view> </view>
<!-- 删除二次确认弹窗 -->
<view class="popup-mask" v-if="showDelPopup" @click="closeDelPopup" @touchmove.prevent>
<view class="popup-content del-popup-content" @click.stop @touchmove.stop>
<image :src="feedingAnalysisRes.delRecordBg" class="del-record-bg" />
<view class="del-buttons-container">
<image :src="feedingAnalysisRes.delRecordCancelBtn" class="del-record-cancel-btn" @click="closeDelPopup" />
<image :src="feedingAnalysisRes.delRecordConfirmBtn" class="del-record-confirm-btn" @click="confirmDelRecord" />
</view>
</view>
</view>
<!-- 编辑记录弹窗 --> <!-- 编辑记录弹窗 -->
<view class="popup-mask" v-if="showEditPopup" @click="closeEditPopup" @touchmove.prevent> <view class="popup-mask" v-if="showEditPopup" @click="closeEditPopup" @touchmove.prevent>
<view class="popup-content" @click.stop @touchmove.stop> <view class="popup-content" @click.stop @touchmove.stop>
...@@ -174,7 +187,7 @@ ...@@ -174,7 +187,7 @@
<script setup> <script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick, getCurrentInstance } from 'vue' import { ref, computed, onMounted, onUnmounted, watch, nextTick, getCurrentInstance } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app' import { onLoad, onShow } from '@dcloudio/uni-app'
import { feedingRecordsStatisticsPeriod, feedingRecordsByDate, feedingRecords as feedingRecordsAPI } from '@/api/feeding.js' import { feedingRecordsStatisticsPeriod, feedingRecordsByDate, feedingRecords as feedingRecordsAPI, feedingRecordsDelete } from '@/api/feeding.js'
import { useUserStore } from '@/stores/user.js' import { useUserStore } from '@/stores/user.js'
// API 集成说明: // API 集成说明:
...@@ -226,6 +239,12 @@ const feedingAnalysisRes = { ...@@ -226,6 +239,12 @@ const feedingAnalysisRes = {
icon_change_btn_cancel: $baseUrl + `feedingRecord/${version}/icon_change_btn_cancel.png`, icon_change_btn_cancel: $baseUrl + `feedingRecord/${version}/icon_change_btn_cancel.png`,
delRecordBg: $baseUrl + `feedingRecord/${version}/delRecordBg.png`,
delRecordCancelBtn: $baseUrl + `feedingRecord/${version}/delRecordCancelBtn.png`,
delRecordConfirmBtn: $baseUrl + `feedingRecord/${version}/delRecordConfirmBtn.png`,
} }
// API 数据存储 // API 数据存储
...@@ -261,6 +280,10 @@ const editForm = ref({ ...@@ -261,6 +280,10 @@ const editForm = ref({
amount: '' amount: ''
}) })
// 删除记录相关状态
const showDelPopup = ref(false)
const deletingRecord = ref(null)
// 喂养类型选项 // 喂养类型选项
const feedingTypes = ['母乳亲喂', '母乳瓶喂', '奶粉喂养', '辅食'] const feedingTypes = ['母乳亲喂', '母乳瓶喂', '奶粉喂养', '辅食']
...@@ -585,6 +608,9 @@ async function loadRecordsByDate(date) { ...@@ -585,6 +608,9 @@ async function loadRecordsByDate(date) {
} }
} }
// 统一错误处理函数 // 统一错误处理函数
function handleApiError(error, context) { function handleApiError(error, context) {
console.error(`${context} 失败:`, error) console.error(`${context} 失败:`, error)
...@@ -783,6 +809,56 @@ function editRecord(index) { ...@@ -783,6 +809,56 @@ function editRecord(index) {
showEditPopup.value = true showEditPopup.value = true
} }
// 删除记录
async function deleteRecord(record) {
console.log('删除记录:', record)
deletingRecord.value = record
showDelPopup.value = true
}
// 关闭删除弹窗
function closeDelPopup() {
showDelPopup.value = false
deletingRecord.value = null
}
// 确认删除记录
async function confirmDelRecord() {
if (!deletingRecord.value) {
uni.showToast({ title: '删除记录不存在', icon: 'none' })
return
}
try {
uni.showLoading({ title: '删除中...' })
const response = await feedingRecordsDelete({
recordId: deletingRecord.value.recordId
})
if (response && response.code === '000000') {
uni.showToast({ title: '删除成功', icon: 'success' })
closeDelPopup()
// 清空缓存,确保获取最新数据
clearCache()
// 重新加载当前日期的记录
if (selectedDate.value) {
await loadRecordsByDate(selectedDate.value)
}
// 更新图表数据
updateChartData(true) // 删除记录后保持当前选择
} else {
throw new Error(response?.message || '删除失败')
}
} catch (error) {
console.error('删除记录失败:', error)
uni.showToast({ title: error.message || '删除失败', icon: 'none' })
} finally {
uni.hideLoading()
}
}
// 返回上一页 // 返回上一页
function goBack() { function goBack() {
uni.navigateBack() uni.navigateBack()
...@@ -1155,7 +1231,7 @@ onLoad(async () => { ...@@ -1155,7 +1231,7 @@ onLoad(async () => {
// 加载宝宝信息 // 加载宝宝信息
await userStore.loadBabyInfo() await userStore.loadBabyInfo()
console.log('宝宝信息加载完成:', userStore.babyInfo) console.log('宝宝信息加载完成:', userStore.babyInfo)
updateChartData(false) // 初始化时使用默认选择 updateChartData(false) // 初始化时使用默认选择
// 初始化API数据 // 初始化API数据
initializeApiData() initializeApiData()
...@@ -1202,7 +1278,7 @@ onMounted(async () => { ...@@ -1202,7 +1278,7 @@ onMounted(async () => {
// 加载宝宝信息 // 加载宝宝信息
await userStore.loadBabyInfo() await userStore.loadBabyInfo()
console.log('宝宝信息加载完成:', userStore.babyInfo) console.log('宝宝信息加载完成:', userStore.babyInfo)
// 先加载统计数据,然后更新图表(updateChartData 中已经包含了加载记录的逻辑) // 先加载统计数据,然后更新图表(updateChartData 中已经包含了加载记录的逻辑)
await initializeChartData() await initializeChartData()
}) })
...@@ -1212,7 +1288,7 @@ onShow(async () => { ...@@ -1212,7 +1288,7 @@ onShow(async () => {
// 加载宝宝信息 // 加载宝宝信息
await userStore.loadBabyInfo() await userStore.loadBabyInfo()
console.log('宝宝信息加载完成:', userStore.babyInfo) console.log('宝宝信息加载完成:', userStore.babyInfo)
// 如果已经有选中日期,刷新当前日期的记录 // 如果已经有选中日期,刷新当前日期的记录
if (selectedDate.value) { if (selectedDate.value) {
loadRecordsByDate(selectedDate.value) loadRecordsByDate(selectedDate.value)
...@@ -1691,6 +1767,17 @@ function testApiIntegration() { ...@@ -1691,6 +1767,17 @@ function testApiIntegration() {
background: #ffffff; background: #ffffff;
opacity: 0.8; opacity: 0.8;
} }
.delete-btn {
font-size: 24rpx;
color: #1d1e25;
padding: 8rpx 16rpx;
border: 1rpx solid #ffffff;
border-radius: 20rpx;
background: #ffffff;
opacity: 0.8;
margin-right: 16rpx;
}
} }
.record-details { .record-details {
...@@ -1907,5 +1994,48 @@ function testApiIntegration() { ...@@ -1907,5 +1994,48 @@ function testApiIntegration() {
} }
} }
} }
}
// 删除二次确认弹窗样式
.del-popup-content {
position: relative;
background: transparent;
width: 100%;
height: 100%;
padding: 0;
border-radius: 0;
max-height: none;
overflow: visible;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.del-record-bg {
width: 618rpx;
height: 493rpx;
display: block;
margin: 0 auto;
}
.del-buttons-container {
position: absolute;
bottom: 80rpx;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 40rpx;
align-items: center;
.del-record-cancel-btn,
.del-record-confirm-btn {
width: 279rpx;
height: 101rpx;
margin-top: -1200rpx;
display: block;
}
}
} }
</style> </style>
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
<view class="record-header"> <view class="record-header">
<image :src="getRecordIcon(record.type)" :class="getRecordIconClass(record.type)" /> <image :src="getRecordIcon(record.type)" :class="getRecordIconClass(record.type)" />
<text class="record-type">{{ record.type }}</text> <text class="record-type">{{ record.type }}</text>
<text class="delete-btn" @click="deleteRecord(record.recordId)">删除</text>
<text class="edit-btn" @click="editRecord(index)">修改</text> <text class="edit-btn" @click="editRecord(index)">修改</text>
</view> </view>
<view class="record-details"> <view class="record-details">
...@@ -180,16 +181,28 @@ ...@@ -180,16 +181,28 @@
</view> </view>
</view> </view>
<!-- 删除二次确认弹窗 -->
<view class="popup-mask" v-if="showDelPopup" @click="closeDelPopup" @touchmove.prevent>
<view class="popup-content del-popup-content" @click.stop @touchmove.stop>
<image :src="feedingRecordRes.delRecordBg" class="del-record-bg" />
<view class="del-buttons-container">
<image :src="feedingRecordRes.delRecordCancelBtn" class="del-record-cancel-btn" @click="closeDelPopup" />
<image :src="feedingRecordRes.delRecordConfirmBtn" class="del-record-confirm-btn" @click="confirmDelRecord" />
</view>
</view>
</view>
<!-- 切换宝宝弹窗 --> <!-- 切换宝宝弹窗 -->
<BabySwitchPopup v-model:visible="showBabySwitchPopup" :selected-index="currentBabyIndex" <BabySwitchPopup v-model:visible="showBabySwitchPopup" :selected-index="currentBabyIndex" @change="onBabyChange"
@change="onBabyChange" v-if="babyList.length > 1" /> v-if="babyList.length > 1" />
</template> </template>
<script setup> <script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick, getCurrentInstance } from 'vue' import { ref, computed, onMounted, onUnmounted, watch, nextTick, getCurrentInstance } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app' import { onLoad, onShow } from '@dcloudio/uni-app'
import BabySwitchPopup from '@/components/BabySwitchPopup.vue' import BabySwitchPopup from '@/components/BabySwitchPopup.vue'
import { feedingRecordsByDate, feedingRecordsCalendarStatus, feedingRecords as feedingRecordsAPI } from '@/api/feeding.js' import { feedingRecordsByDate, feedingRecordsCalendarStatus, feedingRecords as feedingRecordsAPI, feedingRecordsDelete } from '@/api/feeding.js'
import { useUserStore } from '@/stores/user.js' import { useUserStore } from '@/stores/user.js'
// API 集成说明: // API 集成说明:
...@@ -229,6 +242,10 @@ const feedingRecordRes = { ...@@ -229,6 +242,10 @@ const feedingRecordRes = {
icon_change_btn_cancel: $baseUrl + `feedingRecord/${version}/icon_change_btn_cancel.png`, icon_change_btn_cancel: $baseUrl + `feedingRecord/${version}/icon_change_btn_cancel.png`,
avatar: $baseUrl + `feedingIndex/${version}/avatar.png`, avatar: $baseUrl + `feedingIndex/${version}/avatar.png`,
delRecordBg: $baseUrl + `feedingRecord/${version}/delRecordBg.png`,
delRecordCancelBtn: $baseUrl + `feedingRecord/${version}/delRecordCancelBtn.png`,
delRecordConfirmBtn: $baseUrl + `feedingRecord/${version}/delRecordConfirmBtn.png`,
} }
...@@ -272,6 +289,10 @@ const editForm = ref({ ...@@ -272,6 +289,10 @@ const editForm = ref({
const showEditPopup = ref(false) const showEditPopup = ref(false)
const editingRecord = ref(null) const editingRecord = ref(null)
// 删除状态
const showDelPopup = ref(false)
const deletingRecordId = ref(null)
// 喂养类型选项 // 喂养类型选项
const feedingTypes = ['母乳亲喂', '母乳瓶喂', '奶粉喂养', '辅食'] const feedingTypes = ['母乳亲喂', '母乳瓶喂', '奶粉喂养', '辅食']
...@@ -289,9 +310,9 @@ const calendarCache = ref(new Map()) // 日历状态缓存,避免重复请求 ...@@ -289,9 +310,9 @@ const calendarCache = ref(new Map()) // 日历状态缓存,避免重复请求
// 计算属性 - 获取宝宝信息(只显示已出生的宝宝) // 计算属性 - 获取宝宝信息(只显示已出生的宝宝)
const babyList = computed(() => { const babyList = computed(() => {
const allBabies = userStore.babyInfo?.allBabyBaseInfo || [] const allBabies = userStore.babyInfo?.allBabyBaseInfo || []
// 只返回已出生的宝宝(babyStage === 2) // 只返回已出生的宝宝(babyStage === 2)
return allBabies.filter(baby => baby.babyStage === 2) return allBabies.filter(baby => baby.babyStage === 2)
}) })
const currentBabyIndex = computed(() => { const currentBabyIndex = computed(() => {
if (!babyList.value || !currentBaby.value) return 0 if (!babyList.value || !currentBaby.value) return 0
...@@ -607,6 +628,13 @@ function getRecordBgColor(type) { ...@@ -607,6 +628,13 @@ function getRecordBgColor(type) {
return colors[type] || '#FEF2F2' return colors[type] || '#FEF2F2'
} }
async function deleteRecord(recordId) {
console.log('删除记录:', recordId)
// 设置要删除的记录ID并显示确认弹窗
deletingRecordId.value = recordId
showDelPopup.value = true
}
function editRecord(index) { function editRecord(index) {
const record = todayRecords.value[index] const record = todayRecords.value[index]
if (!record) return if (!record) return
...@@ -677,6 +705,66 @@ function closeEditPopup() { ...@@ -677,6 +705,66 @@ function closeEditPopup() {
editForm.value = { time: '', type: '', content: '' } editForm.value = { time: '', type: '', content: '' }
} }
// 关闭删除确认弹窗
function closeDelPopup() {
showDelPopup.value = false
deletingRecordId.value = null
}
// 确认删除记录
async function confirmDelRecord() {
if (!deletingRecordId.value) {
uni.showToast({
title: '删除记录ID不存在',
icon: 'none'
})
return
}
try {
uni.showLoading({
title: '删除中...'
})
// 调用删除接口
const res = await feedingRecordsDelete({ recordId: deletingRecordId.value })
if (res && res.code === '000000') {
uni.showToast({
title: '删除成功',
icon: 'success'
})
// 关闭弹窗
closeDelPopup()
// 清空缓存,确保获取最新数据
clearCache()
// 重新加载当前日期的记录
if (currentSelectedDate.value) {
await loadRecordsByDate(currentSelectedDate.value)
}
// 重新加载当前月份的日历状态
if (currentMonthKey.value) {
const currentMonth = formatMonthString(currentDate.value)
await loadCalendarStatus(currentMonth)
}
} else {
throw new Error(res?.message || '删除失败')
}
} catch (error) {
console.error('删除记录失败:', error)
uni.showToast({
title: error.message || '删除失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
}
function onEditTimeChange(event) { function onEditTimeChange(event) {
editForm.value.time = event.detail.value editForm.value.time = event.detail.value
} }
...@@ -1919,6 +2007,17 @@ function testApiIntegration() { ...@@ -1919,6 +2007,17 @@ function testApiIntegration() {
background: #ffffff; background: #ffffff;
opacity: 0.8; opacity: 0.8;
} }
.delete-btn {
font-size: 24rpx;
color: #1d1e25;
padding: 8rpx 16rpx;
border: 1rpx solid #ffffff;
border-radius: 20rpx;
background: #ffffff;
opacity: 0.8;
margin-right: 16rpx;
}
} }
.record-details { .record-details {
...@@ -2154,4 +2253,45 @@ function testApiIntegration() { ...@@ -2154,4 +2253,45 @@ function testApiIntegration() {
::v-deep .uni-datetime-picker-btn-text { ::v-deep .uni-datetime-picker-btn-text {
color: #D4A574 !important; color: #D4A574 !important;
} }
// 删除二次确认弹窗样式
.del-popup-content {
position: relative;
background: transparent;
width: 100%;
height: 100%;
padding: 0;
border-radius: 0;
max-height: none;
overflow: visible;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.del-record-bg {
width: 618rpx;
height: 493rpx;
display: block;
margin: 0 auto;
}
.del-buttons-container {
position: absolute;
bottom: 80rpx;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 40rpx;
align-items: center;
.del-record-cancel-btn,
.del-record-confirm-btn {
width: 279rpx;
height: 101rpx;
margin-top: -1200rpx;
display: block;
}
}
}
</style> </style>
...@@ -63,9 +63,11 @@ export default { ...@@ -63,9 +63,11 @@ export default {
const cuk = store.cuk; const cuk = store.cuk;
const openId = store.openId; const openId = store.openId;
const unionId = store.unionId; const unionId = store.unionId;
const p = 'xmh';
// 将 options 的所有参数原样作为查询参数传给 H5,并补齐 cuk // 将 options 的所有参数原样作为查询参数传给 H5,并补齐 cuk
const params = { ...(options || {}) }; const params = { ...(options || {}) };
params.p = p;
if (cuk && !params.cuk) params.cuk = cuk; if (cuk && !params.cuk) params.cuk = cuk;
// 添加用户信息参数 // 添加用户信息参数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment