Commit ede6f3ad authored by spc's avatar spc

del

parent 0bf6541a
......@@ -69,6 +69,13 @@ export const feedingRecordsByDate = (data) => api.get('/c/feeding/records', {
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', {
babyId:data.babyId,
......
......@@ -87,6 +87,7 @@
<view class="record-header">
<image :src="getRecordIcon(record.type)" :class="getRecordIconClass(record.type)" />
<text class="record-type">{{ record.type }}</text>
<text class="delete-btn" @click="deleteRecord(record)">删除</text>
<text class="edit-btn" @click="editRecord(index)">修改</text>
</view>
<view class="record-details">
......@@ -141,6 +142,18 @@
</scroll-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-content" @click.stop @touchmove.stop>
......@@ -174,7 +187,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick, getCurrentInstance } from 'vue'
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'
// API 集成说明:
......@@ -226,6 +239,12 @@ const feedingAnalysisRes = {
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 数据存储
......@@ -261,6 +280,10 @@ const editForm = ref({
amount: ''
})
// 删除记录相关状态
const showDelPopup = ref(false)
const deletingRecord = ref(null)
// 喂养类型选项
const feedingTypes = ['母乳亲喂', '母乳瓶喂', '奶粉喂养', '辅食']
......@@ -585,6 +608,9 @@ async function loadRecordsByDate(date) {
}
}
// 统一错误处理函数
function handleApiError(error, context) {
console.error(`${context} 失败:`, error)
......@@ -783,6 +809,56 @@ function editRecord(index) {
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() {
uni.navigateBack()
......@@ -1691,6 +1767,17 @@ function testApiIntegration() {
background: #ffffff;
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 {
......@@ -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>
......@@ -91,6 +91,7 @@
<view class="record-header">
<image :src="getRecordIcon(record.type)" :class="getRecordIconClass(record.type)" />
<text class="record-type">{{ record.type }}</text>
<text class="delete-btn" @click="deleteRecord(record.recordId)">删除</text>
<text class="edit-btn" @click="editRecord(index)">修改</text>
</view>
<view class="record-details">
......@@ -180,16 +181,28 @@
</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"
@change="onBabyChange" v-if="babyList.length > 1" />
<BabySwitchPopup v-model:visible="showBabySwitchPopup" :selected-index="currentBabyIndex" @change="onBabyChange"
v-if="babyList.length > 1" />
</template>
<script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick, getCurrentInstance } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
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'
// API 集成说明:
......@@ -229,6 +242,10 @@ const feedingRecordRes = {
icon_change_btn_cancel: $baseUrl + `feedingRecord/${version}/icon_change_btn_cancel.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({
const showEditPopup = ref(false)
const editingRecord = ref(null)
// 删除状态
const showDelPopup = ref(false)
const deletingRecordId = ref(null)
// 喂养类型选项
const feedingTypes = ['母乳亲喂', '母乳瓶喂', '奶粉喂养', '辅食']
......@@ -607,6 +628,13 @@ function getRecordBgColor(type) {
return colors[type] || '#FEF2F2'
}
async function deleteRecord(recordId) {
console.log('删除记录:', recordId)
// 设置要删除的记录ID并显示确认弹窗
deletingRecordId.value = recordId
showDelPopup.value = true
}
function editRecord(index) {
const record = todayRecords.value[index]
if (!record) return
......@@ -677,6 +705,66 @@ function closeEditPopup() {
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) {
editForm.value.time = event.detail.value
}
......@@ -1919,6 +2007,17 @@ function testApiIntegration() {
background: #ffffff;
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 {
......@@ -2154,4 +2253,45 @@ function testApiIntegration() {
::v-deep .uni-datetime-picker-btn-text {
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>
......@@ -63,9 +63,11 @@ export default {
const cuk = store.cuk;
const openId = store.openId;
const unionId = store.unionId;
const p = 'xmh';
// 将 options 的所有参数原样作为查询参数传给 H5,并补齐 cuk
const params = { ...(options || {}) };
params.p = p;
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